Kanzi Connect  1.1.10
Kanzi Connect C++ API
kanzi::connect::Connection Class Reference

A class that represents the connection to network server and maintains listener for the network traffic. More...

#include <connection.hpp>

Inheritance diagram for kanzi::connect::Connection:
kanzi::connect::ConnectionAdapterProvider kanzi::connect::NetworkListenerClient::Observer

Classes

class  StateObserver
 Alternate approach to listen connection state events - traditional observer pattern. More...
 
class  WorkNotifyCallback
 Callback interface used to notify listeners that there is work to be done. More...
 

Public Types

typedef function< void(State)> ConnectionStateCallbackFunction
 Callback function type for connection state changes. More...
 
typedef shared_ptr< void > ConnectionStateSubscriptionToken
 Subscription token for connection callbacks. More...
 
enum  State { Connecting, Connected, Disconnected }
 Enumeration for connection state. More...
 

Public Member Functions

ConnectionStateSubscriptionToken addStateSubscription (ConnectionStateCallbackFunction function)
 Subscribe to connection state changes. More...
 
ConnectionStateSubscriptionToken addStateSubscriptionEx (StateObserver *observer)
 Subscribe to connection state changes. More...
 
void clearWorkCallback ()
 Clears a previously set work callback. More...
 
bool connect (const string &adapter, const ClientConnectionAdapter::Parameters &parameters, Wait *signal=0)
 Starts connecting to server. More...
 
bool connectEx (const string &adapter, const ClientConnectionAdapter::Parameters &parameters)
 Starts connecting to server. More...
 
 Connection (InterfaceDomain *domain, Wait *signal)
 Constructor. More...
 
ClientConnectionAdapterSharedPtr createAdapter (const string &identifier)
 Create connection adapter based on name. More...
 
void disconnect ()
 Disconnects from server. More...
 
string getAdapterParameter (const string &parameter)
 Retrieve parameter of currently used adapter. More...
 
string getAdapterState (const string &parameter)
 Retrieve state of currently used adapter. More...
 
string getAdapterType ()
 Retrieve currently used adapter type. More...
 
MessageDispatchergetMessageDispatcher ()
 Retrieve message dispatcher that is used to send / receive data across network. More...
 
State getState () const
 Returns current connection state. More...
 
Connection::WorkNotifyCallbackgetWorkCallback () const
 Retrieve previously set work notification callback. More...
 
void notifyWorkAvailable ()
 Notify work available callback if one has been set. More...
 
bool registerConnectionAdapter (const string &identifier, ConnectionAdapterCreateFunc creator)
 Registers new connection adapter type. More...
 
void removeStateSubscription (ConnectionStateSubscriptionToken token)
 Unsubscribe from connection state changes. More...
 
void setWorkCallback (WorkNotifyCallback *callback)
 Registers a work callback. More...
 
bool unregisterConnectionAdapter (const string &identifier)
 Unregister connection adapter. More...
 
void work ()
 Performs work, process received data and connection state changes. More...
 
virtual ~Connection ()
 Destructor. (virtual for SWIG). More...
 
- Public Member Functions inherited from kanzi::connect::ConnectionAdapterProvider
virtual ~ConnectionAdapterProvider ()
 

Static Public Member Functions

static string state2String (const State state)
 Convert state to human readable string. More...
 

Detailed Description

A class that represents the connection to network server and maintains listener for the network traffic.

This class also handles the internal data exchange between the interfaces and the messages that are sent/received across network.

Member Typedef Documentation

◆ ConnectionStateCallbackFunction

Callback function type for connection state changes.

◆ ConnectionStateSubscriptionToken

Subscription token for connection callbacks.

Member Enumeration Documentation

◆ State

Enumeration for connection state.

Enumerator
Connecting 

Client is connecting in to server, but connection is not yet established.

Connected 

Connection is established and services are connected.

Disconnected 

There is no connection and services are unavailable.

Constructor & Destructor Documentation

◆ Connection()

kanzi::connect::Connection::Connection ( InterfaceDomain domain,
Wait signal 
)

Constructor.

Parameters
domainInterface domain that provides access to all network interfaces.
signalSignal that can be used to trigger work().

◆ ~Connection()

virtual kanzi::connect::Connection::~Connection ( )
virtual

Destructor. (virtual for SWIG).

Member Function Documentation

◆ addStateSubscription()

ConnectionStateSubscriptionToken kanzi::connect::Connection::addStateSubscription ( ConnectionStateCallbackFunction  function)

