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

Encapsulates service runtime data. More...

#include <serviceruntimedata.hpp>

Classes

class  ModifiedCallback
 Old school modification callback. More...
 

Public Types

typedef function< void(const string &path)> ModifiedFunction
 Callback function type for change subscriptions. More...
 
typedef shared_ptr< void > ModifiedSubscriptionToken
 Token type that can be used to identify the change subscription. More...
 

Public Member Functions

ModifiedSubscriptionToken addModifiedNotificationHandler (ModifiedFunction callback)
 Allows to subscribe to modifications in this data context. More...
 
ModifiedSubscriptionToken addModifiedNotificationHandlerEx (ModifiedCallback *callback)
 Subscribes to modification notifications within this object. More...
 
bool createElement (const string &parentPath, const string &xml)
 Create a new element to the runtime data in the given path. More...
 
RuntimeDataObjectBoolSharedPtr getBoolObject (const string &path) const
 Retrieve boolean object at specific path. More...
 
bool getBoolValue (const string &path, bool defaultValue=false)
 Retrieve boolean value from runtime data parameter. More...
 
RuntimeDataObjectIntSharedPtr getIntObject (const string &path) const
 Retrieve int object at specific path. More...
 
int getIntValue (const string &path, int defaultValue=0)
 Retrieve int value from runtime data parameter. More...
 
size_t getListItemCount (const string &path) const
 Returns the amount of list items the pointed list has. More...
 
RuntimeDataObjectListSharedPtr getListObject (const string &path) const
 Retrieve list object at specific path. More...
 
RuntimeDataObjectSharedPtr getObject (const string &path) const
 Retrieves object. More...
 
RuntimeDataObject::Type getObjectType (const string &path) const
 Retrieves the type of the object at specific path. More...
 
RuntimeDataObjectRealSharedPtr getRealObject (const string &path) const
 Retrieve real object at specific path. More...
 
double getRealValue (const string &path, double defaultValue=0)
 Retrieve real value from runtime data parameter. More...
 
RuntimeDataObjectSharedPtr getRoot ()
 Retrieve the root node. More...
 
string getSchema ()
 Returns the data schema in XML. More...
 
const string & getServiceName () const
 Retrieves the service name to which the runtime data belongs. More...
 
RuntimeDataObjectStringSharedPtr getStringObject (const string &path) const
 Retrieve string object at specifi path. More...
 
string getStringValue (const string &path, string defaultValue="")
 Retrieve string value from runtime data parameter. More...
 
bool hasObject (const string &path) const
 Checks whether object exists in specific path. More...
 
void notifyModified (string path="")
 Notifies subscriptions when the content changes. More...
 
bool parseFromXML (const string &serviceIdentifier, const string &xml)
 Parses the structure from a XML file. More...
 
bool parseFromXMLElement (const tinyxml2::XMLElement *element)
 Parses structure from xml structure. More...
 
bool removeElement (const string &path)
 Remove the given element from the runtime data, removes intermediate elements if they become empty. More...
 
void removeMethodRecursive (const string &path)
 Remove all existing methods under the given path. More...
 
void removeModifiedNotificationHandler (ModifiedSubscriptionToken token)
 Allows to unsubscribe from modifications in this data context. More...
 
 ServiceRuntimeData (ConnectDomain *domain, const persistence::SettingFactory *settingFactory)
 Runtime data of a service. More...
 
 ServiceRuntimeData (ConnectDomain *domain, const persistence::SettingFactory *settingFactory, const string &service_name)
 Runtime data of a service. More...
 
bool setSerializedValue (const string &path, const string &serializedValue)
 Set value for a runtime data parameter. More...
 
bool setValue (const string &path, int value)
 Set value for a runtime data parameter. More...
 
bool setValue (const string &path, double value)
 Set value for a runtime data parameter. More...
 
bool setValue (const string &path, string value)
 Set value for a runtime data parameter. More...
 
bool setValue (const string &path, const char *value)
 Set value for a runtime data parameter. More...
 
bool setValue (const string &path, bool value)
 Set value for a runtime data parameter. More...
 
virtual ~ServiceRuntimeData ()
 

Protected Member Functions

void createMethodForWritableData (const string &parentPath, const tinyxml2::XMLElement *element)
 Create a method for a writable runtime data. More...
 
RuntimeDataObjectSharedPtr getObjectInternal (const string &path, bool passLists) const
 Retrieves object. More...
 
void processNode (const tinyxml2::XMLElement *element, RuntimeDataObjectSharedPtr parent)
 Processes a single node during construction. More...
 
void processNode (const tinyxml2::XMLElement *element, RuntimeDataObjectSharedPtr parent, bool createMethod)
 Processes a single node during construction. More...
 
void validateHashCodes (RuntimeDataObjectSharedPtr object)
 Processes a nodetree and checks that it does not contain duplicate hash values that might collide. More...
 

Detailed Description

Encapsulates service runtime data.

Member Typedef Documentation

◆ ModifiedFunction

typedef function<void(const string& path)> kanzi::connect::ServiceRuntimeData::ModifiedFunction

