CDPNode Class
(CDP::StudioAPI::CDPNode)The CDPNode is base class for all classes exposed through StudioAPI. More...
Header: | #include <StudioAPI/CDPNode.h> |
Inherits: | ICDPNode |
Inherited By: | ArgumentBase, CDP::IO::Transport, CDPBaseObject, CDPConnector, CDPEnum, CDPPropertyBase, CDPRampTimer, CDPTimer, CDPTimerCounting, CDPTimerMs, Document, ServerIO::ICDPChannel, ServerIO::Translator::TranslatorBase, ServerIO::Translator::TranslatorChannelGroup, and ServerIO::Translator::ValueMapBase |
Public Functions
CDPNode(bool permissionsHandler = false) | |
~CDPNode() override | |
void | AddNodeModeFlags(const CDPNodeModeFlags &flags) |
void | AddPermissionsHandler(const std::string &readonlyRolePermissions) |
void | ClearNodeModeFlags(CDPNodeModeFlags flags = ~( CDPNodeModeFlags() )) |
void | Configure(XMLElementEx *xml) |
virtual void | FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const override |
void | FlushValueChanges(uint64_t timestamp) |
ICDPNode * | GetNodeAbsorbedBy() const |
bool | HasValueSubscription() const |
void | NotifyInvalidatedStructure() const |
void | NotifyValueChange(T oldValue, T newValue) const |
void | SetNodeAbsorbedBy(const ICDPNode *absorber) |
void | SetNodeReparented(bool reparented) |
virtual void | SetVariantValue(const CDP::StudioAPI::CDPVariantValue &value) override |
uint64_t | UpdateNodeTimestamp(uint64_t timestamp) |
Reimplemented Public Functions
virtual bool | AddChild(const std::string &name, const std::string &typeName, const std::string &configuration) override |
virtual CDPNodePermissionFlags | GetEffectivePermissionFlags(const std::shared_ptr<IAuthSession> &session) const override |
virtual unsigned int | GetNodeID() const override |
virtual CDPNodeModeFlags | GetNodeModeFlags() const override |
virtual const std::string | GetNodeName() const override |
virtual CDPNodeType | GetNodeType() const override |
virtual std::string | GetNodeTypeName() const override |
virtual CDPValueType | GetNodeValueType() const override |
virtual INodePermissions * | GetPermissionHandler() const override |
virtual CDPVariantValue | GetVariantValue() const override |
virtual bool | IsNodeLocal() const override |
virtual bool | RemoveChild(const std::string &name) override |
- 22 public functions inherited from CDP::StudioAPI::ICDPNode
Protected Functions
CDPNodeModeFlags & | GetMutableNodeFlags() |
Detailed Description
The CDPNode is base class for all classes exposed through StudioAPI.
A CDPNode is a class that implements base node for CDP structure.
Each class inheriting CDPNode should also provide a model file (<class name>.xml).
Each class that is intended to be used in configuration time by users should expose itself through library model declaration file (<library name>.xml).
Instances of CDPNode are not automatically aggregated in any other CDP class so all instances need to be created in code and also exposed in parents FillNodeChildren() function.
Each node has:
- node id - Unique id in running application
- name - Each node must have unique name inside its parent
- type - Type of closest CDP base class
- type name - Name of the inheriting class itself also called model name
- value type - Type of value when node represents a value
- value - Value when node represents a value
- mode flags - Flags defining capabilities
Examples of CDPNode usage, are found in CDPNode usage examples.
RolePermissions
By default CDPNode security permissions in the running system are always inheriting its parent permissions. When it should be possible to configure the CDPNode security permissions to be different from its parent node, then node-level permissions support for the CDPNode must be enabled.
To enable node-level permissions (i.e. the RolePermissions property) support for the CDPNode, you need to do this:
- Call CDPNode constructor with true in the argument.
- Call CDPNode::Configure() with the node configuration XML snippet (to read RolePermissions property startup values from).
- Enable RolePermissions property in CDP Studio model editor, by locating the CDPNode and its RolePermissions attribute (you may need to disable HideInternal filter for that) and set its Property modifier to checked and the DisplayHint modifier to Important.
You will find more information in Security Manual RolePermissions.
Member Function Documentation
CDPNode::CDPNode(bool permissionsHandler = false)
Constructs an CDPNode.
Usefulness of directly instantiating CDPNode is limited.
CDPNode is intended to be used as base class to expose simple classes over StudioAPI. Set parameter permissionsHandler to true if you need to enable permissions support for the node.
Note, that you should also call CDPNode::Configure() to load permission defaults from XML configuration at startup.
CDPNode::~CDPNode()
Destructs an CDPNode.
[override virtual]
bool CDPNode::AddChild(const std::string &name, const std::string &typeName, const std::string &configuration)
void CDPNode::AddNodeModeFlags(const CDPNodeModeFlags &flags)
Add flags to current node instance.
See also CDPNode::GetMutableNodeFlags and CDPNode::ClearNodeModeFlags.
void CDPNode::AddPermissionsHandler(const std::string &readonlyRolePermissions)
Adds permissions support to the node at runtime, by creating permissions handler and configuring it
Note, that permissions added via this method are runtime only, so that:
- the RolePermissions field is set read-only for StudioAPI user
- any RolePermissions field changes are not written to XML configuration
Note, that you should use CDPNode constructor with permsissionsSupport=true parameter if you want to enable permanent and user configurable permissions support for the node.
void CDPNode::ClearNodeModeFlags(CDPNodeModeFlags flags = ~( CDPNodeModeFlags() ))
Clear flags from current node instance.
Clears all flags when called without argument.
void CDPNode::Configure(XMLElementEx *xml)
Load CDPNode permission defaults from XML configuration
Should always be called when permissions support is enabled in constructor
[override virtual]
void CDPNode::FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const
Exposes child nodes of this node to StudioAPI.
Must be overridden if node has child nodes to expose. CDPNode implementation has no default child nodes to expose.
The CDP::StudioAPI::NodeStream argument implements stream operators to facilitate exposing the nodes, it also implements a std container streamer function to help exposing std containers aggregating nodes.
void MyNode::FillNodeChildren(NodeStream& serializer) const { serializer << nodeName << nodeValue << nodeDescription; serializer.StdContainerStreamer(otherChildNodesList); CDPNode::FillNodeChildren(serializer); //Always call direct base class implementation }
void CDPNode::FlushValueChanges(uint64_t timestamp)
Flushes node value changes if any have been accumulated to be published if samplig time has been reached. The argument timestamp refers to current time. If 0 is passed in flush will be forced.
[override virtual]
CDPNodePermissionFlags CDPNode::GetEffectivePermissionFlags(const std::shared_ptr<IAuthSession> &session) const
[protected]
CDPNodeModeFlags &CDPNode::GetMutableNodeFlags()
Returns a non const reference to internal flags member.
Is used by inheriting classes to assign desired initial value to flags.
See also CDPNode::AddNodeModeFlags and CDPNode::ClearNodeModeFlags.
ICDPNode *CDPNode::GetNodeAbsorbedBy() const
[override virtual]
unsigned int CDPNode::GetNodeID() const
Reimplemented from ICDPNode::GetNodeID().
Returns nodes unique ID in current application.
Node IDs from 0 to 255 are reserved, where 0 indicates a system and rest are allocated for applications.
[override virtual]
CDPNodeModeFlags CDPNode::GetNodeModeFlags() const
Reimplemented from ICDPNode::GetNodeModeFlags().
Returns current nodes runtime characteristics flags.
Node flags should be usually set in inheriting classes constructor. Node may exhibit undesired behavior when flags are not set correctly.
See also CDPNode::GetMutableNodeFlags, CDPNode::AddNodeModeFlags, and CDPNode::ClearNodeModeFlags.
[override virtual]
const std::string CDPNode::GetNodeName() const
Reimplemented from ICDPNode::GetNodeName().
Returns node's unique name in parent.
Must be overridden by inheriting class to return node's name. Base implementation returns empty string.
[override virtual]
CDPNodeType CDPNode::GetNodeType() const
Reimplemented from ICDPNode::GetNodeType().
Returns node's base type CDP::StudioAPI::eCDP_NODE.
Node type is considered the closest CDP base class. For all classes inheriting CDPNode CDP::StudioAPI::eCDP_NODE is the closest base class type.
[override virtual]
std::string CDPNode::GetNodeTypeName() const
Reimplemented from ICDPNode::GetNodeTypeName().
Returns node's class name "CDPNode".
Must be overridden to return inheriting class name. For CDPNode based classes class name is also used as model name.
[override virtual]
CDPValueType CDPNode::GetNodeValueType() const
Reimplemented from ICDPNode::GetNodeValueType().
Returns node's value type.
Must be overridden when inheriting class is a value node. Base implementation returns CDP::StudioAPI::eUNDEFINED.
[override virtual]
INodePermissions *CDPNode::GetPermissionHandler() const
Reimplemented from ICDPNode::GetPermissionHandler().
Returns permissions handler of the node.
If permissions are note supported for this node returns nullptr
[override virtual]
CDPVariantValue CDPNode::GetVariantValue() const
Reimplemented from ICDPNode::GetVariantValue().
Returns variant value representing node's current value.
Must be overridden for value nodes to return node's value. For non value type nodes the CDPValueType of the variant value will be CDP::StudioAPI::eUNDEFINED.
bool CDPNode::HasValueSubscription() const
Returns true if there is a valuesubscription to this node, false if not.
When no value subscription is present, there is no need to call NotifyValueChange().
[override virtual]
bool CDPNode::IsNodeLocal() const
Reimplemented from ICDPNode::IsNodeLocal().
Returns true
if node is present in current application.
Nodes of other application in system are not considered local nodes, but are represented in the tree as non-local nodes.
void CDPNode::NotifyInvalidatedStructure() const
Notifies StudioAPI that subtree of child nodes has changed.
When node's children change during runtime the implementation must call this function after the change is completed. Applies to all changes that happen after configuration phase on startup. Changes can be additions, removals or renames of sub-nodes in the tree.
void CDPNode::NotifyValueChange(T oldValue, T newValue) const
Notify that node's value has changed by providing oldValue and newValue of template type T.
Must be called in value node's implementation immediately before the value is set to value member to guarantee causality of change for chained changes.
Allowed template types are:
bool,char,unsigned char,short,unsigned short,int,unsigned int,float,double,int64_t,uint64_t,std::string,std::string&,const CDPVariantValue&
[override virtual]
bool CDPNode::RemoveChild(const std::string &name)
void CDPNode::SetNodeAbsorbedBy(const ICDPNode *absorber)
Set the node to be absorbed.
Sometimes logical structure of inheritance needs to differ from actual implementation, in case of using composition instead of inheritance in implementation the composited node can be absorbed to achieve this.
When following composition over inheritance paradigm the implementation structure of nodes may not be what is logically reasonable to expose. When using SetNodeAbsorbedBy() on a composited node all its child nodes will appear as children of compositing node (except Name node) when it is exposed in CDPNode::FillNodeChildren and wrapped in CDP::StudioAPI::AbsorbedChild.
See also CDP::StudioAPI::AbsorbedChild.
void CDPNode::SetNodeReparented(bool reparented)
Set the node to be reparented.
Sometimes logical structure of ownership needs to differer from actual implementation, in that case nodes can be reparented to achieve this.
For example CDPNode does not aggregate CDPProperties, this is done by CDPBaseObject, but it is useful to expose CDPProperties as CDPNode based classe's child nodes. This is one case where reparenting node from aggregating CDPBaseObject is used. As a result the reparented node is not exposed by the real parent and must be exposed from new parent in CDPNode::FillNodeChildren wrapping the node in CDP::StudioAPI::AdoptedChild.
In such a case care must be taken with naming of the reparented node, keeping it unique in the real parent and keeping reparented node's full path correct. The name becomes "reparentingNodeName.reparentedNodeName" if the new parent node is a child of the aggregator (the real parent of the reparented node).
See also CDP::StudioAPI::AdoptedChild.
[override virtual]
void CDPNode::SetVariantValue(const CDP::StudioAPI::CDPVariantValue &value)
Sets variant value of node.
Must be overridden for value nodes to set node's value. For non value type nodes this call is ignored.
uint64_t CDPNode::UpdateNodeTimestamp(uint64_t timestamp)
Set current timestamp to override system default timestamp for node value changes Returns previous timestamp for restoring the default.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.