iceoryx_doc  1.0.1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
iox::runtime::IpcInterfaceBase Class Reference

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>

Inheritance diagram for iox::runtime::IpcInterfaceBase:
Inheritance graph
[legend]

Public Member Functions

bool receive (IpcMessage &answer) const noexcept
 Receives a message from the IPC channel and stores it in answer. More...
 
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. More...
 
bool send (const IpcMessage &msg) const noexcept
 Tries to send the message specified in msg. More...
 
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. More...
 
const RuntimeName_t & getRuntimeName () const noexcept
 Returns the interface name, the unique char string which explicitly identifies the IPC channel. More...
 
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. More...
 

Static Public Member 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. More...
 

Protected Member 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. More...
 
bool ipcChannelMapsToFile () noexcept
 Checks if the IPC channel has its counterpart in the file system. More...
 
 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
 
 IpcInterfaceBase (const IpcInterfaceBase &)=delete
 delete copy and move ctor and assignment since they are not needed
 
 IpcInterfaceBase (IpcInterfaceBase &&)=delete
 
IpcInterfaceBaseoperator= (const IpcInterfaceBase &)=delete
 
IpcInterfaceBaseoperator= (IpcInterfaceBase &&)=delete
 
bool openIpcChannel (const posix::IpcChannelSide channelSide) noexcept
 Opens a IPC channel and default permissions stored in m_perms and stores the descriptor. More...
 
bool closeIpcChannel () noexcept
 Closes a IPC channel. More...
 
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. More...
 

Static Protected Member Functions

static bool setMessageFromString (const char *buffer, IpcMessage &answer) noexcept
 Set the content of answer from buffer. More...
 

Protected Attributes

RuntimeName_t m_runtimeName
 
uint64_t m_maxMessageSize {0U}
 
uint64_t m_maxMessages {0U}
 
iox::posix::IpcChannelSide m_channelSide {posix::IpcChannelSide::CLIENT}
 
IpcChannelType m_ipcChannel
 

Friends

class IpcInterfaceUser
 
class IpcInterfaceCreator
 
class IpcRuntimeInterface
 

Detailed Description

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

Member Function Documentation

◆ cleanupOutdatedIpcChannel()

static void iox::runtime::IpcInterfaceBase::cleanupOutdatedIpcChannel ( const RuntimeName_t &  name)
staticnoexcept

Since there might be an outdated IPC channel due to an unclean temination this function closes the IPC channel if it's existing.

Parameters
[in]nameof the IPC channel to clean up

◆ closeIpcChannel()

bool iox::runtime::IpcInterfaceBase::closeIpcChannel ( )
protectednoexcept

Closes a IPC channel.

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

◆ getRuntimeName()

const RuntimeName_t& iox::runtime::IpcInterfaceBase::getRuntimeName ( ) const
noexcept

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

Returns
name of the IPC channel

◆ hasClosableIpcChannel()

bool iox::runtime::IpcInterfaceBase::hasClosableIpcChannel ( ) const
protectednoexcept

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.

◆ ipcChannelMapsToFile()

bool iox::runtime::IpcInterfaceBase::ipcChannelMapsToFile ( )
protectednoexcept

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

◆ isInitialized()

bool iox::runtime::IpcInterfaceBase::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

◆ openIpcChannel()

bool iox::runtime::IpcInterfaceBase::openIpcChannel ( const posix::IpcChannelSide  channelSide)
protectednoexcept

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

Parameters
[in]channelSideof 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.

◆ receive()

bool iox::runtime::IpcInterfaceBase::receive ( IpcMessage answer) const
noexcept

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

Parameters
[out]answerIf a message is received it is stored there.
Returns
If the call failed or an invalid message was received it returns false, otherwise true.

◆ reopen()

bool iox::runtime::IpcInterfaceBase::reopen ( )
protectednoexcept

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

◆ send()

bool iox::runtime::IpcInterfaceBase::send ( const IpcMessage msg) const
noexcept

Tries to send the message specified in msg.

Parameters
[in]msgMust 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.

◆ setMessageFromString()

static bool iox::runtime::IpcInterfaceBase::setMessageFromString ( const char *  buffer,
IpcMessage answer 
)
staticprotectednoexcept

Set the content of answer from buffer.

Parameters
[in]bufferRaw message as char pointer
[out]answerRaw message is setting this IpcMessage
Returns
answer.isValid()

◆ timedReceive()

bool iox::runtime::IpcInterfaceBase::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
[in]timeoutfor receiving a message.
[in]answerThe 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

◆ timedSend()

bool iox::runtime::IpcInterfaceBase::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
[in]msgMust be a valid message, if its an invalid message send will return false
[in]timeoutspecifies 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.

The documentation for this class was generated from the following file: