Method

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

Method class implementation.

Public Types

typedef function<void(MethodSharedPtr, Method::InvocationResult, string)> InvocationCallback

invocation callback function prototype

enum InvocationResult

Result of a method invocation.

Values:

enumerator InvokeInProgress

Returned from invocation methods when invocation requires asynchronous processing or returns a value in which case the final comletion is through callback.

After invoke returns this value then the final value will be available in the callback.

enumerator InvokeSucceeded

Method invocation succeeded.

enumerator InvokeFailedSignatureMismatch

Method could not invoked because either the method name is wrong, or passed in arguments don’t mach with method signature.

enumerator InvokeFailedIntrospectionFailure

Method could not be invoed because method signature introspection failed for some reason.

enumerator InvokeFailedTimedOut

Method was triggered but returnvalue was not received within specified invocation timeout.

enumerator InvokeFailedLinkBroken

Method was triggered but invocation overall status is not known since connection got broken.

enumerator InvokeFailedNoService

returned if service is not available when invoking a method.

enumerator InvokeFailed

Method invocation failed for unknown reason.

Public Functions

Method(GenericServiceClientSharedPtr service, const string &methodName)

C++ constructor.

This is not intenteded to be used directly, instead use GenericServiceClient::createMethod to factorize methods bound to a service.

Parameters
  • service: the service method is bound to

  • methodName: name of the method.

~Method()

dtor

Method &addArgument(const string &argumentName, const string &argumentValue)

Adds named string argument.

Return

reference to the method to allow chaining setup of arguments.

Parameters
  • argumentName: the name of the argument

  • argumentValue: value for the argument.

Method &addArgument(const string &argumentName, const char *argumentValue)

add named string argument

Return

reference to the method to allow chaining setup of arguments.

Parameters
  • argumentName: the name of the argument

  • argumentValue: value for the argument.

Method &addArgument(const string &argumentName, int argumentValue)

add named integer argument

Return

reference to the method to allow chaining setup of arguments.

Parameters
  • argumentName: the name of the argument

  • argumentValue: value for the argument.

Method &addArgument(const string &argumentName, float argumentValue)

add named float argument

Return

reference to the method to allow chaining setup of arguments.

Parameters
  • argumentName: the name of the argument

  • argumentValue: value for the argument.

Method &addArgument(const string &argumentName, bool argumentValue)

add named boolean argument

Return

reference to the method to allow chaining setup of arguments.

Parameters
  • argumentName: the name of the argument

  • argumentValue: value for the argument.

Method &addBinaryArgument(const string &argumentName, const string &argumentValue)

add named binary argument

Return

reference to the method to allow chaining setup of arguments.

Parameters
  • argumentName: the name of the argument

  • argumentValue: value for the argument.

bool argumentHasType(const string &argumentName, int messagePackageArgumentType) const

Check is the argument type correct or not.

Return

true if type matches.

Parameters
  • argumentName: name of the argument to inspect

  • messagePackageArgumentType: one of MessagePackage::ATTRIBUTE_VALUE_TYPE_* enumerations.

bool cancel()

Cancel a method invocation.

Effectivy only if method was invoked in queued manner and it was still waiting for invocation.

Return

true if operation was canceled.

template<class _T>
_T getArgument(const string &argumentName) const

Retrieve typed argument from variant map.

Parameters
  • argumentName: name of the argument

uint32_t getInvocationTimeout() const

Return configured invocation timeout.

Return

milliseconds

const string &getName() const

Returns the method name.

Return

the name

bool hasArgument(const string &argumentName) const

Is the named argument provided.

Return

true if argument with provided name exists.

Parameters
  • argumentName: name of the argument to inspect

InvocationResult invoke(InvocationCallback callback)

Invokes the method immediately.

If immediate invocation is not possible based on preconditions, then returns false.

Return

true if method invocation was started.

Parameters
  • callback: the callback that is invoked when method invocation is complete or it has failed due the some error. If method returns true then callback will be called at some point.

InvocationResult invokeEx(CallbackEx *callback)

See

invokeImmediate

Note

This is intented for external application bindings (Java)

InvocationResult invokeQueued(InvocationCallback callback)

Invokes the method immediately but if that is not possible then invocation is queued and executed later when invocation is possible again.

Return

true if method invocation was started.

Parameters
  • callback: the callback that is invoked when method invocation is complete or it has failed due the some error. If method returns true then callback will be called at some point.

InvocationResult invokeQueuedEx(CallbackEx *callback)

See

invokeQueued

Note

This is intented for external application bindings (Java)

void setInvocationTimeout(uint32_t milliseconds)

Configures method invcation timeout.

Parameters
  • milliseconds: the timeout value. Mimimum accepted value is 100, maximum is INT_MAX.

class CallbackEx

Traditional c++ callback interface for external application bindings (Java)

Public Functions

~CallbackEx()

Required for Java bindings.

void methodComplete(Method *method, InvocationResult result, const string &returnvalue) = 0

Invoked after method is executed to report execution status.

Parameters
  • method: the method that was completed.

  • result: the result of execution

  • returnvalue: the value returned by the function casted to string. If returnvalue is not supported then empty.