Kanzi Connect  3.9.8
Kanzi Connect C++ API
kanzi::connect::GenericServiceClient Class Reference

Limitation: Only one GenericServiceClient instance per Client per Service is allowed. Having multiple instances of the class for same service and same network connection will not work properly. More...

#include <genericserviceclient.hpp>

Inheritance diagram for kanzi::connect::GenericServiceClient:

Classes

class  EventCallbackEx
 Traditional c++ interface for callbacks to be used in android. More...
 

Public Types

typedef function< void(const string &, const map< string, string > &)> EventCallbackFunction
 Signature of event callback function. All arguments converted to strings. More...
 
typedef shared_ptr< void > EventCallbackRegistrationToken
 Opaque token type for callback registration. More...
 
enum  EventRegistrationState { EventRegistrationWaitingForService, EventRegistrationWaitingIntrospection, EventRegistrationFailed, EventRegistrationComplete }
 Enumerates the event registration states. More...
 
typedef function< void(const string &, EventRegistrationState)> EventRegistrationStateCallbackFunction
 Function to be used to receive event registration state changes. More...
 

Public Member Functions

MethodSharedPtr createMethod (const string &methodName)
 Creates a method for invocation. More...
 
 GenericServiceClient (const string &serviceName, ClientConnector &clientConnector)
 Constructor. More...
 
EventRegistrationState getEventListenerRegistrationState (EventCallbackRegistrationToken token)
 Retrieve the state of event registration. More...
 
uint32_t getIntrospectionTimeout () const
 Retrieve currently configured introspection timeout value. More...
 
const string & getMethodIntrospectionXML (const string &methodName) const
 Returns the cached introspection XML for a named method if such is available. More...
 
EventCallbackRegistrationToken registerEventListener (const string &eventName, EventCallbackFunction callback, EventRegistrationStateCallbackFunction stateCallback=EventRegistrationStateCallbackFunction())
 Registers a event listener for a specific event. More...
 
EventCallbackRegistrationToken registerEventListenerEx (const string &eventName, EventCallbackEx *callback)
 Registers a event listener for a specific event. More...
 
bool removeQueuedMethod (MethodSharedPtr method)
 Removes possible queued method. More...
 
bool removeRunningMethod (MethodSharedPtr method)
 Remove a method from the ongoing list of methods. More...
 
bool serviceIsAvailable () const
 Test whetner this particular service is available currently. More...
 
void setIntrospectionTimeout (uint32_t milliseconds)
 Configures introspection timeout for method invocation. More...
 
void unregisterEventListener (EventCallbackRegistrationToken token)
 Unregisters event listener. More...
 
 ~GenericServiceClient ()
 dtor More...
 

Static Public Member Functions

static GenericServiceClientSharedPtr create (const string &service, ClientConnector &cc)
 Factorize a generic service client to communicate with the specified service. More...
 

Protected Types

enum  DispatchResult { DispatchFailed, DispatchComplete, DispatchOngoing }
 Method "dispatch to wire" result. More...
 

Protected Member Functions

void cleanEmptyItemsFromArray (vector< EventCallbackContextSharedPtr > &arr)
 Cleans empty items from an array. More...
 
DispatchResult composeAndDispatchMethod (detail::MethodInvocationContextSharedPtr method, detail::MethodSignatureSharedPtr signature, MessagePackage &mp, InvocationRoute route)
 Composes final message and sends to towards the service. More...
 
void handleServicePresenceChanged (bool present)
 Process service presence changes. More...
 
void initialize ()
 2nd phase construction More...
 
Method::InvocationResult invokeMethod (detail::MethodInvocationContextSharedPtr method, InvocationRoute route)
 Invokes a method within provided context. More...
 
void processIncomingEvent (const MessagePackage &package, EventCallbackContextSharedPtr context)
 Processes an incoming message that will translate itself to an event. More...
 
void requestEventSignatureFromServer (EventCallbackContextSharedPtr eventContext)
 Requests a event signature from the server. More...
 
