ClientConnectionAdapter¶
-
class
kanzi::connect
::
ClientConnectionAdapter
¶ An abstract class that acts as an interface to underlying network transport layer.
This class interface provides functionality to connect to server and transmit & receive data.
Subclassed by ClientSocketConnectionAdapter
Public Types
-
typedef map<string, string>
Parameters
¶ Container type for parameters.
Public Functions
-
inline
ClientConnectionAdapter
()¶ Constructor.
-
inline virtual
~ClientConnectionAdapter
()¶ Destructor.
-
void
addObserver
(Observer *observer)¶ Adds observer to receive notification from this adapter.
- Parameters
observer – Observer to add.
-
virtual bool
configure
(const Parameters ¶meters) = 0¶ Allows to configure the adapter with adapter-specific settings (key-value pairs).
- Parameters
parameters – Configuration parameters, as string-based key value pairs.
- Returns
True if the adapter was successfully configured, otherwise false.
-
virtual bool
connect
() = 0¶ Connects adapter to server.
- Returns
True if connection attempt is successful.
-
virtual void
disconnect
() = 0¶ Disconnects adapter from server.
-
virtual string
getParameter
(const string ¶meter) = 0¶ Adapter can expose it’s parameters using key-value pairs.
This function allows to retrieve a parameter value that was used to configure the adapter.
- Parameters
parameter – Key argument for parameter query.
- Returns
Value for a given key that represents configuration parameter.
-
virtual string
getState
(const string ¶meter) = 0¶ Adapter can expose it’s internal state by using key-value pairs.
This function allows to retrieve a state value from adapter for a given key.
- Parameters
parameter – Key argument for state query.
- Returns
Value for a given key that represents a state of the given parameter.
-
virtual string
getType
() const = 0¶ Returns type of the adapter, this needs to be unique for every adapter.
- Returns
Adapter type as string.
-
virtual void
interrupt
() = 0¶ Signals to stop waiting for events.
-
void
removeObserver
(Observer *observer)¶ Removes observer from this adapter.
- Parameters
observer – Observer to remove.
-
virtual void
send
(const vector<char> &data) = 0¶ Sends data to network.
- Parameters
data – Data to send.
-
virtual int
wait
() = 0¶ Starts waiting event(s) from network, can block to preserve CPU.
- Returns
Must return <0 in case unrecoverable error occured and method should not be called anymore. >= 0 in case processing should continue. In this case returned value is passed to work(..) routine.
-
virtual void
work
(int status) = 0¶ Once wait is completed, this method is called for the adapter to process the received network events.
- Parameters
status – the status (>=0) value returned by the wait() routine called earlier.
-
class
Observer
¶ Observer class that allows to receive notifications from the connection adapter.
Subclassed by NetworkListenerClient
Public Functions
-
inline virtual
~Observer
()¶
-
inline virtual void
onConnected
()¶ Notifies that the connection was established.
Due the internal locking, removeObserver cannot be called from this routine.
-
inline virtual void
onDisconnected
()¶ Notifies that the connection was terminated.
Due the internal locking, removeObserver cannot be called from this routine.
-
inline virtual void
onReceive
(const vector<char>&)¶ Notifies that data was received from server.
- Parameters
data – Data that was received. Due the internal locking, removeObserver cannot be called from this routine.
-
inline virtual
-
typedef map<string, string>