Kanzi Connect 3.9.10
kanzi::connect::ServiceHost Class Referenceabstract

Abstract base class that abstracts the origin of the service and simplifies the service management. More...

#include <service_host.hpp>

Inheritance diagram for kanzi::connect::ServiceHost:
kanzi::connect::LocalServiceHost kanzi::connect::RemoteServiceHost

Public Types

typedef function< void(ServiceHost *, RuntimeDataObjectSharedPtrConfigurationPropertyChangedCallback)
 Callback prototype to invoke when service configuration properties change.
 

Public Member Functions

virtual AbstractSessionSharedPtr acquireSession (ConnectedClientSharedPtr client, int sessionId)=0
 Creates a session to this service.
 
virtual void changeType (const string &type)=0
 Changes the interface name at runtime.
 
virtual int clientID () const =0
 Returns the client identifier.
 
virtual int countSessions () const =0
 Returns amount of sessions towards this service.
 
virtual void ensureDomain (ConnectDomainSharedPtr domain)
 Ensure that service instance (if local) has domain set.
 
virtual ClientDescriptorSharedPtr getClientDescriptor ()=0
 Return the client descriptor.
 
virtual RuntimeDataObjectSharedPtr getConfigurationProperties ()=0
 Retrieve service configuration properties.
 
virtual const AbstractService::ServiceDescriptiongetDescription ()=0
 Retrieve the service description from service host.
 
virtual const string getHash ()
 
virtual string getIdentifier () const =0
 Retrieve interface identifier.
 
virtual RuntimeDataObjectgetRuntimeData ()
 Internal API for across service scripting, not for public use.
 
virtual AbstractServiceSharedPtr getService () const =0
 Returns a service instance.
 
virtual const string getServiceDescriptionSchema (bool details=false)
 Retrieve service description schema.
 
virtual string getServiceRoutingInformationDescription (int serverclientid)=0
 Must be overridden by the corresponding implementation.
 
virtual shared_ptr< ServiceServiceConcept::Session > getServiceSession () const =0
 Returns a session to remote service.
 
virtual const AbstractService::ServiceStategetState ()=0
 Retrieve the service state information.
 
virtual void initialize (InterfaceDomainBase *domain, ContentClientSharedPtr contentClient, WorkQueueInterface *workQueue)=0
 Initialize the service.
 
virtual bool local () const =0
 Is this service local or not.
 
virtual void notifyAll (const MessagePackage &event)
 Internal API for across service scripting, not for public use.
 
virtual void notifyClientDisconnected (int clientId)=0
 Invoked to inform that specific client has disconnected.
 
virtual void receiveMessage (ConnectedClientSharedPtr client, const MessagePackage &message)=0
 Invoked for each message this service should handle.
 
virtual bool registerServiceRuntimeData (const string schema="")
 Invoked to register service runtime data.
 
virtual bool registerServiceRuntimeDataSchemaChange (const string &xml)
 Invoked to change runtime data schema at runtime.
 
virtual void releaseSession (int clientId, int sessionId)=0
 Releases a session.
 
virtual bool reportServiceRuntimeData (const string &path, const string &stream)
 Can be called, mainly for remote services, to inform about new service information that was received.
 
 ServiceHost (ServiceRuntimeDataRegistrySharedPtr registry=ServiceRuntimeDataRegistrySharedPtr())
 C++ constructor.
 
virtual void setConfigurationProperties (RuntimeDataObjectSharedPtr properties)
 Stores service configuration properties.
 
virtual void setConfigurationPropertyChangedCallback (ConfigurationPropertyChangedCallback callback)
 Install a callback to be invoked when configuration property changes.
 
virtual void setHash (const string hash)
 
virtual void setState (const AbstractService::ServiceState &state)=0
 Sets the service state.
 
bool subscribeForRuntimeDataSchemaChanges (GenericSyncObserver<> &observer)
 Start getting notifications of runtime data schema changes.
 
virtual void uninitialize ()=0
 cleanup the service.
 
