Client¶
-
class
kanzi::connect
::
Client
: public InterfaceDomain, public WorkQueueInterface, public enable_shared_from_this<Client>¶ 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.
Unnamed Group
- See
kanzi::connect::WorkQueueInterface
-
int64_t
allocateUniqueHandle
() override¶ Optionally implementable method that should return a handle that can later on be used cancel work item holding that identifier.
-
void
cancelWorkItem
(int64_t handle) override¶ Cancels a work item holding an handle previously allocated using allocateUniqueHandle()
- Parameters
handle
: the handle.
Public Functions
-
Client
()¶ Constructor.
-
~Client
() override¶ Destructor.
Adds client-side network interface to system.
Currently needs to be called before connection is established.
- Parameters
abstractInterface
: Interface to register in to system.
-
void
allowMultiThreadedTasks
(const unsigned int threadCount)¶ Allow clients task queue to process multi-threaded tasks.
- See
kanzi::connect::connect::Client::notifyItem
- Parameters
threadCount
: The number of worker threads used to process the multi-threaded task queue
-
void
clearWorkCallback
()¶ Clears a previously set work callback.
-
bool
connected
() const¶ Check whether client is currently connected.
- Return
true if connected.
-
Connection &
getConnection
()¶ Get connection object, used to connect to server.
- Return
Connection object that represents connection to server.
-
shared_ptr<DiagnosticsServiceClient>
getDiagnosticsClient
()¶ Return diagnostics client instance.
- Return
diagnostics client instance.
-
AbstractInterfaceClient *
getInterfaceById
(const string &id) override¶ See InterfaceDomain::getInterfaceById.
-
AbstractInterfaceClient *
getInterfaceByIndex
(size_t index) override¶ See InterfaceDomain::getInterfaceByIndex.
-
size_t
getInterfaceCount
() const override¶ See InterfaceDomain::getInterfaceCount.
-
P2PClientSharedPtr
getP2PClient
()¶ Retrieve P2P client instance.
- Return
peer to peer functionality on client side.
-
RPCCallStore &
getRPCCallStore
()¶ Retrieve reference to RPC call store implementation.
- Return
the callstore object used to maintain ongoing RPC calls.
-
uint32_t
getRPCCallTimeoutGranularity
() const¶ Retrieve RPC method call timeout granularity.
- Return
millisecond value.
-
RunningServicesMonitor &
getRunningServicesMonitor
()¶ Returns a reference to running services monitor.
- Return
reference to running services monitor. Returned reference remains valid as long as Client object is valid.
-
shared_ptr<ServiceClient>
getServiceClient
()¶ Return service client instance.
- 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.
- Return
work callback.
-
void
initialize
()¶ Complete Construction.
-
void
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
interruptEx
()¶ Interrupts wait/waitEx call.
Use this method if Client execution gets also interrupted directly using the ConnectCondition object.
Generic usage pattern:
-
void
notifyWorkAvailable
()¶ Notify connection about new work.
-
bool
registerConnectionAdapter
(const string &identifier, ConnectionAdapterCreateFunc creator)¶ Registers new connection adapter type into client.
- Parameters
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.
Removes a client-side network interface from client.
- Parameters
abstractInterface
: Interface to unregister from client
-
void
removeInterfaceByPointer
(AbstractInterfaceClient *abstractInterface)¶ Removes a client-side network interface from client.
- Parameters
abstractInterface
: Interface to unregister from client
-
void
removeInterfacesByName
(const string &interfaceName)¶ Removes all interfaces with specific interface name.
- Parameters
interfaceName
: the interface name that should be removed.
-
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.
Smaller the granularity more often the timeouts of the pending RPC method calls is checked. Defaults to 10ms.
- Parameters
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.
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.
- Parameters
privateData
: An instance of ServicePrivateData containing the private data.
-
void
setWorkCallback
(Connection::WorkNotifyCallback *callback)¶ Registers a work callback.
- Parameters
callback
: method to invoke when there is work to be done.
-
string
translateUri
(const string &uri, bool encode)¶ Translate the given uri to contain an actual server address.
- Return
string which contains the <SERVER> tag translated to actual server IP address
- Parameters
uri
: The string which contains <SERVER> tag to translate (allowed to be missing)encode
: If true then the URI is encoded
-
bool
unregisterConnectionAdapter
(const string &identifier)¶ Unregister connection adapter from client.
- Parameters
identifier
: Identifier of the connection adapter.
-
void
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.
- Parameters
ms
: Timeout for wait, -1 for infinite wait.
-
void
waitEx
(int ms = -1)¶ Wait function for external application bindings.
- Parameters
ms
: milliseconds how long to wait.
-
void
work
()¶ This needs to be called periodically, in order for client to process network events.
-
struct
ServicePrivateData
¶ A class representing private data used by service clients and adapters.
Subclassed by Client::ServicePrivateStringData
Public Members
-
const string
Key
¶
-
const string
-
struct
ServicePrivateStringData
: public Client::ServicePrivateData¶ A class used to store a single string value for private use by service clients and adapters.
Public Functions
-
ServicePrivateStringData
(const string &key, const string &data)¶
Public Members
-
const string
Data
¶
-