Skip to content

iox::runtime::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. More...

#include <ipc_interface_base.hpp>

Inherited by iox::runtime::IpcInterfaceCreator, iox::runtime::IpcInterfaceUser

Public Functions🔗

Name
bool receive(IpcMessage & answer) const
Receives a message from the IPC channel and stores it in answer.
bool timedReceive(const units::Duration timeout, IpcMessage & answer) const
Tries to receive a message from the IPC channel within a specified timeout. It stores the message in answer.
bool send(const IpcMessage & msg) const
Tries to send the message specified in msg.
bool timedSend(const IpcMessage & msg, const units::Duration timeout) const
Tries to send the message specified in msg to the message queue within a specified timeout.
const RuntimeName_t & getRuntimeName() const
Returns the interface name, the unique char string which explicitly identifies the IPC channel.
bool isInitialized() const
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.
void cleanupOutdatedIpcChannel(const RuntimeName_t & name)
Since there might be an outdated IPC channel due to an unclean temination this function closes the IPC channel if it's existing.

Protected Functions🔗

Name
bool reopen()
Closes and opens an existing IPC channel using the same parameters as before. If the queue was not open, it is just openened.
bool ipcChannelMapsToFile()
Checks if the IPC channel has its counterpart in the file system.
IpcInterfaceBase()
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)
virtual ~IpcInterfaceBase() =default
IpcInterfaceBase(const IpcInterfaceBase & )
delete copy and move ctor and assignment since they are not needed
IpcInterfaceBase(IpcInterfaceBase && )
IpcInterfaceBase & operator=(const IpcInterfaceBase & )
IpcInterfaceBase & operator=(IpcInterfaceBase && )
bool openIpcChannel(const posix::IpcChannelSide channelSide)
Opens a IPC channel and default permissions stored in m_perms and stores the descriptor.
bool closeIpcChannel()
Closes a IPC channel.
bool hasClosableIpcChannel() const
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.
bool setMessageFromString(const char * buffer, IpcMessage & answer)
Set the content of answer from buffer.

Protected Attributes🔗

Name
RuntimeName_t m_runtimeName
uint64_t m_maxMessageSize
uint64_t m_maxMessages
iox::posix::IpcChannelSide m_channelSide
IpcChannelType m_ipcChannel

Friends🔗

Name
class IpcInterfaceUser
class IpcInterfaceCreator
class IpcRuntimeInterface

Detailed Description🔗

class iox::runtime::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

Public Functions Documentation🔗

function receive🔗

bool receive(
    IpcMessage & answer
) const

Receives a message from the IPC channel and stores it in answer.

Parameters:

  • answer If a message is received it is stored there.

Return: If the call failed or an invalid message was received it returns false, otherwise true.

function timedReceive🔗

bool timedReceive(
    const units::Duration timeout,
    IpcMessage & answer
) const

Tries to receive a message from the IPC channel within a specified timeout. It stores the message in answer.

Parameters:

  • timeout for receiving a message.
  • answer The answer of the IPC channel. If timedReceive failed the content of answer is undefined.

Return: If a valid message was received before the timeout occures it returns true, otherwise false. It also returns false if clock_gettime() failed

function send🔗

bool send(
    const IpcMessage & msg
) const

Tries to send the message specified in msg.

Parameters:

  • msg Must be a valid message, if its an invalid message send will return false

Return: If a valid message was send it returns true, otherwise if the message was invalid it will return false.

function timedSend🔗

bool timedSend(
    const IpcMessage & msg,
    const units::Duration timeout
) const

Tries to send the message specified in msg to the message queue within a specified timeout.

Parameters:

  • msg Must be a valid message, if its an invalid message send will return false
  • timeout specifies the duration to wait for sending.

Return: If a valid message was send it returns true, otherwise if the message was invalid it will return false.

function getRuntimeName🔗

const RuntimeName_t & getRuntimeName() const

Returns the interface name, the unique char string which explicitly identifies the IPC channel.

Return: name of the IPC channel

function isInitialized🔗

bool isInitialized() const

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.

Return: initialization state

function cleanupOutdatedIpcChannel🔗

static void cleanupOutdatedIpcChannel(
    const RuntimeName_t & name
)

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 of the IPC channel to clean up

Protected Functions Documentation🔗

function reopen🔗

bool reopen()

Closes and opens an existing IPC channel using the same parameters as before. If the queue was not open, it is just openened.

Return: true if successfully reopened, false if not

function ipcChannelMapsToFile🔗

bool ipcChannelMapsToFile()

Checks if the IPC channel has its counterpart in the file system.

Return: 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

function IpcInterfaceBase🔗

IpcInterfaceBase()

The default constructor is explicitly deleted since every IPC channel needs a unique string to be identified with.

function IpcInterfaceBase🔗

IpcInterfaceBase(
    const RuntimeName_t & runtimeName,
    const uint64_t maxMessages,
    const uint64_t messageSize
)

function ~IpcInterfaceBase🔗

virtual ~IpcInterfaceBase() =default

function IpcInterfaceBase🔗

IpcInterfaceBase(
    const IpcInterfaceBase & 
)

delete copy and move ctor and assignment since they are not needed

function IpcInterfaceBase🔗

IpcInterfaceBase(
    IpcInterfaceBase && 
)

function operator=🔗

IpcInterfaceBase & operator=(
    const IpcInterfaceBase & 
)

function operator=🔗

IpcInterfaceBase & operator=(
    IpcInterfaceBase && 
)

function openIpcChannel🔗

bool openIpcChannel(
    const posix::IpcChannelSide channelSide
)

Opens a IPC channel and default permissions stored in m_perms and stores the descriptor.

Parameters:

  • channelSide 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

Return: Returns true if a IPC channel could be opened, otherwise false.

function closeIpcChannel🔗

bool closeIpcChannel()

Closes a IPC channel.

Return: Returns true if the IPC channel could be closed, otherwise false.

function hasClosableIpcChannel🔗

bool hasClosableIpcChannel() const

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.

Return: Returns true if the IPC channel is closable, otherwise false.

function setMessageFromString🔗

static bool setMessageFromString(
    const char * buffer,
    IpcMessage & answer
)

Set the content of answer from buffer.

Parameters:

  • buffer Raw message as char pointer
  • answer Raw message is setting this IpcMessage

Return: answer.isValid()

Protected Attributes Documentation🔗

variable m_runtimeName🔗

RuntimeName_t m_runtimeName;

variable m_maxMessageSize🔗

uint64_t m_maxMessageSize {0U};

variable m_maxMessages🔗

uint64_t m_maxMessages {0U};

variable m_channelSide🔗

iox::posix::IpcChannelSide m_channelSide {posix::IpcChannelSide::CLIENT};

variable m_ipcChannel🔗

IpcChannelType m_ipcChannel;

Friends🔗

friend IpcInterfaceUser🔗

friend class IpcInterfaceUser;

friend IpcInterfaceCreator🔗

friend class IpcInterfaceCreator;

friend IpcRuntimeInterface🔗

friend class IpcRuntimeInterface;

Updated on 17 June 2021 at 11:15:27 CEST