bool unsubscribeForRuntimeDataSchemaChanges (GenericSyncObserver<> &observer)
 Stop receiving notifications of runtime data schema changes.
 
virtual void work (ConnectWorkItemSharedPtr workItem)=0
 Routine that get(s) called periodically or especially when object itself has requested it to be called using the work queue.
 
virtual ~ServiceHost ()
 Destructor.
 

Protected Member Functions

virtual void getServiceDescriptionSchemaImpl (string &output)=0
 Sub class specific implementation to fetch the service description.
 

Protected Attributes

ConfigurationPropertyChangedCallback m_configurationPropertyChangedCallback
 
unique_ptr< RuntimeDataChildChangeMonitorm_configurationPropertyChangeMonitor
 
ServiceRuntimeDataRegistry::ContentRegistrationToken m_runtimeDataRegistrationToken
 
ServiceRuntimeDataRegistrySharedPtr m_runtimeDataRegistry
 Runtime data registry for convenient access.
 
GenericSyncPublisher m_runtimeDataSchemaChangePublisher
 Publisher to use when runtime data schema changes within the ServiceHost.
 
AbstractService::RuntimeDataSchemaChangeSubscriptionToken m_runtimeDataSchemaChangeSubscriptionToken
 

Detailed Description

Abstract base class that abstracts the origin of the service and simplifies the service management.

Services can be hosted locally in server or remotely in client. This class simplifies the server-side service management by abstracting the actual origin of the service. See LocalServiceHost and RemoteServiceHost for local and remote variants.

Member Typedef Documentation

◆ ConfigurationPropertyChangedCallback

typedef function<void(ServiceHost*, RuntimeDataObjectSharedPtr) kanzi::connect::ServiceHost::ConfigurationPropertyChangedCallback)

Callback prototype to invoke when service configuration properties change.

Constructor & Destructor Documentation

◆ ServiceHost()

kanzi::connect::ServiceHost::ServiceHost ( ServiceRuntimeDataRegistrySharedPtr registry = ServiceRuntimeDataRegistrySharedPtr())
inline

C++ constructor.

Parameters
registryruntime data registry.

◆ ~ServiceHost()

virtual kanzi::connect::ServiceHost::~ServiceHost ( )
virtual

Destructor.

Member Function Documentation

◆ acquireSession()

virtual AbstractSessionSharedPtr kanzi::connect::ServiceHost::acquireSession ( ConnectedClientSharedPtr client,
int sessionId )
pure virtual

Creates a session to this service.

Parameters
clientidentifies the client.
sessionIdidentifies the session.
Returns
session instance. ownership not transfered.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ changeType()

virtual void kanzi::connect::ServiceHost::changeType ( const string & type)
pure virtual

Changes the interface name at runtime.

Parameters
typenew type for the interface.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ clientID()

virtual int kanzi::connect::ServiceHost::clientID ( ) const
pure virtual

Returns the client identifier.

Relevant only for remote clients. Will return -1 for local clients.

Returns
client identifier.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ countSessions()

virtual int kanzi::connect::ServiceHost::countSessions ( ) const
pure virtual

Returns amount of sessions towards this service.

Returns
amount of sessions

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ ensureDomain()

virtual void kanzi::connect::ServiceHost::ensureDomain ( ConnectDomainSharedPtr domain)
inlinevirtual

Ensure that service instance (if local) has domain set.

If not set earlier will put the provided domain.

Parameters
domainwhich domain to put the service in case not previously bind.

◆ getClientDescriptor()

virtual ClientDescriptorSharedPtr kanzi::connect::ServiceHost::getClientDescriptor ( )
pure virtual

Return the client descriptor.

Relevant only for remote services.

Returns
client descriptor

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getConfigurationProperties()

virtual RuntimeDataObjectSharedPtr kanzi::connect::ServiceHost::getConfigurationProperties ( )
pure virtual

Retrieve service configuration properties.

Returns
properties as shared object.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getDescription()

virtual const AbstractService::ServiceDescription & kanzi::connect::ServiceHost::getDescription ( )
pure virtual

