A class that represents the connection to network server and maintains listener for the network traffic. More...
#include <connection.hpp>
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. | |
typedef shared_ptr< void > | ConnectionStateSubscriptionToken |
Subscription token for connection callbacks. | |
enum | State { Connecting , Connected , Disconnected } |
Enumeration for connection state. More... | |
Public Member Functions | |
ConnectionStateSubscriptionToken | addStateSubscription (ConnectionStateCallbackFunction function) |
Subscribe to connection state changes. | |
ConnectionStateSubscriptionToken | addStateSubscriptionEx (StateObserver *observer) |
Subscribe to connection state changes. | |
void | clearWorkCallback () |
Clears a previously set work callback. | |
bool | connect (const string &adapter, const ClientConnectionAdapter::Parameters ¶meters, Wait *signal=0) |
Starts connecting to server. | |
bool | connectEx (const string &adapter, const ClientConnectionAdapter::Parameters ¶meters) |
Starts connecting to server. | |
Connection (InterfaceDomain *domain, Wait *signal) | |
Constructor. | |
ClientConnectionAdapterSharedPtr | createAdapter (const string &identifier) |
Create connection adapter based on name. | |
void | disconnect () |
Disconnects from server. | |
string | getAdapterParameter (const string ¶meter) |
Retrieve parameter of currently used adapter. | |
string | getAdapterState (const string ¶meter) |
Retrieve state of currently used adapter. | |
string | getAdapterType () |
Retrieve currently used adapter type. | |
MessageDispatcher * | getMessageDispatcher () |
Retrieve message dispatcher that is used to send / receive data across network. | |
State | getState () const |
Returns current connection state. | |
Connection::WorkNotifyCallback * | getWorkCallback () const |
Retrieve previously set work notification callback. | |
void | notifyWorkAvailable () |
Notify work available callback if one has been set. | |
bool | registerConnectionAdapter (const string &identifier, ConnectionAdapterCreateFunc creator) |
Registers new connection adapter type. | |
void | removeStateSubscription (ConnectionStateSubscriptionToken token) |
Unsubscribe from connection state changes. | |
void | setWorkCallback (WorkNotifyCallback *callback) |
Registers a work callback. | |
bool | unregisterConnectionAdapter (const string &identifier) |
Unregister connection adapter. | |
void | work () |
Performs work, process received data and connection state changes. | |
virtual | ~Connection () |
Destructor. (virtual for SWIG). | |
![]() | |
virtual | ~ConnectionAdapterProvider () |
Static Public Member Functions | |
static string | state2String (const State state) |
Convert state to human readable string. | |
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.
typedef function<void(State)> kanzi::connect::Connection::ConnectionStateCallbackFunction |
Callback function type for connection state changes.
typedef shared_ptr<void> kanzi::connect::Connection::ConnectionStateSubscriptionToken |
Subscription token for connection callbacks.
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. |
kanzi::connect::Connection::Connection | ( | InterfaceDomain * | domain, |
Wait * | signal ) |
Constructor.
domain | Interface domain that provides access to all network interfaces. |
signal | Signal that can be used to trigger work(). |
|
virtual |
Destructor. (virtual for SWIG).
ConnectionStateSubscriptionToken kanzi::connect::Connection::addStateSubscription | ( | ConnectionStateCallbackFunction | function | ) |
Subscribe to connection state changes.
function | Callback function. |
ConnectionStateSubscriptionToken kanzi::connect::Connection::addStateSubscriptionEx | ( | StateObserver * | observer | ) |
Subscribe to connection state changes.
observer | interface used to report changes |
void kanzi::connect::Connection::clearWorkCallback | ( | ) |
Clears a previously set work callback.
bool kanzi::connect::Connection::connect | ( | const string & | adapter, |
const ClientConnectionAdapter::Parameters & | parameters, | ||
Wait * | signal = 0 ) |
Starts connecting to server.
adapter | Connection adapter type to use. |
parameters | Configuration parameters for adapter. |
signal | Signal to invoke when connection is established, optional. |
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.
adapter | Connection adapter type to use. |
parameters | Configuration parameters for adapter. |
|
virtual |
Create connection adapter based on name.
identifier | Identifier of the connection adapter. This name needs to match with the ones in configuration files. |
Implements kanzi::connect::ConnectionAdapterProvider.
void kanzi::connect::Connection::disconnect | ( | ) |
Disconnects from server.
string kanzi::connect::Connection::getAdapterParameter | ( | const string & | parameter | ) |
Retrieve parameter of currently used adapter.
parameter | Parameter to retrieve from adapter. |
string kanzi::connect::Connection::getAdapterState | ( | const string & | parameter | ) |
Retrieve state of currently used adapter.
parameter | Parameter to retrieve from adapter. |
string kanzi::connect::Connection::getAdapterType | ( | ) |
Retrieve currently used adapter type.
MessageDispatcher * kanzi::connect::Connection::getMessageDispatcher | ( | ) |
Retrieve message dispatcher that is used to send / receive data across network.
State kanzi::connect::Connection::getState | ( | ) | const |
Returns current connection state.
Connection::WorkNotifyCallback * kanzi::connect::Connection::getWorkCallback | ( | ) | const |
Retrieve previously set work notification callback.
void kanzi::connect::Connection::notifyWorkAvailable | ( | ) |
Notify work available callback if one has been set.
bool kanzi::connect::Connection::registerConnectionAdapter | ( | const string & | identifier, |
ConnectionAdapterCreateFunc | creator ) |
Registers new connection adapter type.
identifier | Identifier of the connection adapter. This name needs to match with the ones in configuration files. |
creator | Function that instantiates a connection adapter of given type. |
void kanzi::connect::Connection::removeStateSubscription | ( | ConnectionStateSubscriptionToken | token | ) |
Unsubscribe from connection state changes.
token | Token that was received when subscription was made. |
void kanzi::connect::Connection::setWorkCallback | ( | WorkNotifyCallback * | callback | ) |
Registers a work callback.
callback | method to invoke when there is work to be done. |
|
static |
Convert state to human readable string.
state | The state to convert |
bool kanzi::connect::Connection::unregisterConnectionAdapter | ( | const string & | identifier | ) |
Unregister connection adapter.
identifier | Identifier of the connection adapter. |
void kanzi::connect::Connection::work | ( | ) |
Performs work, process received data and connection state changes.