bool validateMethodSignature (MethodSharedPtr method, detail::MethodSignatureSharedPtr signature, MessagePackage &mp)
 Validates that Method instance is properly setup and can be fired. More...
 

Friends

class Method
 

Detailed Description

Limitation: Only one GenericServiceClient instance per Client per Service is allowed. Having multiple instances of the class for same service and same network connection will not work properly.

Member Typedef Documentation

◆ EventCallbackFunction

typedef function<void(const string&, const map<string, string>&)> kanzi::connect::GenericServiceClient::EventCallbackFunction

Signature of event callback function. All arguments converted to strings.

◆ EventCallbackRegistrationToken

Opaque token type for callback registration.

◆ EventRegistrationStateCallbackFunction

Function to be used to receive event registration state changes.

Member Enumeration Documentation

◆ DispatchResult

Method "dispatch to wire" result.

Enumerator
DispatchFailed 
DispatchComplete 
DispatchOngoing 

◆ EventRegistrationState

Enumerates the event registration states.

Enumerator
EventRegistrationWaitingForService 

Event registration is waiting for the corresponding service to become available.

EventRegistrationWaitingIntrospection 

Event registration is waiting for service intropsection to complete.

EventRegistrationFailed 

Event registration has failed. This is final status and re-registration is required to retry the operation.

EventRegistrationComplete 

Event registration is complete and events should flow through.

Constructor & Destructor Documentation

◆ GenericServiceClient()

kanzi::connect::GenericServiceClient::GenericServiceClient ( const string &  serviceName,
ClientConnector clientConnector 
)
explicit

Constructor.

Parameters
serviceNamename of the service
clientConnectorthe client instance that should be used to communicate with the server.

◆ ~GenericServiceClient()

kanzi::connect::GenericServiceClient::~GenericServiceClient ( )

dtor

Member Function Documentation

◆ cleanEmptyItemsFromArray()

void kanzi::connect::GenericServiceClient::cleanEmptyItemsFromArray ( vector< EventCallbackContextSharedPtr > &  arr)
protected

Cleans empty items from an array.

Parameters
arrthe array to clean up

◆ composeAndDispatchMethod()

DispatchResult kanzi::connect::GenericServiceClient::composeAndDispatchMethod ( detail::MethodInvocationContextSharedPtr  method,
detail::MethodSignatureSharedPtr  signature,
MessagePackage mp,
InvocationRoute  route 
)
protected

Composes final message and sends to towards the service.

Parameters
methodMethod invocation context
signaturemethod signature
mpmessage package to hold physically "on wire" message.
Returns
true if method was dispatched.

◆ create()

static GenericServiceClientSharedPtr kanzi::connect::GenericServiceClient::create ( const string &  service,
ClientConnector cc 
)
static

Factorize a generic service client to communicate with the specified service.

Parameters
servicename of the service, E.g. Cluster
ccthe clientconnector instance that should be used to communicate with the server.
Returns
instance of GenericServiceClient

◆ createMethod()

MethodSharedPtr kanzi::connect::GenericServiceClient::createMethod ( const string &  methodName)

Creates a method for invocation.

Parameters
methodNamename of the method
Returns
Method instance

◆ getEventListenerRegistrationState()

EventRegistrationState kanzi::connect::GenericServiceClient::getEventListenerRegistrationState ( EventCallbackRegistrationToken  token)

Retrieve the state of event registration.

Parameters
tokenopaque token returned when registering started
Returns
state that indicates whether registration is pending, failed or has it completed.

◆ getIntrospectionTimeout()

uint32_t kanzi::connect::GenericServiceClient::getIntrospectionTimeout ( ) const

Retrieve currently configured introspection timeout value.

Returns
milliseconds

◆ getMethodIntrospectionXML()

const string& kanzi::connect::GenericServiceClient::getMethodIntrospectionXML ( const string &  methodName) const

Returns the cached introspection XML for a named method if such is available.

Parameters
methodNamename of the method to retrieve introspections.
Returns
XML in string format.

◆ handleServicePresenceChanged()

