iceoryx_doc  1.0.1
port_manager.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_PORT_MANAGER_HPP
18 #define IOX_POSH_ROUDI_PORT_MANAGER_HPP
19 
20 #include "iceoryx_posh/iceoryx_posh_config.hpp"
21 #include "iceoryx_posh/iceoryx_posh_types.hpp"
22 #include "iceoryx_posh/internal/capro/capro_message.hpp"
23 #include "iceoryx_posh/internal/mepoo/memory_manager.hpp"
24 #include "iceoryx_posh/internal/popo/ports/application_port.hpp"
25 #include "iceoryx_posh/internal/popo/ports/interface_port.hpp"
26 #include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp"
27 #include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
28 #include "iceoryx_posh/internal/popo/ports/subscriber_port_multi_producer.hpp"
29 #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp"
30 #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"
31 #include "iceoryx_posh/internal/roudi/introspection/port_introspection.hpp"
32 #include "iceoryx_posh/internal/roudi/service_registry.hpp"
33 #include "iceoryx_posh/internal/runtime/ipc_message.hpp"
34 #include "iceoryx_posh/internal/runtime/node_data.hpp"
35 #include "iceoryx_posh/mepoo/chunk_header.hpp"
36 #include "iceoryx_posh/mepoo/memory_info.hpp"
37 #include "iceoryx_posh/mepoo/mepoo_config.hpp"
38 #include "iceoryx_posh/roudi/memory/roudi_memory_interface.hpp"
39 #include "iceoryx_posh/roudi/port_pool.hpp"
40 #include "iceoryx_posh/runtime/port_config_info.hpp"
41 #include "iceoryx_utils/cxx/optional.hpp"
42 #include "iceoryx_utils/cxx/type_traits.hpp"
43 #include "iceoryx_utils/internal/posix_wrapper/shared_memory_object.hpp"
44 #include "iceoryx_utils/posix_wrapper/posix_access_rights.hpp"
45 
46 #include <mutex>
47 
48 namespace iox
49 {
50 namespace roudi
51 {
52 capro::Interfaces StringToCaProInterface(const capro::IdString_t& str) noexcept;
53 
55 {
56  public:
58  PortManager(RouDiMemoryInterface* roudiMemoryInterface) noexcept;
59 
60  virtual ~PortManager() = default;
61 
63  void stopPortIntrospection() noexcept;
64 
65  void doDiscovery() noexcept;
66 
67  cxx::expected<PublisherPortRouDiType::MemberType_t*, PortPoolError>
68  acquirePublisherPortData(const capro::ServiceDescription& service,
69  const popo::PublisherOptions& publisherOptions,
70  const RuntimeName_t& runtimeName,
71  mepoo::MemoryManager* const payloadDataSegmentMemoryManager,
72  const PortConfigInfo& portConfigInfo) noexcept;
73 
74  cxx::expected<SubscriberPortType::MemberType_t*, PortPoolError>
75  acquireSubscriberPortData(const capro::ServiceDescription& service,
76  const popo::SubscriberOptions& subscriberOptions,
77  const RuntimeName_t& runtimeName,
78  const PortConfigInfo& portConfigInfo) noexcept;
79 
80  popo::InterfacePortData* acquireInterfacePortData(capro::Interfaces interface,
81  const RuntimeName_t& runtimeName,
82  const NodeName_t& nodeName = {""}) noexcept;
83 
84  popo::ApplicationPortData* acquireApplicationPortData(const RuntimeName_t& runtimeName) noexcept;
85 
86  cxx::expected<runtime::NodeData*, PortPoolError> acquireNodeData(const RuntimeName_t& runtimeName,
87  const NodeName_t& nodeName) noexcept;
88 
89  cxx::expected<popo::ConditionVariableData*, PortPoolError>
90  acquireConditionVariableData(const RuntimeName_t& runtimeName) noexcept;
91 
94  void unblockProcessShutdown(const RuntimeName_t& runtimeName) noexcept;
95 
97  void unblockRouDiShutdown() noexcept;
98 
99  void deletePortsOfProcess(const RuntimeName_t& runtimeName) noexcept;
100 
101  const std::atomic<uint64_t>* serviceRegistryChangeCounter() noexcept;
102  runtime::IpcMessage findService(const capro::ServiceDescription& service) noexcept;
103 
104  protected:
105  void makeAllPublisherPortsToStopOffer() noexcept;
106 
107  void destroyPublisherPort(PublisherPortRouDiType::MemberType_t* const publisherPortData) noexcept;
108 
109  void destroySubscriberPort(SubscriberPortType::MemberType_t* const subscriberPortData) noexcept;
110 
111  void handlePublisherPorts() noexcept;
112 
113  void doDiscoveryForPublisherPort(PublisherPortRouDiType& publisherPort) noexcept;
114 
115  void handleSubscriberPorts() noexcept;
116 
117  void doDiscoveryForSubscriberPort(SubscriberPortType& subscriberPort) noexcept;
118 
119  void handleInterfaces() noexcept;
120 
121  void handleApplications() noexcept;
122 
123  void handleNodes() noexcept;
124 
125  void handleConditionVariables() noexcept;
126 
127  bool sendToAllMatchingPublisherPorts(const capro::CaproMessage& message,
128  SubscriberPortType& subscriberSource) noexcept;
129 
130  void sendToAllMatchingSubscriberPorts(const capro::CaproMessage& message,
131  PublisherPortRouDiType& publisherSource) noexcept;
132 
133  void sendToAllMatchingInterfacePorts(const capro::CaproMessage& message) noexcept;
134 
135  void addEntryToServiceRegistry(const capro::IdString_t& service, const capro::IdString_t& instance) noexcept;
136  void removeEntryFromServiceRegistry(const capro::IdString_t& service, const capro::IdString_t& instance) noexcept;
137 
138  template <typename T, std::enable_if_t<std::is_same<T, iox::build::OneToManyPolicy>::value>* = nullptr>
139  cxx::optional<RuntimeName_t>
140  doesViolateCommunicationPolicy(const capro::ServiceDescription& service) const noexcept;
141 
142  template <typename T, std::enable_if_t<std::is_same<T, iox::build::ManyToManyPolicy>::value>* = nullptr>
143  cxx::optional<RuntimeName_t>
144  doesViolateCommunicationPolicy(const capro::ServiceDescription& service IOX_MAYBE_UNUSED) const noexcept;
145 
146  private:
147  RouDiMemoryInterface* m_roudiMemoryInterface{nullptr};
148  PortPool* m_portPool{nullptr};
149  ServiceRegistry m_serviceRegistry;
150  PortIntrospectionType m_portIntrospection;
151 };
152 } // namespace roudi
153 } // namespace iox
154 
155 #include "iceoryx_posh/internal/roudi/port_manager.inl"
156 
157 #endif // IOX_POSH_ROUDI_PORT_MANAGER_HPP
The PublisherPortRouDi provides the API for accessing a publisher port from the RouDi middleware daem...
Definition: publisher_port_roudi.hpp:36
Definition: port_manager.hpp:55
void unblockProcessShutdown(const RuntimeName_t &runtimeName) noexcept
Used to unblock potential locks in the shutdown phase of a process.
void stopPortIntrospection() noexcept
void unblockRouDiShutdown() noexcept
Used to unblock potential locks in the shutdown phase of RouDi.
Definition: port_pool.hpp:55
Definition: roudi_memory_interface.hpp:36
PortIntrospection< PublisherPortUserType, SubscriberPortUserType > PortIntrospectionType
typedef for the templated port introspection class that is used by RouDi for the actual port introspe...
Definition: port_introspection.hpp:330
Definition: service_description.hpp:29
Definition: application_port_data.hpp:29
Stores information necessary to create the right type of port on RouDi side. Different types of ports...
Definition: port_config_info.hpp:32