Connection¶
-
class
kanzi::connect
::
Connection
: public ConnectionAdapterProvider, private NetworkListenerClient::Observer¶ 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.
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
¶ Enumeration for connection state.
Values:
-
enumerator
Connecting
¶ Client is connecting in to server, but connection is not yet established.
-
enumerator
Connected
¶ Connection is established and services are connected.
-
enumerator
Disconnected
¶ There is no connection and services are unavailable.
-
enumerator
Public Functions
-
Connection
(InterfaceDomain *domain, Wait *signal)¶ Constructor.
- Parameters
domain
: Interface domain that provides access to all network interfaces.signal
: Signal that can be used to trigger work().
-
~Connection
()¶ Destructor. (virtual for SWIG).
-
ConnectionStateSubscriptionToken
addStateSubscription
(ConnectionStateCallbackFunction function)¶ Subscribe to connection state changes.
- Return
Token that can be used to unsubscribe the callback.
- Parameters
function
: Callback function.
-
ConnectionStateSubscriptionToken
addStateSubscriptionEx
(StateObserver *observer)¶ Subscribe to connection state changes.
- Return
Token that can be used unsubscribe the callback.
- Parameters
observer
: interface used to report 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.
- Return
true if state allowed a new connection establishment to start. false if not.
- Parameters
adapter
: Connection adapter type to use.parameters
: Configuration parameters for adapter.signal
: Signal to invoke when connection is established, optional.
-
bool
connectEx
(const string &adapter, const ClientConnectionAdapter::Parameters ¶meters)¶ Starts connecting to server.
This is override meant to be used by external language bindings.
- Return
true if state allowed a new connection establishment to start. false if not.
- Parameters
adapter
: Connection adapter type to use.parameters
: Configuration parameters for adapter.
-
ClientConnectionAdapterSharedPtr
createAdapter
(const string &identifier)¶
-
void
disconnect
()¶ Disconnects from server.
-
string
getAdapterParameter
(const string ¶meter)¶ Retrieve parameter of currently used adapter.
- Return
State of given parameter.
- Parameters
parameter
: Parameter to retrieve from adapter.
-
string
getAdapterState
(const string ¶meter)¶ Retrieve state of currently used adapter.
- Return
State of given parameter.
- Parameters
parameter
: Parameter to retrieve from adapter.
-
string
getAdapterType
()¶ Retrieve currently used adapter type.
- Return
Adapter type.
-
MessageDispatcher *
getMessageDispatcher
()¶ Retrieve message dispatcher that is used to send / receive data across network.
- Return
Message dispatcher object.
-
State
getState
() const¶ Returns current connection state.
- Return
State enumeration representing the current state of operation.
-
Connection::WorkNotifyCallback *
getWorkCallback
() const¶ Retrieve previously set work notification callback.
- Return
work notification interface. can be nullptr. ownership not transfered.
-
bool
registerConnectionAdapter
(const string &identifier, ConnectionAdapterCreateFunc creator)¶ Registers new connection adapter type.
- Parameters
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
removeStateSubscription
(ConnectionStateSubscriptionToken token)¶ Unsubscribe from connection state changes.
- Parameters
token
: Token that was received when subscription was made.
-
void
setWorkCallback
(WorkNotifyCallback *callback)¶ Registers a work callback.
- Parameters
callback
: method to invoke when there is work to be done.
-
bool
unregisterConnectionAdapter
(const string &identifier)¶ Unregister connection adapter.
- Parameters
identifier
: Identifier of the connection adapter.
-
void
work
()¶ Performs work, process received data and connection state changes.
Public Static Functions
-
class
StateObserver
¶ Alternate approach to listen connection state events - traditional observer pattern.
Public Functions
-
~StateObserver
()¶
-
void
connectionStateChanged
(Connection::State state) = 0¶ called when connection state changes
- Parameters
state
: the new connection state.
-
-
class
WorkNotifyCallback
¶ Callback interface used to notify listeners that there is work to be done.
Subclassed by WorkerBase
-
typedef function<void(State)>