ServiceManager

class kanzi::connect::ServiceManager : public ServiceServiceConcept, public InterfaceDomainBase, public IncomingMessageInterface, public ConnectionManager::Observer, public LocalServiceDiscoveryInterface, public VirtualFileProvider

A class that manages all services in Kanzi Connect Server.

This class allows both local and remote services to register in to system and manages the lifetime, operation and connectivity of all registered services.

Public Types

typedef function<void(vector<ServiceManager::ServiceInfo>)> InformationChangedCallbackFunction

Function prototype to be invoked when information changes.

typedef shared_ptr<void> InformationChangedSubscriptionToken

Handle given as return value to state callback registration.

Public Functions

ServiceManager(ConnectDomain *domain, DiagnosticsManagerSharedPtr diagnostics)

Constructor.

~ServiceManager()

Destructor.

InformationChangedSubscriptionToken addInformationChangeSubscription(InformationChangedCallbackFunction callback)

Adds observer to listen service information change messages.

Return

token that can later on be used to remove subscription.

Parameters
  • callback: function to call on change. Execution contenxt might vary.

void createDefinedServices()

Creates and registers an instance of each service (Connect.Service.

*) that is found from the metadata. Note: This functionality is likely to change in future.

ServiceHostSharedPtr getRemoteServiceHost(AbstractSessionSharedPtr session)

Tries to resolve a remote service host that is somehow bound to a given abstract session.

Return

service host pointer that could be a null.

Parameters
  • session: the abstract session to resolve.

ServiceRuntimeDataRegistrySharedPtr getRuntimeDataRegistry()

Retrieve shared runtime data registry.

Return

runtime data registry.

vector<ContentProviderSharedPtr> getServiceContentProviders(const string &service)

Retrieve the content providers bound to a specific service.

Return

vector of content providers bound to this particular service.

Parameters
  • service: the name of the service

ServiceHostSharedPtr getServiceHost(const string &id)

Retrieves the service host associated with the provided interface identifier.

Return

pointer to service host.

Parameters
  • id: identifies the interface

bool isCoreService(const string &name) const

Determines whether specific service is a core service.

Return

true if service is a core service.

Parameters
  • name: name of the service.

vector<ServiceInfo> listServices()

retrieves list of services with information attached.

Return

list of service decriptors.

virtual AbstractServiceSharedPtr lookupLocalService (const string name) KZ_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 notifyInformationObservers()

Calls all registered information observers in a delayed manner through the mainloop.

bool registerService(AbstractServiceSharedPtr service)

Registers service object to system.

Return

true if ok, false if registration failed, most likely due the fact service with same name already existed.

Parameters
  • service: Service to register.

void removeInformationChangeSubscription(InformationChangedSubscriptionToken token)

Removes observer.

Parameters
  • token: previously returned subscription token

void setPolicyMessageFilter(messagefilter::ServiceMessageFilterHandler handler)

Configures a filter handler for incoming messages.

Parameters
  • handler: the handler to set for incoming messages.

bool start(ConnectDomain *domain, ContentClientSharedPtr contentClient, WorkQueueInterface *workQueue)

Starts and initializes all services.

Return

true if successfully started. false if unable to start services.

Parameters
  • domain: contains setup data

  • contentClient: interface to content service

  • workQueue: global work queue pointer

bool stop()

Stops and uninitializes all services.

Return

true if succeeded. false on error.

bool unregisterService(AbstractServiceSharedPtr service)

Unregisters service object from server.

Return

true if service got removed. false if service not found or passed arguments were invalid.

Parameters
  • service: Service to unregister.

class ServiceInfo

Info and details for a running service.

Public Types

enum Location

Enumeration to describe where the service is being hosted and run.

Values:

enumerator Local

Service is local, it’s running on this server.

enumerator Remote

Service is remote, one of the clients is runnning the service remotely.

Public Members

string m_address

Address of the service. Empty for locally running service(s).

AbstractService::ServiceDescription m_description

Service description.

int m_instances

Amount of references to this service.

string m_interface

Name of the service interface.

Location m_location

Location of the service.

string m_serviceDescriptionHash

Running number to identify when service info has changed.

AbstractService::ServiceState m_state

State information regarding the service.