• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • CDPBaseObject
  • 5.0.0

CDPBaseObject Class

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

Header: #include <CDPBaseObject>
Inherits: CDP::StudioAPI::CDPNode
Inherited By:

CDPObject, CDPOperatorBase, IIRFilter, Integrator, MessageArgument, and RateLimitedFilter

  • List of all members, including inherited members

Public Functions

CDPBaseObject()
CDPBaseObject(CDPBaseObject &&other) = default
~CDPBaseObject() override
virtual void Activate()
virtual bool Activated() const
void AddToCDPEngine()
virtual void ClockIn()
virtual void ClockOut()
virtual void Configure(XMLPrimitive *pObjectXML)
virtual void Create(const char *shortName, CDPBaseObject *pParentObject)
virtual void CreateModel()
virtual void Destroy()
CDPSchedulable *GetCDPSchedulable() 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 propertyName) 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)
void OnInScopeNodes(std::function<void( CDPNode &, T & ) > onNode, std::function<void( T ) > onFinished, bool scanSiblings)
void OnInScopeTags(std::function<void( std::map<std::string, std::string> ) > onTags)
virtual int ReceiveMessage(void *message)
virtual int ReceiveMessage(const MessagePacketHandle &handle)
int RecvMessage(const MessagePacketHandle &handle)
virtual void RegisterCDPNode(CDP::StudioAPI::CDPNode *pCDPNode)
virtual void RegisterMessage(int command, const char *textCommand, const char *description, CDPOBJECT_MESSAGEHANDLER messageHandler = nullptr, const char *parameterName = nullptr, CDP::StudioAPI::CDPNodeModeFlags flags = {})
virtual void RegisterMessage(int command, const char *textCommand, const char *description, const std::function<int( void * ) > &messageHandler, const char *parameterName, CDP::StudioAPI::CDPNodeModeFlags flags = {})
virtual void RegisterMessage(int command, const char *textCommand, const char *description, const std::function<int( const MessagePacketHandle & message ) > &messageHandler, const char *parameterName, CDP::StudioAPI::CDPNodeModeFlags flags = {})
virtual void RegisterProperty(CDPPropertyBase *pProp)
void RemoveFromCDPEngine()
void RemoveMessage(int command)
void RemoveMessage(const char *textCommand)
virtual void ReportFailedReceive(const MessagePacketHandle &handle, const std::string &source)
void SendNotify(MessageRequestHandle *message) const
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 SuspendByException()
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
  • 27 public functions inherited from CDP::StudioAPI::CDPNode
  • 22 public functions inherited from CDP::StudioAPI::ICDPNode

Static Public Members

const char *GetTemplateSubTypeInfo(const char *pzSubTypeInfo)

Protected Types

typedef CDPNodeList

Protected Variables

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

Additional Inherited Members

  • 1 protected function inherited from CDP::StudioAPI::CDPNode

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

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.

Messages

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

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

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

CDPBaseObject::CDPBaseObject()

Constructs the CDPBaseObject, initializing members to correct defaults.

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

Move-copy constructor.

CDPBaseObject::~CDPBaseObject()

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.

void CDPBaseObject::AddToCDPEngine()

Registers itself in CDPEngine in order to be able to receive messages.

[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::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()

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

[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 (if object is able to receive messages) and nodelist.

CDPSchedulable *CDPBaseObject::GetCDPSchedulable() const

Returns pointer to the GetCDPSchedulable of this object. If this object is actually a CDPSchedulable then it is simply cast, otherwise nearest parent CDPSchedulable is returned.

[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().

Returns CDP::StudioAPI::eCDP_BASE_OBJECT_NODE.

[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 propertyName) const

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

CDPPropertyBase* pUnit= signal.GetPropertyObject("Unit");
if(pUnit!=nullptr)
  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] 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.

void CDPBaseObject::OnInScopeNodes(std::function<void( CDPNode &, T & ) > onNode, std::function<void( T ) > onFinished, bool scanSiblings)

void CDPBaseObject::OnInScopeTags(std::function<void( std::map<std::string, std::string> ) > onTags)

Fills tags map with all the in scope CDPTag values and calls onTags callback

onTags callback is either called immediately during configuration or asynchronously during runtime in but initial CDPBaseObject::OnInScopeTags callsite context with locked parent mutex if needed.

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

Forwards the message to the correct messagehandler.

[virtual] int CDPBaseObject::ReceiveMessage(const MessagePacketHandle &handle)

int CDPBaseObject::RecvMessage(const MessagePacketHandle &handle)

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 = nullptr, const char *parameterName = nullptr, CDP::StudioAPI::CDPNodeModeFlags flags = {})

Registers message with description and message handler. Example:

void MyDerived::CreateModel(const char* pzModel)
{
  CDPBaseObject::CreateModel(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 :

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

[virtual] void CDPBaseObject::RegisterMessage(int command, const char *textCommand, const char *description, const std::function<int( void * ) > &messageHandler, const char *parameterName, CDP::StudioAPI::CDPNodeModeFlags flags = {})

Registers message with description and message handler. Example:

void MyDerived::CreateModel(const char* pzModel)
{
  CDPBaseObject::CreateModel(pzModel);
  ...
  RegisterMessage(CM_TEXTCOMMAND,"MySpecialMessage","MySpecialMesssage handler", std::bind(&MySpecialObject::MessageMySpecialMessageHandler, this, std::placeholders::_1));
}

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 :

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

[virtual] void CDPBaseObject::RegisterMessage(int command, const char *textCommand, const char *description, const std::function<int( const MessagePacketHandle & message ) > &messageHandler, const char *parameterName, CDP::StudioAPI::CDPNodeModeFlags flags = {})

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

Registers pProp in the property database.

void CDPBaseObject::RemoveFromCDPEngine()

Deregisters itself from CDPEngine

void CDPBaseObject::RemoveMessage(int command)

Removes a previously registered message identified by command.

void CDPBaseObject::RemoveMessage(const char *textCommand)

Removes a previously registered message identified by textCommand.

[virtual] void CDPBaseObject::ReportFailedReceive(const MessagePacketHandle &handle, const std::string &source)

Called when instance based on CDPBaseObject does not successfully handle message it receives.

CDPBaseObject sets parent components ConfigurationAlarm with the details of the unhandled message. Function arguments are MessagePacketHandle to the failed message as handle and message source URI as source (or origin number if the message is from an external application).

void CDPBaseObject::SendNotify(MessageRequestHandle *message) const

Sends a CM_NOTIFY message back to the origin of message.

The notify message is used to notify the existence of an object. The requesting object uses the notify reply to determine the existence and handle of an object.

Uses the origin of message as destination for notify message.

[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:

object.SetProperty("Unit","m/s");

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::SuspendByException()

Suspends the object because of the unhandled C++ exception happened. Resulting the same state as by calling the Suspend() but this state will not be synced by redundancy.

[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.

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.

std::list<MessageListItem> CDPBaseObject::messages

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

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top