Callback function type for change subscriptions.

◆ ModifiedSubscriptionToken

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

Constructor & Destructor Documentation

◆ ServiceRuntimeData() [1/2]

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

Runtime data of a service.

Parameters
domainthe domain where the runtime data operates in.
settingFactoryfactory to access persistence service

◆ ServiceRuntimeData() [2/2]

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

Runtime data of a service.

Parameters
domainthe domain where the runtime data operates in.
settingFactoryfactory to access persistence service
service_namethe service name to which the runtime data belongs to

◆ ~ServiceRuntimeData()

virtual kanzi::connect::ServiceRuntimeData::~ServiceRuntimeData ( )
virtual

Member Function Documentation

◆ addModifiedNotificationHandler()

ModifiedSubscriptionToken kanzi::connect::ServiceRuntimeData::addModifiedNotificationHandler ( ModifiedFunction  callback)

Allows to subscribe to modifications in this data context.

Parameters
callbackCallback that is invoked when a change occurs in this data context.
Returns
Token that can be used to identify and remove given subscription.

◆ addModifiedNotificationHandlerEx()

ModifiedSubscriptionToken kanzi::connect::ServiceRuntimeData::addModifiedNotificationHandlerEx ( ModifiedCallback callback)

Subscribes to modification notifications within this object.

Parameters
callbackthe callback interface whom method is to be called on change.
Returns
token that can be used to identify and remove given subscription.

◆ createElement()

bool kanzi::connect::ServiceRuntimeData::createElement ( const string &  parentPath,
const string &  xml 
)

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

Parameters
parentPathSpecifies where to add the new element.
xmlContains the xml defining the element contents
Returns
True if the new element was successfully added

◆ createMethodForWritableData()

void kanzi::connect::ServiceRuntimeData::createMethodForWritableData ( const string &  parentPath,
const tinyxml2::XMLElement *  element 
)
protected

Create a method for a writable runtime data.

Parameters
parentPathparetn path of the given element
elementthe element contains runtime data contents
Returns
True if the new element was successfully added

◆ getBoolObject()

RuntimeDataObjectBoolSharedPtr kanzi::connect::ServiceRuntimeData::getBoolObject ( const string &  path) const

Retrieve boolean object at specific path.

Parameters
pathfull path to object to retrieve.
Returns
boolean object or empty pointer.

◆ getBoolValue()

bool kanzi::connect::ServiceRuntimeData::getBoolValue ( const string &  path,
bool  defaultValue = false 
)

Retrieve boolean value from runtime data parameter.

Parameters
pathidentify the data object.
defaultValuevalue to return in case named parameter not found.
Returns
runtime data value

◆ getIntObject()

RuntimeDataObjectIntSharedPtr kanzi::connect::ServiceRuntimeData::getIntObject ( const string &  path) const

Retrieve int object at specific path.

Parameters
pathfull path to object to retrieve.
Returns
int object or empty pointer.

◆ getIntValue()

int kanzi::connect::ServiceRuntimeData::getIntValue ( const string &  path,
int  defaultValue = 0 
)

Retrieve int value from runtime data parameter.

Parameters
pathidentify the data object.
defaultValuevalue to return in case named parameter not found.
Returns
runtime data value

◆ getListItemCount()

size_t kanzi::connect::ServiceRuntimeData::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
paththe path to list to inspect
Returns
amount of objects. >= 0.

◆ getListObject()

RuntimeDataObjectListSharedPtr kanzi::connect::ServiceRuntimeData::getListObject ( const string &  path) const

Retrieve list object at specific path.

Parameters
pathfull path to object to retrieve.
Returns
string object or empty pointer.

◆ getObject()

RuntimeDataObjectSharedPtr kanzi::connect::ServiceRuntimeData::getObject ( const string &  path) const

Retrieves object.

Parameters
pathFull path to object
Returns
object or empty pointer.

◆ getObjectInternal()

RuntimeDataObjectSharedPtr kanzi::connect::ServiceRuntimeData::getObjectInternal ( const string &  path,
bool  passLists 
) const
protected

Retrieves object.

Parameters
pathFull path to object
passListsif true, then also lists are gone through
Returns
object or empty pointer.

◆ getObjectType()

RuntimeDataObject::Type kanzi::connect::ServiceRuntimeData::getObjectType ( const string &  path) const

Retrieves the type of the object at specific path.

Parameters
pathFull path to object.
Returns
type of object.

◆ getRealObject()

RuntimeDataObjectRealSharedPtr kanzi::connect::ServiceRuntimeData::getRealObject ( const string &  path) const

Retrieve real object at specific path.

Parameters
pathfull path to object to retrieve.
Returns
real object or empty pointer.

◆ getRealValue()

double kanzi::connect::ServiceRuntimeData::getRealValue ( const string &  path,
double  defaultValue = 0 
)

Retrieve real value from runtime data parameter.

Parameters
pathidentify the data object.
defaultValuevalue to return in case named parameter not found.
Returns
runtime data value

◆ getRoot()

RuntimeDataObjectSharedPtr kanzi::connect::ServiceRuntimeData::getRoot ( )

