Kanzi Connect  3.9.9
Kanzi Connect C++ API
kanzi::connect::Context Class Reference

Context class is used to manage all client side objects that are related either to connectivity or services. More...

#include <context.hpp>

Public Types

typedef function< void(shared_ptr< void > handler, const string &resourceUri, bool result)> ResourceLoadedCallback
 
typedef function< AbstractServiceClientSharedPtr(ClientSharedPtr, const string &)> ServiceCreationFunction
 A function callback type that is invoked when a registered service needs to be instantiated. More...
 

Public Member Functions

ResourceSharedPtr acquireResourceAsync (string resourceUri, shared_ptr< void > handler, ResourceLoadedCallback resourceLoadedCallback, size_t retryCount=5, unsigned int retryIntervalMs=5000)
 Request loading remote resource using the server attached to this instance of Context. More...
 
AbstractServiceClientSharedPtr acquireService (const string &identifier, ServiceCreationFunction creator)
 Provides access to service. More...
 
template<class T >
shared_ptr< T > acquireService (const string &identifier)
 Provides type-safe access to service instance. More...
 
template<class T >
shared_ptr< T > acquireService ()
 Provides type-safe access to service. More...
 
template<class T >
kanzi::shared_ptr< T > acquireService (Domain &domain)
 
 Context ()
 Constructor. More...
 
ClientSharedPtr getClient () const
 Access to client, which is used to connect to server. More...
 
int getContextValue (int key, int defaultValue=0)
 Retrieves a free format value for a specific key. More...
 
string getFileServerAddress () const
 Returns IP address of the remote file server. More...
 
string getName () const
 Access to name of the connected client. More...
 
string getResourceDirectory () const
 Returns directory where local resources are stored. More...
 
bool registerConnectionAdapter (const string &identifier, ConnectionAdapterCreateFunc creator)
 Registers new connection adapter type into context. More...
 
void registerService (const string &identifier, ServiceCreationFunction creator)
 Registers service type to context. More...
 
template<class T >
void registerService ()
 Convenience function to register service creators. More...
 
void releaseService (const string &identifier)
 Ask context to release its handle to a service. More...
 
void setContextValue (int key, int value)
 Stores a key-value pair into the context. More...
 
void setServiceEnabledState (const string &serviceIdentifier, bool enabled)
 Enable/disable the specified service. More...
 
bool unregisterConnectionAdapter (const string &identifier)
 Unregister connection adapter from context. More...
 
void unregisterService (const string &identifier)
 Unregister service type from context. More...
 
 ~Context ()
 Destructor. More...
 

Static Public Member Functions

template<class T >
static shared_ptr< T > acquireService (Domain &domain)
 
static ContextSharedPtr createOrFetchInstance (Domain &domain, const string &serverName)
 Create or fetch a context instance This function will create a new context if one does not yet exist. More...
 
static ContextSharedPtr findContextForService (Domain &domain, const string &serviceIdentifier)
 Provides access for the client-side context instance for registered service. More...
 
static ContextSharedPtr instance (Domain &domain, const string &serverName)
 Provides access for the client-side context instance. More...
 
static void notifyResourceLoadingResult (Domain *domain, const string &uri, bool result)
 Notify resource loading status. Called by framework. More...
 
static bool registerConnectionAdapterCreator (const string &identifier, ConnectionAdapterCreateFunc creator)
 Register creator for connection adapters Each Context constructor will use these to actually register the connection adapters to client. More...
 
static void registerServiceToServerConnection (const string &serviceIdentifier, const string &serverName)
 Register certain service to be handled by specified server. More...
 
static void releaseService (Domain &domain, const string &identifier)
 Ask context to release its handle to a service. More...
 

Detailed Description

Context class is used to manage all client side objects that are related either to connectivity or services.

Member Typedef Documentation

◆ ResourceLoadedCallback

typedef function<void(shared_ptr<void> handler, const string& resourceUri, bool result)> kanzi::connect::Context::ResourceLoadedCallback

