iceoryx_doc  1.0.1
roudi_app.hpp
1 // Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_POSH_ROUDI_ROUDI_APP_HPP
17 #define IOX_POSH_ROUDI_ROUDI_APP_HPP
18 
19 #include "iceoryx_posh/iceoryx_posh_config.hpp"
20 #include "iceoryx_posh/mepoo/mepoo_config.hpp"
21 #include "iceoryx_posh/roudi/cmd_line_args.hpp"
22 #include "iceoryx_utils/log/logcommon.hpp"
23 #include "iceoryx_utils/posix_wrapper/semaphore.hpp"
24 
25 #include <cstdint>
26 #include <cstdio>
27 
28 namespace iox
29 {
30 namespace roudi
31 {
33 class RouDiApp
34 {
35  public:
37  static void roudiSigHandler(int32_t signal) noexcept;
38 
42  RouDiApp(const config::CmdLineArgs_t& cmdLineArgs, const RouDiConfig_t& config) noexcept;
43 
44  virtual ~RouDiApp() noexcept {};
45 
48  virtual uint8_t run() noexcept = 0;
49 
50  protected:
52  void registerSigHandler() noexcept;
53 
55  bool waitForSignal() const noexcept;
56 
57  iox::log::LogLevel m_logLevel{iox::log::LogLevel::kWarn};
58  roudi::MonitoringMode m_monitoringMode{roudi::MonitoringMode::ON};
59  bool m_run{true};
60  RouDiConfig_t m_config;
61 
62  posix::Semaphore m_semaphore =
63  std::move(posix::Semaphore::create(posix::CreateUnnamedSingleProcessSemaphore, 0u)
64  .or_else([](posix::SemaphoreError&) {
65  errorHandler(Error::kROUDI_APP__FAILED_TO_CREATE_SEMAPHORE, nullptr, ErrorLevel::FATAL);
66  })
67  .value());
68  version::CompatibilityCheckLevel m_compatibilityCheckLevel{version::CompatibilityCheckLevel::PATCH};
69  units::Duration m_processKillDelay{roudi::PROCESS_DEFAULT_KILL_DELAY};
70 
71  private:
72  bool checkAndOptimizeConfig(const RouDiConfig_t& config) noexcept;
73 };
74 
75 } // namespace roudi
76 } // namespace iox
77 
78 #endif // IOX_POSH_ROUDI_ROUDI_APP_HPP
base class for RouDi daemons
Definition: roudi_app.hpp:34
void registerSigHandler() noexcept
Tells the OS which signals shall be hooked.
RouDiApp(const config::CmdLineArgs_t &cmdLineArgs, const RouDiConfig_t &config) noexcept
C'tor with command line parser, which has already parsed the command line parameters.
virtual uint8_t run() noexcept=0
interface to start the execution of the RouDi daemon
bool waitForSignal() const noexcept
waits for the next signal to RouDi daemon
static void roudiSigHandler(int32_t signal) noexcept
Method passed to the OS signal handler.
MonitoringMode
Controls process alive monitoring. Upon timeout, a monitored process is removed and its resources are...
Definition: iceoryx_posh_types.hpp:221
Definition: service_description.hpp:29
Definition: cmd_line_args.hpp:30