Kanzi Connect 3.9.10
kanzi::connect::ClientConnector Class Reference

Base connector. More...

#include <clientconnector.hpp>

Classes

class  ExternalControlCallback
 Callback interface thta can be used to stop a synchronous loop. More...
 
class  StateCallback
 Callback interface from client connector(s) More...
 

Public Types

typedef function< void(void)> CleanupCallback
 Callback function prototype that is called as part of connector destruction.
 
typedef shared_ptr< void > CleanupCallbackToken
 Token type for cleanup callback registration and unregistration.
 
enum  P2PAttribute { P2P_ATTRIBUTE_DEFAULT_UNRELIABLE_BEARER = 1 }
 
typedef enum kanzi::connect::ClientConnector::P2PAttribute P2PAttribute
 
enum  RunMode { None , RunAsync , RunSync }
 
typedef enum kanzi::connect::ClientConnector::RunMode RunMode
 
enum  State {
  NotPrepared , WaitingReconnect , Connecting , Connected ,
  RegisteringService , Disconnected
}
 
typedef enum kanzi::connect::ClientConnector::State State
 

Public Member Functions

void addStateChangeCallback (StateCallback *callback)
 Adds a traditional callback interface that is invoked when connector state changes.
 
 ClientConnector (const string &configurationFile=string())
 Constructor.
 
 ClientConnector (FileSet &fileset)
 Constructor.
 
bool configureP2PAttribute (P2PAttribute attribute, const string &attributeValue)
 Configures a free form P2P attribute.
 
int getAutomaticReconnectInterval () const
 Retrieve automatic reconnect interval.
 
ClientSharedPtr getClient ()
 Retrieve the contained client instance.
 
RemoteContentClientSharedPtr getContentClient ()
 Retrieve the content client for this connector.
 
ConnectDomainSharedPtr getDomain () const
 Retrieve domain.
 
ClientRemoteServiceHostgetRemoteServiceHost ()
 Retrieve the contained remote service host instance.
 
ClientConnector::RunMode getRunMode () const
 Return the runmode of the connector.
 
ClientConnector::State getState () const
 Return the state of operation.
 
VirtualFileRemoteClientSharedPtr getVirtualFileClient ()
 Retrieve the virtual file client that can be used to shared content via http.
 
WorkQueueInterfacegetWorkQueueEx ()
 Retrieve the contained work queue Note: for android convenience, getRemoteServiceHost returns the same instance but with accurate cast.
 
bool initialize (const string &adapter, const ClientConnectionAdapter::Parameters &parameters, AbstractServiceSharedPtr service=AbstractServiceSharedPtr())
 Configures the connector with given arguments.
 
void performAsyncWork ()
 This should be invoked, in application main thread context, as result to workAvailable callback.
 
CleanupCallbackToken registerCleanupCallback (CleanupCallback callback)
 Registers a routine that will be invoked upon the object is being destroyed.
 
void removeStateChangeCallback (StateCallback *callback)
 Removes a traditional callback interface that is invoked when connector state changes.
 
void setAutomaticReconnectInterval (int milliseconds)
 Automatic reconnection interval.
 
void setConnectionParameters (const ClientConnectionAdapter::Parameters &parameters)
 Can change connection parameters while connector is running.
 
bool setService (AbstractServiceSharedPtr service)
 Sets the service to connector.
 
bool startAsync (Connection::WorkNotifyCallback *callback)
 Starts asynchronous operation of the client connector.
 
bool startSync (int periodMs, ExternalControlCallback *callback=nullptr)
 Runs continuously until explicitly stopped with stopRun() method.
 
void stop ()
 Aborts either asynchronous or synchronous running of connector.
 
void stopRun ()
 Aborts either asynchronous or synchronous running of connector.
 
void uninitialize ()
 Unprepares the connector.
 
void unregisterCleanupCallback (CleanupCallbackToken token)
 Unregister previously registered cleanup routine.
 
virtual ~ClientConnector ()
 Destructor.
 

Protected Member Functions

const string & getIP () const
 Returns IP Address to connect.
 
void maintainConnectionState ()
 Maintains connection state.
 
void parseConnectionParameters ()
 Processes connection parameters.
 
void selectNextIPAddress ()
 Selects next ip address in case multiple addresses configured.
 
void startReconnectCycle ()
 Starts a reconnect procedure.
 
void toState (State state)
 Moves the object to requested state.
 
void updateConnectionParameters ()
 Updates connection parameters with possible alternate ip addresses.
 

