CDPBaseObject Class

The CDPBaseObject is the base-class for all objects that need a Property-database and optional message-handling. More...

Header: #include <CDPSystem/Base/CDPBaseObject.h>
Inherits: CDP::StudioAPI::CDPNode
Inherited By:

CDPObject, CDPOperatorBase, IIRFilter, Integrator, and RateLimitedFilter

Public Functions

CDPBaseObject(CDPBaseObject &&other) = default
~CDPBaseObject() override
virtual void Activate()
virtual bool Activated() const
virtual void ChangeModelIfSpecified(XMLPrimitive *pObjectXML)
virtual void ClockIn()
virtual void ClockOut()
virtual void Configure(XMLPrimitive *pObjectXML)
virtual void ConfigureModel()
virtual void Create(const char *shortName, CDPBaseObject *pParentObject)
virtual void CreateModel(const char *pzModel)
virtual void CreateModel()
virtual void Destroy()
void FindAndCreateModelContainer(const std::string strType, bool bUseTypeName = false)
virtual CDPModel *GetModel() const
virtual CDPBaseObject *GetOwner() const
CDPComponent *GetParent() const
virtual std::string GetProperty(std::string propertyName)
virtual const CDPPropDB &GetPropertyList() const
virtual CDPPropertyBase *GetPropertyObject(std::string strProperty) const
virtual std::string GetTypeIdName() const
virtual unsigned int Handle() const
virtual bool IsComponent() const
virtual bool IsSystemMessage(Message *message) const
virtual int MessageGetProperty(void *message)
virtual int MessageSetProperty(void *message)
const char *ModelTypeName() const
virtual int ReceiveMessage(void *message)
int RecvMessage(void *message)
virtual void RegisterCDPNode(CDP::StudioAPI::CDPNode *pCDPNode)
virtual void RegisterMessage(int command, const char *textCommand, const char *description, CDPOBJECT_MESSAGEHANDLER messageHandler = 0, const char *parameterName = nullptr, CDP::StudioAPI::CDPNodeModeFlags flags = {})
virtual void RegisterProperty(CDPPropertyBase *pProp)
virtual unsigned int SetHandle(unsigned int handle)
virtual void SetProperty(std::string propertyName, std::string propertyValue)
virtual void SetTypeIdName(const std::string &strPromotedModelName)
virtual const char *ShortName() const
virtual unsigned int Status() const
virtual void Suspend()
virtual void UnRegisterCDPNode(CDP::StudioAPI::CDPNode *pCDPNode)
void UnRegisterProperty(CDPPropertyBase *pProp)

Reimplemented Public Functions

virtual void FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const override
virtual const std::string GetNodeName() const override
virtual CDP::StudioAPI::CDPNodeType GetNodeType() const override
virtual std::string GetNodeTypeName() const override

Static Public Members

const char *GetTemplateSubTypeInfo(const char *pzSubTypeInfo)

Protected Types

typedef CDPNodeList

Protected Functions

virtual void InitializeModel(const char *pzModel)

Protected Variables

CDPNodeList m_CDPNodeList
CDPPropDB m_cProperties
unsigned int m_handle
CDPBaseObject *m_owner
CDPModel *m_pModel
CDPComponent *m_pParent
std::string m_promotedModelName
CDPProperty<std::string> m_strShortName
CDPProperty<bool> m_suspended
std::list<MessageListItem> messages

Detailed Description

The CDPBaseObject is the base-class for all objects that need a Property-database and optional message-handling.

CDPBaseObjects are serialized to StudioAPI by their parent CDPObject.


Properties are registered through the property Create() call , and their value can be retrieved by calling GetProperty(). For more efficient (repeated) access of properties, the function GetPropertyObject() can be used.


To allow message-handling, the CDPBaseObject derived object must have a handle. It can be assigned by connecting to CDPEngine in the derived Create() function:

#include <CDPSystem/Engine/CDPEngine.h>
void MyDerived::Create(const char* shortName, CDPBaseObject* pParent)

The CDPEngine will then register the object and assign a handle to it.

The following messages are handled by CDPBaseObject:

CM_TEXTCOMMANDCan handle SetProperty and GetProperty messages

Other messages can be registered in the derived CreateModel() function, via the RegisterMessage API.

Member Type Documentation

typedef CDPBaseObject::CDPNodeList

Synonym for std::vector<CDP::StudioAPI::CDPNode*>

Member Function Documentation


Constructs the CDPBaseObject, initializing members to correct defaults.

[default] CDPBaseObject::CDPBaseObject(CDPBaseObject &&other)

Move-copy constructor.


Destructs the object.

[virtual] void CDPBaseObject::Activate()

Causes the object to be activated so it can receive messages.

This function is typically called by the CDP Framework, or from a derived class's Activate function. When this function is called, the member mutex of the CDPComponent (if this is not a CDPComponent: then the member mutex of the object owner) has already been locked. Activate() may be called from another thread, typically the main thread or the Application process thread, or from the correct CDPEngine scheduler.

