GenericServiceClient

class kanzi::connect::GenericServiceClient : public enable_shared_from_this<GenericServiceClient>

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.

Public Types

typedef function<void(const string&, const map<string, string>&)> EventCallbackFunction

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

typedef shared_ptr<void> EventCallbackRegistrationToken

Opaque token type for callback registration.

enum EventRegistrationState

Enumerates the event registration states.

Values:

enumerator EventRegistrationWaitingForService

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

enumerator EventRegistrationWaitingIntrospection

Event registration is waiting for service intropsection to complete.

enumerator EventRegistrationFailed

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

enumerator EventRegistrationComplete

Event registration is complete and events should flow through.

typedef function<void(const string&, EventRegistrationState)> EventRegistrationStateCallbackFunction

Function to be used to receive event registration state changes.

Public Functions

GenericServiceClient(const string &serviceName, ClientConnector &clientConnector)

Constructor.

Parameters
  • serviceName: name of the service

  • clientConnector: the client instance that should be used to communicate with the server.

~GenericServiceClient()

dtor

MethodSharedPtr createMethod(const string &methodName)

Creates a method for invocation.

Return

Method instance

Parameters
  • methodName: name of the method

EventRegistrationState getEventListenerRegistrationState(EventCallbackRegistrationToken token)

Retrieve the state of event registration.

Return

state that indicates whether registration is pending, failed or has it completed.

Parameters
  • token: opaque token returned when registering started

uint32_t getIntrospectionTimeout() const

Retrieve currently configured introspection timeout value.

Return

milliseconds

const string &getMethodIntrospectionXML(const string &methodName) const

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

Return

XML in string format.

Parameters
  • methodName: name of the method to retrieve introspections.

EventCallbackRegistrationToken registerEventListener(const string &eventName, EventCallbackFunction callback, EventRegistrationStateCallbackFunction stateCallback = EventRegistrationStateCallbackFunction())

Registers a event listener for a specific event.

Return

opaque registration token that is used in unregistration.

Parameters
  • eventName: name of the event to listen

  • callback: function to invoke when event is received

  • stateCallback: the 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

EventCallbackRegistrationToken registerEventListenerEx(const string &eventName, EventCallbackEx *callback)

Registers a event listener for a specific event.

Return

opaque registration token that is used in unregistration.

Parameters
  • eventName: the name of the event to listen

  • callback: callback interface whom onEventReceived method is called when ever particular event is received

bool removeQueuedMethod(MethodSharedPtr method)

Removes possible queued method.

Return

true if method was actually removed from the queue

Parameters
  • method: that was queued.

bool removeRunningMethod(MethodSharedPtr method)

Remove a method from the ongoing list of methods.

This is mainly for internal use.

Return

true if method got removed.

Parameters
  • method: the method to remove

bool serviceIsAvailable() const

Test whetner this particular service is available currently.

Return

true if available.

void setIntrospectionTimeout(uint32_t milliseconds)

Configures introspection timeout for method invocation.

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

void unregisterEventListener(EventCallbackRegistrationToken token)

Unregisters event listener.

Parameters
  • token: opaque token received during registration.

Public Static Functions

GenericServiceClientSharedPtr create(const string &service, ClientConnector &cc)

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

Return

instance of GenericServiceClient

Parameters
  • service: name of the service, E.g. Cluster

  • cc: the clientconnector instance that should be used to communicate with the server.

class EventCallbackEx

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

Public Functions

~EventCallbackEx()

Allows generic client side interface to a named service. Introspects service details along the way when service methods are invoked.

Required for Java bindings

void onEventReceived(const string &eventName, const EventArguments &eventArguments) = 0

Invoked when event is received.

Parameters
  • eventName: the name of the event.

  • eventArguments: named arguments for the event.

void onEventRegistrationStateChanged(const string &eventName, EventRegistrationState state) = 0

Invoked when event registration state changes.

Parameters
  • eventName: name of the event whom registration status changed

  • state: the new state of registration. Generally either ..Failed or ..Complete

class EventArguments

Wrapper class for event arguments. Used in external application bindings.

Public Functions

EventArguments(const map<string, string> &argumentMap)

Construct event arguments from argument map.

vector<string> getKeys()

Get all the keys.

Return

vector of keys currently held.

string getValue(const string &key)

Get value with a key.

Return

value indexed with the key. empty string if not found.

Parameters
  • name: of the key

bool hasKey(const string &key)

Checks whether specific key is present.

Return

true if there is a value with the key.

Parameters
  • key: the key to check