Kanzi Connect  1.1.10
Kanzi Connect C++ API
kanzi::connect::Client Class Reference

A class that is used to connect an application to Kanzi Connect server. More...

#include <client.hpp>

Inheritance diagram for kanzi::connect::Client:
kanzi::connect::InterfaceDomain kanzi::connect::WorkQueueInterface kanzi::connect::InterfaceDomainBase

Public Member Functions

void addInterface (AbstractInterfaceClient *abstractInterface)
 Adds client-side network interface to system. More...
 
void allowMultiThreadedTasks (const unsigned int threadCount)
 Allow clients task queue to process multi-threaded tasks. More...
 
void clearWorkCallback ()
 Clears a previously set work callback. More...
 
 Client ()
 Constructor. More...
 
bool connected () const
 Check whether client is currently connected. More...
 
ConnectiongetConnection ()
 Get connection object, used to connect to server. More...
 
shared_ptr< DiagnosticsServiceClient > getDiagnosticsClient ()
 Return diagnostics client instance. More...
 
template<typename T >
T * getInterface ()
 Retrieves network interface by it's type. More...
 
virtual AbstractInterfaceClientgetInterfaceById (const string &id) KZ_OVERRIDE
 See InterfaceDomain::getInterfaceById. More...
 
virtual AbstractInterfaceClientgetInterfaceByIndex (size_t index) KZ_OVERRIDE
 See InterfaceDomain::getInterfaceByIndex. More...
 
virtual size_t getInterfaceCount () const KZ_OVERRIDE
 See InterfaceDomain::getInterfaceCount. More...
 
P2PClientSharedPtr getP2PClient ()
 Retrieve P2P client instance. More...
 
RPCCallStoregetRPCCallStore ()
 Retrieve reference to RPC call store implementation. More...
 
uint32_t getRPCCallTimeoutGranularity () const
 Retrieve RPC method call timeout granularity. More...
 
RunningServicesMonitorgetRunningServicesMonitor ()
 Returns a reference to running services monitor. More...
 
shared_ptr< ServiceClientgetServiceClient ()
 Return service client instance. More...
 
Connection::WorkNotifyCallbackgetWorkCallback ()
 Retrieve work callback if any. More...
 
void initialize ()
 Complete Construction. More...
 
void interrupt ()
 Interrupt wait/waitEx call. More...
 
void interruptEx ()
 Interrupts wait/waitEx call. More...
 
void notifyWorkAvailable ()
 Notify connection about new work. More...
 
bool registerConnectionAdapter (const string &identifier, ConnectionAdapterCreateFunc creator)
 Registers new connection adapter type into client. More...
 
void removeInterface (AbstractInterfaceClient *abstractInterface)
 Removes a client-side network interface from client. More...
 
void reset ()
 Resets all internal structures and ensures client is disconnected. More...
 
void setRPCCallTimeoutGranularity (uint32_t ms)
 Sets the granularity for pending RPC method call timeouts. More...
 
void setWorkCallback (Connection::WorkNotifyCallback *callback)
 Registers a work callback. More...
 
Waitsignal ()
 Get pointer to signal that is used to notify new work on main thread. More...
 
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. More...
 
bool unregisterConnectionAdapter (const string &identifier)
 Unregister connection adapter from client. More...
 
void wait (int ms=-1)
 Function to wait for network events to occur. More...
 
void waitEx (int ms=-1)
 Wait function for external application bindings. More...
 
void work ()
 This needs to be called periodically, in order for client to process network events. More...
 
virtual ~Client () KZ_OVERRIDE
 Destructor. More...
 
virtual void notifyItem (ConnectWorkItemSharedPtr workItem) KZ_OVERRIDE
 
virtual int64_t allocateUniqueHandle () KZ_OVERRIDE
 Optionally implementable method that should return a handle that can later on be used cancel work item holding that identifier. More...
 
virtual void cancelWorkItem (int64_t handle) KZ_OVERRIDE
 Cancels a work item holding an handle previously allocated using allocateUniqueHandle() More...
 
- Public Member Functions inherited from kanzi::connect::InterfaceDomain
virtual ~InterfaceDomain () KZ_OVERRIDE=default
 Destructor. More...
 
- Public Member Functions inherited from kanzi::connect::InterfaceDomainBase
const string & getResourceDirectory () const
 Retrieves the content & resource directory of the system. More...
 
UriTranslatorgetUriTranslator ()
 Returns translator for Uris. More...
 
void setResourceDirectory (const string &path)
 Sets resource directory of the system. More...
 
virtual ~InterfaceDomainBase ()=default
 Destructor. More...
 
- Public Member Functions inherited from kanzi::connect::WorkQueueInterface
virtual ~WorkQueueInterface ()
 Virtual destructor (for SWIG). More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Client()

kanzi::connect::Client::Client ( )

Constructor.

◆ ~Client()

virtual kanzi::connect::Client::~Client ( )
virtual

Destructor.

Member Function Documentation

◆ addInterface()

void kanzi::connect::Client::addInterface ( AbstractInterfaceClient abstractInterface)

Adds client-side network interface to system.

Currently needs to be called before connection is established. Note: The Client takes ownership of the interface, the instance should not be destructed by other party unless removeInterface is called first to resume ownership back to someone else.

Parameters
abstractInterfaceInterface to register in to system.

◆ allocateUniqueHandle()

virtual int64_t kanzi::connect::Client::allocateUniqueHandle ( )
virtual

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.

◆ allowMultiThreadedTasks()

void kanzi::connect::Client::allowMultiThreadedTasks ( const unsigned int  threadCount)

