Skip to content

Commit

Permalink
Merge pull request #2273 from elBoberido/iox-2272-compile-time-resour…
Browse files Browse the repository at this point in the history
…ce-prefix

iox-#2272 Make iceoryx resource prefix a compile time option
  • Loading branch information
elBoberido authored Apr 23, 2024
2 parents e1c82d6 + 4be9a7b commit e880982
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- Add support for `iox::string` in `MessageQueue` and created `message_queue.inl` [#1963](https://github.com/eclipse-iceoryx/iceoryx/issues/1963)
- Add support for `iox::string` in `NamedPipe` and created `named_pipe.inl` [#1693](https://github.com/eclipse-iceoryx/iceoryx/issues/1693)
- Add an `iox1` prefix to all resources created by `iceoryx_posh` and `RouDi` [#2185](https://github.com/eclipse-iceoryx/iceoryx/issues/2185)
- Make iceoryx resource prefix a compile time option [#2272](https://github.com/eclipse-iceoryx/iceoryx/issues/2272)

**Bugfixes:**

Expand Down
5 changes: 0 additions & 5 deletions iceoryx_platform/mac/include/iceoryx_platform/signal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@

#include <signal.h>

inline void psignal(int sig, const char* s)
{
psignal(static_cast<unsigned int>(sig), s);
}

#endif // IOX_HOOFS_MAC_PLATFORM_SIGNAL_HPP
2 changes: 2 additions & 0 deletions iceoryx_posh/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ configure_file(
# FIXME: for values see "iceoryx_posh/cmake/IceoryxPoshDeployment.cmake" ... for now some nice defaults
"@platforms//os:macos": {
"IOX_COMMUNICATION_POLICY": "ManyToManyPolicy",
"IOX_DEFAULT_RESOURCE_PREFIX": "iox1",
"IOX_EXPERIMENTAL_POSH_FLAG": "false",
"IOX_MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY": "8",
"IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY": "256",
Expand All @@ -55,6 +56,7 @@ configure_file(
},
"//conditions:default": {
"IOX_COMMUNICATION_POLICY": "ManyToManyPolicy",
"IOX_DEFAULT_RESOURCE_PREFIX": "iox1",
"IOX_EXPERIMENTAL_POSH_FLAG": "false",
"IOX_MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY": "8",
"IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY": "256",
Expand Down
5 changes: 5 additions & 0 deletions iceoryx_posh/cmake/IceoryxPoshDeployment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ configure_option(
DEFAULT_VALUE 4
)

configure_option(
NAME IOX_DEFAULT_RESOURCE_PREFIX
DEFAULT_VALUE "iox1"
)

if(IOX_EXPERIMENTAL_POSH)
set(IOX_EXPERIMENTAL_POSH_FLAG true)
else()
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_posh/cmake/iceoryx_posh_deployment.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ constexpr uint32_t IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY =
constexpr uint32_t IOX_MAX_RESPONSE_QUEUE_CAPACITY = static_cast<uint32_t>(@IOX_MAX_RESPONSE_QUEUE_CAPACITY@);
constexpr uint32_t IOX_MAX_REQUEST_QUEUE_CAPACITY = static_cast<uint32_t>(@IOX_MAX_REQUEST_QUEUE_CAPACITY@);
constexpr uint32_t IOX_MAX_CLIENTS_PER_SERVER = static_cast<uint32_t>(@IOX_MAX_CLIENTS_PER_SERVER@);
constexpr bool IOX_EXPERIMENTAL_POSH_FLAG = @IOX_EXPERIMENTAL_POSH_FLAG@;
constexpr uint32_t IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY = static_cast<uint32_t>(@IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY@);
constexpr const char IOX_DEFAULT_RESOURCE_PREFIX[] = "@IOX_DEFAULT_RESOURCE_PREFIX@";
constexpr bool IOX_EXPERIMENTAL_POSH_FLAG = @IOX_EXPERIMENTAL_POSH_FLAG@;
// clang-format on
} // namespace build
} // namespace iox
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ constexpr const char SERVICE_DISCOVERY_INSTANCE_NAME[] = "RouDi_ID";
constexpr const char SERVICE_DISCOVERY_EVENT_NAME[] = "ServiceRegistry";

// Resource prefix
constexpr uint32_t RESOURCE_PREFIX_LENGTH = 13; // 'iox1_' + MAX_UINT16_SIZE + '_' + optional 'x_'
constexpr uint32_t RESOURCE_PREFIX_LENGTH = 13; // 'iox1_' + MAX_UINT16_SIZE + '_i_'/'_u_'

// Nodes
constexpr uint32_t MAX_NODE_NAME_LENGTH = build::IOX_MAX_NODE_NAME_LENGTH;
Expand Down Expand Up @@ -221,7 +221,7 @@ IOX_NEW_TYPE(DomainId,

constexpr DomainId DEFAULT_DOMAIN_ID{0};

constexpr const char ICEORYX_RESOURCE_PREFIX[] = "iox1";
using build::IOX_DEFAULT_RESOURCE_PREFIX;

/// @brief The resource type is used to customize the resource prefix by adding an 'i' or 'u' depending whether the
/// resource is defined by iceoryx, e.g. the roudi IPC channel, or by the user, e.g. the runtime name. This shall
Expand Down
5 changes: 4 additions & 1 deletion iceoryx_posh/source/iceoryx_posh_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iox/size.hpp"

#include <atomic>

Expand All @@ -23,6 +24,8 @@ namespace iox

ResourcePrefix_t iceoryxResourcePrefix(const DomainId domainId, const ResourceType resourceType) noexcept
{
static_assert(iox::size(IOX_DEFAULT_RESOURCE_PREFIX) <= 5,
"The 'IOX_DEFAULT_RESOURCE_PREFIX' must not have more than 4 characters + the null-termination!");
static_assert(std::is_same_v<uint16_t, DomainId::value_type>,
"Please adjust 'MAX_UINT16_WIDTH' to the new fixed width type to have enough space for the "
"stringified Domain ID");
Expand All @@ -37,7 +40,7 @@ ResourcePrefix_t iceoryxResourcePrefix(const DomainId domainId, const ResourceTy
iox::convert::toString(usedDomainId).c_str()};

auto resourceTypeString{resourceType == ResourceType::ICEORYX_DEFINED ? iox::string<1>{"i"} : iox::string<1>{"u"}};
return concatenate(ICEORYX_RESOURCE_PREFIX, "_", uniqueDomainIdString, "_", resourceTypeString, "_");
return concatenate(IOX_DEFAULT_RESOURCE_PREFIX, "_", uniqueDomainIdString, "_", resourceTypeString, "_");
}

namespace experimental
Expand Down
2 changes: 2 additions & 0 deletions iceoryx_posh/source/roudi/roudi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ void RouDi::processRuntimeMessages(runtime::IpcInterfaceCreator&& roudiIpcInterf

setThreadName("IPC-msg-process");

IOX_LOG(INFO, "Resource prefix: " << IOX_DEFAULT_RESOURCE_PREFIX);
IOX_LOG(INFO, "Domain ID: " << static_cast<DomainId::value_type>(m_roudiConfig.domainId));
IOX_LOG(INFO, "RouDi is ready for clients");
fflush(stdout); // explicitly flush 'stdout' for 'launch_testing'

Expand Down
3 changes: 3 additions & 0 deletions iceoryx_posh/source/runtime/posh_runtime_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ PoshRuntimeImpl::PoshRuntimeImpl(optional<const RuntimeName_t*> name,
"KeepAlive",
*this,
&PoshRuntimeImpl::sendKeepAliveAndHandleShutdownPreparation);

IOX_LOG(DEBUG, "Resource prefix: " << IOX_DEFAULT_RESOURCE_PREFIX);
}

PoshRuntimeImpl::PoshRuntimeImpl(optional<const RuntimeName_t*> name,
Expand Down Expand Up @@ -113,6 +115,7 @@ PoshRuntimeImpl::PoshRuntimeImpl(optional<const RuntimeName_t*> name,
std::move(shmInterface)};
}())
{
IOX_LOG(INFO, "Domain ID: " << static_cast<DomainId::value_type>(domainId));
}

PoshRuntimeImpl::~PoshRuntimeImpl() noexcept
Expand Down
27 changes: 22 additions & 5 deletions iceoryx_posh/test/moduletests/test_posh_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,44 @@ TEST(PoshTypes_test, IceoryxResourcePrefixWithDefaultDomainIdWorks)
{
::testing::Test::RecordProperty("TEST_ID", "35f1d638-8efa-41dd-859b-bcc23450844f");

EXPECT_THAT(iceoryxResourcePrefix(DEFAULT_DOMAIN_ID, ResourceType::ICEORYX_DEFINED).c_str(), StrEq("iox1_0_i_"));
const auto expected_prefix = iox::concatenate(IOX_DEFAULT_RESOURCE_PREFIX, "_0_i_");

EXPECT_THAT(iceoryxResourcePrefix(DEFAULT_DOMAIN_ID, ResourceType::ICEORYX_DEFINED).c_str(),
StrEq(expected_prefix.c_str()));
}

TEST(PoshTypes_test, IceoryxResourcePrefixWithMaxDomainIdWorks)
{
::testing::Test::RecordProperty("TEST_ID", "049e79d7-d0ca-4951-8d44-c80aebab7a88");

const char* EXPECTED_PREFIX = experimental::hasExperimentalPoshFeaturesEnabled() ? "iox1_65535_i_" : "iox1_0_i_";
constexpr uint64_t CAPACITY{100};
char expected_prefix[CAPACITY];
snprintf(expected_prefix,
CAPACITY,
"%s_%s_i_",
IOX_DEFAULT_RESOURCE_PREFIX,
experimental::hasExperimentalPoshFeaturesEnabled() ? "65535" : "0");
expected_prefix[CAPACITY - 1] = 0;

EXPECT_THAT(
iceoryxResourcePrefix(DomainId{std::numeric_limits<uint16_t>::max()}, ResourceType::ICEORYX_DEFINED).c_str(),
StrEq(EXPECTED_PREFIX));
StrEq(expected_prefix));
}

TEST(PoshTypes_test, IceoryxResourcePrefixWithMaxDomainIdAndUserDefinedResourceTypeWorks)
{
::testing::Test::RecordProperty("TEST_ID", "b63bbdca-ff19-41bc-9f8a-c657b0ee8009");

const char* EXPECTED_PREFIX = experimental::hasExperimentalPoshFeaturesEnabled() ? "iox1_65535_u_" : "iox1_0_u_";
constexpr uint64_t CAPACITY{100};
char expected_prefix[CAPACITY];
snprintf(expected_prefix,
CAPACITY,
"%s_%s_u_",
IOX_DEFAULT_RESOURCE_PREFIX,
experimental::hasExperimentalPoshFeaturesEnabled() ? "65535" : "0");
expected_prefix[CAPACITY - 1] = 0;

EXPECT_THAT(
iceoryxResourcePrefix(DomainId{std::numeric_limits<uint16_t>::max()}, ResourceType::USER_DEFINED).c_str(),
StrEq(EXPECTED_PREFIX));
StrEq(expected_prefix));
}

0 comments on commit e880982

Please sign in to comment.