RuntimeDataObject

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

RuntimeDataObject is a base class for hierarchical runtime data.

Subclassed by RuntimeDataObjectList, RuntimeDataObjectTyped< DataType, DataTypeEnum >

Public Types

typedef ChildContainer::const_iterator ChildConstIterator
typedef ChildContainer::const_reverse_iterator ChildConstReverseIterator
typedef vector<RuntimeDataObjectSharedPtr> ChildContainer

Iterators for children.

typedef function<void(RuntimeDataObject *self)> ModifiedFunction

Callback function type for change subscriptions.

typedef shared_ptr<void> ModifiedSubscriptionToken

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

enum Persistence

Is the runtime data object persistent or not.

Values:

enumerator NON_PERSISTENT
enumerator PERSISTENT
enum Type

Type enumerations for different data object types.

Values:

enumerator Object
enumerator Integer
enumerator Real
enumerator Bool
enumerator String
enumerator List
enumerator Unknown

Public Functions

RuntimeDataObject(ConnectDomainSharedPtr domain, const string &name, const string nameOverride = "")

Standard constructor.

Parameters
  • domain: connect domain

  • name: Name of the data object.

  • nameOverride: overridden name of the object.

RuntimeDataObject(ConnectDomainSharedPtr domain, const string &path, const string &name, const string nameOverride)

Standard constructor.

Parameters
  • domain: connect domain

  • path: Path that contains names of the parents separated with ‘.’

  • name: Name of the data object.

  • nameOverride: overridden name of the object.

~RuntimeDataObject()

C++ destructor.

void addChild(const RuntimeDataObjectSharedPtr &child)

Adds data object as child of this object.

Parameters
  • child: Child object to add.

ModifiedSubscriptionToken addModifiedNotificationHandler(ModifiedFunction callback)

Allows to subscribe to modifications in this data context.

Return

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

Parameters
  • callback: Callback that is invoked when a change occurs in this data context.

ChildConstIterator beginChildren() const

Returns iterator to start of the child container.

Return

Iterator at the beginning of the container.

template<typename _ToClass>
shared_ptr<_ToClass> castTo()

Cast this object to specific type.

RuntimeDataObjectSharedPtr clone()

Clones an object and creates exact duplicate of it.

How ever, possible modification subscriptions are not duplicated.

Return

newly allocated object with exactly same contents.

void copyDataFrom(RuntimeDataObject &from)

Copies basic data from provided object.

Parameters
  • from: where the copying is done from.

bool copyValueFrom(RuntimeDataObjectSharedPtr other)

Copies a value from other object.

Return

true if copied successfully.

Parameters
  • other: the object where-from copying takes place

bool createChild(const string &name, const RuntimeDataObject::Type dataType, const string &serializedDefaultValue, const bool persistent, const int flags, const persistence::SettingFactory *settingFactory)

Create a child under this runtime data object.

Return

True if the child was successfully added

Parameters
  • name: The name of the child

  • dataType: The data type of the child

  • serializedDefaultValue: The default value in serialized format, to be deserialized based on given data type

  • persistent: Is the element persisted over reboots

  • flags: Should the element have modifier method (used by code generation only)

  • settingFactory: Used to create children with persistent values

bool createChildRecursive(const string &path, RuntimeDataObject::Type dataType, const string &serializedDefaultValue, const bool persistent, const int flags, const persistence::SettingFactory *settingFactory)

Create a child data object in the correct place in hierarchy specified by path.

Return

True if the child was successfully added

Parameters
  • path: Specifies the location of the child, if needed then intermediate layers are created on the way

  • dataType: The data type of the child

  • serializedDefaultValue: The default value in serialized format, to be deserialized based on given data type

  • persistent: Is the element persisted over reboots

  • flags: Should the element have modifier method (used by code generation only)

  • settingFactory: Used to create children with persistent values

