Skip to content

Commit

Permalink
iox-#27 Add client and server port to PortPool
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Feb 9, 2022
1 parent dd30a28 commit b704a61
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -59,6 +61,9 @@ struct PortPoolData
FixedPositionContainer<iox::popo::PublisherPortData, MAX_PUBLISHERS> m_publisherPortMembers;
FixedPositionContainer<iox::popo::SubscriberPortData, MAX_SUBSCRIBERS> m_subscriberPortMembers;

FixedPositionContainer<iox::popo::ServerPortData, MAX_SERVERS> m_serverPortMembers;
FixedPositionContainer<iox::popo::ClientPortData, MAX_CLIENTS> m_clientPortMembers;

// required to be atomic since a service can be offered or stopOffered while reading
// this variable in a user application
std::atomic<uint64_t> m_serviceRegistryChangeCounter{0};
Expand Down
26 changes: 26 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/roudi/port_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -60,6 +68,8 @@ class PortPool
/// update this member if the publisher ports actually changed
cxx::vector<PublisherPortRouDiType::MemberType_t*, MAX_PUBLISHERS> getPublisherPortDataList() noexcept;
cxx::vector<SubscriberPortType::MemberType_t*, MAX_SUBSCRIBERS> getSubscriberPortDataList() noexcept;
cxx::vector<popo::ClientPortRouDi::MemberType_t*, MAX_CLIENTS> getClientPortDataList() noexcept;
cxx::vector<popo::ServerPortRouDi::MemberType_t*, MAX_SERVERS> getServerPortDataList() noexcept;
cxx::vector<popo::InterfacePortData*, MAX_INTERFACE_NUMBER> getInterfacePortDataList() noexcept;
cxx::vector<runtime::NodeData*, MAX_NODE_NUMBER> getNodeDataList() noexcept;
cxx::vector<popo::ConditionVariableData*, MAX_NUMBER_OF_CONDITION_VARIABLES>
Expand Down Expand Up @@ -90,6 +100,20 @@ class PortPool
const popo::SubscriberOptions& subscriberOptions,
const mepoo::MemoryInfo& memoryInfo) noexcept;

cxx::expected<popo::ClientPortRouDi::MemberType_t*, PortPoolError>
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<popo::ServerPortRouDi::MemberType_t*, PortPoolError>
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<popo::InterfacePortData*, PortPoolError> addInterfacePort(const RuntimeName_t& runtimeName,
const capro::Interfaces interface) noexcept;

Expand All @@ -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;
Expand Down
55 changes: 55 additions & 0 deletions iceoryx_posh/source/roudi/port_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,52 @@ PortPool::addSubscriberPort(const capro::ServiceDescription& serviceDescription,
}
}

cxx::vector<popo::ClientPortRouDi::MemberType_t*, MAX_CLIENTS> PortPool::getClientPortDataList() noexcept
{
return m_portPoolData->m_clientPortMembers.content();
}

cxx::vector<popo::ServerPortRouDi::MemberType_t*, MAX_SERVERS> PortPool::getServerPortDataList() noexcept
{
return m_portPoolData->m_serverPortMembers.content();
}

cxx::expected<popo::ClientPortRouDi::MemberType_t*, PortPoolError>
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>(PortPoolError::CLIENT_PORT_LIST_FULL);
}

auto clientPortData = m_portPoolData->m_clientPortMembers.insert(
serviceDescription, runtimeName, clientOptions, memoryManager, memoryInfo);
return cxx::success<popo::ClientPortRouDi::MemberType_t*>(clientPortData);
}

cxx::expected<popo::ServerPortRouDi::MemberType_t*, PortPoolError>
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>(PortPoolError::SERVER_PORT_LIST_FULL);
}

auto serverPortData = m_portPoolData->m_serverPortMembers.insert(
serviceDescription, runtimeName, serverOptions, memoryManager, memoryInfo);
return cxx::success<popo::ServerPortRouDi::MemberType_t*>(serverPortData);
}

void PortPool::removePublisherPort(PublisherPortRouDiType::MemberType_t* const portData) noexcept
{
m_portPoolData->m_publisherPortMembers.erase(portData);
Expand All @@ -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

0 comments on commit b704a61

Please sign in to comment.