void kanzi::connect::GenericServiceClient::handleServicePresenceChanged ( bool  present)
protected

Process service presence changes.

Parameters
presenttrue should be passed when service becomes available, false if it disappears.

◆ initialize()

void kanzi::connect::GenericServiceClient::initialize ( )
protected

2nd phase construction

◆ invokeMethod()

Method::InvocationResult kanzi::connect::GenericServiceClient::invokeMethod ( detail::MethodInvocationContextSharedPtr  method,
InvocationRoute  route 
)
protected

Invokes a method within provided context.

Parameters
methodthe method invocation context
routedescribes where the invocation orignates from
Returns
true if method invocation started.

◆ processIncomingEvent()

void kanzi::connect::GenericServiceClient::processIncomingEvent ( const MessagePackage package,
EventCallbackContextSharedPtr  context 
)
protected

Processes an incoming message that will translate itself to an event.

Parameters
packagethe message package received
contextthe context describing the event.

◆ registerEventListener()

EventCallbackRegistrationToken kanzi::connect::GenericServiceClient::registerEventListener ( const string &  eventName,
EventCallbackFunction  callback,
EventRegistrationStateCallbackFunction  stateCallback = EventRegistrationStateCallbackFunction() 
)

Registers a event listener for a specific event.

Parameters
eventNamename of the event to listen
callbackfunction to invoke when event is received
stateCallbackthe state change callback that can be optionally listened to ensure event registrations is functional. If registration completes inline, then this callback is not invoked. Registration status can be explicitly queried with function getEventListenerRegistrationState
Returns
opaque registration token that is used in unregistration.

◆ registerEventListenerEx()

EventCallbackRegistrationToken kanzi::connect::GenericServiceClient::registerEventListenerEx ( const string &  eventName,
EventCallbackEx callback 
)

Registers a event listener for a specific event.

Parameters
eventNamethe name of the event to listen
callbackcallback interface whom onEventReceived method is called when ever particular event is received
Returns
opaque registration token that is used in unregistration.

◆ removeQueuedMethod()

bool kanzi::connect::GenericServiceClient::removeQueuedMethod ( MethodSharedPtr  method)

Removes possible queued method.

Parameters
methodthat was queued.
Returns
true if method was actually removed from the queue

◆ removeRunningMethod()

bool kanzi::connect::GenericServiceClient::removeRunningMethod ( MethodSharedPtr  method)

Remove a method from the ongoing list of methods.

This is mainly for internal use.

Parameters
methodthe method to remove
Returns
true if method got removed.

◆ requestEventSignatureFromServer()

void kanzi::connect::GenericServiceClient::requestEventSignatureFromServer ( EventCallbackContextSharedPtr  eventContext)
protected

Requests a event signature from the server.

Will populate information to attached object

Parameters
eventContextthe context where the partial event information is and will thus be more populated.

◆ serviceIsAvailable()

bool kanzi::connect::GenericServiceClient::serviceIsAvailable ( ) const

Test whetner this particular service is available currently.

Returns
true if available.

◆ setIntrospectionTimeout()

void kanzi::connect::GenericServiceClient::setIntrospectionTimeout ( uint32_t  milliseconds)

Configures introspection timeout for method invocation.

Parameters
millisecondsamount of milliseconds the introspection can maximally take. Mimimum accepted value is 100, maximum is INT_MAX.

◆ unregisterEventListener()

void kanzi::connect::GenericServiceClient::unregisterEventListener ( EventCallbackRegistrationToken  token)

Unregisters event listener.

Parameters
tokenopaque token received during registration.

◆ validateMethodSignature()

bool kanzi::connect::GenericServiceClient::validateMethodSignature ( MethodSharedPtr  method,
detail::MethodSignatureSharedPtr  signature,
MessagePackage mp 
)
protected

Validates that Method instance is properly setup and can be fired.

Parameters
methodthe method to be inspected
signaturethe method signature introspected from service
mpMessage package where to all arguments are transfered.
Returns
true if method object is considered valid.

Friends And Related Function Documentation

◆ Method

friend class Method
friend

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