ClientConnector

class kanzi::connect::ClientConnector

Base connector.

Public Types

enum P2PAttribute

Values:

enumerator P2P_ATTRIBUTE_DEFAULT_UNRELIABLE_BEARER
typedef enum kanzi::connect::ClientConnector::P2PAttribute P2PAttribute
enum RunMode

Values:

enumerator None
enumerator RunAsync
enumerator RunSync
typedef enum kanzi::connect::ClientConnector::RunMode RunMode
enum State

Values:

enumerator NotPrepared
enumerator WaitingReconnect

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

enumerator Connecting
enumerator Connected
enumerator RegisteringService
enumerator Disconnected
typedef enum kanzi::connect::ClientConnector::State State

Public Functions

ClientConnector(const string &configurationFile = string())

Constructor.

Parameters
  • configurationFile: optinal (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()

Destructor.

void addStateChangeCallback(StateCallback *callback)

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

Parameters
  • callback: to be invoked.

bool configureP2PAttribute(P2PAttribute attribute, const string &attributeValue)

Configures a free form P2P attribute.

Return

true if attribute was recognized and usable.

Parameters
  • attribute: the identifier of the attribute to configure.

  • attributeValue: the value for the attribute

int getAutomaticReconnectInterval() const

Retrieve automatic reconnect interval.

Return

milliseconds how fast after reconnect the connection reconnect is tried.

ClientSharedPtr getClient()

Retrieve the contained client instance.

Return

client instance.

RemoteContentClientSharedPtr getContentClient()

Retrieve the content client for this connector.

Return

content client.

ConnectDomain *getDomain() const

Retrieve domain.

Return

domain

ClientRemoteServiceHost &getRemoteServiceHost()

Retrieve the contained remote service host instance.

Return

remote service host instance.

ClientConnector::RunMode getRunMode() const

Return the runmode of the connector.

Return

run mode that define how the connector works.

ClientConnector::State getState() const

Return the state of operation.

Return

the state of operation

VirtualFileRemoteClientSharedPtr getVirtualFileClient()

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

Return

shared pointer to object.

WorkQueueInterface *getWorkQueueEx()

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

Return

The work queue where its possible to add work items

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

Configures the connector with given arguments.

Parameters
  • adapter: the connection adapter to be used

  • parameters: adapter specific parameters.

  • service: optional service that is run on this device.

void 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.

void removeStateChangeCallback(StateCallback *callback)

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

Parameters
  • callback: to be invoked.

void setAutomaticReconnectInterval(int milliseconds)

Automatic reconnection interval.

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

void setConnectionParameters(const ClientConnectionAdapter::Parameters &parameters)

Can change connection parameters while connector is running.

Changes will affect on next time when connecting.

bool 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.

Return

true if service was cached, false on problems.

Parameters
  • service: the service to set.

bool 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.

Return

true if operation started, false if could not be started.

Parameters
  • callback: interface that is invoked when there is known to be data to process.

bool startSync(int periodMs, ExternalControlCallback *callback = nullptr)

Runs continuously until explicitly stopped with stopRun() method.

Return

true if loop actually got run. false if initialization failed.

Parameters
  • periodMs: how 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.

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.

class ExternalControlCallback

Callback interface thta can be used to stop a synchronous loop.

Public Functions

~ExternalControlCallback()

Destructor.

int requestToStop() = 0

Invoked on every cycle and allows external entity to break the loop.

Return

if != 0 is returned then the loop gets broken.

class StateCallback

Callback interface from client connector(s)

Public Functions

~StateCallback()

virtual destructor for SWIG.

void stateChanged(ClientConnector::State state) = 0

Invoked when state changes.

Parameters
  • state: the new state.