RuntimeDataObjectSharedPtr createPathObjects(const string &path, const persistence::SettingFactory *settingFactory)

Create objects enough to have the given path in the runtime data and return the leaf object All created objects are of Type::Object.

Return

The created leaf object which can be used as parent for future children

Parameters
  • path: Identifies the objects to create

  • settingFactory: Used to create children with persistent values (passed to future children, not used directly)

ChildConstIterator endChildren() const

Returns iterator in the end of the child container.

Return

Iterator in the end of the container.

bool equals(RuntimeDataObjectSharedPtr other)

Compares objects and returns true if objects, including childs, are equal.

Return

true if equal.

Parameters
  • other: where to compare

RuntimeDataObjectSharedPtr findChild(const string &name)

Tries to find a child with given name.

Return

Child object that was found, or empty pointer if there is no such child.

RuntimeDataObjectSharedPtr findChild(uint32_t hash)

Tries to find a child with given name hash code.

Parameters
  • hash: the hashcode to be used in lookup.

template<typename _T>
shared_ptr<_T> findChild(const string &name)

Retrieve a typed children with specific name.

Return

typed shared pointer or empty pointer.

Parameters
  • name: the name of children to look for

template<typename _T>
shared_ptr<_T> findChild(uint32_t hash)

Retrieve a typed children with specific name hash code.

Return

typed shared pointer or empty pointer.

Parameters
  • hash: The hash of the children to look for.

RuntimeDataObjectSharedPtr findChildRecursive(const string &path, bool passLists = true)

Locates childs recursively.

Return

Object that was found or empty pointer if path could not be resolved.

Parameters
  • path: full path to object, items separated with dot (‘.’). i.e. Engine.Speed

  • passLists: whether to go over lists.

template<typename _T>
shared_ptr<_T> findChildRecursive(const string &path, bool passLists = true)

Locates childs recursively.

Return

Object that was found or empty pointer if path could not be resolved.

Parameters
  • path: full path to object, items separated with dot (‘.’). i.e. Engine.Speed

  • passLists: whether to go over lists.

bool generatesGetter() const

Retrieve getter generation status.

Return

getter generation status.

RuntimeDataObjectSharedPtr getChild(size_t index) const

Retrieves a child object in given index.

Return

Child data object in given index.

template<typename _T>
shared_ptr<_T> getChild(size_t index) const
size_t getChildCount() const

Retrieves the count of child objects in this data object.

Return

Child object count.

size_t getChildIndex(const RuntimeDataObject &child) const

Retrieves the index of a child data object.

Return

Index of the item in question, throws exception if there is no such child.

string getDefaultValueStr() const

Virtual function which exists in this base class but should never be used. This is overridden in classes where its appropriate.

void getFreeformProperties(vector<pair<string, string>> &output)

Get list of the free form properties defined for the object output The freeform properties will be copied here,.

See

RuntimeDataObject::isFreeformProperty

int getIntProperty(const string &name, int defaultValue = 0) const

Retrieve int property value.

Return

retrieved value

Parameters
  • name: the name of the property

  • defaultValue: the value for the property

string getName() const

Allows to retrieve the name of the object.

Return

Returns the name of the object.

uint32_t getNameHash()

retrieve hash code for the name portion of node

Return

CRC32 hash.

string getNameOverride() const

Retrieve the overriden name.

Return

the overriden name. if not specified then returns same as getName

const string &getPath() const
string getSerializedValue() const

Get the runtimedata object value in serialized format.

Return

The value, empty string if object has no value

string getStringProperty(const string &name, const string defaultValue = "") const

Retrieve string property value.

Return

retrieved value

Parameters
  • name: the name of the property

  • defaultValue: the value for the property

Type getType() const

Allows to retrieve the type of the object.

Return

Type enumeration of the object.

template<typename _ToClass>
shared_ptr<_ToClass> getUIDelegate()

Retrieve UI Delegate and cast it to approriate type.

