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

A class that can be used to host a remote service on a client device. More...

#include <remote_service_host.hpp>

Inheritance diagram for kanzi::connect::ClientRemoteServiceHost:
kanzi::connect::ServiceClientObserver kanzi::connect::MessageDispatcher kanzi::connect::WorkQueueInterface kanzi::connect::p2p::RuntimeDataProvider kanzi::connect::ClientRemoteServiceHostInterface kanzi::connect::LocalServiceDiscoveryInterface

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
 
- Public Member Functions inherited from kanzi::connect::MessageDispatcher
virtual bool getParameter (size_t id, size_t &param)
 Allows to retrieve a dispatcher specific parameter, mostly for internal use.
 
 MessageDispatcher ()
 Constructor.
 
virtual ~MessageDispatcher ()
 Destructor.
 
- Public Member Functions inherited from kanzi::connect::WorkQueueInterface
virtual ~WorkQueueInterface ()
 Virtual destructor (for SWIG).
 
- Public Member Functions inherited from kanzi::connect::ClientRemoteServiceHostInterface
virtual ~ClientRemoteServiceHostInterface ()
 Destructor.
 
- Public Member Functions inherited from kanzi::connect::LocalServiceDiscoveryInterface
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.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ClientRemoteServiceHost()

kanzi::connect::ClientRemoteServiceHost::ClientRemoteServiceHost ( ClientSharedPtr client)
explicit

Constructor.

Parameters
clientProvides network access to server

◆ ~ClientRemoteServiceHost()

virtual kanzi::connect::ClientRemoteServiceHost::~ClientRemoteServiceHost ( )
overridevirtual

Destructor.

Member Function Documentation

◆ abortRun()

void kanzi::connect::ClientRemoteServiceHost::abortRun ( )

Aborts above runContinuously call if available.

◆ createConnectedClientFromMessage()

ConnectedClientSharedPtr kanzi::connect::ClientRemoteServiceHost::createConnectedClientFromMessage ( const MessagePackage & message)
protected

◆ dispatch()

virtual void kanzi::connect::ClientRemoteServiceHost::dispatch ( const MessagePackage & message)
overridevirtual

Wraps outgoing event to a message package and dispatches it.

Parameters
messageOutgoing message (event).

Implements kanzi::connect::MessageDispatcher.

◆ enableVerboseLogging()

void kanzi::connect::ClientRemoteServiceHost::enableVerboseLogging ( bool enable)

Control verbose debug logging on/off.

Parameters
enableif true then verbose logging is enabled, else false.

◆ getContentClient()

RemoteContentClientSharedPtr kanzi::connect::ClientRemoteServiceHost::getContentClient ( )

Provide access to content client.

Returns
the content client.

◆ getDomain()

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

Retrieve domain instance.

Returns
domain instance. ownership not transfered.

◆ getService()

AbstractServiceSharedPtr kanzi::connect::ClientRemoteServiceHost::getService ( ) const

Retrieve the service.

Returns
shared pointer to service.

◆ hasService()

bool kanzi::connect::ClientRemoteServiceHost::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()

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.

Parameters
servicethe service this client is running.
preferredReliableP2PAdapterif nothing else specified, this particular adapter should be used for reliable communications
preferredUnreliableP2PAdapterif nothing else specified, this particular adapter should be used for unreliable communications
SSLParameterspreferred SSL parameters to be used in server functionality.
virtualFileClientinstance 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.

◆ initializeEx()

void kanzi::connect::ClientRemoteServiceHost::initializeEx ( ExternalServiceAdapterSharedPtr service,
const string preferredP2PAdapter = string("") )

Initialize the object with the provided service.

Parameters
servicethe service this client is running.
preferredP2PAdapterif nothing else specified, this particular adapter should be used for reliable P2P transfer.

◆ lookupLocalService()

virtual AbstractServiceSharedPtr kanzi::connect::ClientRemoteServiceHost::lookupLocalService ( const string name)
inlineoverridevirtual

