Kanzi Connect  1.1.10
Kanzi Connect C++ API
kanzi::connect::ConnectionAdapter Class Referenceabstract

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

#include <connection_adapter_server.hpp>

Inheritance diagram for kanzi::connect::ConnectionAdapter:
kanzi::connect::SocketConnectionAdapter

Classes

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

Public Types

using Parameters = map< string, string >
 Key-value pairs that can be used to configure an adapter. More...
 

Public Member Functions

virtual void aboutToStop ()
 Invoked when the adapter should stop. Called before the object will be destroyed. More...
 
void addObserver (Observer *observer)
 Adds observer to receive notifications. More...
 
virtual bool clientExists (size_t clientId)
 Check whether a client identifier is valid one. More...
 
virtual void configure (const Parameters &parameters)=0
 Configures adapter according to given parameters. More...
 
 ConnectionAdapter (ClientIdManager &clientIdManager)
 Constructor. More...
 
virtual void disconnect (size_t clientId)=0
 Terminates connection to given client. More...
 
virtual void getClientSideParameters (vector< ClientSideParameter > &outputList) const
 Get list of parameters on the client side that are user configurable. More...
 
virtual const string & getConnectionType () const =0
 Get the connection type identifier of this connection adapter. More...
 
ConnectDomaingetDomain () const
 Retrieve the domain where class operates in. More...
 
unsigned int getFileBlockSize () const
 Get the file block size configured for this adapter. More...
 
unsigned int getFileTransferTimeout () const
 How long timeout should be used (milliseconds) when transferring file through this connection adapter. More...
 
virtual unsigned int getMaximumConnectionCount () const =0
 Get maximum number of simultaneous connections for this adapters connection type. More...
 
bool getParameterBool (const string &key, bool defaultValue=false) const
 Gets a configuration boolean value. More...
 
int getParameterInt (const string &key, int defaultValue=0) const
 Gets a configuration integer value. More...
 
const string getParameterString (const string &key, const string defaultValue=string("")) const
 Gets a configuration string value. More...
 
int getParameterUInt (const string &key, unsigned int defaultValue=0) const
 Gets a configuration integer value. More...
 
virtual const string getRemoteIPAddress (size_t)
 Gets the IP Address of the remote peer. More...
 
virtual const string getTrustedPeerName () const
 For SSL connections return the CN of the client peer certificate for other connections return "Unknown". More...
 
virtual const string getType () const =0
 Retrieves the type of the adapter. More...
 
virtual void interrupt ()=0
 Allows to interrupt the wait loop and return from the blocking loop. More...
 
virtual bool isReliable ()
 Must be overridden if adapter does not provide reliable transfer. More...
 
virtual void listen ()=0
 Starts to listen for connections. More...
 
