Class ClientPortUser

Inheritance Relationships

Base Type

Class Documentation

class ClientPortUser : public iox::popo::BasePort

The ClientPortUser provides the API for accessing a client port from the user side. The client port is divided in the three parts ClientPortData, ClientPortRouDi and ClientPortUser. The ClientPortUser uses the functionality of a ChunkSender and ChunReceiver for sending requests and receiving responses. Additionally it provides the connect / disconnect API which controls whether the client port shall connect to the server.

Note

This class is not thread-safe and must be guarded by a mutex if used in a multithreaded context.

Public Types

using MemberType_t = ClientPortData

Public Functions

explicit ClientPortUser(MemberType_t &clientPortData) noexcept

Creates a ClientPortUser from ClientPortData which are shared with ClientPortRouDi.

Parameters:

clientPortData[in] to be are accessed by the ClientPortUser interface

ClientPortUser(const ClientPortUser &other) = delete
ClientPortUser &operator=(const ClientPortUser&) = delete
ClientPortUser(ClientPortUser &&rhs) noexcept = default
ClientPortUser &operator=(ClientPortUser &&rhs) noexcept = default
~ClientPortUser() = default
cxx::expected<RequestHeader*, AllocationError> allocateRequest(const uint32_t userPayloadSize, const uint32_t userPayloadAlignment) noexcept

Allocate a chunk, the ownerhip of the SharedChunk remains in the ClientPortUser for being able to cleanup if the user process disappears.

Parameters:
  • userPayloadSize, size[in] of the user-paylaod without additional headers

  • userPayloadAlignment, alignment[in] of the user-paylaod without additional headers

Returns:

on success pointer to a RequestHeader which can be used to access the chunk-header, user-header and user-payload fields, error if not

void releaseRequest(const RequestHeader *const requestHeader) noexcept

Releases an allocated request without sending it.

Parameters:

requestHeader, pointer[in] to the RequestHeader to free

cxx::expected<ClientSendError> sendRequest(RequestHeader *const requestHeader) noexcept

Send an allocated request chunk to the server port.

Parameters:

requestHeader, pointer[in] to the RequestHeader to send

Returns:

ClientSendError if sending was not successful

void connect() noexcept

try to connect to the server Caution: There can be delays between calling connect and a change in the connection state

myPort.connect();
while(myPort.getConnectionState() != ConnectionState::CONNECTED)
    sleep(1_s);
void disconnect() noexcept

disconnect from the server

ConnectionState getConnectionState() const noexcept

get the current connection state. Caution: There can be delays between calling connect and a change in the connection state. The connection state can also change without user interaction if the server comes and goes

Returns:

ConnectionState

cxx::expected<const ResponseHeader*, ChunkReceiveResult> getResponse() noexcept

Tries to get the next response from the queue. If there is a new one, the ResponseHeader of the oldest response in the queue is returned (FiFo queue)

Returns:

cxx::expected that has a new ResponseHeader if there are new responses in the underlying queue, ChunkReceiveResult on error

void releaseResponse(const ResponseHeader *const responseHeader) noexcept

Release a response that was obtained with getResponseChunk.

Parameters:

requestHeader, pointer[in] to the ResponseHeader to release

void releaseQueuedResponses() noexcept

Release all the responses that are currently queued up.

bool hasNewResponses() const noexcept

check if there are responses in the queue

Returns:

if there are responses in the queue return true, otherwise false

bool hasLostResponsesSinceLastCall() noexcept

check if there was a queue overflow since the last call of hasLostResponseChunks

Returns:

true if the underlying queue overflowed since last call of this method, otherwise false

void setConditionVariable(ConditionVariableData &conditionVariableData, const uint64_t notificationIndex) noexcept

set a condition variable (via its pointer) to the client

void unsetConditionVariable() noexcept

unset a condition variable from the client

bool isConditionVariableSet() const noexcept

check if there’s a condition variable set

Returns:

true if a condition variable attached, otherwise false