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. | |
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. | |
template<class T > | |
shared_ptr< T > | acquireService () |
Provides type-safe access to service. | |
template<class T > | |
shared_ptr< T > | acquireService (const string &identifier) |
Provides type-safe access to service instance. | |
AbstractServiceClientSharedPtr | acquireService (const string &identifier, ServiceCreationFunction creator) |
Provides access to service. | |
template<class T > | |
kanzi::shared_ptr< T > | acquireService (Domain &domain) |
Context () | |
Constructor. | |
ClientSharedPtr | getClient () const |
Access to client, which is used to connect to server. | |
int | getContextValue (int key, int defaultValue=0) |
Retrieves a free format value for a specific key. | |
string | getFileServerAddress () const |
Returns IP address of the remote file server. | |
string | getName () const |
Access to name of the connected client. | |
string | getResourceDirectory () const |
Returns directory where local resources are stored. | |
bool | registerConnectionAdapter (const string &identifier, ConnectionAdapterCreateFunc creator) |
Registers new connection adapter type into context. | |
template<class T > | |
void | registerService () |
Convenience function to register service creators. | |
void | registerService (const string &identifier, ServiceCreationFunction creator) |
Registers service type to context. | |
void | releaseService (const string &identifier) |
Ask context to release its handle to a service. | |
void | setContextValue (int key, int value) |
Stores a key-value pair into the context. | |
void | setServiceEnabledState (const string &serviceIdentifier, bool enabled) |
Enable/disable the specified service. | |
bool | unregisterConnectionAdapter (const string &identifier) |
Unregister connection adapter from context. | |
void | unregisterService (const string &identifier) |
Unregister service type from context. | |
~Context () | |
Destructor. | |
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. | |
static ContextSharedPtr | findContextForService (Domain &domain, const string &serviceIdentifier) |
Provides access for the client-side context instance for registered service. | |
static ContextSharedPtr | instance (Domain &domain, const string &serverName) |
Provides access for the client-side context instance. | |
static void | notifyResourceLoadingResult (Domain *domain, const string &uri, bool result) |
Notify resource loading status. Called by framework. | |
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. | |
static void | registerServiceToServerConnection (const string &serviceIdentifier, const string &serverName) |
Register certain service to be handled by specified server. | |
static void | releaseService (Domain &domain, const string &identifier) |
Ask context to release its handle to a service. | |
Context class is used to manage all client side objects that are related either to connectivity or services.
typedef function<void(shared_ptr<void> handler, const string& resourceUri, bool result) kanzi::connect::Context::ResourceLoadedCallback) |
typedef function<AbstractServiceClientSharedPtr(ClientSharedPtr, const string&) kanzi::connect::Context::ServiceCreationFunction) |
A function callback type that is invoked when a registered service needs to be instantiated.
kanzi::connect::Context::~Context | ( | ) |
Destructor.
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.
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.
resourceUri | Resource identifier. |
handler | Handler to be passed to callback. Is used for ensuring the validity of callback. |
resourceLoadedCallback | Callback to be called when operation completes. |
retryCount | Count of the retries if loading fails. This is common for all requests for same resource uri. |
retryIntervalMs | Time, in milli seconds, to wait before retrying resource loading. |
|
inline |
Provides type-safe access to service.
|
inline |
Provides type-safe access to service instance.
identifier | Identifier of the new service instance, usually equals to Service::TYPE. |
AbstractServiceClientSharedPtr kanzi::connect::Context::acquireService | ( | const string & | identifier, |
ServiceCreationFunction | creator ) |
Provides access to service.
identifier | Identifier of the service instance, usually equals to Service::TYPE. |
creator | A callback function that can be used to construct an instance of the service. |
|
static |
|
inline |
|
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
domain | Kanzi UI Domain that is used to host all Kanzi Connect runtime plugins. |
serverName | Identifies which server configuration to use |
|
static |
Provides access for the client-side context instance for registered service.
domain | Kanzi UI Domain that is used to host all Kanzi Connect runtime plugins. |
serviceIdentifier | Registered service. |
ClientSharedPtr kanzi::connect::Context::getClient | ( | ) | const |
Access to client, which is used to connect to server.
int kanzi::connect::Context::getContextValue | ( | int | key, |
int | defaultValue = 0 ) |
Retrieves a free format value for a specific key.
key | identifies to object to retrieve. |
string kanzi::connect::Context::getFileServerAddress | ( | ) | const |
Returns IP address of the remote file server.
string kanzi::connect::Context::getName | ( | ) | const |
Access to name of the connected client.
string kanzi::connect::Context::getResourceDirectory | ( | ) | const |
Returns directory where local resources are stored.
|
static |
Provides access for the client-side context instance.
Never creates the instance
domain | Kanzi UI Domain that is used to host all Kanzi Connect runtime plugins. |
serverName | Identifies which server configuration to use |
|
static |
Notify resource loading status. Called by framework.
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.
identifier | Identifier of the connection adapter. This name needs to match with the ones in configuration files. |
creator | Function that instantiates a connection adapter of given type. |
|
static |
Register creator for connection adapters Each Context constructor will use these to actually register the connection adapters to client.
identifier | Identifies the connection adapter |
creator | The factory method to construct the connection adapter |
|
inline |
Convenience function to register service creators.
void kanzi::connect::Context::registerService | ( | const string & | identifier, |
ServiceCreationFunction | creator ) |
Registers service type to context.
identifier | Identifier of the service. In most cases this matches with type of a service. |
creator | Function that instantiates a new service of given type. |
|
static |
Register certain service to be handled by specified server.
serviceIdentifier | Identifies the service |
serverName | Identifies the server |
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.
identifier | Identifier of the service instance, usually equals to Service::TYPE. |
|
static |
Ask context to release its handle to a service.
If there no other users for the service service will be released.
identifier | Identifier of the service instance, usually equals to Service::TYPE. |
void kanzi::connect::Context::setContextValue | ( | int | key, |
int | value ) |
Stores a key-value pair into the context.
key | the key to identify the value |
value | the value to save. |
void kanzi::connect::Context::setServiceEnabledState | ( | const string & | serviceIdentifier, |
bool | enabled ) |
Enable/disable the specified service.
serviceIdentifier | Identifies the service to enable/disable |
enabled | True enables and false disables the service |
bool kanzi::connect::Context::unregisterConnectionAdapter | ( | const string & | identifier | ) |
Unregister connection adapter from context.
Context must not have been started when unregistering an adapter.
identifier | Identifier of the connection adapter. |
void kanzi::connect::Context::unregisterService | ( | const string & | identifier | ) |
Unregister service type from context.
identifier | Identifier of the service. |