iceoryx_doc  1.0.1
process_introspection.hpp
1 // Copyright (c) 2019 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_INTROSPECTION_PROCESS_INTROSPECTION_HPP
18 #define IOX_POSH_ROUDI_INTROSPECTION_PROCESS_INTROSPECTION_HPP
19 
20 #include "iceoryx_posh/iceoryx_posh_types.hpp"
21 #include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
22 #include "iceoryx_posh/roudi/introspection_types.hpp"
23 #include "iceoryx_utils/cxx/list.hpp"
24 #include "iceoryx_utils/cxx/method_callback.hpp"
25 #include "iceoryx_utils/internal/concurrent/periodic_task.hpp"
26 
27 #include <mutex>
28 
29 namespace iox
30 {
31 namespace roudi
32 {
38 template <typename PublisherPort>
40 {
41  public:
42  ProcessIntrospection() noexcept;
43  ~ProcessIntrospection() noexcept;
44 
45  // delete copy constructor and assignment operator
47  ProcessIntrospection& operator=(ProcessIntrospection const&) = delete;
48  // delete move constructor and assignment operator
50  ProcessIntrospection& operator=(ProcessIntrospection&&) = delete;
51 
52 
56  void addProcess(const int pid, const RuntimeName_t& name) noexcept;
57 
60  void removeProcess(const int pid) noexcept;
61 
65  void addNode(const RuntimeName_t& runtimeName, const NodeName_t& node) noexcept;
66 
70  void removeNode(const RuntimeName_t& runtimeName, const NodeName_t& node) noexcept;
71 
75  void registerPublisherPort(PublisherPort&& publisherPort) noexcept;
76 
82  void run() noexcept;
83 
85  void stop() noexcept;
86 
90  void setSendInterval(const units::Duration interval) noexcept;
91 
92  protected:
93  cxx::optional<PublisherPort> m_publisherPort;
94  void send() noexcept;
95 
96  private:
97  using ProcessList_t = cxx::list<ProcessIntrospectionData, MAX_PROCESS_NUMBER>;
98  ProcessList_t m_processList;
99  bool m_processListNewData{true}; // true because we want to have a valid field, even with an empty list
100 
101  std::mutex m_mutex;
102 
103  units::Duration m_sendInterval{units::Duration::fromSeconds(1U)};
104  concurrent::PeriodicTask<cxx::MethodCallback<void>> m_publishingTask{
105  concurrent::PeriodicTaskManualStart, "ProcessIntr", *this, &ProcessIntrospection::send};
106 };
107 
111 
112 } // namespace roudi
113 } // namespace iox
114 
115 #include "iceoryx_posh/internal/roudi/introspection/process_introspection.inl"
116 
117 #endif // IOX_POSH_ROUDI_INTROSPECTION_PROCESS_INTROSPECTION_HPP
This class handles the process intropection for RouDi. It is recommended to use the ProcessIntrospect...
Definition: process_introspection.hpp:40
void addNode(const RuntimeName_t &runtimeName, const NodeName_t &node) noexcept
This function is used to add a node to the process introspection.
Definition: process_introspection.inl:77
void removeNode(const RuntimeName_t &runtimeName, const NodeName_t &node) noexcept
This function is used to remove a node from the process introspection.
Definition: process_introspection.inl:111
void stop() noexcept
This function stops the thread previously started by run().
Definition: process_introspection.inl:195
void run() noexcept
This function starts a thread which periodically sends the introspection data to the client....
Definition: process_introspection.inl:156
void addProcess(const int pid, const RuntimeName_t &name) noexcept
This function is used to add a process to the process introspection.
Definition: process_introspection.inl:47
void setSendInterval(const units::Duration interval) noexcept
This function configures the interval for the transmission of the port introspection data.
Definition: process_introspection.inl:201
void registerPublisherPort(PublisherPort &&publisherPort) noexcept
This functions registers the POSH publisher port which is used to send the data to the instrospcetion...
Definition: process_introspection.inl:146
void removeProcess(const int pid) noexcept
This function is used to remove the process from the process introspection.
Definition: process_introspection.inl:61
Definition: service_description.hpp:29