Allow clients task queue to process multi-threaded tasks.

See also
kanzi::connect::connect::Client::notifyItem
Parameters
threadCountThe number of worker threads used to process the multi-threaded task queue

◆ cancelWorkItem()

virtual void kanzi::connect::Client::cancelWorkItem ( int64_t  handle)
virtual

Cancels a work item holding an handle previously allocated using allocateUniqueHandle()

Parameters
handlethe handle.

Reimplemented from kanzi::connect::WorkQueueInterface.

◆ clearWorkCallback()

void kanzi::connect::Client::clearWorkCallback ( )

Clears a previously set work callback.

◆ connected()

bool kanzi::connect::Client::connected ( ) const

Check whether client is currently connected.

Returns
true if connected.

◆ getConnection()

Connection& kanzi::connect::Client::getConnection ( )

Get connection object, used to connect to server.

Returns
Connection object that represents connection to server.

◆ getDiagnosticsClient()

shared_ptr<DiagnosticsServiceClient> kanzi::connect::Client::getDiagnosticsClient ( )

Return diagnostics client instance.

Returns
diagnostics client instance.

◆ getInterface()

template<typename T >
T* kanzi::connect::Client::getInterface ( )
inline

Retrieves network interface by it's type.

◆ getInterfaceById()

virtual AbstractInterfaceClient* kanzi::connect::Client::getInterfaceById ( const string &  id)
virtual

◆ getInterfaceByIndex()

virtual AbstractInterfaceClient* kanzi::connect::Client::getInterfaceByIndex ( size_t  index)
virtual

◆ getInterfaceCount()

virtual size_t kanzi::connect::Client::getInterfaceCount ( ) const
virtual

◆ getP2PClient()

P2PClientSharedPtr kanzi::connect::Client::getP2PClient ( )

Retrieve P2P client instance.

Returns
peer to peer functionality on client side.

◆ getRPCCallStore()

RPCCallStore& kanzi::connect::Client::getRPCCallStore ( )

Retrieve reference to RPC call store implementation.

Returns
the callstore object used to maintain ongoing RPC calls.

◆ getRPCCallTimeoutGranularity()

uint32_t kanzi::connect::Client::getRPCCallTimeoutGranularity ( ) const

Retrieve RPC method call timeout granularity.

Returns
millisecond value.

◆ getRunningServicesMonitor()

RunningServicesMonitor& kanzi::connect::Client::getRunningServicesMonitor ( )

Returns a reference to running services monitor.

Returns
reference to running services monitor. Returned reference remains valid as long as Client object is valid.

◆ getServiceClient()

shared_ptr<ServiceClient> kanzi::connect::Client::getServiceClient ( )

Return service client instance.

Returns
service client instance.

◆ getWorkCallback()

Connection::WorkNotifyCallback* kanzi::connect::Client::getWorkCallback ( )

Retrieve work callback if any.

Returns
work callback.

◆ initialize()

void kanzi::connect::Client::initialize ( )

Complete Construction.

◆ interrupt()

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.

◆ interruptEx()

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:

while (..)
{
m_client.waitEx();
m_client.work();
}
// .. in some another thread ..
m_client.interruptEx();
// .. in some another thread ..
m_client.signal()->notify_one();

◆ notifyItem()

virtual void kanzi::connect::Client::notifyItem ( ConnectWorkItemSharedPtr  workItem)
virtual

◆ notifyWorkAvailable()

void kanzi::connect::Client::notifyWorkAvailable ( )
inline

Notify connection about new work.

◆ registerConnectionAdapter()

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

Registers new connection adapter type into client.

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.

◆ removeInterface()

void kanzi::connect::Client::removeInterface ( AbstractInterfaceClient abstractInterface)

Removes a client-side network interface from client.

Note: The Client shifts the ownership of the object to the caller of this function. The caller is responsible for memory management of the pointed object after this point.

Parameters
abstractInterfaceInterface to unregister from client

◆ reset()

void kanzi::connect::Client::reset ( )

Resets all internal structures and ensures client is disconnected.

◆ setRPCCallTimeoutGranularity()

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.

Parameters
msmilliseconds how often timeoutted rpc methods are checked. If 0 is passed then pending RPC method calls are checked for each work() routine call.

◆ setWorkCallback()

void kanzi::connect::Client::setWorkCallback ( Connection::WorkNotifyCallback callback)

Registers a work callback.

Parameters
callbackmethod to invoke when there is work to be done.

◆ signal()

Wait* kanzi::connect::Client::signal ( )

Get pointer to signal that is used to notify new work on main thread.

◆ submitTask()

template<typename Func , typename... Args>
void kanzi::connect::Client::submitTask ( Func &&  func,
Args &&...  args 
)
inline

◆ translateUri()

string kanzi::connect::Client::translateUri ( const string &  uri,
bool  encode 
)

Translate the given uri to contain an actual server address.

Parameters
uriThe string which contains <SERVER> tag to translate (allowed to be missing)
encodeIf true then the URI is encoded
Returns
string which contains the <SERVER> tag translated to actual server IP address

◆ unregisterConnectionAdapter()

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

Unregister connection adapter from client.

Parameters
identifierIdentifier of the connection adapter.

◆ wait()

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.

Parameters
msTimeout for wait, -1 for infinite wait.

◆ waitEx()

void kanzi::connect::Client::waitEx ( int  ms = -1)

Wait function for external application bindings.

Parameters
msmilliseconds how long to wait.

◆ work()

void kanzi::connect::Client::work ( )

This needs to be called periodically, in order for client to process network events.


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