[virtual] bool CDPBaseObject::Activated() const

Returns true if object is activated.

[virtual] void CDPBaseObject::ChangeModelIfSpecified(XMLPrimitive *pObjectXML)

Changes the model of this object to what it is defined to in the model file.

Falls back to orignal model name on failure.

[virtual] void CDPBaseObject::ClockIn()

Performs consistent state update of inputs.

[virtual] void CDPBaseObject::ClockOut()

Performs consistent state update of outputs.

[virtual] void CDPBaseObject::Configure(XMLPrimitive *pObjectXML)

Configures this object from the XML tree provided.

[virtual] void CDPBaseObject::ConfigureModel()

Configures the model (reads model xml file, sets default values).

[virtual] void CDPBaseObject::Create(const char *shortName, CDPBaseObject *pParentObject)

Creates the object, names it and gives it a parent (Note: Parent can be nullptr)

This function must be called from the derived class' Create() implementation. If this CDPBaseObject is not CDPObject based, the Create() function will add the object to m_listBaseObject in the parent (CDPObject) if parent is not nullptr.

[virtual] void CDPBaseObject::CreateModel(const char *pzModel)

Creates the model named pzModel and registers the SetProperty and GetProperty message-handlers.

[virtual] void CDPBaseObject::CreateModel()

Creates the model by using the name returned by GetNodeTypeName().

[virtual] void CDPBaseObject::Destroy()

Destroys the object.

[override virtual] void CDPBaseObject::FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const

Reimplemented from CDPNode::FillNodeChildren().

Serializes shortname, suspended, properties, messages and nodelist.

void CDPBaseObject::FindAndCreateModelContainer(const std::string strType, bool bUseTypeName = false)

Initializes the model, creates and configures it if needed.

[virtual] CDPModel *CDPBaseObject::GetModel() const

Returns the CDPModel pointer, or nullptr, for this object

[override virtual] const std::string CDPBaseObject::GetNodeName() const

Reimplemented from ICDPNode::GetNodeName().

Returns the ShortName of this object.

[override virtual] CDP::StudioAPI::CDPNodeType CDPBaseObject::GetNodeType() const

Reimplemented from ICDPNode::GetNodeType().


[override virtual] std::string CDPBaseObject::GetNodeTypeName() const

Reimplemented from ICDPNode::GetNodeTypeName().

Returns "CDPBaseObject".

[virtual] CDPBaseObject *CDPBaseObject::GetOwner() const

CDPComponent *CDPBaseObject::GetParent() const

Returns the parent CDPComponent, or nullptr if 'this' is a CDPCompoent.

[virtual] std::string CDPBaseObject::GetProperty(std::string propertyName)

Gets the value of propertyName. Example:

std::string strUnit = signal.GetProperty("Unit");

The returned string is empty if there is no property with propertyName.

[virtual] const CDPPropDB &CDPBaseObject::GetPropertyList() const

Returns the property database.

[virtual] CDPPropertyBase *CDPBaseObject::GetPropertyObject(std::string strProperty) const

Returns the pointer to the named property object, or nullptr if not found. Example:

CDPPropertyBase* pUnit= signal.GetPropertyObject("Unit");
  pUnit->SetPropertyChangeHandler([this](CDPPropertyBase*){ CDPMessage("Unit changed!\n"); });

[static] const char *CDPBaseObject::GetTemplateSubTypeInfo(const char *pzSubTypeInfo)

Returns the template part of pzSubTypeInfo.

This function can be called from a template<T> class like this:

string typeName = GetTemplateSubTypeInfo(typeid(T).name());

The returned string would then contain the type (int, double, etc) of the class.

[virtual] std::string CDPBaseObject::GetTypeIdName() const

Gets the model name derived from the compiler dependent TypeId.

[virtual] unsigned int CDPBaseObject::Handle() const

Returns the complete 32 bit handle for this object (appHandle:object).

The unique Handle is typically not used for CDPBaseObjects, but some operators, like AlarmOperator, uses it.

[virtual protected] void CDPBaseObject::InitializeModel(const char *pzModel)

Sets the model pointer by calling CreateModel().

[virtual] bool CDPBaseObject::IsComponent() const

Returns true if this object is of type CDPComponent.

[virtual] bool CDPBaseObject::IsSystemMessage(Message *message) const

Returns true if message is a message that should be processed even if suspended.

[virtual] int CDPBaseObject::MessageGetProperty(void *message)

Responds with a MessageCDPMessage with the property=value.

This function can be invoked by doing SendMessage(msg,true) so a MessageACK packet is returned to sender. This function expects to receive a MessageTextCommandWithParameterSend where the field 'textCommand' is set to 'GetProperty' (without the quotes) and the field 'parameters' is set to the name of the property to retrieve. This function will modify the message to contain 'propertyName=propertyValue' (without the quotes). The max length of the returned string in the message is capped at 1000 bytes including nullterminator.

See also CDPBaseObject::GetProperty.

[virtual] int CDPBaseObject::MessageSetProperty(void *message)