Retrieve the service description from service host.

Returns
const reference to service description

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getHash()

virtual const string kanzi::connect::ServiceHost::getHash ( )
virtual

◆ getIdentifier()

virtual string kanzi::connect::ServiceHost::getIdentifier ( ) const
pure virtual

Retrieve interface identifier.

Returns
interface ID this service handles.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getRuntimeData()

virtual RuntimeDataObject * kanzi::connect::ServiceHost::getRuntimeData ( )
inlinevirtual

Internal API for across service scripting, not for public use.

Request a pointer to service host runtime data. Returned data (if any) may be a mirror to a service registry so modifying values here may not be visible for the hosted service itself.

Reimplemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getService()

virtual AbstractServiceSharedPtr kanzi::connect::ServiceHost::getService ( ) const
pure virtual

Returns a service instance.

Relevant only for local services.

Returns
service

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getServiceDescriptionSchema()

virtual const string kanzi::connect::ServiceHost::getServiceDescriptionSchema ( bool details = false)
virtual

Retrieve service description schema.

Parameters
detailsif true more detailed description is provided. if false then only limited set of information that kanzi studio can handle is provided.
Returns
xml format service description.

◆ getServiceDescriptionSchemaImpl()

virtual void kanzi::connect::ServiceHost::getServiceDescriptionSchemaImpl ( string & output)
protectedpure virtual

Sub class specific implementation to fetch the service description.

Parameters
outputThe target to set the description to

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getServiceRoutingInformationDescription()

virtual string kanzi::connect::ServiceHost::getServiceRoutingInformationDescription ( int serverclientid)
pure virtual

Must be overridden by the corresponding implementation.

Returns
xml format routing information for the service.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getServiceSession()

virtual shared_ptr< ServiceServiceConcept::Session > kanzi::connect::ServiceHost::getServiceSession ( ) const
pure virtual

Returns a session to remote service.

Relevant only for remote services.

Returns
session

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ getState()

virtual const AbstractService::ServiceState & kanzi::connect::ServiceHost::getState ( )
pure virtual

Retrieve the service state information.

Returns
const reference to service state information.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ initialize()

virtual void kanzi::connect::ServiceHost::initialize ( InterfaceDomainBase * domain,
ContentClientSharedPtr contentClient,
WorkQueueInterface * workQueue )
pure virtual

Initialize the service.

Parameters
domainenvironment where the service is run in.
contentClientaccess to content system
workQueueinterface to work queue used to dispatch work service is ready will eventually cause the services work() method to be invoked.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ local()

virtual bool kanzi::connect::ServiceHost::local ( ) const
pure virtual

Is this service local or not.

Returns
true if service is local

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ notifyAll()

virtual void kanzi::connect::ServiceHost::notifyAll ( const MessagePackage & event)
inlinevirtual

Internal API for across service scripting, not for public use.

Notify all client sessions with message.

Reimplemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ notifyClientDisconnected()

virtual void kanzi::connect::ServiceHost::notifyClientDisconnected ( int clientId)
pure virtual

Invoked to inform that specific client has disconnected.

Parameters
clientIdIdentifies the client.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ receiveMessage()

virtual void kanzi::connect::ServiceHost::receiveMessage ( ConnectedClientSharedPtr client,
const MessagePackage & message )
pure virtual

Invoked for each message this service should handle.

Parameters
clientidentifies the message sender
messagethe message to process.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ registerServiceRuntimeData()

virtual bool kanzi::connect::ServiceHost::registerServiceRuntimeData ( const string schema = "")
virtual

Invoked to register service runtime data.

Parameters
schemathe schema (xml)
Returns
true if registered successfully.

◆ registerServiceRuntimeDataSchemaChange()

virtual bool kanzi::connect::ServiceHost::registerServiceRuntimeDataSchemaChange ( const string & xml)
virtual

Invoked to change runtime data schema at runtime.

Parameters
xmlthe xml structure
Returns
true on success.

◆ releaseSession()