Retrieve the root node.

Returns
the root node.

◆ getSchema()

string kanzi::connect::ServiceRuntimeData::getSchema ( )

Returns the data schema in XML.

Returns
XML Schema.

◆ getServiceName()

const string& kanzi::connect::ServiceRuntimeData::getServiceName ( ) const

Retrieves the service name to which the runtime data belongs.

Returns
the service name to which the runtime data belongs

◆ getStringObject()

RuntimeDataObjectStringSharedPtr kanzi::connect::ServiceRuntimeData::getStringObject ( const string &  path) const

Retrieve string object at specifi path.

Parameters
pathfull path to object to retrieve.
Returns
string object or empty pointer.

◆ getStringValue()

string kanzi::connect::ServiceRuntimeData::getStringValue ( const string &  path,
string  defaultValue = "" 
)

Retrieve string value from runtime data parameter.

Parameters
pathidentify the data object.
defaultValuevalue to return in case named parameter not found.
Returns
runtime data value

◆ hasObject()

bool kanzi::connect::ServiceRuntimeData::hasObject ( const string &  path) const

Checks whether object exists in specific path.

Parameters
pathFull path to object, using dotted format First.Second.Third
Returns
true if path points to a valid object.

◆ notifyModified()

void kanzi::connect::ServiceRuntimeData::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
paththe path that needs to be reported.

◆ parseFromXML()

bool kanzi::connect::ServiceRuntimeData::parseFromXML ( const string &  serviceIdentifier,
const string &  xml 
)

Parses the structure from a XML file.

Parameters
serviceIdentifierIdentifies the service for which the runtime data belongs to
xmlstructure
Returns
true if file parsed successfully

◆ parseFromXMLElement()

bool kanzi::connect::ServiceRuntimeData::parseFromXMLElement ( const tinyxml2::XMLElement *  element)

Parses structure from xml structure.

Parameters
elementthe element whom childs are to be enumerated
Returns
true if success, false otherwise.

◆ processNode() [1/2]

void kanzi::connect::ServiceRuntimeData::processNode ( const tinyxml2::XMLElement *  element,
RuntimeDataObjectSharedPtr  parent 
)
protected

Processes a single node during construction.

Parameters
elementthe element to process
parentparent node

◆ processNode() [2/2]

void kanzi::connect::ServiceRuntimeData::processNode ( const tinyxml2::XMLElement *  element,
RuntimeDataObjectSharedPtr  parent,
bool  createMethod 
)
protected

Processes a single node during construction.

Parameters
elementthe element to process
parentparent node
createMethodif true, create method for writable runtime data

◆ removeElement()

bool kanzi::connect::ServiceRuntimeData::removeElement ( const string &  path)

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

Parameters
pathIdentifies the element to remove
Returns
True if removal succeeded

◆ removeMethodRecursive()

void kanzi::connect::ServiceRuntimeData::removeMethodRecursive ( const string &  path)

Remove all existing methods under the given path.

◆ removeModifiedNotificationHandler()

void kanzi::connect::ServiceRuntimeData::removeModifiedNotificationHandler ( ModifiedSubscriptionToken  token)

Allows to unsubscribe from modifications in this data context.

Parameters
tokenToken to identify the subscription that should be removed.

◆ setSerializedValue()

bool kanzi::connect::ServiceRuntimeData::setSerializedValue ( const string &  path,
const string &  serializedValue 
)

Set value for a runtime data parameter.

Parameters
pathidentify the data object
serializedValuenew value to set in serialized format, it will deserialized based on the type of path target.
Returns
true if values set.

◆ setValue() [1/5]

bool kanzi::connect::ServiceRuntimeData::setValue ( const string &  path,
int  value 
)

Set value for a runtime data parameter.

Parameters
pathidentify the data object
valuenew value to set.
Returns
true if values set.

◆ setValue() [2/5]

bool kanzi::connect::ServiceRuntimeData::setValue ( const string &  path,
double  value 
)

Set value for a runtime data parameter.

Parameters
pathidentify the data object
valuenew value to set.
Returns
true if values set.

◆ setValue() [3/5]

bool kanzi::connect::ServiceRuntimeData::setValue ( const string &  path,
string  value 
)

Set value for a runtime data parameter.

Parameters
pathidentify the data object
valuenew value to set.
Returns
true if values set.

◆ setValue() [4/5]

bool kanzi::connect::ServiceRuntimeData::setValue ( const string &  path,
const char *  value 
)

Set value for a runtime data parameter.

Parameters
pathidentify the data object
valuenew value to set.
Returns
true if values set.

◆ setValue() [5/5]

bool kanzi::connect::ServiceRuntimeData::setValue ( const string &  path,
bool  value 
)

Set value for a runtime data parameter.

Parameters
pathidentify the data object
valuenew value to set.
Returns
true if values set.

◆ validateHashCodes()

void kanzi::connect::ServiceRuntimeData::validateHashCodes ( RuntimeDataObjectSharedPtr  object)
protected

Processes a nodetree and checks that it does not contain duplicate hash values that might collide.

Parameters
objectidentifier.

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