ConnectionAdapter

class kanzi::connect::ConnectionAdapter

An abstract class that acts as an interface to underlying network transport layer.

This class interface provides functionality to listen for connections, send and receive data.

Subclassed by SocketConnectionAdapter

Public Types

using Parameters = map<string, string>

Key-value pairs that can be used to configure an adapter.

Public Functions

ConnectionAdapter(ClientIdManager &clientIdManager)

Constructor.

~ConnectionAdapter()

Destructor.

void aboutToStop()

Invoked when the adapter should stop. Called before the object will be destroyed.

void addObserver(Observer *observer)

Adds observer to receive notifications.

Parameters
  • observer: Observer to add.

bool clientExists(size_t clientId)

Check whether a client identifier is valid one.

Return

True if client exists.

Parameters
  • clientId: Identifier of the client.

void configure(const Parameters &parameters) = 0

Configures adapter according to given parameters.

Parameters
  • parameters: Parameters for adapter.

void disconnect(size_t clientId) = 0

Terminates connection to given client.

If a file descriptor related to this client has been returned by the implementation then implementation must not closed the file descriptor. Instead it should mark the client disconnected and issue interrupt() call that will cause the disconnectPendingClients() to be invoked that can be used to close the file descriptors.

Parameters
  • clientId: Id of the client that will be disconnected.

void getClientSideParameters(vector<ClientSideParameter> &outputList) const

Get list of parameters on the client side that are user configurable.

Parameters
  • outputList: Contains the parameters

const string &getConnectionType() const = 0

Get the connection type identifier of this connection adapter.

Return

string which identifies the connection type (e.g. “socket”)

ConnectDomainSharedPtr getDomain() const

Retrieve the domain where class operates in.

Return

the domain. Will have non-null pointer after class is fully constructed. Ownership not transfered.

unsigned int getFileBlockSize() const

Get the file block size configured for this adapter.

Return

Maximum number of bytes for a single block when transferring file through the connection adapter

unsigned int getFileTransferTimeout() const

How long timeout should be used (milliseconds) when transferring file through this connection adapter.

Return

The timeout (milliseconds) for a file transfer

unsigned int getMaximumConnectionCount() const = 0

Get maximum number of simultaneous connections for this adapters connection type.

See

getConnectionType

shared_ptr<MessageTranslator> getNetworkTranslator(MessagePackage::SerializationFormat format = MessagePackage::SerializationFormatBinary)

Get message translator used with this connection adapter.

bool getParameterBool(const string &key, bool defaultValue = false) const

Gets a configuration boolean value.

Return

value from the configuration

Parameters
  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

int getParameterInt(const string &key, int defaultValue = 0) const

Gets a configuration integer value.

Return

value from the configuration

Parameters
  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

const string getParameterString(const string &key, const string defaultValue = string("")) const

Gets a configuration string value.

Return

value from the configuration

Parameters
  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

int getParameterUInt(const string &key, unsigned int defaultValue = 0) const

Gets a configuration integer value.

Return

value from the configuration

Parameters
  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

const string getRemoteIPAddress(size_t handle)

Gets the IP Address of the remote peer.

Return

IP address of the remote peer.

Parameters
  • handle: identifies the remote peer.

const string getTrustedPeerName() const

For SSL connections return the CN of the client peer certificate for other connections return “Unknown”.

Return

CN of the peer certificate

const string getType() const = 0

Retrieves the type of the adapter.

void interrupt() = 0

Allows to interrupt the wait loop and return from the blocking loop.

bool isReliable()

Must be overridden if adapter does not provide reliable transfer.

Return

true if reliable transfer is guaranteed.

void listen() = 0

Starts to listen for connections.

void releaseResources()

Potentially invoked before software is being terminated, the object itself might not get deleted in controlled manner (i.e.

destructors might not run at all). and this allows it to free system wide reserved resources (such as shared memory regions).

void removeObserver(Observer *observer)

Removes observer.

Parameters
  • observer: Observer to remove.

void send(size_t clientId, const vector<char> &data) = 0

Sends data to given client.

Parameters
  • clientId: Id of the client that will receive the data.

  • data: Data to send.

void setDomain(ConnectDomainSharedPtr domain)

Configure the domain for the class.

Parameters
  • domain: the domain. Ownership not transfered.

bool supportsListen()

Must be overridden to disable listening.

Return

true if server listens and handles incoming client connections.

void wait() = 0

Starts blocking loop that waits for work, should preserve resources & CPU.

void work() = 0

Performs all work that was received during the wait loop.

Public Static Functions

bool getConfigurationBool(const Parameters &parameters, const string &key, bool defaultValue = false)

Gets a configuration boolean value.

Return

value from the configuration

Parameters
  • parameters: the parameter set

  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

int getConfigurationInt(const Parameters &parameters, const string &key, int defaultValue = 0)

Gets a configuration integer value.

Return

value from the configuration

Parameters
  • parameters: the parameter set

  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

const string getConfigurationString(const Parameters &parameters, const string &key, const string defaultValue = string(""))

Gets a configuration string value.

Return

value from the configuration

Parameters
  • parameters: the parameter set

  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

int getConfigurationUInt(const Parameters &parameters, const string &key, unsigned int defaultValue = 0)

Gets a configuration integer value.

Return

value from the configuration

Parameters
  • parameters: the parameter set

  • key: the parameter key to get

  • defaultValue: value to return in case value with key is not found.

Public Static Attributes

const string FILE_BLOCK_SIZE_ATTRIBUTE_KEY

Parameter key for the file block size in the configuration parameters.

const string FILE_TRANSFER_TIMEOUT_KEY

Parameter key for the file transfer timeout in the configuration parameters.

struct ClientSideParameter

Public Functions

ClientSideParameter(const string &name, const string &value, const string &type, const string &displayName, const string &tooltip)

Public Members

string m_displayName
string m_name
string m_tooltip
string m_type
string m_value
class Observer

Observer class that is used for notifications such as new connections or data.

Subclassed by NetworkListener

Public Functions

bool clientExists(size_t clientId) const = 0

Check whether a client identifier is valid one.

Return

True if client exists.

Parameters
  • clientId: Identifier of the client.

void onConnected(size_t clientId, ConnectionAdapter &adapter)

Notification of a newly connected client.

Parameters
  • clientId: The id of the connected client.

void onDisconnected(size_t clientId, ConnectionAdapter &adapter)

Notification of a disconnected client.

Parameters
  • clientId: The id of the disconnected client.

void onReceive(size_t clientId, const vector<char> &data)

Notification of new data from a a client.

Parameters
  • clientId: The id of the client that sent the data.

  • data: The data that was received.