virtual void releaseResources ()
 Potentially invoked before software is being terminated, the object itself might not get deleted in controlled manner (i.e. More...
 
void removeObserver (Observer *observer)
 Removes observer. More...
 
virtual void send (size_t clientId, const vector< char > &data)=0
 Sends data to given client. More...
 
void setDomain (ConnectDomain *domain)
 Configure the domain for the class. More...
 
virtual void wait ()=0
 Starts blocking loop that waits for work, should preserve resources & CPU. More...
 
virtual void work ()=0
 Performs all work that was received during the wait loop. More...
 
virtual ~ConnectionAdapter ()
 Destructor. More...
 

Static Public Member Functions

static bool getConfigurationBool (const Parameters &parameters, const string &key, bool defaultValue=false)
 Gets a configuration boolean value. More...
 
static int getConfigurationInt (const Parameters &parameters, const string &key, int defaultValue=0)
 Gets a configuration integer value. More...
 
static const string getConfigurationString (const Parameters &parameters, const string &key, const string defaultValue=string(""))
 Gets a configuration string value. More...
 
static int getConfigurationUInt (const Parameters &parameters, const string &key, unsigned int defaultValue=0)
 Gets a configuration integer value. More...
 

Static Public Attributes

static const string FILE_BLOCK_SIZE_ATTRIBUTE_KEY
 Parameter key for the file block size in the configuration parameters. More...
 
static const string FILE_TRANSFER_TIMEOUT_KEY
 Parameter key for the file transfer timeout in the configuration parameters. More...
 

Protected Types

typedef vector< Observer * > ObserverContainer
 

Protected Member Functions

void notifyConnected (size_t clientId)
 Fires connected event for observers. More...
 
void notifyDisconnected (size_t clientId)
 Fires disconnected event for observers. More...
 
void notifyReceive (size_t clientId, const vector< char > &data)
 Fires receive event for observers. More...
 
void setParameter (const string &key, const int value)
 Set parameter value, create if does not yet exist. More...
 
void setParameter (const string &key, const string &value)
 Set parameter value, create if does not yet exist. More...
 

Protected Attributes

ClientIdManagerm_clientIdManager
 
ConnectDomainm_domain
 
recursive_mutex m_mutex
 
ObserverContainer m_observers
 
Parameters m_parameters
 Contains the configuration parameters for the connection adapter, regardless of adapter type. More...
 

Detailed Description

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.

Member Typedef Documentation

◆ ObserverContainer

◆ Parameters

using kanzi::connect::ConnectionAdapter::Parameters = map<string, string>

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

Constructor & Destructor Documentation

◆ ConnectionAdapter()

kanzi::connect::ConnectionAdapter::ConnectionAdapter ( ClientIdManager clientIdManager)

Constructor.

◆ ~ConnectionAdapter()

virtual kanzi::connect::ConnectionAdapter::~ConnectionAdapter ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ aboutToStop()

virtual void kanzi::connect::ConnectionAdapter::aboutToStop ( )
inlinevirtual

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

◆ addObserver()

void kanzi::connect::ConnectionAdapter::addObserver ( Observer observer)

Adds observer to receive notifications.

Parameters
observerObserver to add.

◆ clientExists()

virtual bool kanzi::connect::ConnectionAdapter::clientExists ( size_t  clientId)
virtual

Check whether a client identifier is valid one.

Parameters
clientIdIdentifier of the client.
Returns
True if client exists.

◆ configure()

virtual void kanzi::connect::ConnectionAdapter::configure ( const Parameters parameters)
pure virtual

Configures adapter according to given parameters.

Parameters
parametersParameters for adapter.

Implemented in kanzi::connect::SocketConnectionAdapter.

◆ disconnect()

virtual void kanzi::connect::ConnectionAdapter::disconnect ( size_t  clientId)
pure virtual

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
clientIdId of the client that will be disconnected.

Implemented in kanzi::connect::SocketConnectionAdapter.

◆ getClientSideParameters()

virtual void kanzi::connect::ConnectionAdapter::getClientSideParameters ( vector< ClientSideParameter > &  outputList) const
virtual

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

Parameters
outputListContains the parameters

Reimplemented in kanzi::connect::SocketConnectionAdapter.

◆ getConfigurationBool()

static bool kanzi::connect::ConnectionAdapter::getConfigurationBool ( const Parameters parameters,
const string &  key,
bool  defaultValue = false 
)
static

Gets a configuration boolean value.

Parameters
parametersthe parameter set
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getConfigurationInt()

static int kanzi::connect::ConnectionAdapter::getConfigurationInt ( const Parameters parameters,
const string &  key,
int  defaultValue = 0 
)
static

Gets a configuration integer value.

Parameters
parametersthe parameter set
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getConfigurationString()

static const string kanzi::connect::ConnectionAdapter::getConfigurationString ( const Parameters parameters,
const string &  key,
const string  defaultValue = string("") 
)
static

Gets a configuration string value.

Parameters
parametersthe parameter set
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getConfigurationUInt()

static int kanzi::connect::ConnectionAdapter::getConfigurationUInt ( const Parameters parameters,
const string &  key,
unsigned int  defaultValue = 0 
)
static

Gets a configuration integer value.

Parameters
parametersthe parameter set
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getConnectionType()

virtual const string& kanzi::connect::ConnectionAdapter::getConnectionType ( ) const
pure virtual

Get the connection type identifier of this connection adapter.

Returns
string which identifies the connection type (e.g. "socket")

Implemented in kanzi::connect::SocketConnectionAdapter.

◆ getDomain()

ConnectDomain* kanzi::connect::ConnectionAdapter::getDomain ( ) const

Retrieve the domain where class operates in.

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

◆ getFileBlockSize()

unsigned int kanzi::connect::ConnectionAdapter::getFileBlockSize ( ) const

Get the file block size configured for this adapter.

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

◆ getFileTransferTimeout()

unsigned int kanzi::connect::ConnectionAdapter::getFileTransferTimeout ( ) const

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

Returns
The timeout (milliseconds) for a file transfer

◆ getMaximumConnectionCount()

virtual unsigned int kanzi::connect::ConnectionAdapter::getMaximumConnectionCount ( ) const
pure virtual

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

See also
getConnectionType

Implemented in kanzi::connect::SocketConnectionAdapter.

◆ getParameterBool()

bool kanzi::connect::ConnectionAdapter::getParameterBool ( const string &  key,
bool  defaultValue = false 
) const

Gets a configuration boolean value.

Parameters
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getParameterInt()

int kanzi::connect::ConnectionAdapter::getParameterInt ( const string &  key,
int  defaultValue = 0 
) const

Gets a configuration integer value.

Parameters
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getParameterString()

const string kanzi::connect::ConnectionAdapter::getParameterString ( const string &  key,
const string  defaultValue = string("") 
) const

Gets a configuration string value.

Parameters
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getParameterUInt()

int kanzi::connect::ConnectionAdapter::getParameterUInt ( const string &  key,
unsigned int  defaultValue = 0 
) const

Gets a configuration integer value.

Parameters
keythe parameter key to get
defaultValuevalue to return in case value with key is not found.
Returns
value from the configuration

◆ getRemoteIPAddress()

virtual const string kanzi::connect::ConnectionAdapter::getRemoteIPAddress ( size_t  )
inlinevirtual

Gets the IP Address of the remote peer.

Parameters
handleidentifies the remote peer.
Returns
IP address of the remote peer.

Reimplemented in kanzi::connect::SocketConnectionAdapter.

◆ getTrustedPeerName()

virtual const string kanzi::connect::ConnectionAdapter::getTrustedPeerName ( ) const
inlinevirtual

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

Returns
CN of the peer certificate

◆ getType()

virtual const string kanzi::connect::ConnectionAdapter::getType ( ) const
pure virtual

Retrieves the type of the adapter.

◆ interrupt()

virtual void kanzi::connect::ConnectionAdapter::interrupt ( )
pure virtual

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

Implemented in kanzi::connect::SocketConnectionAdapter.

◆ isReliable()

virtual bool kanzi::connect::ConnectionAdapter::isReliable ( )
inlinevirtual

Must be overridden if adapter does not provide reliable transfer.

Returns
true if reliable transfer is guaranteed.

◆ listen()

virtual void kanzi::connect::ConnectionAdapter::listen ( )
pure virtual

Starts to listen for connections.

Implemented in kanzi::connect::SocketConnectionAdapter.

◆ notifyConnected()

void kanzi::connect::ConnectionAdapter::notifyConnected ( size_t  clientId)
protected

Fires connected event for observers.

Helper function for a derived class.

Parameters
clientIdId of the client that was connected.

◆ notifyDisconnected()

void kanzi::connect::ConnectionAdapter::notifyDisconnected ( size_t  clientId)
protected

Fires disconnected event for observers.

Helper function for a derived class.

Parameters
clientIdId of the client that was disconnected.

◆ notifyReceive()

void kanzi::connect::ConnectionAdapter::notifyReceive ( size_t  clientId,
const vector< char > &  data 
)
protected

Fires receive event for observers.

Helper function for a derived class.

Parameters
clientIdId of the client that sent the data.
dataData received.

◆ releaseResources()

virtual void kanzi::connect::ConnectionAdapter::releaseResources ( )
inlinevirtual

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).