◆ ServiceCreationFunction

A function callback type that is invoked when a registered service needs to be instantiated.

Constructor & Destructor Documentation

◆ ~Context()

kanzi::connect::Context::~Context ( )

Destructor.

◆ Context()

kanzi::connect::Context::Context ( )

Constructor.

One instance of this class should be created (per connected server). During the application start-up, the Kanzi runtime plug-ins are loaded and an instance of the Context class is instantiated per server. Usually this is created by the plugin that is loaded first and then instance() function can be used to access / share it elsewhere.

Member Function Documentation

◆ acquireResourceAsync()

ResourceSharedPtr kanzi::connect::Context::acquireResourceAsync ( string  resourceUri,
shared_ptr< void >  handler,
ResourceLoadedCallback  resourceLoadedCallback,
size_t  retryCount = 5,
unsigned int  retryIntervalMs = 5000 
)

Request loading remote resource using the server attached to this instance of Context.

Parameters
resourceUriResource identifier.
handlerHandler to be passed to callback. Is used for ensuring the validity of callback.
resourceLoadedCallbackCallback to be called when operation completes.
retryCountCount of the retries if loading fails. This is common for all requests for same resource uri.
retryIntervalMsTime, in milli seconds, to wait before retrying resource loading.
Returns
pointer to resource if resource has been previously loaded, nullptr otherwise.

◆ acquireService() [1/5]

template<class T >
static shared_ptr<T> kanzi::connect::Context::acquireService ( Domain &  domain)
static

◆ acquireService() [2/5]

AbstractServiceClientSharedPtr kanzi::connect::Context::acquireService ( const string &  identifier,
ServiceCreationFunction  creator 
)

Provides access to service.

Parameters
identifierIdentifier of the service instance, usually equals to Service::TYPE.
creatorA callback function that can be used to construct an instance of the service.
Returns
Pointer to service.

◆ acquireService() [3/5]

template<class T >
shared_ptr<T> kanzi::connect::Context::acquireService ( const string &  identifier)
inline

Provides type-safe access to service instance.

Parameters
identifierIdentifier of the new service instance, usually equals to Service::TYPE.
Returns
Pointer to service.

◆ acquireService() [4/5]

template<class T >
shared_ptr<T> kanzi::connect::Context::acquireService ( )
inline

Provides type-safe access to service.

Returns
Pointer to service.

◆ acquireService() [5/5]

template<class T >
kanzi::shared_ptr<T> kanzi::connect::Context::acquireService ( Domain &  domain)
inline

◆ createOrFetchInstance()

static ContextSharedPtr kanzi::connect::Context::createOrFetchInstance ( Domain &  domain,
const string &  serverName 
)
static

Create or fetch a context instance This function will create a new context if one does not yet exist.

Use this version only in places where creating new context instance is allowed. For normal instance access use the Context::instance method

Parameters
domainKanzi UI Domain that is used to host all Kanzi Connect runtime plugins.
serverNameIdentifies which server configuration to use
Returns
Shared pointer to Context.

◆ findContextForService()

static ContextSharedPtr kanzi::connect::Context::findContextForService ( Domain &  domain,
const string &  serviceIdentifier 
)
static

Provides access for the client-side context instance for registered service.

Parameters
domainKanzi UI Domain that is used to host all Kanzi Connect runtime plugins.
serviceIdentifierRegistered service.
Returns
Shared pointer to Context.

◆ getClient()

ClientSharedPtr kanzi::connect::Context::getClient ( ) const

Access to client, which is used to connect to server.

Returns
Client instance.

◆ getContextValue()

int kanzi::connect::Context::getContextValue ( int  key,
int  defaultValue = 0 
)

Retrieves a free format value for a specific key.

Parameters
keyidentifies to object to retrieve.
Returns
value that was found or provided default value otherwise. (default defaults to 0).

◆ getFileServerAddress()

string kanzi::connect::Context::getFileServerAddress ( ) const

Returns IP address of the remote file server.

