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

ClientConnectionAdapter()

Constructor.

~ClientConnectionAdapter()

Destructor.

void aboutToStop()

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

void addObserver(Observer *observer)

Adds observer to receive notification from this adapter.

Parameters
  • observer: Observer to add.

bool configure(const Parameters &parameters)

Allows to configure the adapter with adapter-specific settings (key-value pairs).

Return

True if the adapter was successfully configured, otherwise false.

Parameters
  • parameters: Configuration parameters, as string-based key value pairs.

bool connect() = 0

Connects adapter to server.

Return

True if connection attempt is successful.

void disconnect() = 0

Disconnects adapter from server.

shared_ptr<MessageTranslator> getNetworkTranslator(MessagePackage::SerializationFormat format = MessagePackage::SerializationFormatBinary)
string getParameter(const string &parameter)

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.

Return

Value for a given key that represents configuration parameter.

Parameters
  • parameter: Key argument for parameter query.

string getState(const string &parameter) = 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.

Return

Value for a given key that represents a state of the given parameter.

Parameters
  • parameter: Key argument for state query.

string getType() const = 0

Returns type of the adapter, this needs to be unique for every adapter.

Return

Adapter type as string.

void interrupt() = 0

Signals to stop waiting for events.

void removeObserver(Observer *observer)

Removes observer from this adapter.

Parameters
  • observer: Observer to remove.

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

Sends data to network.

Parameters
  • data: Data to send.

void setClient(Client *client)

Allows to set a pointer to the Client instance for this adapter.

This enables adapters, to access service functionality provided by the Client instance.

Parameters
  • client: Client instance associated with this adapters.

int wait() = 0

Starts waiting event(s) from network, can block to preserve CPU.

Return

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.

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

~Observer()
void onConnected()

Notifies that the connection was established.

Due the internal locking, removeObserver cannot be called from this routine.

void onDisconnected()

Notifies that the connection was terminated.

Due the internal locking, removeObserver cannot be called from this routine.

void onReceive(const vector<char> &data)

Notifies that data was received from server.

Parameters
  • data: Data that was received. Due the internal locking, removeObserver cannot be called from this routine.