◆ removeObserver()

void kanzi::connect::ConnectionAdapter::removeObserver ( Observer observer)

Removes observer.

Parameters
observerObserver to remove.

◆ send()

virtual void kanzi::connect::ConnectionAdapter::send ( size_t  clientId,
const vector< char > &  data 
)
pure virtual

Sends data to given client.

Parameters
clientIdId of the client that will receive the data.
dataData to send.

◆ setDomain()

void kanzi::connect::ConnectionAdapter::setDomain ( ConnectDomain domain)

Configure the domain for the class.

Parameters
domainthe domain. Ownership not transfered.

◆ setParameter() [1/2]

void kanzi::connect::ConnectionAdapter::setParameter ( const string &  key,
const int  value 
)
protected

Set parameter value, create if does not yet exist.

Parameters
keyIdentifies the value
valueThe value to set

◆ setParameter() [2/2]

void kanzi::connect::ConnectionAdapter::setParameter ( const string &  key,
const string &  value 
)
protected

Set parameter value, create if does not yet exist.

Parameters
keyIdentifies the value
valueThe value to set

◆ wait()

virtual void kanzi::connect::ConnectionAdapter::wait ( )
pure virtual

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

Implemented in kanzi::connect::SocketConnectionAdapter.

◆ work()

virtual void kanzi::connect::ConnectionAdapter::work ( )
pure virtual

Performs all work that was received during the wait loop.

Implemented in kanzi::connect::SocketConnectionAdapter.

Member Data Documentation

◆ FILE_BLOCK_SIZE_ATTRIBUTE_KEY

const string kanzi::connect::ConnectionAdapter::FILE_BLOCK_SIZE_ATTRIBUTE_KEY
static

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

◆ FILE_TRANSFER_TIMEOUT_KEY

const string kanzi::connect::ConnectionAdapter::FILE_TRANSFER_TIMEOUT_KEY
static

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

◆ m_clientIdManager

ClientIdManager& kanzi::connect::ConnectionAdapter::m_clientIdManager
protected

◆ m_domain

ConnectDomain* kanzi::connect::ConnectionAdapter::m_domain
protected

◆ m_mutex

recursive_mutex kanzi::connect::ConnectionAdapter::m_mutex
protected

◆ m_observers

ObserverContainer kanzi::connect::ConnectionAdapter::m_observers
protected

◆ m_parameters

Parameters kanzi::connect::ConnectionAdapter::m_parameters
protected

Contains the configuration parameters for the connection adapter, regardless of adapter type.


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