virtual void kanzi::connect::ServiceHost::releaseSession ( int clientId,
int sessionId )
pure virtual

Releases a session.

Parameters
clientIdidentifies the client
sessionIdidentifies the session

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ reportServiceRuntimeData()

virtual bool kanzi::connect::ServiceHost::reportServiceRuntimeData ( const string & path,
const string & stream )
inlinevirtual

Can be called, mainly for remote services, to inform about new service information that was received.

Reimplemented in kanzi::connect::RemoteServiceHost.

◆ setConfigurationProperties()

virtual void kanzi::connect::ServiceHost::setConfigurationProperties ( RuntimeDataObjectSharedPtr properties)
inlinevirtual

Stores service configuration properties.

Default implementation is empty, should be overridden by the remote service host implementation

Parameters
propertiesdata object describing the properties.

Reimplemented in kanzi::connect::RemoteServiceHost.

◆ setConfigurationPropertyChangedCallback()

virtual void kanzi::connect::ServiceHost::setConfigurationPropertyChangedCallback ( ConfigurationPropertyChangedCallback callback)
virtual

Install a callback to be invoked when configuration property changes.

Parameters
callbackto be invoked.

◆ setHash()

virtual void kanzi::connect::ServiceHost::setHash ( const string hash)
virtual

◆ setState()

virtual void kanzi::connect::ServiceHost::setState ( const AbstractService::ServiceState & state)
pure virtual

Sets the service state.

Relevant only for remote clients.

Parameters
statenew state for remote clients.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ subscribeForRuntimeDataSchemaChanges()

bool kanzi::connect::ServiceHost::subscribeForRuntimeDataSchemaChanges ( GenericSyncObserver<> & observer)

Start getting notifications of runtime data schema changes.

Parameters
observerThe instance which will start receiving notifications
Returns
True if subscription was successful, will not accept double subscription

◆ uninitialize()

virtual void kanzi::connect::ServiceHost::uninitialize ( )
pure virtual

cleanup the service.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

◆ unsubscribeForRuntimeDataSchemaChanges()

bool kanzi::connect::ServiceHost::unsubscribeForRuntimeDataSchemaChanges ( GenericSyncObserver<> & observer)

Stop receiving notifications of runtime data schema changes.

Parameters
observerThe instance which will stop receiving notifications
Returns
True if unsubscription was successful

◆ work()

virtual void kanzi::connect::ServiceHost::work ( ConnectWorkItemSharedPtr workItem)
pure virtual

Routine that get(s) called periodically or especially when object itself has requested it to be called using the work queue.

Parameters
workItemItem to be processed.

Implemented in kanzi::connect::LocalServiceHost, and kanzi::connect::RemoteServiceHost.

Member Data Documentation

◆ m_configurationPropertyChangedCallback

ConfigurationPropertyChangedCallback kanzi::connect::ServiceHost::m_configurationPropertyChangedCallback
protected

◆ m_configurationPropertyChangeMonitor

unique_ptr<RuntimeDataChildChangeMonitor> kanzi::connect::ServiceHost::m_configurationPropertyChangeMonitor
protected

◆ m_runtimeDataRegistrationToken

ServiceRuntimeDataRegistry::ContentRegistrationToken kanzi::connect::ServiceHost::m_runtimeDataRegistrationToken
protected

◆ m_runtimeDataRegistry

ServiceRuntimeDataRegistrySharedPtr kanzi::connect::ServiceHost::m_runtimeDataRegistry
protected

Runtime data registry for convenient access.

◆ m_runtimeDataSchemaChangePublisher

GenericSyncPublisher kanzi::connect::ServiceHost::m_runtimeDataSchemaChangePublisher
protected

Publisher to use when runtime data schema changes within the ServiceHost.

◆ m_runtimeDataSchemaChangeSubscriptionToken

AbstractService::RuntimeDataSchemaChangeSubscriptionToken kanzi::connect::ServiceHost::m_runtimeDataSchemaChangeSubscriptionToken
protected

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