Sets a property in the object by decoding message and calling SetProperty(propertyName,propertyValue) Expects that message is sent as a MessageTextCommandWithParameterSend, where the field 'textCommand' is set to nullterminated string value 'SetProperty' (without the quotes), and the field 'parameters' is set to nullterminated string containing 'propertyName=propertyValue' (without the quotes).

Optionally the form 'propertyName=propertyValue;Save=0' (or ...Save=1) may be used. Then the SaveOnChange setting of the CDPProperty is ignored and the parameter of the message is temporarily used instead.

If either propertyName or propertyValue contains special characters, they must be surrounded with single or double quotes ("propertyName"="property;Value";Save=1). Quotes inside values must always be escaped using backslash (propertyName=Quotes\'In\"Value).

See also CDPBaseObject::SetProperty and CDPConnector::SetProperty.

const char *CDPBaseObject::ModelTypeName() const

Returns the name of the model, or empty string if no model is set.

[virtual] int CDPBaseObject::ReceiveMessage(void *message)

Forwards the message to the correct messagehandler.

int CDPBaseObject::RecvMessage(void *message)

Handles message reception, with notification to StudioAPI.

[virtual] void CDPBaseObject::RegisterCDPNode(CDP::StudioAPI::CDPNode *pCDPNode)

Adds pCDPNode to m_CDPNodeList.

m_CDPNodeList is serialized in FillNodeChildren().

[virtual] void CDPBaseObject::RegisterMessage(int command, const char *textCommand, const char *description, CDPOBJECT_MESSAGEHANDLER messageHandler = 0, const char *parameterName = nullptr, CDP::StudioAPI::CDPNodeModeFlags flags = {})

Registers message with description and message handler. Example:

void MyDerived::CreateModel(const char* pzModel)
  RegisterMessage(CM_TEXTCOMMAND,"MySpecialMessage","MySpecialMesssage handler",(CDPOBJECT_MESSAGEHANDLER)&MySpecialObject::MessageMySpecialMessageHandler);

The above code registers a message 'MySpecialMessage' into MySpecialObject. Note that the Model .xml file for the object must also be updated for the message to be visible in CDP Studio :

  <Message Command="CM_TEXTCOMMAND" Name="MySpecialMessage" Description="MySpecialMesssage handler"></Message>

[virtual] void CDPBaseObject::RegisterProperty(CDPPropertyBase *pProp)

Registers pProp in the property database.

[virtual] unsigned int CDPBaseObject::SetHandle(unsigned int handle)

Sets the object part of the handle for this CDPObject.

Returns the full 32 bit handle.

[virtual] void CDPBaseObject::SetProperty(std::string propertyName, std::string propertyValue)

Sets propertyName in the object to propertyValue. Example:


If there is no property named propertyName then an error-message will be printed and the property will not be set.

[virtual] void CDPBaseObject::SetTypeIdName(const std::string &strPromotedModelName)

Sets the TypeId name to strPromotedModelName.

[virtual] const char *CDPBaseObject::ShortName() const

Returns the "short" name of the object (relative to the parent object).

[virtual] unsigned int CDPBaseObject::Status() const

Returns a status according to Alarm Status Defines.

This base implementation returns STATUS_OK.

[virtual] void CDPBaseObject::Suspend()

Causes the object to be suspended.

This function is typically called by the CDP Framework, or from a derived class's Suspend function. Calling it stops the message processing. The member mutex of the Component or owner object has already been locked when this function is called. Suspend() will be called from the correct CDPEngine scheduler during runtime, or from the main task on shutdown.

[virtual] void CDPBaseObject::UnRegisterCDPNode(CDP::StudioAPI::CDPNode *pCDPNode)

Removes pCDPNode from m_CDPNodeList.

Call this in Destroy() when you have called RegisterCDPNode().

void CDPBaseObject::UnRegisterProperty(CDPPropertyBase *pProp)

Unregisters pProp from the property database.

Member Variable Documentation

CDPNodeList CDPBaseObject::m_CDPNodeList

This variable holds a list of nodes to expose to StudioAPI.

CDPPropDB CDPBaseObject::m_cProperties

This variable holds property database, containing all the properties registered in this object.

unsigned int CDPBaseObject::m_handle

This variable holds a system-unique handle.

CDPBaseObject *CDPBaseObject::m_owner

This variable holds the owner object.

CDPModel *CDPBaseObject::m_pModel

This variable holds a pointer to the model.

CDPComponent *CDPBaseObject::m_pParent

This variable holds a pointer to the parent.

std::string CDPBaseObject::m_promotedModelName

This variable holds the promoted model name.

CDPProperty<std::string> CDPBaseObject::m_strShortName

This variable holds a string containing the short name of the object.

CDPProperty<bool> CDPBaseObject::m_suspended

This variable holds a string containing the suspended status of the object.

std::list<MessageListItem> CDPBaseObject::messages

This variable holds a list containing all the messagehandlers in this object.

© CDP Technologies AS - All rights reserved