UserComponentB.cpp

#include "UserComponentB.h"
#include "UserNodeB.h"

using namespace UserDefinedStructureLib;
/*!
  \class UserComponentB
  \inmodule UserDefinedStructureLib

  \section1 Usage

  Add documentation for UserComponentB here.
*/

/*!
  \internal
  \brief Component constructor. The first function to be called. Can be used to initialize member variables, etc.
*/
UserComponentB::UserComponentB()
{
}

/*!
  \internal
  \brief Component destructor. The last function to be called. Typically used to clean up when stopping, like freeing
  allocated memory, etc.
*/
UserComponentB::~UserComponentB()
{
    for (auto node: m_userNodesB)
        delete node;
}

/*!
  \internal
  \brief Creates the component instance and other related CDP objects. Called after constructor

  Note, that this function is normally filled automatically by the code generator.
*/
void UserComponentB::Create(const char* fullName)
{
    CDPComponent::Create(fullName);
}

/*!
  \internal
  \brief Creates a model instance for this class and fills model data. Registers messages, states and state transitions.

  Note, that this function is normally filled automatically by the code generator.
*/
void UserComponentB::CreateModel()
{
    CDPComponent::CreateModel();

    RegisterStateProcess("Null", (CDPCOMPONENT_STATEPROCESS)&UserComponentB::ProcessNull, "Initial Null state");
}

/*!
  \internal
  \brief Configures the component by reading the configuration. Called after Create()/CreateModel().

  Note, that this function is normally filled automatically by the code generator.
*/
void UserComponentB::Configure(const char* componentXML)
{
    CDPComponent::Configure(componentXML);
}

bool UserComponentB::HandleXMLElement(XMLElementEx *pEx)
{
    const XMLString& currentElement = pEx->GetName();

    if (currentElement == "UserNodesB") // this is just wrapper element for UserNode elements
        return false; //not done with handling, handleElement for childern also

    if (currentElement == "UserNodeB")
    {
        m_userNodesB.push_back(new UserNodeB(pEx, this));
        return true; // done with handling the structure
    }

    return CDPComponent::HandleXMLElement(pEx);
}

void UserComponentB::FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const
{
    serializer.StdContainerStreamer(m_userNodesB);
    CDPComponent::FillNodeChildren(serializer);
}

/*!
 \brief Component Null state processing function

 Write your component's processing code here. When the component is simple, all the processing code may reside here.
 This function gets called periodically. The period is changed by setting the "fs" (frequency) Property when you use
 the component in a project.
 Functions called ProcessSTATENAME(), like ProcessNull(), are state processing functions and are only called when
 components are in given state. The default component state is "Null".
 Note, that state processing functions are not allowed to block (i.e. read files, sleep, communicate with network in
 blocking mode etc.) For blocking code use the 'Threaded Component Model' wizard instead.

 Please consult CDP Studio "Code Mode Manual" for more information and examples.
*/
void UserComponentB::ProcessNull()
{
    /* Write your code here */
}

© CDP Technologies AS - All rights reserved