A class that is used to connect an application to Kanzi Connect server. More...
#include <client.hpp>
Classes | |
struct | ServicePrivateData |
A class representing private data used by service clients and adapters. More... | |
struct | ServicePrivateStringData |
A class used to store a single string value for private use by service clients and adapters. More... | |
Public Member Functions | |
void | addInterface (AbstractInterfaceClientSharedPtr abstractInterface) |
Adds client-side network interface to system. | |
void | allowMultiThreadedTasks (const unsigned int threadCount) |
Allow clients task queue to process multi-threaded tasks. | |
void | clearWorkCallback () |
Clears a previously set work callback. | |
Client () | |
Constructor. | |
bool | connected () const |
Check whether client is currently connected. | |
Connection & | getConnection () |
Get connection object, used to connect to server. | |
shared_ptr< DiagnosticsServiceClient > | getDiagnosticsClient () |
Return diagnostics client instance. | |
template<typename T > | |
T * | getInterface () |
Retrieves network interface by it's type. | |
virtual AbstractInterfaceClient * | getInterfaceById (const string &id) override |
See InterfaceDomain::getInterfaceById. | |
virtual AbstractInterfaceClient * | getInterfaceByIndex (size_t index) override |
See InterfaceDomain::getInterfaceByIndex. | |
virtual size_t | getInterfaceCount () const override |
See InterfaceDomain::getInterfaceCount. | |
P2PClientSharedPtr | getP2PClient () |
Retrieve P2P client instance. | |
RPCCallStore & | getRPCCallStore () |
Retrieve reference to RPC call store implementation. | |
uint32_t | getRPCCallTimeoutGranularity () const |
Retrieve RPC method call timeout granularity. | |
RunningServicesMonitor & | getRunningServicesMonitor () |
Returns a reference to running services monitor. | |
shared_ptr< ServiceClient > | getServiceClient () |
Return service client instance. | |
shared_ptr< ServicePrivateData > | getServicePrivateData (const string_view &key) |
Gets private data perviously stored for the service. | |
Connection::WorkNotifyCallback * | getWorkCallback () |
Retrieve work callback if any. | |
void | initialize () |
Complete Construction. | |
void | interrupt () |
Interrupt wait/waitEx call. | |
void | interruptEx () |
Interrupts wait/waitEx call. | |
void | notifyWorkAvailable () |
Notify connection about new work. | |
bool | registerConnectionAdapter (const string &identifier, ConnectionAdapterCreateFunc creator) |
Registers new connection adapter type into client. | |
void | removeInterface (AbstractInterfaceClientSharedPtr abstractInterface) |
Removes a client-side network interface from client. | |
void | removeInterfaceByPointer (AbstractInterfaceClient *abstractInterface) |
Removes a client-side network interface from client. | |
void | removeInterfacesByName (const string &interfaceName) |
Removes all interfaces with specific interface name. | |
void | reset () |
Resets all internal structures and ensures client is disconnected. | |
void | setRPCCallTimeoutGranularity (uint32_t ms) |
Sets the granularity for pending RPC method call timeouts. | |
void | setServicePrivateData (const shared_ptr< ServicePrivateData > &privateData) |
Sets private data for internal use by a service clients and adapters. | |
void | setWorkCallback (Connection::WorkNotifyCallback *callback) |
Registers a work callback. | |
Wait * | signal () |
Get pointer to signal that is used to notify new work on main thread. | |
template<typename Func , typename... Args> | |
void | submitTask (Func &&func, Args &&... args) |
string | translateUri (const string &uri, bool encode) |
Translate the given uri to contain an actual server address. | |
bool | unregisterConnectionAdapter (const string &identifier) |
Unregister connection adapter from client. | |
void | wait (int ms=-1) |
Function to wait for network events to occur. | |
void | waitEx (int ms=-1) |
Wait function for external application bindings. | |
void | work () |
This needs to be called periodically, in order for client to process network events. | |
virtual | ~Client () override |
Destructor. | |
virtual void | notifyItem (ConnectWorkItemSharedPtr workItem) override |
virtual int64_t | allocateUniqueHandle () override |
Optionally implementable method that should return a handle that can later on be used cancel work item holding that identifier. | |
virtual void | cancelWorkItem (int64_t handle) override |
Cancels a work item holding an handle previously allocated using allocateUniqueHandle() | |
![]() | |
virtual | ~InterfaceDomain () override=default |
Destructor. | |
![]() | |
const string & | getResourceDirectory () const |
Retrieves the content & resource directory of the system. | |
UriTranslator & | getUriTranslator () |
Returns translator for Uris. | |
void | setResourceDirectory (const string &path) |
Sets resource directory of the system. | |
virtual | ~InterfaceDomainBase ()=default |
Destructor. | |
![]() | |
virtual | ~WorkQueueInterface () |
Virtual destructor (for SWIG). | |
A class that is used to connect an application to Kanzi Connect server.
This class allows to set up network connectivity and provides client-side access to network interfaces of the connected services.
kanzi::connect::Client::Client | ( | ) |
Constructor.
|
overridevirtual |
Destructor.
void kanzi::connect::Client::addInterface | ( | AbstractInterfaceClientSharedPtr | abstractInterface | ) |
Adds client-side network interface to system.
Currently needs to be called before connection is established.
abstractInterface | Interface to register in to system. |
|
overridevirtual |
Optionally implementable method that should return a handle that can later on be used cancel work item holding that identifier.
Reimplemented from kanzi::connect::WorkQueueInterface.
void kanzi::connect::Client::allowMultiThreadedTasks | ( | const unsigned int | threadCount | ) |
Allow clients task queue to process multi-threaded tasks.
threadCount | The number of worker threads used to process the multi-threaded task queue |
|
overridevirtual |
Cancels a work item holding an handle previously allocated using allocateUniqueHandle()
handle | the handle. |
Reimplemented from kanzi::connect::WorkQueueInterface.
void kanzi::connect::Client::clearWorkCallback | ( | ) |
Clears a previously set work callback.
bool kanzi::connect::Client::connected | ( | ) | const |
Check whether client is currently connected.
Connection & kanzi::connect::Client::getConnection | ( | ) |
Get connection object, used to connect to server.
shared_ptr< DiagnosticsServiceClient > kanzi::connect::Client::getDiagnosticsClient | ( | ) |
Return diagnostics client instance.
|
inline |
Retrieves network interface by it's type.
|
overridevirtual |
See InterfaceDomain::getInterfaceById.
Implements kanzi::connect::InterfaceDomain.
|
overridevirtual |
See InterfaceDomain::getInterfaceByIndex.
Implements kanzi::connect::InterfaceDomain.
|
overridevirtual |
See InterfaceDomain::getInterfaceCount.
Implements kanzi::connect::InterfaceDomain.
P2PClientSharedPtr kanzi::connect::Client::getP2PClient | ( | ) |
Retrieve P2P client instance.
RPCCallStore & kanzi::connect::Client::getRPCCallStore | ( | ) |
Retrieve reference to RPC call store implementation.
uint32_t kanzi::connect::Client::getRPCCallTimeoutGranularity | ( | ) | const |
Retrieve RPC method call timeout granularity.
RunningServicesMonitor & kanzi::connect::Client::getRunningServicesMonitor | ( | ) |
Returns a reference to running services monitor.
shared_ptr< ServiceClient > kanzi::connect::Client::getServiceClient | ( | ) |
Return service client instance.
shared_ptr< ServicePrivateData > kanzi::connect::Client::getServicePrivateData | ( | const string_view & | key | ) |
Gets private data perviously stored for the service.
Connection::WorkNotifyCallback * kanzi::connect::Client::getWorkCallback | ( | ) |
Retrieve work callback if any.
void kanzi::connect::Client::initialize | ( | ) |
Complete Construction.
void kanzi::connect::Client::interrupt | ( | ) |
Interrupt wait/waitEx call.
Use this method if Client execution gets always interrupted using the Client class API (interrupt()) and never directly using the underlying ConnectCondition object.
void kanzi::connect::Client::interruptEx | ( | ) |
Interrupts wait/waitEx call.
Use this method if Client execution gets also interrupted directly using the ConnectCondition object.
Generic usage pattern:
|
overridevirtual |
Implements kanzi::connect::WorkQueueInterface.
|
inline |
Notify connection about new work.
bool kanzi::connect::Client::registerConnectionAdapter | ( | const string & | identifier, |
ConnectionAdapterCreateFunc | creator ) |
Registers new connection adapter type into client.
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. |
void kanzi::connect::Client::removeInterface | ( | AbstractInterfaceClientSharedPtr | abstractInterface | ) |
Removes a client-side network interface from client.
abstractInterface | Interface to unregister from client |
void kanzi::connect::Client::removeInterfaceByPointer | ( | AbstractInterfaceClient * | abstractInterface | ) |
Removes a client-side network interface from client.
abstractInterface | Interface to unregister from client |
void kanzi::connect::Client::removeInterfacesByName | ( | const string & | interfaceName | ) |
Removes all interfaces with specific interface name.
interfaceName | the interface name that should be removed. |
void kanzi::connect::Client::reset | ( | ) |
Resets all internal structures and ensures client is disconnected.
void kanzi::connect::Client::setRPCCallTimeoutGranularity | ( | uint32_t | ms | ) |
Sets the granularity for pending RPC method call timeouts.
Smaller the granularity more often the timeouts of the pending RPC method calls is checked. Defaults to 10ms.
ms | milliseconds how often timeoutted rpc methods are checked. If 0 is passed then pending RPC method calls are checked for each work() routine call. |
void kanzi::connect::Client::setServicePrivateData | ( | const shared_ptr< ServicePrivateData > & | privateData | ) |
Sets private data for internal use by a service clients and adapters.
A service may update or replace this data at any point. The private data contains a key used to store and later find the data instance.
privateData | An instance of ServicePrivateData containing the private data. |
void kanzi::connect::Client::setWorkCallback | ( | Connection::WorkNotifyCallback * | callback | ) |
Registers a work callback.
callback | method to invoke when there is work to be done. |
Wait * kanzi::connect::Client::signal | ( | ) |
Get pointer to signal that is used to notify new work on main thread.
|
inline |
string kanzi::connect::Client::translateUri | ( | const string & | uri, |
bool | encode ) |
Translate the given uri to contain an actual server address.
uri | The string which contains <SERVER> tag to translate (allowed to be missing) |
encode | If true then the URI is encoded |
bool kanzi::connect::Client::unregisterConnectionAdapter | ( | const string & | identifier | ) |
Unregister connection adapter from client.
identifier | Identifier of the connection adapter. |
void kanzi::connect::Client::wait | ( | int | ms = -1 | ) |
Function to wait for network events to occur.
Blocks (but does not consume CPU) until events are received or timeout occurs. After this call returns, one should call work() in order to process the received events.
ms | Timeout for wait, -1 for infinite wait. |
void kanzi::connect::Client::waitEx | ( | int | ms = -1 | ) |
Wait function for external application bindings.
ms | milliseconds how long to wait. |
void kanzi::connect::Client::work | ( | ) |
This needs to be called periodically, in order for client to process network events.