Skip to content

Commit

Permalink
iox-#2044 Port 'PortPool' to new FixedPositionContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Oct 24, 2023
1 parent d9c3857 commit 7075e6b
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 341 deletions.
18 changes: 13 additions & 5 deletions iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.inl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,25 @@ inline optional<RuntimeName_t>
PortManager::doesViolateCommunicationPolicy(const capro::ServiceDescription& service) noexcept
{
// check if the publisher is already in the list
for (auto publisherPortData : m_portPool->getPublisherPortDataList())
auto& publisherPorts = m_portPool->getPublisherPortDataList();
auto port = publisherPorts.begin();
while (port != publisherPorts.end())
{
popo::PublisherPortRouDi publisherPort(publisherPortData);
popo::PublisherPortRouDi publisherPort(port.to_ptr());

if (service == publisherPort.getCaProServiceDescription())
{
if (publisherPortData->m_toBeDestroyed)
if (publisherPort.toBeDestroyed())
{
destroyPublisherPort(publisherPortData);
destroyPublisherPort(port.to_ptr());
port = publisherPorts.begin();
continue;
}
return make_optional<RuntimeName_t>(publisherPortData->m_runtimeName);
return make_optional<RuntimeName_t>(port->m_runtimeName);
}
else
{
++port;
}
}
return nullopt;
Expand Down
42 changes: 16 additions & 26 deletions iceoryx_posh/include/iceoryx_posh/internal/roudi/port_pool_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,39 @@
#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"
#include "iox/fixed_position_container.hpp"
#include "iox/optional.hpp"
#include "iox/vector.hpp"

namespace iox
{
namespace roudi
{
/// @brief workaround container until we have a fixed list with the needed functionality
template <typename T, uint64_t Capacity>
class FixedPositionContainer
struct PortPoolData
{
public:
static constexpr uint64_t FIRST_ELEMENT = std::numeric_limits<uint64_t>::max();
using InterfaceContainer = FixedPositionContainer<popo::InterfacePortData, MAX_INTERFACE_NUMBER>;
InterfaceContainer m_interfacePortMembers;

bool hasFreeSpace() noexcept;
using NodeContainer = FixedPositionContainer<runtime::NodeData, MAX_NODE_NUMBER>;
NodeContainer m_nodeMembers;

template <typename... Targs>
T* insert(Targs&&... args) noexcept;
using CondVarContainer = FixedPositionContainer<popo::ConditionVariableData, MAX_NUMBER_OF_CONDITION_VARIABLES>;
CondVarContainer m_conditionVariableMembers;

void erase(const T* const element) noexcept;
using PublisherContainer = FixedPositionContainer<iox::popo::PublisherPortData, MAX_PUBLISHERS>;
PublisherContainer m_publisherPortMembers;

vector<T*, Capacity> content() noexcept;
using SubscriberContainer = FixedPositionContainer<iox::popo::SubscriberPortData, MAX_SUBSCRIBERS>;
SubscriberContainer m_subscriberPortMembers;

private:
vector<optional<T>, Capacity> m_data;
};
using ServerContainer = FixedPositionContainer<iox::popo::ServerPortData, MAX_SERVERS>;
ServerContainer m_serverPortMembers;

struct PortPoolData
{
FixedPositionContainer<popo::InterfacePortData, MAX_INTERFACE_NUMBER> m_interfacePortMembers;
FixedPositionContainer<runtime::NodeData, MAX_NODE_NUMBER> m_nodeMembers;
FixedPositionContainer<popo::ConditionVariableData, MAX_NUMBER_OF_CONDITION_VARIABLES> m_conditionVariableMembers;

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;
using ClientContainer = FixedPositionContainer<iox::popo::ClientPortData, MAX_CLIENTS>;
ClientContainer m_clientPortMembers;
};

} // namespace roudi
} // namespace iox

#include "iceoryx_posh/internal/roudi/port_pool_data.inl"

#endif // IOX_POSH_ROUDI_PORT_POOL_DATA_BASE_HPP

This file was deleted.

14 changes: 7 additions & 7 deletions iceoryx_posh/include/iceoryx_posh/roudi/port_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class PortPool

virtual ~PortPool() noexcept = default;

vector<PublisherPortRouDiType::MemberType_t*, MAX_PUBLISHERS> getPublisherPortDataList() noexcept;
vector<SubscriberPortType::MemberType_t*, MAX_SUBSCRIBERS> getSubscriberPortDataList() noexcept;
vector<popo::ClientPortData*, MAX_CLIENTS> getClientPortDataList() noexcept;
vector<popo::ServerPortData*, MAX_SERVERS> getServerPortDataList() noexcept;
vector<popo::InterfacePortData*, MAX_INTERFACE_NUMBER> getInterfacePortDataList() noexcept;
vector<runtime::NodeData*, MAX_NODE_NUMBER> getNodeDataList() noexcept;
vector<popo::ConditionVariableData*, MAX_NUMBER_OF_CONDITION_VARIABLES> getConditionVariableDataList() noexcept;
PortPoolData::PublisherContainer& getPublisherPortDataList() noexcept;
PortPoolData::SubscriberContainer& getSubscriberPortDataList() noexcept;
PortPoolData::ClientContainer& getClientPortDataList() noexcept;
PortPoolData::ServerContainer& getServerPortDataList() noexcept;
PortPoolData::InterfaceContainer& getInterfacePortDataList() noexcept;
PortPoolData::NodeContainer& getNodeDataList() noexcept;
PortPoolData::CondVarContainer& getConditionVariableDataList() noexcept;

expected<PublisherPortRouDiType::MemberType_t*, PortPoolError>
addPublisherPort(const capro::ServiceDescription& serviceDescription,
Expand Down
16 changes: 14 additions & 2 deletions iceoryx_posh/include/iceoryx_posh/roudi/port_pool.inl
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ inline iox::popo::SubscriberPortData* PortPool::constructSubscriber(const capro:
const popo::SubscriberOptions& subscriberOptions,
const mepoo::MemoryInfo& memoryInfo) noexcept
{
return m_portPoolData->m_subscriberPortMembers.insert(
auto port = getSubscriberPortDataList().emplace(
serviceDescription,
runtimeName,
(subscriberOptions.queueFullPolicy == popo::QueueFullPolicy::DISCARD_OLDEST_DATA)
? cxx::VariantQueueTypes::SoFi_MultiProducerSingleConsumer
: cxx::VariantQueueTypes::FiFo_MultiProducerSingleConsumer,
subscriberOptions,
memoryInfo);
if (port == getSubscriberPortDataList().end())
{
return nullptr;
}

return port.to_ptr();
}

template <typename T, std::enable_if_t<std::is_same<T, iox::build::OneToManyPolicy>::value>*>
Expand All @@ -43,14 +49,20 @@ inline iox::popo::SubscriberPortData* PortPool::constructSubscriber(const capro:
const popo::SubscriberOptions& subscriberOptions,
const mepoo::MemoryInfo& memoryInfo) noexcept
{
return m_portPoolData->m_subscriberPortMembers.insert(
auto port = getSubscriberPortDataList().emplace(
serviceDescription,
runtimeName,
(subscriberOptions.queueFullPolicy == popo::QueueFullPolicy::DISCARD_OLDEST_DATA)
? cxx::VariantQueueTypes::SoFi_SingleProducerSingleConsumer
: cxx::VariantQueueTypes::FiFo_SingleProducerSingleConsumer,
subscriberOptions,
memoryInfo);
if (port == getSubscriberPortDataList().end())
{
return nullptr;
}

return port.to_ptr();
}
} // namespace roudi
} // namespace iox
Expand Down
Loading

0 comments on commit 7075e6b

Please sign in to comment.