An abstract class that acts as an interface to underlying network transport layer. More...
#include <connection_adapter_server.hpp>
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. | |
Public Member Functions | |
virtual void | aboutToStop () |
Invoked when the adapter should stop. Called before the object will be destroyed. | |
void | addObserver (Observer *observer) |
Adds observer to receive notifications. | |
virtual bool | clientExists (size_t clientId) |
Check whether a client identifier is valid one. | |
virtual void | configure (const Parameters ¶meters)=0 |
Configures adapter according to given parameters. | |
ConnectionAdapter (ClientIdManager &clientIdManager) | |
Constructor. | |
virtual void | disconnect (size_t clientId)=0 |
Terminates connection to given client. | |
virtual void | getClientSideParameters (vector< ClientSideParameter > &outputList) const |
Get list of parameters on the client side that are user configurable. | |
virtual const string & | getConnectionType () const =0 |
Get the connection type identifier of this connection adapter. | |
ConnectDomainSharedPtr | getDomain () const |
Retrieve the domain where class operates in. | |
unsigned int | getFileBlockSize () const |
Get the file block size configured for this adapter. | |
unsigned int | getFileTransferTimeout () const |
How long timeout should be used (milliseconds) when transferring file through this connection adapter. | |
virtual unsigned int | getMaximumConnectionCount () const =0 |
Get maximum number of simultaneous connections for this adapters connection type. | |
virtual 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. | |
int | getParameterInt (const string &key, int defaultValue=0) const |
Gets a configuration integer value. | |
const string | getParameterString (const string &key, const string defaultValue=string("")) const |
Gets a configuration string value. | |
int | getParameterUInt (const string &key, unsigned int defaultValue=0) const |
Gets a configuration integer value. | |
virtual const string | getRemoteIPAddress (size_t handle) |
Gets the IP Address of the remote peer. | |
virtual const string | getTrustedPeerName () const |
For SSL connections return the CN of the client peer certificate for other connections return "Unknown". | |
virtual const string | getType () const =0 |
Retrieves the type of the adapter. | |
virtual void | interrupt ()=0 |
Allows to interrupt the wait loop and return from the blocking loop. | |
virtual bool | isReliable () |
Must be overridden if adapter does not provide reliable transfer. | |
virtual void | listen ()=0 |
Starts to listen for connections. | |
virtual void | releaseResources () |
Potentially invoked before software is being terminated, the object itself might not get deleted in controlled manner (i.e. | |
void | removeObserver (Observer *observer) |
Removes observer. | |
virtual void | send (size_t clientId, const vector< char > &data)=0 |
Sends data to given client. | |
void | setDomain (ConnectDomainSharedPtr domain) |
Configure the domain for the class. | |
virtual bool | supportsListen () |
Must be overridden to disable listening. | |
virtual void | wait ()=0 |
Starts blocking loop that waits for work, should preserve resources & CPU. | |
virtual void | work ()=0 |
Performs all work that was received during the wait loop. | |
virtual | ~ConnectionAdapter () |
Destructor. | |
Static Public Member Functions | |
static bool | getConfigurationBool (const Parameters ¶meters, const string &key, bool defaultValue=false) |
Gets a configuration boolean value. | |
static int | getConfigurationInt (const Parameters ¶meters, const string &key, int defaultValue=0) |
Gets a configuration integer value. | |
static const string | getConfigurationString (const Parameters ¶meters, const string &key, const string defaultValue=string("")) |
Gets a configuration string value. | |
static int | getConfigurationUInt (const Parameters ¶meters, const string &key, unsigned int defaultValue=0) |
Gets a configuration integer value. | |
Static Public Attributes | |
static const string | FILE_BLOCK_SIZE_ATTRIBUTE_KEY |
Parameter key for the file block size in the configuration parameters. | |
static const string | FILE_TRANSFER_TIMEOUT_KEY |
Parameter key for the file transfer timeout in the configuration parameters. | |
Protected Types | |
typedef vector< Observer * > | ObserverContainer |
Protected Member Functions | |
void | notifyConnected (size_t clientId) |
Fires connected event for observers. | |
void | notifyDisconnected (size_t clientId) |
Fires disconnected event for observers. | |
void | notifyReceive (size_t clientId, const vector< char > &data) |
Fires receive event for observers. | |
void | setParameter (const string &key, const int value) |
Set parameter value, create if does not yet exist. | |
void | setParameter (const string &key, const string &value) |
Set parameter value, create if does not yet exist. | |
Protected Attributes | |
ClientIdManager & | m_clientIdManager |
ConnectDomainSharedPtr | m_domain |
recursive_mutex | m_mutex |
ObserverContainer | m_observers |
Parameters | m_parameters |
Contains the configuration parameters for the connection adapter, regardless of adapter type. | |
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.
|
protected |
using kanzi::connect::ConnectionAdapter::Parameters = map<string, string> |
Key-value pairs that can be used to configure an adapter.
kanzi::connect::ConnectionAdapter::ConnectionAdapter | ( | ClientIdManager & | clientIdManager | ) |
Constructor.
|
inlinevirtual |
Destructor.
|
inlinevirtual |
Invoked when the adapter should stop. Called before the object will be destroyed.
void kanzi::connect::ConnectionAdapter::addObserver | ( | Observer * | observer | ) |
Adds observer to receive notifications.
observer | Observer to add. |
|
virtual |
Check whether a client identifier is valid one.
clientId | Identifier of the client. |
|
pure virtual |
Configures adapter according to given parameters.
parameters | Parameters for adapter. |
Implemented in kanzi::connect::SocketConnectionAdapter.
|
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.
clientId | Id of the client that will be disconnected. |
Implemented in kanzi::connect::SocketConnectionAdapter.
|
virtual |
Get list of parameters on the client side that are user configurable.
outputList | Contains the parameters |
Reimplemented in kanzi::connect::SocketConnectionAdapter.
|
static |
Gets a configuration boolean value.
parameters | the parameter set |
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
|
static |
Gets a configuration integer value.
parameters | the parameter set |
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
|
static |
Gets a configuration string value.
parameters | the parameter set |
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
|
static |
Gets a configuration integer value.
parameters | the parameter set |
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
|
pure virtual |
Get the connection type identifier of this connection adapter.
Implemented in kanzi::connect::SocketConnectionAdapter.
ConnectDomainSharedPtr kanzi::connect::ConnectionAdapter::getDomain | ( | ) | const |
Retrieve the domain where class operates in.
unsigned int kanzi::connect::ConnectionAdapter::getFileBlockSize | ( | ) | const |
Get the file block size configured for this adapter.
unsigned int kanzi::connect::ConnectionAdapter::getFileTransferTimeout | ( | ) | const |
How long timeout should be used (milliseconds) when transferring file through this connection adapter.
|
pure virtual |
Get maximum number of simultaneous connections for this adapters connection type.
Implemented in kanzi::connect::SocketConnectionAdapter.
|
virtual |
Get message translator used with this connection adapter.
bool kanzi::connect::ConnectionAdapter::getParameterBool | ( | const string & | key, |
bool | defaultValue = false ) const |
Gets a configuration boolean value.
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
int kanzi::connect::ConnectionAdapter::getParameterInt | ( | const string & | key, |
int | defaultValue = 0 ) const |
Gets a configuration integer value.
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
const string kanzi::connect::ConnectionAdapter::getParameterString | ( | const string & | key, |
const string | defaultValue = string("") ) const |
Gets a configuration string value.
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
int kanzi::connect::ConnectionAdapter::getParameterUInt | ( | const string & | key, |
unsigned int | defaultValue = 0 ) const |
Gets a configuration integer value.
key | the parameter key to get |
defaultValue | value to return in case value with key is not found. |
|
inlinevirtual |
Gets the IP Address of the remote peer.
handle | identifies the remote peer. |
Reimplemented in kanzi::connect::SocketConnectionAdapter.
|
inlinevirtual |
For SSL connections return the CN of the client peer certificate for other connections return "Unknown".
|
pure virtual |
Retrieves the type of the adapter.
|
pure virtual |
Allows to interrupt the wait loop and return from the blocking loop.
Implemented in kanzi::connect::SocketConnectionAdapter.
|
inlinevirtual |
Must be overridden if adapter does not provide reliable transfer.
|
pure virtual |
Starts to listen for connections.
Implemented in kanzi::connect::SocketConnectionAdapter.
|
protected |
Fires connected event for observers.
Helper function for a derived class.
clientId | Id of the client that was connected. |
|
protected |
Fires disconnected event for observers.
Helper function for a derived class.
clientId | Id of the client that was disconnected. |
|
protected |
Fires receive event for observers.
Helper function for a derived class.
clientId | Id of the client that sent the data. |
data | Data received. |
|
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).
void kanzi::connect::ConnectionAdapter::removeObserver | ( | Observer * | observer | ) |
Removes observer.
observer | Observer to remove. |
|
pure virtual |
Sends data to given client.
clientId | Id of the client that will receive the data. |
data | Data to send. |
void kanzi::connect::ConnectionAdapter::setDomain | ( | ConnectDomainSharedPtr | domain | ) |
Configure the domain for the class.
domain | the domain. Ownership not transfered. |
|
protected |
Set parameter value, create if does not yet exist.
key | Identifies the value |
value | The value to set |
|
protected |
Set parameter value, create if does not yet exist.
key | Identifies the value |
value | The value to set |
|
inlinevirtual |
Must be overridden to disable listening.
|
pure virtual |
Starts blocking loop that waits for work, should preserve resources & CPU.
Implemented in kanzi::connect::SocketConnectionAdapter.
|
pure virtual |
Performs all work that was received during the wait loop.
Implemented in kanzi::connect::SocketConnectionAdapter.
|
static |
Parameter key for the file block size in the configuration parameters.
|
static |
Parameter key for the file transfer timeout in the configuration parameters.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Contains the configuration parameters for the connection adapter, regardless of adapter type.