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. | |
ClientRemoteServiceHost & | getRemoteServiceHost () |
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. | |
WorkQueueInterface * | getWorkQueueEx () |
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 ¶meters, 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 ¶meters) |
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. | |
ExternalControlCallback * | m_syncControlCallback |
External callback. | |
thread | m_thread |
Thread used for temporary scheduling between connection establishments. | |
Base connector.
typedef function<void(void)> kanzi::connect::ClientConnector::CleanupCallback |
Callback function prototype that is called as part of connector destruction.
typedef shared_ptr<void> kanzi::connect::ClientConnector::CleanupCallbackToken |
Token type for cleanup callback registration and unregistration.
typedef enum kanzi::connect::ClientConnector::P2PAttribute kanzi::connect::ClientConnector::P2PAttribute |
kanzi::connect::ClientConnector::ClientConnector | ( | const string & | configurationFile = string() | ) |
Constructor.
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 |
kanzi::connect::ClientConnector::ClientConnector | ( | FileSet & | fileset | ) |
Constructor.
fileset | set 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. |
|
virtual |
Destructor.
void kanzi::connect::ClientConnector::addStateChangeCallback | ( | StateCallback * | callback | ) |
Adds a traditional callback interface that is invoked when connector state changes.
callback | to be invoked. |
bool kanzi::connect::ClientConnector::configureP2PAttribute | ( | P2PAttribute | attribute, |
const string & | attributeValue ) |
Configures a free form P2P attribute.
attribute | the identifier of the attribute to configure. |
attributeValue | the value for the attribute |
int kanzi::connect::ClientConnector::getAutomaticReconnectInterval | ( | ) | const |
Retrieve automatic reconnect interval.
ClientSharedPtr kanzi::connect::ClientConnector::getClient | ( | ) |
Retrieve the contained client instance.
RemoteContentClientSharedPtr kanzi::connect::ClientConnector::getContentClient | ( | ) |
Retrieve the content client for this connector.
|
inline |
Retrieve domain.
|
protected |
Returns IP Address to connect.
ClientRemoteServiceHost & kanzi::connect::ClientConnector::getRemoteServiceHost | ( | ) |
Retrieve the contained remote service host instance.
ClientConnector::RunMode kanzi::connect::ClientConnector::getRunMode | ( | ) | const |
Return the runmode of the connector.
ClientConnector::State kanzi::connect::ClientConnector::getState | ( | ) | const |
Return the state of operation.
VirtualFileRemoteClientSharedPtr kanzi::connect::ClientConnector::getVirtualFileClient | ( | ) |
Retrieve the virtual file client that can be used to shared content via http.
WorkQueueInterface * kanzi::connect::ClientConnector::getWorkQueueEx | ( | ) |
Retrieve the contained work queue Note: for android convenience, getRemoteServiceHost returns the same instance but with accurate cast.
bool kanzi::connect::ClientConnector::initialize | ( | const string & | adapter, |
const ClientConnectionAdapter::Parameters & | parameters, | ||
AbstractServiceSharedPtr | service = AbstractServiceSharedPtr() ) |
Configures the connector with given arguments.
adapter | the connection adapter to be used |
parameters | adapter specific parameters. |
service | optional service that is run on this device. |
|
protected |
Maintains connection state.
|
protected |
Processes connection parameters.
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.
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
void kanzi::connect::ClientConnector::removeStateChangeCallback | ( | StateCallback * | callback | ) |
Removes a traditional callback interface that is invoked when connector state changes.
callback | to be invoked. |
|
protected |
Selects next ip address in case multiple addresses configured.
void kanzi::connect::ClientConnector::setAutomaticReconnectInterval | ( | int | milliseconds | ) |
Automatic reconnection interval.
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 kanzi::connect::ClientConnector::setConnectionParameters | ( | const ClientConnectionAdapter::Parameters & | parameters | ) |
Can change connection parameters while connector is running.
Changes will affect on next time when connecting.
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.
service | the service to set. |
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.
callback | interface that is invoked when there is known to be data to process. |
|
protected |
Starts a reconnect procedure.
bool kanzi::connect::ClientConnector::startSync | ( | int | periodMs, |
ExternalControlCallback * | callback = nullptr ) |
Runs continuously until explicitly stopped with stopRun() method.
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 kanzi::connect::ClientConnector::stop | ( | ) |
Aborts either asynchronous or synchronous running of connector.
void kanzi::connect::ClientConnector::stopRun | ( | ) |
Aborts either asynchronous or synchronous running of connector.
|
protected |
Moves the object to requested state.
void kanzi::connect::ClientConnector::uninitialize | ( | ) |
Unprepares the connector.
void kanzi::connect::ClientConnector::unregisterCleanupCallback | ( | CleanupCallbackToken | token | ) |
Unregister previously registered cleanup routine.
|
protected |
Updates connection parameters with possible alternate ip addresses.
|
protected |
Connection adapter.
|
protected |
Automatic reconnect interval.
|
protected |
true when running destructor.
|
protected |
Vector of routines to be called on cleanup.
|
protected |
The client instance.
|
protected |
Handle for connection state subscriptions.
|
protected |
Default unreliable P2P Adapter.
|
protected |
Connect domain instance.
|
protected |
Whether connection got established on last run.
|
protected |
The HTTP Client.
|
protected |
Active ip address.
|
protected |
|
protected |
Connection parameters.
|
protected |
Reconnection timepoint.
|
protected |
Asynchronous response to register service command.
|
protected |
Remote service host instance for executing a remote service in parallel with a client.
|
protected |
Execution mode, either synchronous or asynchronous.
|
protected |
Flag to hold the running state.
|
protected |
The service.
|
protected |
The state.
|
protected |
Vector of callback interfaces that listen state changes.
|
protected |
External callback.
|
protected |
Thread used for temporary scheduling between connection establishments.