iceoryx_doc  1.0.1
process_manager.hpp
1 // Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 #ifndef IOX_POSH_ROUDI_PROCESS_MANAGER_HPP
18 #define IOX_POSH_ROUDI_PROCESS_MANAGER_HPP
19 
20 #include "iceoryx_posh/internal/mepoo/segment_manager.hpp"
21 #include "iceoryx_posh/internal/roudi/introspection/process_introspection.hpp"
22 #include "iceoryx_posh/internal/roudi/port_manager.hpp"
23 #include "iceoryx_posh/internal/roudi/process.hpp"
24 #include "iceoryx_posh/internal/runtime/ipc_interface_user.hpp"
25 #include "iceoryx_posh/mepoo/chunk_header.hpp"
26 #include "iceoryx_posh/version/compatibility_check_level.hpp"
27 #include "iceoryx_posh/version/version_info.hpp"
28 #include "iceoryx_utils/cxx/list.hpp"
29 #include "iceoryx_utils/error_handling/error_handling.hpp"
30 #include "iceoryx_utils/posix_wrapper/posix_access_rights.hpp"
31 
32 #include <cstdint>
33 #include <ctime>
34 
35 namespace iox
36 {
37 namespace roudi
38 {
40 {
41  public:
42  virtual void sendServiceRegistryChangeCounterToProcess(const RuntimeName_t& process_name) noexcept = 0;
43  virtual void discoveryUpdate() noexcept = 0;
44 
45  virtual ~ProcessManagerInterface() noexcept = default;
46 };
47 
49 {
50  public:
51  using ProcessList_t = cxx::list<Process, MAX_PROCESS_NUMBER>;
53 
54  enum class TerminationFeedback
55  {
56  SEND_ACK_TO_PROCESS,
57  DO_NOT_SEND_ACK_TO_PROCESS
58  };
59 
60  ProcessManager(RouDiMemoryInterface& roudiMemoryInterface,
61  PortManager& portManager,
62  const version::CompatibilityCheckLevel compatibilityCheckLevel) noexcept;
63  virtual ~ProcessManager() noexcept override = default;
64 
65  ProcessManager(const ProcessManager& other) = delete;
66  ProcessManager& operator=(const ProcessManager& other) = delete;
67 
77  bool registerProcess(const RuntimeName_t& name,
78  const uint32_t pid,
79  const posix::PosixUser user,
80  const bool isMonitored,
81  const int64_t transmissionTimestamp,
82  const uint64_t sessionId,
83  const version::VersionInfo& versionInfo) noexcept;
84 
88  bool unregisterProcess(const RuntimeName_t& name) noexcept;
89 
92  void killAllProcesses() noexcept;
93 
96 
100 
103  void handleProcessShutdownPreparationRequest(const RuntimeName_t& name) noexcept;
104 
107 
108  void updateLivelinessOfProcess(const RuntimeName_t& name) noexcept;
109 
110  void findServiceForProcess(const RuntimeName_t& name, const capro::ServiceDescription& service) noexcept;
111 
112  void
113  addInterfaceForProcess(const RuntimeName_t& name, capro::Interfaces interface, const NodeName_t& node) noexcept;
114 
115  void addApplicationForProcess(const RuntimeName_t& name) noexcept;
116 
117  void addNodeForProcess(const RuntimeName_t& process, const NodeName_t& node) noexcept;
118 
119  void addSubscriberForProcess(const RuntimeName_t& name,
120  const capro::ServiceDescription& service,
121  const popo::SubscriberOptions& subscriberOptions,
122  const PortConfigInfo& portConfigInfo = PortConfigInfo()) noexcept;
123 
124  void addPublisherForProcess(const RuntimeName_t& name,
125  const capro::ServiceDescription& service,
126  const popo::PublisherOptions& publisherOptions,
127  const PortConfigInfo& portConfigInfo = PortConfigInfo()) noexcept;
128 
129  void addConditionVariableForProcess(const RuntimeName_t& runtimeName) noexcept;
130 
131  void initIntrospection(ProcessIntrospectionType* processIntrospection) noexcept;
132 
133  void run() noexcept;
134 
135  popo::PublisherPortData* addIntrospectionPublisherPort(const capro::ServiceDescription& service,
136  const RuntimeName_t& process_name) noexcept;
137 
139  void sendMessageNotSupportedToRuntime(const RuntimeName_t& name) noexcept;
140 
141  void sendServiceRegistryChangeCounterToProcess(const RuntimeName_t& process_name) noexcept override;
142 
143  private:
144  bool searchForProcessAndThen(const RuntimeName_t& name,
145  cxx::function_ref<void(Process&)> AndThenCallable,
146  cxx::function_ref<void()> OrElseCallable) noexcept;
147 
148  void monitorProcesses() noexcept;
149  void discoveryUpdate() noexcept override;
150 
159  bool addProcess(const RuntimeName_t& name,
160  const uint32_t pid,
161  const posix::PosixUser& user,
162  const bool isMonitored,
163  const int64_t transmissionTimestamp,
164  const uint64_t sessionId,
165  const version::VersionInfo& versionInfo) noexcept;
166 
171  bool searchForProcessAndRemoveIt(const RuntimeName_t& name, const TerminationFeedback feedback) noexcept;
172 
178  bool removeProcessAndDeleteRespectiveSharedMemoryObjects(ProcessList_t::iterator& processIter,
179  const TerminationFeedback feedback) noexcept;
180 
181  enum class ShutdownPolicy
182  {
183  SIG_TERM,
184  SIG_KILL
185  };
186 
192  bool requestShutdownOfProcess(Process& process, ShutdownPolicy shutdownPolicy) noexcept;
193 
197  bool isProcessAlive(const Process& process) noexcept;
198 
205  void evaluateKillError(const Process& process,
206  const int32_t& errnum,
207  const char* errorString,
208  ShutdownPolicy shutdownPolicy) noexcept;
209 
210  RouDiMemoryInterface& m_roudiMemoryInterface;
211  PortManager& m_portManager;
212  mepoo::SegmentManager<>* m_segmentManager{nullptr};
213  mepoo::MemoryManager* m_introspectionMemoryManager{nullptr};
214  rp::BaseRelativePointer::id_t m_mgmtSegmentId{rp::BaseRelativePointer::NULL_POINTER_ID};
215  ProcessList_t m_processList;
216  ProcessIntrospectionType* m_processIntrospection{nullptr};
217  version::CompatibilityCheckLevel m_compatibilityCheckLevel;
218 };
219 
220 } // namespace roudi
221 } // namespace iox
222 
223 #endif // IOX_POSH_ROUDI_PROCESS_MANAGER_HPP
Definition: memory_manager.hpp:45
Definition: segment_manager.hpp:43
Definition: port_manager.hpp:55
Definition: process_manager.hpp:40
Definition: process_manager.hpp:49
bool unregisterProcess(const RuntimeName_t &name) noexcept
Unregisters a process at the ProcessManager.
bool isAnyRegisteredProcessStillRunning() noexcept
Is one or more of the registered processes running?
void handleProcessShutdownPreparationRequest(const RuntimeName_t &name) noexcept
A process is about to shut down and needs to be unblock by a potentially block publisher.
void sendMessageNotSupportedToRuntime(const RuntimeName_t &name) noexcept
Notify the application that it sent an unsupported message.
void printWarningForRegisteredProcessesAndClearProcessList() noexcept
Informs the user about the processes which are registered and then clears the process list.
void requestShutdownOfAllProcesses() noexcept
Tries to gracefully terminate all registered processes.
bool registerProcess(const RuntimeName_t &name, const uint32_t pid, const posix::PosixUser user, const bool isMonitored, const int64_t transmissionTimestamp, const uint64_t sessionId, const version::VersionInfo &versionInfo) noexcept
Registers a process at the ProcessManager.
void killAllProcesses() noexcept
Kills all registered processes. If RouDi doesn't have sufficient rights to kill the process,...
Definition: process.hpp:39
Definition: roudi_memory_interface.hpp:36
ProcessIntrospection< PublisherPortUserType > ProcessIntrospectionType
typedef for the templated process introspection class that is used by RouDi for the actual process in...
Definition: process_introspection.hpp:110
Definition: service_description.hpp:29
container for publisher port introspection data.
Definition: introspection_types.hpp:80
Stores information necessary to create the right type of port on RouDi side. Different types of ports...
Definition: port_config_info.hpp:32