From 5029c05b9326c77fa3ce02e865c58dd3c0156652 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 9 Feb 2022 18:39:02 +0100 Subject: [PATCH] iox-#27 Add client and server port to PortPool --- .../error_handling/error_handling.hpp | 2 + .../internal/roudi/port_pool_data.hpp | 5 ++ .../include/iceoryx_posh/roudi/port_pool.hpp | 26 +++++++++ iceoryx_posh/source/roudi/port_pool.cpp | 55 +++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp index cbc37efc5ae..25032677c56 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp @@ -122,6 +122,8 @@ namespace iox error(MEPOO__MAXIMUM_NUMBER_OF_MEMPOOLS_REACHED) \ error(PORT_POOL__PUBLISHERLIST_OVERFLOW) \ error(PORT_POOL__SUBSCRIBERLIST_OVERFLOW) \ + error(PORT_POOL__CLIENTLIST_OVERFLOW) \ + error(PORT_POOL__SERVERLIST_OVERFLOW) \ error(PORT_POOL__INTERFACELIST_OVERFLOW) \ error(PORT_POOL__APPLICATIONLIST_OVERFLOW) \ error(PORT_POOL__NODELIST_OVERFLOW) \ diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_pool_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_pool_data.hpp index 3aae26ba7ef..a9326b12b17 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_pool_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_pool_data.hpp @@ -21,8 +21,10 @@ #include "iceoryx_hoofs/cxx/vector.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" +#include "iceoryx_posh/internal/popo/ports/client_port_data.hpp" #include "iceoryx_posh/internal/popo/ports/interface_port.hpp" #include "iceoryx_posh/internal/popo/ports/publisher_port_data.hpp" +#include "iceoryx_posh/internal/popo/ports/server_port_data.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" @@ -59,6 +61,9 @@ struct PortPoolData FixedPositionContainer m_publisherPortMembers; FixedPositionContainer m_subscriberPortMembers; + FixedPositionContainer m_serverPortMembers; + FixedPositionContainer m_clientPortMembers; + // required to be atomic since a service can be offered or stopOffered while reading // this variable in a user application std::atomic m_serviceRegistryChangeCounter{0}; diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/port_pool.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/port_pool.hpp index e743ced285f..dbfef58eaee 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/port_pool.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/port_pool.hpp @@ -20,15 +20,21 @@ #include "iceoryx_hoofs/cxx/type_traits.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" +#include "iceoryx_posh/internal/popo/ports/client_port_data.hpp" +#include "iceoryx_posh/internal/popo/ports/client_port_roudi.hpp" #include "iceoryx_posh/internal/popo/ports/interface_port.hpp" #include "iceoryx_posh/internal/popo/ports/publisher_port_data.hpp" #include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp" +#include "iceoryx_posh/internal/popo/ports/server_port_data.hpp" +#include "iceoryx_posh/internal/popo/ports/server_port_roudi.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_multi_producer.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp" #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" +#include "iceoryx_posh/popo/client_options.hpp" #include "iceoryx_posh/popo/publisher_options.hpp" +#include "iceoryx_posh/popo/server_options.hpp" #include "iceoryx_posh/popo/subscriber_options.hpp" namespace iox @@ -43,6 +49,8 @@ enum class PortPoolError : uint8_t PUBLISHER_PORT_LIST_FULL, SUBSCRIBER_PORT_LIST_FULL, INTERFACE_PORT_LIST_FULL, + CLIENT_PORT_LIST_FULL, + SERVER_PORT_LIST_FULL, NODE_DATA_LIST_FULL, CONDITION_VARIABLE_LIST_FULL, EVENT_VARIABLE_LIST_FULL, @@ -60,6 +68,8 @@ class PortPool /// update this member if the publisher ports actually changed cxx::vector getPublisherPortDataList() noexcept; cxx::vector getSubscriberPortDataList() noexcept; + cxx::vector getClientPortDataList() noexcept; + cxx::vector getServerPortDataList() noexcept; cxx::vector getInterfacePortDataList() noexcept; cxx::vector getNodeDataList() noexcept; cxx::vector @@ -90,6 +100,20 @@ class PortPool const popo::SubscriberOptions& subscriberOptions, const mepoo::MemoryInfo& memoryInfo) noexcept; + cxx::expected + addClientPort(const capro::ServiceDescription& serviceDescription, + mepoo::MemoryManager* const memoryManager, + const RuntimeName_t& runtimeName, + const popo::ClientOptions& clientOptions, + const mepoo::MemoryInfo& memoryInfo = mepoo::MemoryInfo()) noexcept; + + cxx::expected + addServerPort(const capro::ServiceDescription& serviceDescription, + mepoo::MemoryManager* const memoryManager, + const RuntimeName_t& runtimeName, + const popo::ServerOptions& serverOptions, + const mepoo::MemoryInfo& memoryInfo = mepoo::MemoryInfo()) noexcept; + cxx::expected addInterfacePort(const RuntimeName_t& runtimeName, const capro::Interfaces interface) noexcept; @@ -102,6 +126,8 @@ class PortPool void removePublisherPort(PublisherPortRouDiType::MemberType_t* const portData) noexcept; void removeSubscriberPort(SubscriberPortType::MemberType_t* const portData) noexcept; + void removeClientPort(popo::ClientPortRouDi::MemberType_t* const portData) noexcept; + void removeServerPort(popo::ServerPortRouDi::MemberType_t* const portData) noexcept; void removeInterfacePort(popo::InterfacePortData* const portData) noexcept; void removeNodeData(runtime::NodeData* const nodeData) noexcept; void removeConditionVariableData(popo::ConditionVariableData* const conditionVariableData) noexcept; diff --git a/iceoryx_posh/source/roudi/port_pool.cpp b/iceoryx_posh/source/roudi/port_pool.cpp index 4f6d1dfd1ee..da0d6a21b3e 100644 --- a/iceoryx_posh/source/roudi/port_pool.cpp +++ b/iceoryx_posh/source/roudi/port_pool.cpp @@ -160,6 +160,52 @@ PortPool::addSubscriberPort(const capro::ServiceDescription& serviceDescription, } } +cxx::vector PortPool::getClientPortDataList() noexcept +{ + return m_portPoolData->m_clientPortMembers.content(); +} + +cxx::vector PortPool::getServerPortDataList() noexcept +{ + return m_portPoolData->m_serverPortMembers.content(); +} + +cxx::expected +PortPool::addClientPort(const capro::ServiceDescription& serviceDescription, + mepoo::MemoryManager* const memoryManager, + const RuntimeName_t& runtimeName, + const popo::ClientOptions& clientOptions, + const mepoo::MemoryInfo& memoryInfo) noexcept +{ + if (!m_portPoolData->m_clientPortMembers.hasFreeSpace()) + { + errorHandler(Error::kPORT_POOL__CLIENTLIST_OVERFLOW, nullptr, ErrorLevel::MODERATE); + return cxx::error(PortPoolError::CLIENT_PORT_LIST_FULL); + } + + auto clientPortData = m_portPoolData->m_clientPortMembers.insert( + serviceDescription, runtimeName, clientOptions, memoryManager, memoryInfo); + return cxx::success(clientPortData); +} + +cxx::expected +PortPool::addServerPort(const capro::ServiceDescription& serviceDescription, + mepoo::MemoryManager* const memoryManager, + const RuntimeName_t& runtimeName, + const popo::ServerOptions& serverOptions, + const mepoo::MemoryInfo& memoryInfo) noexcept +{ + if (!m_portPoolData->m_serverPortMembers.hasFreeSpace()) + { + errorHandler(Error::kPORT_POOL__SERVERLIST_OVERFLOW, nullptr, ErrorLevel::MODERATE); + return cxx::error(PortPoolError::SERVER_PORT_LIST_FULL); + } + + auto serverPortData = m_portPoolData->m_serverPortMembers.insert( + serviceDescription, runtimeName, serverOptions, memoryManager, memoryInfo); + return cxx::success(serverPortData); +} + void PortPool::removePublisherPort(PublisherPortRouDiType::MemberType_t* const portData) noexcept { m_portPoolData->m_publisherPortMembers.erase(portData); @@ -170,5 +216,14 @@ void PortPool::removeSubscriberPort(SubscriberPortType::MemberType_t* const port m_portPoolData->m_subscriberPortMembers.erase(portData); } +void PortPool::removeClientPort(popo::ClientPortRouDi::MemberType_t* const portData) noexcept +{ + m_portPoolData->m_clientPortMembers.erase(portData); +} +void PortPool::removeServerPort(popo::ServerPortRouDi::MemberType_t* const portData) noexcept +{ + m_portPoolData->m_serverPortMembers.erase(portData); +} + } // namespace roudi } // namespace iox