A class that can be used to host a remote service on a client device. More...
#include <remote_service_host.hpp>
Public Member Functions | |
void | abortRun () |
Aborts above runContinuously call if available. | |
ClientRemoteServiceHost (ClientSharedPtr client) | |
Constructor. | |
virtual void | dispatch (const MessagePackage &message) override |
Wraps outgoing event to a message package and dispatches it. | |
void | enableVerboseLogging (bool enable) |
Control verbose debug logging on/off. | |
RemoteContentClientSharedPtr | getContentClient () |
Provide access to content client. | |
ConnectDomainSharedPtr | getDomain () const |
Retrieve domain instance. | |
AbstractServiceSharedPtr | getService () const |
Retrieve the service. | |
bool | hasService () const |
Determines whether there is a service bound to remote service host. | |
void | initialize (AbstractServiceSharedPtr service, const string preferredReliableP2PAdapter=string(""), const string preferredUnreliableP2PAdapter=string("connect.bearer.udp"), ConnectionAdapter::Parameters SSLParameters=ConnectionAdapter::Parameters(), VirtualFileClient *virtualFileClient=nullptr) |
Initialize the object with the provided service. | |
void | initializeEx (ExternalServiceAdapterSharedPtr service, const string preferredP2PAdapter=string("")) |
Initialize the object with the provided service. | |
virtual AbstractServiceSharedPtr | lookupLocalService (const string name) override |
Performs a lookup for local service that is registered with specific name. | |
virtual void | onMessageReceived (const MessagePackage &message) override |
Unwraps the received package and passes it to the hosted service. | |
void | runContinuously (int periodMs) |
Runs continuously until explicitly stopped with abortRun() method. | |
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. | |
void | setConnectionIdentity (const string &identity) |
Sets the identity information for connection. | |
void | setDomain (ConnectDomainSharedPtr domain) |
Configure the connect domain. | |
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). | |
RPCResult< bool > | setState (int state, string stateDetail=string()) |
Reports the service state. | |
RPCResult< bool > | start () |
Starts to run the service by registring the remote service to the server. | |
RPCResult< bool > | stop () |
Unregisters the remote service from the server and cleans up local sessions. | |
void | uninitialize () |
Cleanup previous service initialization. | |
virtual | ~ClientRemoteServiceHost () override |
Destructor. | |
virtual void | onClientDisconnected (const int &clientId) override |
virtual void | onServiceRegistered (const string &name) override |
virtual void | onServiceUnregistered (const string &name) override |
virtual void | serviceSessionAvailable () override |
Called to notify service session created. | |
virtual void | serviceSessionUnavailable () override |
Called to noitfy service session destroyed. | |
virtual void | onControlRemoteService (const string &id, const string &action, const string &targetname, const vector< string > &argument) override |
virtual void | onServiceConfigurationPropertiesChanged (const string &name, const string &stream) override |
virtual void | onReturnCredits (const string &name, const int &credits) override |
![]() | |
virtual bool | getParameter (size_t id, size_t ¶m) |
Allows to retrieve a dispatcher specific parameter, mostly for internal use. | |
MessageDispatcher () | |
Constructor. | |
virtual | ~MessageDispatcher () |
Destructor. | |
![]() | |
virtual | ~WorkQueueInterface () |
Virtual destructor (for SWIG). | |
![]() | |
virtual | ~ClientRemoteServiceHostInterface () |
Destructor. | |
![]() | |
virtual | ~LocalServiceDiscoveryInterface () |
Virtual destructor. | |
Protected Member Functions | |
ConnectedClientSharedPtr | createConnectedClientFromMessage (const MessagePackage &message) |
void | reportConfigurationProperties (bool changesOnly=true) |
void | reportRuntimeData (const string path="") |
void | work () |
Work routine - not to be called externally. | |
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).
|
explicit |
Constructor.
client | Provides network access to server |
|
overridevirtual |
Destructor.
void kanzi::connect::ClientRemoteServiceHost::abortRun | ( | ) |
Aborts above runContinuously call if available.
|
protected |
|
overridevirtual |
Wraps outgoing event to a message package and dispatches it.
message | Outgoing message (event). |
Implements kanzi::connect::MessageDispatcher.
void kanzi::connect::ClientRemoteServiceHost::enableVerboseLogging | ( | bool | enable | ) |
Control verbose debug logging on/off.
enable | if true then verbose logging is enabled, else false. |
RemoteContentClientSharedPtr kanzi::connect::ClientRemoteServiceHost::getContentClient | ( | ) |
Provide access to content client.
|
inline |
Retrieve domain instance.
AbstractServiceSharedPtr kanzi::connect::ClientRemoteServiceHost::getService | ( | ) | const |
Retrieve the service.
bool kanzi::connect::ClientRemoteServiceHost::hasService | ( | ) | const |
Determines whether there is a service bound to remote service host.
void kanzi::connect::ClientRemoteServiceHost::initialize | ( | AbstractServiceSharedPtr | service, |
const string | preferredReliableP2PAdapter = string(""), | ||
const string | preferredUnreliableP2PAdapter = string("connect.bearer.udp"), | ||
ConnectionAdapter::Parameters | SSLParameters = ConnectionAdapter::Parameters(), | ||
VirtualFileClient * | virtualFileClient = nullptr ) |
Initialize the object with the provided service.
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. |
void kanzi::connect::ClientRemoteServiceHost::initializeEx | ( | ExternalServiceAdapterSharedPtr | service, |
const string | preferredP2PAdapter = string("") ) |
Initialize the object with the provided service.
service | the service this client is running. |
preferredP2PAdapter | if nothing else specified, this particular adapter should be used for reliable P2P transfer. |
|
inlineoverridevirtual |
Performs a lookup for local service that is registered with specific name.
name | the name of the service, usually something like Connect.Service.MyProService or just MyProService |
Implements kanzi::connect::LocalServiceDiscoveryInterface.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Unwraps the received package and passes it to the hosted service.
message | Message that was received. |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
protected |
|
protected |
void kanzi::connect::ClientRemoteServiceHost::runContinuously | ( | int | periodMs | ) |
Runs continuously until explicitly stopped with abortRun() 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::ClientRemoteServiceHost::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.
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. |
|
overridevirtual |
Called to notify service session created.
Implements kanzi::connect::ServiceClientObserver.
|
overridevirtual |
Called to noitfy service session destroyed.
Implements kanzi::connect::ServiceClientObserver.
void kanzi::connect::ClientRemoteServiceHost::setConnectionIdentity | ( | const string & | identity | ) |
Sets the identity information for connection.
If not set, then defaults to "RemoteService: <servicename>"
identity | the connection identity. |
|
inline |
Configure the connect domain.
domain | the domain to set. ownership not transfered. |
void kanzi::connect::ClientRemoteServiceHost::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.
IPAddress | the IP Address. |
RPCResult< bool > kanzi::connect::ClientRemoteServiceHost::setState | ( | int | state, |
string | stateDetail = string() ) |
Reports the service state.
state | the state |
stateDetail | state description |
RPCResult< bool > kanzi::connect::ClientRemoteServiceHost::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.
RPCResult< bool > kanzi::connect::ClientRemoteServiceHost::stop | ( | ) |
Unregisters the remote service from the server and cleans up local sessions.
void kanzi::connect::ClientRemoteServiceHost::uninitialize | ( | ) |
Cleanup previous service initialization.
|
protected |
Work routine - not to be called externally.