Class IpcInterfaceBase
Defined in File ipc_interface_base.hpp
Inheritance Relationships
Derived Types
public iox::runtime::IpcInterfaceCreator(Class IpcInterfaceCreator)public iox::runtime::IpcInterfaceUser(Class IpcInterfaceUser)
Class Documentation
-
class IpcInterfaceBase
Base-Class should never be used by the end-user. Handles the common properties and methods for the childs. The handling of the IPC channels must be done by the children.
Note
This class won’t uniquely identify if another object is using the same IPC channel
Subclassed by iox::runtime::IpcInterfaceCreator, iox::runtime::IpcInterfaceUser
Public Functions
-
bool receive(IpcMessage &answer) const noexcept
Receives a message from the IPC channel and stores it in answer.
- Parameters:
answer – [out] If a message is received it is stored there.
- Returns:
If the call failed or an invalid message was received it returns false, otherwise true.
-
bool timedReceive(const units::Duration timeout, IpcMessage &answer) const noexcept
Tries to receive a message from the IPC channel within a specified timeout. It stores the message in answer.
- Parameters:
timeout – [in] for receiving a message.
answer – [in] The answer of the IPC channel. If timedReceive failed the content of answer is undefined.
- Returns:
If a valid message was received before the timeout occures it returns true, otherwise false. It also returns false if clock_gettime() failed
-
bool send(const IpcMessage &msg) const noexcept
Tries to send the message specified in msg.
- Parameters:
msg – [in] Must be a valid message, if its an invalid message send will return false
- Returns:
If a valid message was send it returns true, otherwise if the message was invalid it will return false.
-
bool timedSend(const IpcMessage &msg, const units::Duration timeout) const noexcept
Tries to send the message specified in msg to the message queue within a specified timeout.
- Parameters:
msg – [in] Must be a valid message, if its an invalid message send will return false
timeout – [in] specifies the duration to wait for sending.
- Returns:
If a valid message was send it returns true, otherwise if the message was invalid it will return false.
-
const RuntimeName_t &getRuntimeName() const noexcept
Returns the interface name, the unique char string which explicitly identifies the IPC channel.
- Returns:
name of the IPC channel
-
bool isInitialized() const noexcept
If the IPC channel could not be opened or linked in the constructor it will return false, otherwise true. This is needed since the constructor is not allowed to throw an exception. You should always check a IPC channel with isInitialized before using it, since all other methods will fail and return false if a message could not be successfully initialized.
- Returns:
initialization state
Public Static Functions
-
static void cleanupOutdatedIpcChannel(const RuntimeName_t &name) noexcept
Since there might be an outdated IPC channel due to an unclean temination this function closes the IPC channel if it’s existing.
- Parameters:
name – [in] of the IPC channel to clean up
Protected Functions
-
bool reopen() noexcept
Closes and opens an existing IPC channel using the same parameters as before. If the queue was not open, it is just openened.
- Returns:
true if successfully reopened, false if not
-
bool ipcChannelMapsToFile() noexcept
Checks if the IPC channel has its counterpart in the file system.
- Returns:
If the IPC channel, which corresponds to a descriptor, is still availabe in the file system it returns true, otherwise it was deleted or the IPC channel was not open and returns false
-
IpcInterfaceBase() = delete
The default constructor is explicitly deleted since every IPC channel needs a unique string to be identified with.
-
IpcInterfaceBase(const RuntimeName_t &runtimeName, const uint64_t maxMessages, const uint64_t messageSize) noexcept
-
virtual ~IpcInterfaceBase() noexcept = default
-
IpcInterfaceBase(const IpcInterfaceBase&) = delete
delete copy and move ctor and assignment since they are not needed
-
IpcInterfaceBase(IpcInterfaceBase&&) = delete
-
IpcInterfaceBase &operator=(const IpcInterfaceBase&) = delete
-
IpcInterfaceBase &operator=(IpcInterfaceBase&&) = delete
-
bool openIpcChannel(const posix::IpcChannelSide channelSide) noexcept
Opens a IPC channel and default permissions stored in m_perms and stores the descriptor.
- Parameters:
channelSide – [in] of the queue. SERVER will also destroy the IPC channel in the dTor, while CLIENT keeps the IPC channel in the file system after the dTor is called
- Returns:
Returns true if a IPC channel could be opened, otherwise false.
-
bool closeIpcChannel() noexcept
Closes a IPC channel.
- Returns:
Returns true if the IPC channel could be closed, otherwise false.
-
bool hasClosableIpcChannel() const noexcept
If a IPC channel was moved then m_runtimeName was cleared and this object gave up the control of that specific IPC channel and therefore shouldnt unlink or close it. Otherwise the object which it was moved to can end up with an invalid IPC channel descriptor.
- Returns:
Returns true if the IPC channel is closable, otherwise false.
Protected Attributes
-
RuntimeName_t m_runtimeName
-
uint64_t m_maxMessageSize = {0U}
-
uint64_t m_maxMessages = {0U}
-
iox::posix::IpcChannelSide m_channelSide = {posix::IpcChannelSide::CLIENT}
-
platform::IoxIpcChannelType m_ipcChannel
Protected Static Functions
-
static bool setMessageFromString(const char *buffer, IpcMessage &answer) noexcept
Set the content of answer from buffer.
- Parameters:
buffer – [in] Raw message as char pointer
answer – [out] Raw message is setting this IpcMessage
- Returns:
answer.isValid()
Friends
- friend class IpcInterfaceUser
- friend class IpcInterfaceCreator
- friend class IpcRuntimeInterface
-
bool receive(IpcMessage &answer) const noexcept