Skip to content

Commit e880982

Browse files
authored
Merge pull request #2273 from elBoberido/iox-2272-compile-time-resource-prefix
iox-#2272 Make iceoryx resource prefix a compile time option
2 parents e1c82d6 + 4be9a7b commit e880982

File tree

10 files changed

+43
-14
lines changed

10 files changed

+43
-14
lines changed

doc/website/release-notes/iceoryx-unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
- Add support for `iox::string` in `MessageQueue` and created `message_queue.inl` [#1963](https://github.com/eclipse-iceoryx/iceoryx/issues/1963)
6464
- Add support for `iox::string` in `NamedPipe` and created `named_pipe.inl` [#1693](https://github.com/eclipse-iceoryx/iceoryx/issues/1693)
6565
- Add an `iox1` prefix to all resources created by `iceoryx_posh` and `RouDi` [#2185](https://github.com/eclipse-iceoryx/iceoryx/issues/2185)
66+
- Make iceoryx resource prefix a compile time option [#2272](https://github.com/eclipse-iceoryx/iceoryx/issues/2272)
6667

6768
**Bugfixes:**
6869

iceoryx_platform/mac/include/iceoryx_platform/signal.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,4 @@
1919

2020
#include <signal.h>
2121

22-
inline void psignal(int sig, const char* s)
23-
{
24-
psignal(static_cast<unsigned int>(sig), s);
25-
}
26-
2722
#endif // IOX_HOOFS_MAC_PLATFORM_SIGNAL_HPP

iceoryx_posh/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ configure_file(
2929
# FIXME: for values see "iceoryx_posh/cmake/IceoryxPoshDeployment.cmake" ... for now some nice defaults
3030
"@platforms//os:macos": {
3131
"IOX_COMMUNICATION_POLICY": "ManyToManyPolicy",
32+
"IOX_DEFAULT_RESOURCE_PREFIX": "iox1",
3233
"IOX_EXPERIMENTAL_POSH_FLAG": "false",
3334
"IOX_MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY": "8",
3435
"IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY": "256",
@@ -55,6 +56,7 @@ configure_file(
5556
},
5657
"//conditions:default": {
5758
"IOX_COMMUNICATION_POLICY": "ManyToManyPolicy",
59+
"IOX_DEFAULT_RESOURCE_PREFIX": "iox1",
5860
"IOX_EXPERIMENTAL_POSH_FLAG": "false",
5961
"IOX_MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY": "8",
6062
"IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY": "256",

iceoryx_posh/cmake/IceoryxPoshDeployment.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ configure_option(
132132
DEFAULT_VALUE 4
133133
)
134134

135+
configure_option(
136+
NAME IOX_DEFAULT_RESOURCE_PREFIX
137+
DEFAULT_VALUE "iox1"
138+
)
139+
135140
if(IOX_EXPERIMENTAL_POSH)
136141
set(IOX_EXPERIMENTAL_POSH_FLAG true)
137142
else()

iceoryx_posh/cmake/iceoryx_posh_deployment.hpp.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ constexpr uint32_t IOX_MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY =
6565
constexpr uint32_t IOX_MAX_RESPONSE_QUEUE_CAPACITY = static_cast<uint32_t>(@IOX_MAX_RESPONSE_QUEUE_CAPACITY@);
6666
constexpr uint32_t IOX_MAX_REQUEST_QUEUE_CAPACITY = static_cast<uint32_t>(@IOX_MAX_REQUEST_QUEUE_CAPACITY@);
6767
constexpr uint32_t IOX_MAX_CLIENTS_PER_SERVER = static_cast<uint32_t>(@IOX_MAX_CLIENTS_PER_SERVER@);
68-
constexpr bool IOX_EXPERIMENTAL_POSH_FLAG = @IOX_EXPERIMENTAL_POSH_FLAG@;
6968
constexpr uint32_t IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY = static_cast<uint32_t>(@IOX_MAX_REQUESTS_PROCESSED_SIMULTANEOUSLY@);
69+
constexpr const char IOX_DEFAULT_RESOURCE_PREFIX[] = "@IOX_DEFAULT_RESOURCE_PREFIX@";
70+
constexpr bool IOX_EXPERIMENTAL_POSH_FLAG = @IOX_EXPERIMENTAL_POSH_FLAG@;
7071
// clang-format on
7172
} // namespace build
7273
} // namespace iox

iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ constexpr const char SERVICE_DISCOVERY_INSTANCE_NAME[] = "RouDi_ID";
143143
constexpr const char SERVICE_DISCOVERY_EVENT_NAME[] = "ServiceRegistry";
144144

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

148148
// Nodes
149149
constexpr uint32_t MAX_NODE_NAME_LENGTH = build::IOX_MAX_NODE_NAME_LENGTH;
@@ -221,7 +221,7 @@ IOX_NEW_TYPE(DomainId,
221221

222222
constexpr DomainId DEFAULT_DOMAIN_ID{0};
223223

224-
constexpr const char ICEORYX_RESOURCE_PREFIX[] = "iox1";
224+
using build::IOX_DEFAULT_RESOURCE_PREFIX;
225225

226226
/// @brief The resource type is used to customize the resource prefix by adding an 'i' or 'u' depending whether the
227227
/// resource is defined by iceoryx, e.g. the roudi IPC channel, or by the user, e.g. the runtime name. This shall

iceoryx_posh/source/iceoryx_posh_types.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// SPDX-License-Identifier: Apache-2.0
1616

1717
#include "iceoryx_posh/iceoryx_posh_types.hpp"
18+
#include "iox/size.hpp"
1819

1920
#include <atomic>
2021

@@ -23,6 +24,8 @@ namespace iox
2324

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

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

4346
namespace experimental

iceoryx_posh/source/roudi/roudi.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ void RouDi::processRuntimeMessages(runtime::IpcInterfaceCreator&& roudiIpcInterf
249249

250250
setThreadName("IPC-msg-process");
251251

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

iceoryx_posh/source/runtime/posh_runtime_impl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ PoshRuntimeImpl::PoshRuntimeImpl(optional<const RuntimeName_t*> name,
5252
"KeepAlive",
5353
*this,
5454
&PoshRuntimeImpl::sendKeepAliveAndHandleShutdownPreparation);
55+
56+
IOX_LOG(DEBUG, "Resource prefix: " << IOX_DEFAULT_RESOURCE_PREFIX);
5557
}
5658

5759
PoshRuntimeImpl::PoshRuntimeImpl(optional<const RuntimeName_t*> name,
@@ -113,6 +115,7 @@ PoshRuntimeImpl::PoshRuntimeImpl(optional<const RuntimeName_t*> name,
113115
std::move(shmInterface)};
114116
}())
115117
{
118+
IOX_LOG(INFO, "Domain ID: " << static_cast<DomainId::value_type>(domainId));
116119
}
117120

118121
PoshRuntimeImpl::~PoshRuntimeImpl() noexcept

iceoryx_posh/test/moduletests/test_posh_types.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,44 @@ TEST(PoshTypes_test, IceoryxResourcePrefixWithDefaultDomainIdWorks)
2525
{
2626
::testing::Test::RecordProperty("TEST_ID", "35f1d638-8efa-41dd-859b-bcc23450844f");
2727

28-
EXPECT_THAT(iceoryxResourcePrefix(DEFAULT_DOMAIN_ID, ResourceType::ICEORYX_DEFINED).c_str(), StrEq("iox1_0_i_"));
28+
const auto expected_prefix = iox::concatenate(IOX_DEFAULT_RESOURCE_PREFIX, "_0_i_");
29+
30+
EXPECT_THAT(iceoryxResourcePrefix(DEFAULT_DOMAIN_ID, ResourceType::ICEORYX_DEFINED).c_str(),
31+
StrEq(expected_prefix.c_str()));
2932
}
3033

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

35-
const char* EXPECTED_PREFIX = experimental::hasExperimentalPoshFeaturesEnabled() ? "iox1_65535_i_" : "iox1_0_i_";
38+
constexpr uint64_t CAPACITY{100};
39+
char expected_prefix[CAPACITY];
40+
snprintf(expected_prefix,
41+
CAPACITY,
42+
"%s_%s_i_",
43+
IOX_DEFAULT_RESOURCE_PREFIX,
44+
experimental::hasExperimentalPoshFeaturesEnabled() ? "65535" : "0");
45+
expected_prefix[CAPACITY - 1] = 0;
3646

3747
EXPECT_THAT(
3848
iceoryxResourcePrefix(DomainId{std::numeric_limits<uint16_t>::max()}, ResourceType::ICEORYX_DEFINED).c_str(),
39-
StrEq(EXPECTED_PREFIX));
49+
StrEq(expected_prefix));
4050
}
4151

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

46-
const char* EXPECTED_PREFIX = experimental::hasExperimentalPoshFeaturesEnabled() ? "iox1_65535_u_" : "iox1_0_u_";
56+
constexpr uint64_t CAPACITY{100};
57+
char expected_prefix[CAPACITY];
58+
snprintf(expected_prefix,
59+
CAPACITY,
60+
"%s_%s_u_",
61+
IOX_DEFAULT_RESOURCE_PREFIX,
62+
experimental::hasExperimentalPoshFeaturesEnabled() ? "65535" : "0");
63+
expected_prefix[CAPACITY - 1] = 0;
4764

4865
EXPECT_THAT(
4966
iceoryxResourcePrefix(DomainId{std::numeric_limits<uint16_t>::max()}, ResourceType::USER_DEFINED).c_str(),
50-
StrEq(EXPECTED_PREFIX));
67+
StrEq(expected_prefix));
5168
}

0 commit comments

Comments
 (0)