Performs a lookup for local service that is registered with specific name.

Parameters
namethe name of the service, usually something like Connect.Service.MyProService or just MyProService
Returns
pointer to service or null.

Implements kanzi::connect::LocalServiceDiscoveryInterface.

◆ onClientDisconnected()

virtual void kanzi::connect::ClientRemoteServiceHost::onClientDisconnected ( const int & clientId)
overridevirtual

◆ onControlRemoteService()

virtual void kanzi::connect::ClientRemoteServiceHost::onControlRemoteService ( const string & id,
const string & action,
const string & targetname,
const vector< string > & argument )
overridevirtual

◆ onMessageReceived()

virtual void kanzi::connect::ClientRemoteServiceHost::onMessageReceived ( const MessagePackage & message)
overridevirtual

Unwraps the received package and passes it to the hosted service.

Parameters
messageMessage that was received.

◆ onReturnCredits()

virtual void kanzi::connect::ClientRemoteServiceHost::onReturnCredits ( const string & name,
const int & credits )
overridevirtual

◆ onServiceConfigurationPropertiesChanged()

virtual void kanzi::connect::ClientRemoteServiceHost::onServiceConfigurationPropertiesChanged ( const string & name,
const string & stream )
overridevirtual

◆ onServiceRegistered()

virtual void kanzi::connect::ClientRemoteServiceHost::onServiceRegistered ( const string & name)
overridevirtual

◆ onServiceUnregistered()

virtual void kanzi::connect::ClientRemoteServiceHost::onServiceUnregistered ( const string & name)
overridevirtual

◆ reportConfigurationProperties()

void kanzi::connect::ClientRemoteServiceHost::reportConfigurationProperties ( bool changesOnly = true)
protected

◆ reportRuntimeData()

void kanzi::connect::ClientRemoteServiceHost::reportRuntimeData ( const string path = "")
protected

◆ runContinuously()

void kanzi::connect::ClientRemoteServiceHost::runContinuously ( int periodMs)

Runs continuously until explicitly stopped with abortRun() 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.

◆ runOnce()

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.

Parameters
mshow 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.

◆ serviceSessionAvailable()

virtual void kanzi::connect::ClientRemoteServiceHost::serviceSessionAvailable ( )
overridevirtual

Called to notify service session created.

Implements kanzi::connect::ServiceClientObserver.

◆ serviceSessionUnavailable()

virtual void kanzi::connect::ClientRemoteServiceHost::serviceSessionUnavailable ( )
overridevirtual

Called to noitfy service session destroyed.

Implements kanzi::connect::ServiceClientObserver.

◆ setConnectionIdentity()

void kanzi::connect::ClientRemoteServiceHost::setConnectionIdentity ( const string & identity)

Sets the identity information for connection.

If not set, then defaults to "RemoteService: <servicename>"

Parameters
identitythe connection identity.

◆ setDomain()

void kanzi::connect::ClientRemoteServiceHost::setDomain ( ConnectDomainSharedPtr domain)
inline

Configure the connect domain.

Parameters
domainthe domain to set. ownership not transfered.

◆ setServerIPAddress()

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.

Parameters
IPAddressthe IP Address.

◆ setState()

RPCResult< bool > kanzi::connect::ClientRemoteServiceHost::setState ( int state,
string stateDetail = string() )

Reports the service state.

Parameters
statethe state
stateDetailstate description
Returns
RPC variable that can be listened for completion.

◆ start()

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.

Returns
RPC variable that can be used to listen for completion.

◆ stop()

RPCResult< bool > kanzi::connect::ClientRemoteServiceHost::stop ( )

Unregisters the remote service from the server and cleans up local sessions.

Returns
RPC variable that can be used to listen for completion.

◆ uninitialize()

void kanzi::connect::ClientRemoteServiceHost::uninitialize ( )

Cleanup previous service initialization.

◆ work()

void kanzi::connect::ClientRemoteServiceHost::work ( )
protected

Work routine - not to be called externally.


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