Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2185 Use 'iox1' prefix for the ipc channels
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Feb 12, 2024
1 parent 61a2cf7 commit beacc98
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ IpcMessageErrorType stringToIpcMessageErrorType(const char* str) noexcept;
/// @param[in] msg enum value to convert
std::string IpcMessageErrorTypeToString(const IpcMessageErrorType msg) noexcept;

/// @brief Transforms an IPC channel name to a prefixed interface name
/// @param[in] channelName the name of the channel without the 'iox1_#_' prefix
/// @return the interface name with the 'iox1_#_' prefix or a 'nullopt' if the resulting name would be too long
iox::optional<RuntimeName_t> ipcChannelNameToInterfaceName(RuntimeName_t channelName);

class IpcInterfaceUser;
class IpcInterfaceCreator;

Expand Down Expand Up @@ -263,6 +268,7 @@ class IpcInterface
bool hasClosableIpcChannel() const noexcept;

protected:
RuntimeName_t m_interfaceName;
RuntimeName_t m_runtimeName;
uint64_t m_maxMessageSize{0U};
uint64_t m_maxMessages{0U};
Expand Down
41 changes: 33 additions & 8 deletions iceoryx_posh/source/runtime/ipc_interface_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,34 @@ std::string IpcMessageErrorTypeToString(const IpcMessageErrorType msg) noexcept
return convert::toString(static_cast<UnderlyingType>(msg));
}

iox::optional<RuntimeName_t> ipcChannelNameToInterfaceName(RuntimeName_t channelName)
{
iox::string<1> uniqueRoudiIdString{TruncateToCapacity,
iox::convert::toString(roudi::DEFAULT_UNIQUE_ROUDI_ID).c_str()};
RuntimeName_t interfaceName = concatenate(ICEORYX_RESOURCE_PREFIX, "_", uniqueRoudiIdString, "_");
if (interfaceName.size() + channelName.size() > RuntimeName_t::capacity())
{
return nullopt;
}
interfaceName.append(TruncateToCapacity, channelName);
return interfaceName;
}

template <typename IpcChannelType>
IpcInterface<IpcChannelType>::IpcInterface(const RuntimeName_t& runtimeName,
const uint64_t maxMessages,
const uint64_t messageSize) noexcept
: m_runtimeName(runtimeName)
: m_interfaceName(
ipcChannelNameToInterfaceName(runtimeName)
.or_else([&runtimeName] {
IOX_LOG(FATAL,
"The runtime with the name '"
<< runtimeName.size()
<< "' would exceed the maximum allowed size when used with the 'iox1_#_' prefix!");
IOX_PANIC("The runtime name exceeds the max size");
})
.value())
, m_runtimeName(runtimeName)
{
m_maxMessages = maxMessages;
m_maxMessageSize = messageSize;
Expand All @@ -99,7 +122,8 @@ bool IpcInterface<IpcChannelType>::receive(IpcMessage& answer) const noexcept
{
if (!m_ipcChannel.has_value())
{
IOX_LOG(WARN, "Trying to receive data on an non-initialized IPC interface! Interface name: " << m_runtimeName);
IOX_LOG(WARN,
"Trying to receive data on an non-initialized IPC interface! Interface name: " << m_interfaceName);
return false;
}

Expand All @@ -117,7 +141,8 @@ bool IpcInterface<IpcChannelType>::timedReceive(const units::Duration timeout, I
{
if (!m_ipcChannel.has_value())
{
IOX_LOG(WARN, "Trying to receive data on an non-initialized IPC interface! Interface name: " << m_runtimeName);
IOX_LOG(WARN,
"Trying to receive data on an non-initialized IPC interface! Interface name: " << m_interfaceName);
return false;
}

Expand Down Expand Up @@ -146,7 +171,7 @@ bool IpcInterface<IpcChannelType>::send(const IpcMessage& msg) const noexcept
{
if (!m_ipcChannel.has_value())
{
IOX_LOG(WARN, "Trying to send data on an non-initialized IPC interface! Interface name: " << m_runtimeName);
IOX_LOG(WARN, "Trying to send data on an non-initialized IPC interface! Interface name: " << m_interfaceName);
return false;
}

Expand All @@ -173,7 +198,7 @@ bool IpcInterface<IpcChannelType>::timedSend(const IpcMessage& msg, units::Durat
{
if (!m_ipcChannel.has_value())
{
IOX_LOG(WARN, "Trying to send data on an non-initialized IPC interface! Interface name: " << m_runtimeName);
IOX_LOG(WARN, "Trying to send data on an non-initialized IPC interface! Interface name: " << m_interfaceName);
return false;
}

Expand Down Expand Up @@ -214,7 +239,7 @@ bool IpcInterface<IpcChannelType>::openIpcChannel(const PosixIpcChannelSide chan

using IpcChannelBuilder_t = typename IpcChannelType::Builder_t;
IpcChannelBuilder_t()
.name(m_runtimeName)
.name(m_interfaceName)
.channelSide(m_channelSide)
.maxMsgSize(m_maxMessageSize)
.maxMsgNumber(m_maxMessages)
Expand All @@ -224,7 +249,7 @@ bool IpcInterface<IpcChannelType>::openIpcChannel(const PosixIpcChannelSide chan
if (this->m_channelSide == PosixIpcChannelSide::SERVER)
{
IOX_LOG(ERROR,
"Unable to create ipc channel '" << this->m_runtimeName
"Unable to create ipc channel '" << this->m_interfaceName
<< "'. Error code: " << static_cast<uint8_t>(err));
}
else
Expand All @@ -233,7 +258,7 @@ bool IpcInterface<IpcChannelType>::openIpcChannel(const PosixIpcChannelSide chan
// therefore resulting in a wall of error messages on the console which leads to missing the important
// one that roudi is not running if this would be LogLevel::ERROR instead of LogLevel::TRACE
IOX_LOG(TRACE,
"Unable to open ipc channel '" << this->m_runtimeName
"Unable to open ipc channel '" << this->m_interfaceName
<< "'. Error code: " << static_cast<uint8_t>(err));
}
});
Expand Down
11 changes: 6 additions & 5 deletions iceoryx_posh/source/runtime/ipc_interface_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,30 @@ IpcInterfaceCreator::IpcInterfaceCreator(const RuntimeName_t& runtimeName,
const uint64_t messageSize) noexcept
: IpcInterfaceBase(runtimeName, maxMessages, messageSize)
, m_fileLock(std::move(FileLockBuilder()
.name(runtimeName)
.name(m_interfaceName)
.permission(iox::perms::owner_read | iox::perms::owner_write)
.create()
.or_else([&runtimeName](auto& error) {
.or_else([this](auto& error) {
if (error == FileLockError::LOCKED_BY_OTHER_PROCESS)
{
IOX_LOG(FATAL,
"An application with the name " << runtimeName
"An application with the name " << m_runtimeName
<< " is still running. Using the "
"same name twice is not supported.");
IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__APP_WITH_SAME_NAME_STILL_RUNNING);
}
else
{
IOX_LOG(FATAL, "Error occurred while acquiring file lock named " << runtimeName);
IOX_LOG(FATAL,
"Error occurred while acquiring file lock named " << m_interfaceName);
IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__COULD_NOT_ACQUIRE_FILE_LOCK);
}
})
.value()))
{
// check if the IPC channel is still there (e.g. because of no proper termination
// of the process)
cleanupOutdatedIpcChannel(runtimeName);
cleanupOutdatedIpcChannel(m_interfaceName);

openIpcChannel(PosixIpcChannelSide::SERVER);
}
Expand Down

0 comments on commit beacc98

Please sign in to comment.