Note

This is Kanzi Connect frameworks internal use only.

Return

caseted type or null.

ModifiedSubscriptionToken getUIDelegateModificationHandlerToken() const

Retrieve UI Delegate specific modification handlers registration token.

Note

This is Kanzi Connect frameworks internal use only.

Return

registration token.

bool getWritable() const

Retrieve writable status.

Return

writable status.

bool hasChild(const RuntimeDataObject &child) const

Checks whether or not the child exists.

Return

true if there is such child, otherwise false.

bool hasProperty(const string &name)

Checks whether there is a property with given name.

Return

true if property with name exists.

Parameters
  • name: the name to check.

void notifyModified(RuntimeDataObject *object = 0)

Triggers modification procedure in this data context, which invokes the subscriptions.

Should be called by derived classes whenever the value of the object is changed.

void removeAllChildren()

Removes all children.

void removeChild(const RuntimeDataObject &child)

Removes a child object from list of childs.

Parameters
  • child: Child object to remove.

void removeChild(size_t index)

Removes a child object in given index.

Parameters
  • index: The index of the child object to remove.

bool removeChild(const string &name)

Remove specified child of this object.

Return

True if a child is found and removed

Parameters
  • name: Identifies the child to remove

bool removeChildRecursive(const string &path)

Remove specified child and all elements in the path that would become empty.

Return

True if at least one element was removed

Parameters
  • path: Identifies the element to remove

void removeModifiedNotificationHandler(ModifiedSubscriptionToken token)

Allows to unsubscribe from modifications in this data context.

Parameters
  • token: Token to identify the subscription that should be removed.

void removeProperty(const string &name)

Removes a property with specific name.

Parameters
  • name: the name of the property to remove.

bool sendsEvent() const

Retrieve notifier event generation status.

Return

notifier event generation status.

void setGenerateGetter(bool creteGetter)

Set generate getter flag.

param createGetter if true, the object will have a direct method to read its value

void setName(const string &value)

Sets the name of the object.

Parameters
  • value: New name that is assigned to object.

void setNameOverride(const string &value)

Sets the overriden name of the object.

Parameters
  • value: New name that is assigned to object.

void setProperty(const string &name, const string &value)

Sets a local property - this information is not serialized.

Parameters
  • name: name of the property

  • value: the value for the property.

void setProperty(const string &name, int value)

Sets a local property - this information is not serialized.

Parameters
  • name: the name of the property

  • value: the value of the property

void setSendsEvent(bool createEventOnChange)

Set generate notifier event flag.

param createEventOnChange if true, the object will emit an event when its value changes

bool setSerializedValue(const string &serializedValue)

Set the value for this data object, if this is not typed or list type then this will fail.

Return

False if fails due to object type or data deserialization failure

Parameters
  • serializedValue: Contains the data value to set in serialized format

void setUIDelegateModificationHandlerToken(ModifiedSubscriptionToken token)

Store UI Delegate modification handler handle.

Note

This is Kanzi Connect frameworks internal use only.

Parameters
  • token: the token to store

void setUIDelegete(shared_ptr<DataObject> deleg)

Configures UI Delegate object for this content object.

Note

This is Kanzi Connect frameworks internal use only.

Parameters
  • deleg: delegate object

void setWritable(bool writable)

Set writable flag.

Parameters
  • writable: state

Public Static Functions

bool isFreeformProperty(const string &propertyName)

Checks whether the named property is one of the defined properties or not.

Return

True if property is not one of the specially defined ones

Parameters
  • propertyName: Identifies what kind of property is

Type str2Type(const string &str)

Convert a string to Type.

Return

The identified Type, Unknown if not identified

Parameters
  • str: Contains the data type, interchangeable with type2Str

string type2Str(const Type type)

Convert the type enumeration value to human readable string.

Return

string containing the value in human readable form

Parameters
  • type: The enumeration value to convert