Returns
IP address of the remote file server.

◆ getName()

string kanzi::connect::Context::getName ( ) const

Access to name of the connected client.

Returns
Name of this client.

◆ getResourceDirectory()

string kanzi::connect::Context::getResourceDirectory ( ) const

Returns directory where local resources are stored.

Returns
File path to local resource folder.

◆ instance()

static ContextSharedPtr kanzi::connect::Context::instance ( Domain &  domain,
const string &  serverName 
)
static

Provides access for the client-side context instance.

Never creates the instance

Parameters
domainKanzi UI Domain that is used to host all Kanzi Connect runtime plugins.
serverNameIdentifies which server configuration to use
Returns
Shared pointer to Context. Null if not found

◆ notifyResourceLoadingResult()

static void kanzi::connect::Context::notifyResourceLoadingResult ( Domain *  domain,
const string &  uri,
bool  result 
)
static

Notify resource loading status. Called by framework.

◆ registerConnectionAdapter()

bool kanzi::connect::Context::registerConnectionAdapter ( const string &  identifier,
ConnectionAdapterCreateFunc  creator 
)

Registers new connection adapter type into context.

Context must not have been started when registering new adapter.

Parameters
identifierIdentifier of the connection adapter. This name needs to match with the ones in configuration files.
creatorFunction that instantiates a connection adapter of given type.
Returns
true if registration was successful

◆ registerConnectionAdapterCreator()

static bool kanzi::connect::Context::registerConnectionAdapterCreator ( const string &  identifier,
ConnectionAdapterCreateFunc  creator 
)
static

Register creator for connection adapters Each Context constructor will use these to actually register the connection adapters to client.

Parameters
identifierIdentifies the connection adapter
creatorThe factory method to construct the connection adapter
Returns
True if the creator was registered successfully

◆ registerService() [1/2]

void kanzi::connect::Context::registerService ( const string &  identifier,
ServiceCreationFunction  creator 
)

Registers service type to context.

Parameters
identifierIdentifier of the service. In most cases this matches with type of a service.
creatorFunction that instantiates a new service of given type.

◆ registerService() [2/2]

template<class T >
void kanzi::connect::Context::registerService ( )
inline

Convenience function to register service creators.

◆ registerServiceToServerConnection()

static void kanzi::connect::Context::registerServiceToServerConnection ( const string &  serviceIdentifier,
const string &  serverName 
)
static

Register certain service to be handled by specified server.

Parameters
serviceIdentifierIdentifies the service
serverNameIdentifies the server

◆ releaseService() [1/2]

static void kanzi::connect::Context::releaseService ( Domain &  domain,
const string &  identifier 
)
static

Ask context to release its handle to a service.

If there no other users for the service service will be released.

Parameters
identifierIdentifier of the service instance, usually equals to Service::TYPE.

◆ releaseService() [2/2]

void kanzi::connect::Context::releaseService ( const string &  identifier)

Ask context to release its handle to a service.

If there no other users for the service service will be released.

Parameters
identifierIdentifier of the service instance, usually equals to Service::TYPE.

◆ setContextValue()

void kanzi::connect::Context::setContextValue ( int  key,
int  value 
)

Stores a key-value pair into the context.

Parameters
keythe key to identify the value
valuethe value to save.

◆ setServiceEnabledState()

void kanzi::connect::Context::setServiceEnabledState ( const string &  serviceIdentifier,
bool  enabled 
)

Enable/disable the specified service.

Parameters
serviceIdentifierIdentifies the service to enable/disable
enabledTrue enables and false disables the service

◆ unregisterConnectionAdapter()

bool kanzi::connect::Context::unregisterConnectionAdapter ( const string &  identifier)

Unregister connection adapter from context.

Context must not have been started when unregistering an adapter.

Parameters
identifierIdentifier of the connection adapter.

◆ unregisterService()

void kanzi::connect::Context::unregisterService ( const string &  identifier)

Unregister service type from context.

Parameters
identifierIdentifier of the service.

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