Subscribe to connection state changes.

Parameters
functionCallback function.
Returns
Token that can be used to unsubscribe the callback.

◆ addStateSubscriptionEx()

ConnectionStateSubscriptionToken kanzi::connect::Connection::addStateSubscriptionEx ( StateObserver observer)

Subscribe to connection state changes.

Parameters
observerinterface used to report changes
Returns
Token that can be used unsubscribe the callback.

◆ clearWorkCallback()

void kanzi::connect::Connection::clearWorkCallback ( )

Clears a previously set work callback.

◆ connect()

bool kanzi::connect::Connection::connect ( const string &  adapter,
const ClientConnectionAdapter::Parameters parameters,
Wait signal = 0 
)

Starts connecting to server.

Parameters
adapterConnection adapter type to use.
parametersConfiguration parameters for adapter.
signalSignal to invoke when connection is established, optional.
Returns
true if state allowed a new connection establishment to start. false if not.

◆ connectEx()

bool kanzi::connect::Connection::connectEx ( const string &  adapter,
const ClientConnectionAdapter::Parameters parameters 
)

Starts connecting to server.

This is override meant to be used by external language bindings.

Parameters
adapterConnection adapter type to use.
parametersConfiguration parameters for adapter.
Returns
true if state allowed a new connection establishment to start. false if not.

◆ createAdapter()

ClientConnectionAdapterSharedPtr kanzi::connect::Connection::createAdapter ( const string &  identifier)
virtual

Create connection adapter based on name.

Parameters
identifierIdentifier of the connection adapter. This name needs to match with the ones in configuration files.
Returns
newly created adapter

Implements kanzi::connect::ConnectionAdapterProvider.

◆ disconnect()

void kanzi::connect::Connection::disconnect ( )

Disconnects from server.

◆ getAdapterParameter()

string kanzi::connect::Connection::getAdapterParameter ( const string &  parameter)

Retrieve parameter of currently used adapter.

Parameters
parameterParameter to retrieve from adapter.
Returns
State of given parameter.

◆ getAdapterState()

string kanzi::connect::Connection::getAdapterState ( const string &  parameter)

Retrieve state of currently used adapter.

Parameters
parameterParameter to retrieve from adapter.
Returns
State of given parameter.

◆ getAdapterType()

string kanzi::connect::Connection::getAdapterType ( )

Retrieve currently used adapter type.

Returns
Adapter type.

◆ getMessageDispatcher()

MessageDispatcher* kanzi::connect::Connection::getMessageDispatcher ( )

Retrieve message dispatcher that is used to send / receive data across network.

Returns
Message dispatcher object.

◆ getState()

State kanzi::connect::Connection::getState ( ) const

Returns current connection state.

Returns
State enumeration representing the current state of operation.

◆ getWorkCallback()

Connection::WorkNotifyCallback* kanzi::connect::Connection::getWorkCallback ( ) const

Retrieve previously set work notification callback.

Returns
work notification interface. can be nullptr. ownership not transfered.

◆ notifyWorkAvailable()

void kanzi::connect::Connection::notifyWorkAvailable ( )

Notify work available callback if one has been set.

◆ registerConnectionAdapter()

bool kanzi::connect::Connection::registerConnectionAdapter ( const string &  identifier,
ConnectionAdapterCreateFunc  creator 
)

Registers new connection adapter type.

Parameters
identifierIdentifier of the connection adapter. This name needs to match with the ones in configuration files.
creatorFunction that instantiates a connection adapter of given type.

◆ removeStateSubscription()

void kanzi::connect::Connection::removeStateSubscription ( ConnectionStateSubscriptionToken  token)

Unsubscribe from connection state changes.

Parameters
tokenToken that was received when subscription was made.

◆ setWorkCallback()

void kanzi::connect::Connection::setWorkCallback ( WorkNotifyCallback callback)

Registers a work callback.

Parameters
callbackmethod to invoke when there is work to be done.

◆ state2String()

static string kanzi::connect::Connection::state2String ( const State  state)
static

Convert state to human readable string.

Parameters
stateThe state to convert
Returns
string which represents given state

◆ unregisterConnectionAdapter()

bool kanzi::connect::Connection::unregisterConnectionAdapter ( const string &  identifier)

Unregister connection adapter.

Parameters
identifierIdentifier of the connection adapter.

◆ work()

void kanzi::connect::Connection::work ( )

Performs work, process received data and connection state changes.


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