ClientRemoteServiceHost

class kanzi::connect::ClientRemoteServiceHost : public ServiceClientObserver, public MessageDispatcher, public WorkQueueInterface, public RuntimeDataProvider, public ClientRemoteServiceHostInterface, public LocalServiceDiscoveryInterface

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

void onClientDisconnected(const int &clientId) override

See

kanzi::connect::ServiceClientObserver

void onServiceRegistered(const string &name) override
void onServiceUnregistered(const string &name) override
void serviceSessionAvailable() override

Called to notify service session created.

void serviceSessionUnavailable() override

Called to noitfy service session destroyed.

void onControlRemoteService(const string &id, const string &action, const string &targetname, const vector<string> &argument) override
void onServiceConfigurationPropertiesChanged(const string &name, const string &stream) override
void onReturnCredits(const string &name, const int &credits) override

Public Functions

ClientRemoteServiceHost(ClientSharedPtr client)

Constructor.

Parameters
  • client: Provides network access to server

~ClientRemoteServiceHost() override

Destructor.

void abortRun()

Aborts above runContinuously call if available.

void dispatch(const MessagePackage &message) 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.

Return

the content client.

ConnectDomainSharedPtr getDomain() const

Retrieve domain instance.

Return

domain instance. ownership not transfered.

AbstractServiceSharedPtr getService() const

Retrieve the service.

Return

shared pointer to service.

bool hasService() const

Determines whether there is a service bound to remote service host.

Return

true if remote service host is bound to a service.

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.

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.

void initializeEx(ExternalServiceAdapterSharedPtr service, const string preferredP2PAdapter = string(""))

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.

AbstractServiceSharedPtr lookupLocalService(const string name) override

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

Return

pointer to service or null.

Parameters
  • name: the name of the service, usually something like Connect.Service.MyProService or just MyProService

void onMessageReceived(const MessagePackage &message) 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.

void setDomain(ConnectDomainSharedPtr 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.

Return

RPC variable that can be listened for completion.

Parameters
  • state: the state

  • stateDetail: state description

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.

Return

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.

Return

RPC variable that can be used to listen for completion.

void uninitialize()

Cleanup previous service initialization.