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.
-
inline virtual
~ConnectionAdapter
()¶ Destructor.
-
inline 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.
- Parameters
observer – Observer to add.
-
virtual bool
clientExists
(size_t clientId)¶ Check whether a client identifier is valid one.
- Parameters
clientId – Identifier of the client.
- Returns
True if client exists.
-
virtual void
configure
(const Parameters ¶meters) = 0¶ Configures adapter according to given parameters.
- Parameters
parameters – Parameters for adapter.
-
virtual 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.
-
virtual void
getClientSideParameters
(vector<ClientSideParameter> &outputList) const¶ Get list of parameters on the client side that are user configurable.
- Parameters
outputList – Contains the parameters
-
virtual const string &
getConnectionType
() const = 0¶ Get the connection type identifier of this connection adapter.
- Returns
string which identifies the connection type (e.g. “socket”)
-
ConnectDomain *
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.
-
unsigned int
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
-
unsigned int
getFileTransferTimeout
() const¶ How long timeout should be used (milliseconds) when transferring file through this connection adapter.
- Returns
The timeout (milliseconds) for a file transfer
-
virtual unsigned int
getMaximumConnectionCount
() const = 0¶ Get maximum number of simultaneous connections for this adapters connection type.
- See
getConnectionType
-
bool
getParameterBool
(const string &key, bool defaultValue = false) const¶ Gets a configuration boolean value.
- Parameters
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
-
int
getParameterInt
(const string &key, int defaultValue = 0) const¶ Gets a configuration integer value.
- Parameters
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
-
const string
getParameterString
(const string &key, const string defaultValue = string("")) const¶ Gets a configuration string value.
- Parameters
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
-
int
getParameterUInt
(const string &key, unsigned int defaultValue = 0) const¶ Gets a configuration integer value.
- Parameters
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
-
inline virtual const string
getRemoteIPAddress
(size_t)¶ Gets the IP Address of the remote peer.
- Parameters
handle – identifies the remote peer.
- Returns
IP address of the remote peer.
-
inline virtual const string
getTrustedPeerName
() const¶ For SSL connections return the CN of the client peer certificate for other connections return “Unknown”.
- Returns
CN of the peer certificate
-
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.
-
inline virtual bool
isReliable
()¶ Must be overridden if adapter does not provide reliable transfer.
- Returns
true if reliable transfer is guaranteed.
-
virtual void
listen
() = 0¶ Starts to listen for connections.
-
inline virtual 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.
-
virtual 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
(ConnectDomain *domain)¶ Configure the domain for the class.
- Parameters
domain – the domain. Ownership not transfered.
-
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.
Public Static Functions
-
static bool
getConfigurationBool
(const Parameters ¶meters, const string &key, bool defaultValue = false)¶ Gets a configuration boolean value.
- Parameters
parameters – the parameter set
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
-
static int
getConfigurationInt
(const Parameters ¶meters, const string &key, int defaultValue = 0)¶ Gets a configuration integer value.
- Parameters
parameters – the parameter set
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
-
static const string
getConfigurationString
(const Parameters ¶meters, const string &key, const string defaultValue = string(""))¶ Gets a configuration string value.
- Parameters
parameters – the parameter set
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
-
static int
getConfigurationUInt
(const Parameters ¶meters, const string &key, unsigned int defaultValue = 0)¶ Gets a configuration integer value.
- Parameters
parameters – the parameter set
key – the parameter key to get
defaultValue – value to return in case value with key is not found.
- Returns
value from the configuration
Public Static 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.
-
struct
ClientSideParameter
¶ Public Functions
-
inline
ClientSideParameter
(const string &name, const string &value, const string &type, const string &displayName, const string &tooltip)¶
-
inline
-
class
Observer
¶ Observer class that is used for notifications such as new connections or data.
Subclassed by NetworkListener
Public Functions
-
virtual bool
clientExists
(size_t clientId) const = 0¶ Check whether a client identifier is valid one.
- Parameters
clientId – Identifier of the client.
- Returns
True if client exists.
-
inline virtual void
onConnected
(size_t)¶ Notification of a newly connected client.
- Parameters
clientId – The id of the connected client.
-
inline virtual void
onDisconnected
(size_t)¶ Notification of a disconnected client.
- Parameters
clientId – The id of the disconnected client.
-
inline virtual void
onReceive
(size_t, const vector<char>&)¶ 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.
-
virtual bool
-
using