ServiceRuntimeData

class kanzi::connect::ServiceRuntimeData

Encapsulates service runtime data.

Public Types

typedef function<void(const string &path)> ModifiedFunction

Callback function type for change subscriptions.

typedef shared_ptr<void> ModifiedSubscriptionToken

Token type that can be used to identify the change subscription.

Public Functions

explicit ServiceRuntimeData(ConnectDomain *domain, const persistence::SettingFactory *settingFactory)

Runtime data of a service.

Parameters
  • domain – the domain where the runtime data operates in.

  • settingFactory – factory to access persistence service

explicit ServiceRuntimeData(ConnectDomain *domain, const persistence::SettingFactory *settingFactory, const string &service_name)

Runtime data of a service.

Parameters
  • domain – the domain where the runtime data operates in.

  • settingFactory – factory to access persistence service

  • service_name – the service name to which the runtime data belongs to

virtual ~ServiceRuntimeData()
ModifiedSubscriptionToken addModifiedNotificationHandler(ModifiedFunction callback)

Allows to subscribe to modifications in this data context.

Parameters

callback – Callback that is invoked when a change occurs in this data context.

Returns

Token that can be used to identify and remove given subscription.

ModifiedSubscriptionToken addModifiedNotificationHandlerEx(ModifiedCallback *callback)

Subscribes to modification notifications within this object.

Parameters

callback – the callback interface whom method is to be called on change.

Returns

token that can be used to identify and remove given subscription.

bool createElement(const string &parentPath, const string &xml)

Create a new element to the runtime data in the given path.

Parameters
  • parentPath – Specifies where to add the new element.

  • xml – Contains the xml defining the element contents

Returns

True if the new element was successfully added

RuntimeDataObjectBoolSharedPtr getBoolObject(const string &path) const

Retrieve boolean object at specific path.

Parameters

path – full path to object to retrieve.

Returns

boolean object or empty pointer.

bool getBoolValue(const string &path, bool defaultValue = false)

Retrieve boolean value from runtime data parameter.

Parameters
  • path – identify the data object.

  • defaultValue – value to return in case named parameter not found.

Returns

runtime data value

RuntimeDataObjectIntSharedPtr getIntObject(const string &path) const

Retrieve int object at specific path.

Parameters

path – full path to object to retrieve.

Returns

int object or empty pointer.

int getIntValue(const string &path, int defaultValue = 0)

Retrieve int value from runtime data parameter.

Parameters
  • path – identify the data object.

  • defaultValue – value to return in case named parameter not found.

Returns

runtime data value

size_t getListItemCount(const string &path) const

Returns the amount of list items the pointed list has.

Shall the path point to something else than a list then 0 is returned.

Parameters

path – the path to list to inspect

Returns

amount of objects. >= 0.

RuntimeDataObjectListSharedPtr getListObject(const string &path) const

Retrieve list object at specific path.

Parameters

path – full path to object to retrieve.

Returns

string object or empty pointer.

RuntimeDataObjectSharedPtr getObject(const string &path) const

Retrieves object.

Parameters

path – Full path to object

Returns

object or empty pointer.

RuntimeDataObject::Type getObjectType(const string &path) const

Retrieves the type of the object at specific path.

Parameters

path – Full path to object.

Returns

type of object.

RuntimeDataObjectRealSharedPtr getRealObject(const string &path) const

Retrieve real object at specific path.

Parameters

path – full path to object to retrieve.

Returns

real object or empty pointer.

double getRealValue(const string &path, double defaultValue = 0)

Retrieve real value from runtime data parameter.

Parameters
  • path – identify the data object.

  • defaultValue – value to return in case named parameter not found.

Returns

runtime data value

RuntimeDataObjectSharedPtr getRoot()

Retrieve the root node.

Returns

the root node.

string getSchema()

Returns the data schema in XML.

Returns

XML Schema.

const string &getServiceName() const

Retrieves the service name to which the runtime data belongs.

Returns

the service name to which the runtime data belongs

RuntimeDataObjectStringSharedPtr getStringObject(const string &path) const

Retrieve string object at specifi path.

Parameters

path – full path to object to retrieve.

Returns

string object or empty pointer.

string getStringValue(const string &path, string defaultValue = "")

Retrieve string value from runtime data parameter.

Parameters
  • path – identify the data object.

  • defaultValue – value to return in case named parameter not found.

Returns

runtime data value

bool hasObject(const string &path) const

Checks whether object exists in specific path.

Parameters

path – Full path to object, using dotted format First.Second.Third

Returns

true if path points to a valid object.

void notifyModified(string path = "")

Notifies subscriptions when the content changes.

Framework reports changed values to clients asynchronously if an instance of ConnectDomain is given to the class during construction. However, by manually notifying changes, one can flush the pending notifications and also patch several changes into single notification. It is up to subscription, what values will be actually sent to client.

Parameters

path – the path that needs to be reported.

bool parseFromXML(const string &serviceIdentifier, const string &xml)

Parses the structure from a XML file.

Parameters
  • serviceIdentifier – Identifies the service for which the runtime data belongs to

  • xml – structure

Returns

true if file parsed successfully

bool parseFromXMLElement(const tinyxml2::XMLElement *element)

Parses structure from xml structure.

Parameters

element – the element whom childs are to be enumerated

Returns

true if success, false otherwise.

bool removeElement(const string &path)

Remove the given element from the runtime data, removes intermediate elements if they become empty.

Parameters

path – Identifies the element to remove

Returns

True if removal succeeded

void removeMethodRecursive(const string &path)

Remove all existing methods under the given path.

void removeModifiedNotificationHandler(ModifiedSubscriptionToken token)

Allows to unsubscribe from modifications in this data context.

Parameters

token – Token to identify the subscription that should be removed.

bool setSerializedValue(const string &path, const string &serializedValue)

Set value for a runtime data parameter.

Parameters
  • path – identify the data object

  • serializedValue – new value to set in serialized format, it will deserialized based on the type of path target.

Returns

true if values set.

bool setValue(const string &path, bool value)

Set value for a runtime data parameter.

Parameters
  • path – identify the data object

  • value – new value to set.

Returns

true if values set.

bool setValue(const string &path, const char *value)

Set value for a runtime data parameter.

Parameters
  • path – identify the data object

  • value – new value to set.

Returns

true if values set.

bool setValue(const string &path, double value)

Set value for a runtime data parameter.

Parameters
  • path – identify the data object

  • value – new value to set.

Returns

true if values set.

bool setValue(const string &path, int value)

Set value for a runtime data parameter.

Parameters
  • path – identify the data object

  • value – new value to set.

Returns

true if values set.

bool setValue(const string &path, string value)

Set value for a runtime data parameter.

Parameters
  • path – identify the data object

  • value – new value to set.

Returns

true if values set.

class ModifiedCallback

Old school modification callback.

Public Functions

inline virtual ~ModifiedCallback()

Virtual destructor for external language bindings.

virtual void runtimeDataModified(const string &path) = 0

Invoked when ever content(s) is modified.

Parameters

path – the path that got changed.