Protected Attributes

string m_adapter
 Connection adapter.
 
int m_automaticReconnectInterval
 Automatic reconnect interval.
 
bool m_cleaningUp
 true when running destructor.
 
vector< CleanupCallbackRegistrationSharedPtr > m_cleanupCallbacks
 Vector of routines to be called on cleanup.
 
ClientSharedPtr m_client
 The client instance.
 
shared_ptr< void > m_connectionStateSubscriptionHandle
 Handle for connection state subscriptions.
 
string m_defaultUnreliableP2PAdapter
 Default unreliable P2P Adapter.
 
ConnectDomainSharedPtr m_domain
 Connect domain instance.
 
bool m_gotConnected
 Whether connection got established on last run.
 
VirtualFileRemoteClientSharedPtr m_httpclient
 The HTTP Client.
 
vector< string > m_ip
 Active ip address.
 
int m_ipIndex
 
ClientConnectionAdapter::Parameters m_parameters
 Connection parameters.
 
chrono::time_point< chrono::steady_clock > m_reconnectAt
 Reconnection timepoint.
 
RPCResult< bool > m_registerServiceResponse
 Asynchronous response to register service command.
 
ClientRemoteServiceHostSharedPtr m_remoteServiceHost
 Remote service host instance for executing a remote service in parallel with a client.
 
RunMode m_runMode
 Execution mode, either synchronous or asynchronous.
 
bool m_running
 Flag to hold the running state.
 
AbstractServiceSharedPtr m_service
 The service.
 
State m_state
 The state.
 
vector< StateCallback * > m_stateCallbacks
 Vector of callback interfaces that listen state changes.
 
ExternalControlCallbackm_syncControlCallback
 External callback.
 
thread m_thread
 Thread used for temporary scheduling between connection establishments.
 

Detailed Description

Base connector.

Member Typedef Documentation

◆ CleanupCallback

Callback function prototype that is called as part of connector destruction.

◆ CleanupCallbackToken

Token type for cleanup callback registration and unregistration.

◆ P2PAttribute

◆ RunMode

◆ State

Member Enumeration Documentation

◆ P2PAttribute

Enumerator
P2P_ATTRIBUTE_DEFAULT_UNRELIABLE_BEARER 

◆ RunMode

Enumerator
None 
RunAsync 
RunSync 

◆ State

Enumerator
NotPrepared 
WaitingReconnect 

While this state is reported, client can safely reconfigure the connection parameters and those will be taken into use on next connection try.

Connecting 
Connected 
RegisteringService 
Disconnected 

Constructor & Destructor Documentation

◆ ClientConnector() [1/2]

kanzi::connect::ClientConnector::ClientConnector ( const string & configurationFile = string())

Constructor.

Parameters
configurationFileoptinal (server) configuration file that specifies policy related configurations. Nothing else is taken into account from the passed in configuration file. To be used when running remote service using the connector

◆ ClientConnector() [2/2]

kanzi::connect::ClientConnector::ClientConnector ( FileSet & fileset)

Constructor.

Parameters
filesetset of files to be used to configure the connector. From fileset, the server configuration file is utilized if its present. This is targeted to be used on when running remote service on android context.

◆ ~ClientConnector()

virtual kanzi::connect::ClientConnector::~ClientConnector ( )
virtual

Destructor.

Member Function Documentation

◆ addStateChangeCallback()

void kanzi::connect::ClientConnector::addStateChangeCallback ( StateCallback * callback)

Adds a traditional callback interface that is invoked when connector state changes.

Parameters
callbackto be invoked.

◆ configureP2PAttribute()

bool kanzi::connect::ClientConnector::configureP2PAttribute ( P2PAttribute attribute,
const string & attributeValue )

Configures a free form P2P attribute.

Parameters
attributethe identifier of the attribute to configure.
attributeValuethe value for the attribute
Returns
true if attribute was recognized and usable.

◆ getAutomaticReconnectInterval()

int kanzi::connect::ClientConnector::getAutomaticReconnectInterval ( ) const

Retrieve automatic reconnect interval.

Returns
milliseconds how fast after reconnect the connection reconnect is tried.

◆ getClient()

ClientSharedPtr kanzi::connect::ClientConnector::getClient ( )

Retrieve the contained client instance.

Returns
client instance.

◆ getContentClient()

RemoteContentClientSharedPtr kanzi::connect::ClientConnector::getContentClient ( )

Retrieve the content client for this connector.

Returns
content client.

