ClientRemoteServiceHost¶
-
class
kanzi::connect
::
ClientRemoteServiceHost
: public ServiceClientObserver, public MessageDispatcher, public WorkQueueInterface, public RuntimeDataProvider, public ClientRemoteServiceHostInterface¶ A class that can be used to host a remote service on a client device.
This class manages the connectivity between the remote service and the server. It works as an adapter, which hides the network and connectivity from the actual service class. This makes it possible to write services that can be run either locally (in the server) or remotely (in the client).
Unnamed Group
-
virtual void onClientDisconnected (const int &clientId) KZ_OVERRIDE
- See
kanzi::connect::ServiceClientObserver
-
virtual void onServiceRegistered (const string &name) KZ_OVERRIDE
-
virtual void onServiceUnregistered (const string &name) KZ_OVERRIDE
-
virtual void serviceSessionAvailable () KZ_OVERRIDE
Called to notify service session created.
-
virtual void serviceSessionUnavailable () KZ_OVERRIDE
Called to noitfy service session destroyed.
-
virtual void onControlRemoteService (const string &id, const string &action, const string &targetname, const vector< string > &argument) KZ_OVERRIDE
-
virtual void onServiceConfigurationPropertiesChanged (const string &name, const string &stream) KZ_OVERRIDE
-
virtual void onReturnCredits (const string &name, const int &credits) KZ_OVERRIDE
Public Functions
Constructor.
- Parameters
client – Provides network access to server
-
virtual ~ClientRemoteServiceHost () KZ_OVERRIDE
Destructor.
-
void
abortRun
()¶ Aborts above runContinuously call if available.
-
virtual void dispatch (const MessagePackage &message) KZ_OVERRIDE
Wraps outgoing event to a message package and dispatches it.
- Parameters
message – Outgoing message (event).
-
void
enableVerboseLogging
(bool enable)¶ Control verbose debug logging on/off.
- Parameters
enable – if true then verbose logging is enabled, else false.
-
RemoteContentClientSharedPtr
getContentClient
()¶ Provide access to content client.
- Returns
the content client.
-
inline ConnectDomain *
getDomain
() const¶ Retrieve domain instance.
- Returns
domain instance. ownership not transfered.
-
AbstractServiceSharedPtr
getService
() const¶ Retrieve the service.
- Returns
shared pointer to service.
-
bool
hasService
() const¶ Determines whether there is a service bound to remote service host.
- Returns
true if remote service host is bound to a service.
Initialize the object with the provided service.
- Parameters
service – the service this client is running.
preferredReliableP2PAdapter – if nothing else specified, this particular adapter should be used for reliable communications
preferredUnreliableP2PAdapter – if nothing else specified, this particular adapter should be used for unreliable communications
SSLParameters – preferred SSL parameters to be used in server functionality.
virtualFileClient – instance to access VirtualFileService Parameters should be passed with following keys “server_cert” Server certificate “server_pkey” Server private key “client_ca” Client CA certificate. “server_name” server name identity (optional) for reliable P2P transfer.
Initialize the object with the provided service.
- Parameters
service – the service this client is running.
preferredP2PAdapter – if nothing else specified, this particular adapter should be used for reliable P2P transfer.
-
virtual void onMessageReceived (const MessagePackage &message) KZ_OVERRIDE
Unwraps the received package and passes it to the hosted service.
- Parameters
message – Message that was received.
-
void
runContinuously
(int periodMs)¶ Runs continuously until explicitly stopped with abortRun() method.
- 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
runOnce
(int ms)¶ Runs event based run loop at max given time after which executes the work operations regardless whether there are any arrived yet.
- Parameters
ms – how long to wait for first event. Give -1 for infinitely. If hosted service uses timers then the provided value defines the works case granularity for the timers used by the service.
-
void
setConnectionIdentity
(const string &identity)¶ Sets the identity information for connection.
If not set, then defaults to “RemoteService: <servicename>”
- Parameters
identity – the connection identity.
-
inline void
setDomain
(ConnectDomain *domain)¶ Configure the connect domain.
- Parameters
domain – the domain to set. ownership not transfered.
-
void
setServerIPAddress
(const string &IPAddress)¶ Remote service might need to access the server via IP protocol even if its not connected by default using such (for example shared memory bearer is used).
This could happen for example is remote service needs to download some content from server via HTTP. For such cases this method can be used to tell the ip address. If server is contacted with IP address that address is always used and the address set with this method is ignored.
- Parameters
IPAddress – the IP Address.
-
RPCResult<bool>
setState
(int state, string stateDetail = string())¶ Reports the service state.
- Parameters
state – the state
stateDetail – state description
- Returns
RPC variable that can be listened for completion.
-
RPCResult<bool>
start
()¶ Starts to run the service by registring the remote service to the server.
Note: this should be called only after there is a functional connection.
- Returns
RPC variable that can be used to listen for completion.
-
RPCResult<bool>
stop
()¶ Unregisters the remote service from the server and cleans up local sessions.
- Returns
RPC variable that can be used to listen for completion.
-
void
uninitialize
()¶ Cleanup previous service initialization.
-