iceoryx_doc  1.0.1
port_pool.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2020 - 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_POOL_HPP
18 #define IOX_POSH_ROUDI_PORT_POOL_HPP
19 
20 #include "iceoryx_posh/iceoryx_posh_types.hpp"
21 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp"
22 #include "iceoryx_posh/internal/popo/ports/application_port.hpp"
23 #include "iceoryx_posh/internal/popo/ports/interface_port.hpp"
24 #include "iceoryx_posh/internal/popo/ports/publisher_port_data.hpp"
25 #include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp"
26 #include "iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp"
27 #include "iceoryx_posh/internal/popo/ports/subscriber_port_multi_producer.hpp"
28 #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp"
29 #include "iceoryx_posh/internal/roudi/port_pool_data.hpp"
30 #include "iceoryx_posh/internal/runtime/node_data.hpp"
31 #include "iceoryx_posh/popo/publisher_options.hpp"
32 #include "iceoryx_posh/popo/subscriber_options.hpp"
33 #include "iceoryx_utils/cxx/type_traits.hpp"
34 
35 namespace iox
36 {
37 namespace roudi
38 {
39 struct PortPoolDataBase;
40 
41 enum class PortPoolError : uint8_t
42 {
43  INVALID_STATE,
44  UNIQUE_PUBLISHER_PORT_ALREADY_EXISTS,
45  PUBLISHER_PORT_LIST_FULL,
46  SUBSCRIBER_PORT_LIST_FULL,
47  INTERFACE_PORT_LIST_FULL,
48  APPLICATION_PORT_LIST_FULL,
49  NODE_DATA_LIST_FULL,
50  CONDITION_VARIABLE_LIST_FULL,
51  EVENT_VARIABLE_LIST_FULL,
52 };
53 
54 class PortPool
55 {
56  public:
57  PortPool(PortPoolData& portPoolData) noexcept;
58 
59  virtual ~PortPool() noexcept = default;
60 
64  cxx::vector<PublisherPortRouDiType::MemberType_t*, MAX_PUBLISHERS> getPublisherPortDataList() noexcept;
65  cxx::vector<SubscriberPortType::MemberType_t*, MAX_SUBSCRIBERS> getSubscriberPortDataList() noexcept;
66  cxx::vector<popo::InterfacePortData*, MAX_INTERFACE_NUMBER> getInterfacePortDataList() noexcept;
67  cxx::vector<popo::ApplicationPortData*, MAX_PROCESS_NUMBER> getApplicationPortDataList() noexcept;
68  cxx::vector<runtime::NodeData*, MAX_NODE_NUMBER> getNodeDataList() noexcept;
69  cxx::vector<popo::ConditionVariableData*, MAX_NUMBER_OF_CONDITION_VARIABLES>
70  getConditionVariableDataList() noexcept;
71 
72  cxx::expected<PublisherPortRouDiType::MemberType_t*, PortPoolError>
73  addPublisherPort(const capro::ServiceDescription& serviceDescription,
74  mepoo::MemoryManager* const memoryManager,
75  const RuntimeName_t& runtimeName,
76  const popo::PublisherOptions& publisherOptions,
77  const mepoo::MemoryInfo& memoryInfo = mepoo::MemoryInfo()) noexcept;
78 
79  cxx::expected<SubscriberPortType::MemberType_t*, PortPoolError>
80  addSubscriberPort(const capro::ServiceDescription& serviceDescription,
81  const RuntimeName_t& runtimeName,
82  const popo::SubscriberOptions& subscriberOptions,
83  const mepoo::MemoryInfo& memoryInfo = mepoo::MemoryInfo()) noexcept;
84 
85  template <typename T, std::enable_if_t<std::is_same<T, iox::build::ManyToManyPolicy>::value>* = nullptr>
86  iox::popo::SubscriberPortData* constructSubscriber(const capro::ServiceDescription& serviceDescription,
87  const RuntimeName_t& runtimeName,
88  const popo::SubscriberOptions& subscriberOptions,
89  const mepoo::MemoryInfo& memoryInfo) noexcept;
90 
91  template <typename T, std::enable_if_t<std::is_same<T, iox::build::OneToManyPolicy>::value>* = nullptr>
92  iox::popo::SubscriberPortData* constructSubscriber(const capro::ServiceDescription& serviceDescription,
93  const RuntimeName_t& runtimeName,
94  const popo::SubscriberOptions& subscriberOptions,
95  const mepoo::MemoryInfo& memoryInfo) noexcept;
96 
97  cxx::expected<popo::InterfacePortData*, PortPoolError> addInterfacePort(const RuntimeName_t& runtimeName,
98  const capro::Interfaces interface) noexcept;
99 
100  cxx::expected<popo::ApplicationPortData*, PortPoolError>
101  addApplicationPort(const RuntimeName_t& runtimeName) noexcept;
102 
103  cxx::expected<runtime::NodeData*, PortPoolError> addNodeData(const RuntimeName_t& runtimeName,
104  const NodeName_t& nodeName,
105  const uint64_t nodeDeviceIdentifier) noexcept;
106 
107  cxx::expected<popo::ConditionVariableData*, PortPoolError>
108  addConditionVariableData(const RuntimeName_t& runtimeName) noexcept;
109 
110  void removePublisherPort(PublisherPortRouDiType::MemberType_t* const portData) noexcept;
111  void removeSubscriberPort(SubscriberPortType::MemberType_t* const portData) noexcept;
112  void removeInterfacePort(popo::InterfacePortData* const portData) noexcept;
113  void removeApplicationPort(popo::ApplicationPortData* const portData) noexcept;
114  void removeNodeData(runtime::NodeData* const nodeData) noexcept;
115  void removeConditionVariableData(popo::ConditionVariableData* const conditionVariableData) noexcept;
116 
117  std::atomic<uint64_t>* serviceRegistryChangeCounter() noexcept;
118 
119  private:
120  PortPoolData* m_portPoolData;
121 };
122 
123 } // namespace roudi
124 } // namespace iox
125 
126 #include "iceoryx_posh/roudi/port_pool.inl"
127 
128 #endif // IOX_POSH_ROUDI_PORT_POOL_HPP
The PublisherPortRouDi provides the API for accessing a publisher port from the RouDi middleware daem...
Definition: publisher_port_roudi.hpp:36
Definition: port_pool.hpp:55
cxx::vector< PublisherPortRouDiType::MemberType_t *, MAX_PUBLISHERS > getPublisherPortDataList() noexcept
Definition: service_description.hpp:29
constexpr uint32_t MAX_INTERFACE_NUMBER
Definition: iceoryx_posh_types.hpp:88
container for common port data which is related to the subscriber port as well as the publisher port
Definition: introspection_types.hpp:68
Definition: port_pool_data.hpp:55