◆ getDomain()

ConnectDomainSharedPtr kanzi::connect::ClientConnector::getDomain ( ) const
inline

Retrieve domain.

Returns
domain

◆ getIP()

const string & kanzi::connect::ClientConnector::getIP ( ) const
protected

Returns IP Address to connect.

◆ getRemoteServiceHost()

ClientRemoteServiceHost & kanzi::connect::ClientConnector::getRemoteServiceHost ( )

Retrieve the contained remote service host instance.

Returns
remote service host instance.

◆ getRunMode()

ClientConnector::RunMode kanzi::connect::ClientConnector::getRunMode ( ) const

Return the runmode of the connector.

Returns
run mode that define how the connector works.

◆ getState()

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

Return the state of operation.

Returns
the state of operation

◆ getVirtualFileClient()

VirtualFileRemoteClientSharedPtr kanzi::connect::ClientConnector::getVirtualFileClient ( )

Retrieve the virtual file client that can be used to shared content via http.

Returns
shared pointer to object.

◆ getWorkQueueEx()

WorkQueueInterface * kanzi::connect::ClientConnector::getWorkQueueEx ( )

Retrieve the contained work queue Note: for android convenience, getRemoteServiceHost returns the same instance but with accurate cast.

Returns
The work queue where its possible to add work items

◆ initialize()

bool kanzi::connect::ClientConnector::initialize ( const string & adapter,
const ClientConnectionAdapter::Parameters & parameters,
AbstractServiceSharedPtr service = AbstractServiceSharedPtr() )

Configures the connector with given arguments.

Parameters
adapterthe connection adapter to be used
parametersadapter specific parameters.
serviceoptional service that is run on this device.

◆ maintainConnectionState()

void kanzi::connect::ClientConnector::maintainConnectionState ( )
protected

Maintains connection state.

◆ parseConnectionParameters()

void kanzi::connect::ClientConnector::parseConnectionParameters ( )
protected

Processes connection parameters.

◆ performAsyncWork()

void kanzi::connect::ClientConnector::performAsyncWork ( )

This should be invoked, in application main thread context, as result to workAvailable callback.

the method implementation will check the calling thread and it must be the same used to call startAsync method.

◆ registerCleanupCallback()

CleanupCallbackToken kanzi::connect::ClientConnector::registerCleanupCallback ( CleanupCallback callback)

Registers a routine that will be invoked upon the object is being destroyed.

This can be used to register notification when corresponding connector is being destroyed

◆ removeStateChangeCallback()

void kanzi::connect::ClientConnector::removeStateChangeCallback ( StateCallback * callback)

Removes a traditional callback interface that is invoked when connector state changes.

Parameters
callbackto be invoked.

◆ selectNextIPAddress()

void kanzi::connect::ClientConnector::selectNextIPAddress ( )
protected

Selects next ip address in case multiple addresses configured.

◆ setAutomaticReconnectInterval()

void kanzi::connect::ClientConnector::setAutomaticReconnectInterval ( int milliseconds)

Automatic reconnection interval.

Parameters
millisecondshow long to wait, after detected disconnect, to reconnect. If negative value passed then reconnect functionality is not enabled and after disconnect the

◆ setConnectionParameters()

void kanzi::connect::ClientConnector::setConnectionParameters ( const ClientConnectionAdapter::Parameters & parameters)

Can change connection parameters while connector is running.

Changes will affect on next time when connecting.

◆ setService()

bool kanzi::connect::ClientConnector::setService ( AbstractServiceSharedPtr service)

Sets the service to connector.

This method can be successfully called only when connector has not been started yet. Passing service with initialize will override the service set with this method. Calling stop method will clear the previously configure service.

Parameters
servicethe service to set.
Returns
true if service was cached, false on problems.

◆ startAsync()

bool kanzi::connect::ClientConnector::startAsync ( Connection::WorkNotifyCallback * callback)

Starts asynchronous operation of the client connector.

Client connector will maintain server connection in a background. This method is intended to be used with external language bindings (Android) where the connect mainloop is run as part of android applications main loop.

Parameters
callbackinterface that is invoked when there is known to be data to process.
Returns
true if operation started, false if could not be started.

◆ startReconnectCycle()

void kanzi::connect::ClientConnector::startReconnectCycle ( )
protected

Starts a reconnect procedure.

◆ startSync()

bool kanzi::connect::ClientConnector::startSync ( int periodMs,
ExternalControlCallback * callback = nullptr )

Runs continuously until explicitly stopped with stopRun() method.

Parameters
periodMshow often to manually executed background work regarless of whether we receive any signals about work availability. Note, in case the hosted service uses timers (AbstractService::setTimer) the period given here defines the worst case granularity for the timers used by the service.
Returns
true if loop actually got run. false if initialization failed.

◆ stop()

void kanzi::connect::ClientConnector::stop ( )

Aborts either asynchronous or synchronous running of connector.

◆ stopRun()

void kanzi::connect::ClientConnector::stopRun ( )

Aborts either asynchronous or synchronous running of connector.

◆ toState()

void kanzi::connect::ClientConnector::toState ( State state)
protected

Moves the object to requested state.

◆ uninitialize()

void kanzi::connect::ClientConnector::uninitialize ( )

Unprepares the connector.

◆ unregisterCleanupCallback()

void kanzi::connect::ClientConnector::unregisterCleanupCallback ( CleanupCallbackToken token)

Unregister previously registered cleanup routine.

◆ updateConnectionParameters()

void kanzi::connect::ClientConnector::updateConnectionParameters ( )
protected

Updates connection parameters with possible alternate ip addresses.

Member Data Documentation

◆ m_adapter

string kanzi::connect::ClientConnector::m_adapter
protected

Connection adapter.

◆ m_automaticReconnectInterval

int kanzi::connect::ClientConnector::m_automaticReconnectInterval
protected

Automatic reconnect interval.

◆ m_cleaningUp

bool kanzi::connect::ClientConnector::m_cleaningUp
protected

true when running destructor.

◆ m_cleanupCallbacks

vector<CleanupCallbackRegistrationSharedPtr> kanzi::connect::ClientConnector::m_cleanupCallbacks
protected

Vector of routines to be called on cleanup.

◆ m_client

ClientSharedPtr kanzi::connect::ClientConnector::m_client
protected

The client instance.

◆ m_connectionStateSubscriptionHandle

shared_ptr<void> kanzi::connect::ClientConnector::m_connectionStateSubscriptionHandle
protected

Handle for connection state subscriptions.

◆ m_defaultUnreliableP2PAdapter

string kanzi::connect::ClientConnector::m_defaultUnreliableP2PAdapter
protected

Default unreliable P2P Adapter.

◆ m_domain

ConnectDomainSharedPtr kanzi::connect::ClientConnector::m_domain
protected

Connect domain instance.

◆ m_gotConnected

bool kanzi::connect::ClientConnector::m_gotConnected
protected

Whether connection got established on last run.

◆ m_httpclient

VirtualFileRemoteClientSharedPtr kanzi::connect::ClientConnector::m_httpclient
protected

The HTTP Client.

◆ m_ip

vector<string> kanzi::connect::ClientConnector::m_ip
protected

Active ip address.

◆ m_ipIndex

int kanzi::connect::ClientConnector::m_ipIndex
protected

◆ m_parameters

ClientConnectionAdapter::Parameters kanzi::connect::ClientConnector::m_parameters
protected

Connection parameters.

◆ m_reconnectAt

chrono::time_point<chrono::steady_clock> kanzi::connect::ClientConnector::m_reconnectAt
protected

Reconnection timepoint.

◆ m_registerServiceResponse

RPCResult<bool> kanzi::connect::ClientConnector::m_registerServiceResponse
protected

Asynchronous response to register service command.

◆ m_remoteServiceHost

ClientRemoteServiceHostSharedPtr kanzi::connect::ClientConnector::m_remoteServiceHost
protected

Remote service host instance for executing a remote service in parallel with a client.

◆ m_runMode

RunMode kanzi::connect::ClientConnector::m_runMode
protected

Execution mode, either synchronous or asynchronous.

◆ m_running

bool kanzi::connect::ClientConnector::m_running
protected

Flag to hold the running state.

◆ m_service

AbstractServiceSharedPtr kanzi::connect::ClientConnector::m_service
protected

The service.

◆ m_state

State kanzi::connect::ClientConnector::m_state
protected

The state.

◆ m_stateCallbacks

vector<StateCallback*> kanzi::connect::ClientConnector::m_stateCallbacks
protected

Vector of callback interfaces that listen state changes.

◆ m_syncControlCallback

ExternalControlCallback* kanzi::connect::ClientConnector::m_syncControlCallback
protected

External callback.

◆ m_thread

thread kanzi::connect::ClientConnector::m_thread
protected

Thread used for temporary scheduling between connection establishments.


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