Skip to content

Commit

Permalink
organise nested Struct members in new Struct Action Info
Browse files Browse the repository at this point in the history
  • Loading branch information
m-meingast authored and azoitl committed Jan 20, 2025
1 parent 09d7712 commit 25d5fb0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 17 deletions.
20 changes: 15 additions & 5 deletions src/com/opc_ua/opcua_objectstruct_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "opcua_objectstruct_helper_gen.cpp"
#endif
#include "opcua_layer.h"
#include "struct_member_action_info.h"
#include "struct_action_info.h"
#include "../../core/cominfra/basecommfb.h"
#include "opcua_local_handler.h"
Expand Down Expand Up @@ -223,6 +224,10 @@ bool COPC_UA_ObjectStruct_Helper::addOPCUAStructTypeObjectComponent(UA_Server *p
}

forte::com_infra::EComResponse COPC_UA_ObjectStruct_Helper::createObjectNode(CActionInfo& paActionInfo, CIEC_STRUCT &paStructType) {
return createObjectNode(paActionInfo, paStructType, mStructMemberActionInfos);
}

forte::com_infra::EComResponse COPC_UA_ObjectStruct_Helper::createObjectNode(CActionInfo& paActionInfo, CIEC_STRUCT &paStructType, std::vector<std::shared_ptr<CActionInfo>> &paMemberActionInfos) {
std::string browsePath = paActionInfo.getNodePairInfo().begin()->getBrowsePath();
CActionInfo::CNodePairInfo nodePair(nullptr, browsePath);
if(!isOPCUAObjectPresent(nodePair)) {
Expand All @@ -236,7 +241,7 @@ forte::com_infra::EComResponse COPC_UA_ObjectStruct_Helper::createObjectNode(CAc
mOpcuaObjectNamespaceIndex = paActionInfo.getNodePairInfo().begin()->getNodeId()->namespaceIndex;
}
}
return initializeMemberAction(paActionInfo, browsePath, paStructType);
return initializeMemberAction(paActionInfo, browsePath, paStructType, paMemberActionInfos);
}

CIEC_ANY const *COPC_UA_ObjectStruct_Helper::getStructMember(CActionInfo &paActionInfo, bool paIsSD) {
Expand Down Expand Up @@ -322,7 +327,7 @@ std::shared_ptr<CActionInfo> COPC_UA_ObjectStruct_Helper::getCreateObjectActionI
return actionInfo;
}

forte::com_infra::EComResponse COPC_UA_ObjectStruct_Helper::initializeMemberAction(CActionInfo& paActionInfo, std::string &paBrowsePath, CIEC_STRUCT &paStructType) {
forte::com_infra::EComResponse COPC_UA_ObjectStruct_Helper::initializeMemberAction(CActionInfo& paActionInfo, std::string &paBrowsePath, CIEC_STRUCT &paStructType, std::vector<std::shared_ptr<CActionInfo>> &paMemberActionInfos) {
COPC_UA_Local_Handler* localHandler = static_cast<COPC_UA_Local_Handler*>(mHandler);
if(!localHandler) {
DEVLOG_ERROR("[OPC UA OBJECT STRUCT HELPER]: Failed to get LocalHandler because LocalHandler is null!\n");
Expand All @@ -333,28 +338,33 @@ forte::com_infra::EComResponse COPC_UA_ObjectStruct_Helper::initializeMemberActi

for(size_t i = 0; i < paStructType.getStructSize(); i++) {
std::string memberBrowsePath(getStructMemberBrowsePathWithNSIndex(paBrowsePath, structMemberNames[i]));
std::shared_ptr<CActionInfo> actionInfo = std::make_shared<CStructMemberActionInfo>(*this, mLayer, paActionInfo.getAction(), paActionInfo.getEndpoint());
CIEC_ANY* memberVariable = paStructType.getMember(i);

if(memberVariable->getDataTypeID() == CIEC_ANY::e_STRUCT) {
CIEC_STRUCT &objectStruct = static_cast<CIEC_STRUCT&>(memberVariable->unwrap());
std::shared_ptr<CStructActionInfo> actionInfo = std::make_shared<CStructActionInfo>(*this, mLayer, paActionInfo.getAction(), paActionInfo.getEndpoint());
actionInfo->getNodePairInfo().emplace_back(nullptr, memberBrowsePath);
if(createObjectNode(*actionInfo, static_cast<CIEC_STRUCT&>(memberVariable->unwrap())) != e_InitOk) {
std::vector<std::shared_ptr<CActionInfo>> newActionInfos;
if(createObjectNode(*actionInfo, objectStruct, newActionInfos) != e_InitOk) {
DEVLOG_ERROR("[OPC UA OBJECT STRUCT HELPER]: Error occured in FB %s while initializing Struct Object member %s of Struct Type %s\n", mLayer.getCommFB()->getInstanceName(),
CStringDictionary::getInstance().get(structMemberNames[i]), CStringDictionary::getInstance().get(paStructType.getTypeNameID()));
return e_InitTerminated;
}
actionInfo->addMemberActionInfos(newActionInfos);
paMemberActionInfos.emplace_back(std::move(actionInfo));
} else {
UA_NodeId* nodeId = nullptr;
if(!isNodeIdPresent) {
nodeId = createStringNodeIdFromBrowsepath(memberBrowsePath);
}
std::shared_ptr<CActionInfo> actionInfo = std::make_shared<CStructMemberActionInfo>(*this, mLayer, paActionInfo.getAction(), paActionInfo.getEndpoint());
actionInfo->getNodePairInfo().emplace_back(nodeId, memberBrowsePath);
if(UA_STATUSCODE_GOOD != localHandler->initializeActionForObjectStruct(actionInfo, *memberVariable)) {
DEVLOG_ERROR("[OPC UA OBJECT STRUCT HELPER]: Error occured in FB %s while initializing Struct Variable member %s of Struct Type %s\n", mLayer.getCommFB()->getInstanceName(),
CStringDictionary::getInstance().get(structMemberNames[i]), CStringDictionary::getInstance().get(paStructType.getTypeNameID()));
return e_InitTerminated;
}
mStructMemberActionInfos.push_back(std::move(actionInfo));
paMemberActionInfos.emplace_back(std::move(actionInfo));
}
}
return e_InitOk;
Expand Down
12 changes: 11 additions & 1 deletion src/com/opc_ua/opcua_objectstruct_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,24 @@ class COPC_UA_ObjectStruct_Helper {
*/
bool createOPCUAStructType(CActionInfo &paActionInfo, UA_NodeId &paTypeNodeId, const std::string &paStructTypeName, CIEC_STRUCT &paStructType);

/**
* Create an OPC UA Object Node from Struct Type, if it is not present
* @param paActionInfo The ActionInfo to create the Object Node from
* @param paStructType The Struct Type
* @param paMemberActionInfos The vector in which the ActionInfos of the members should be added. If no vector is provided, the default vector is used.
* @return e_InitOk if Object Node was created successfully, e_InitTerminated otherwise
*/
forte::com_infra::EComResponse createObjectNode(CActionInfo& paActionInfo, CIEC_STRUCT &paStructType, std::vector<std::shared_ptr<CActionInfo>> &paMemberActionInfos);

/**
* Perform initialization for Object Struct Members
* @param paActionInfo The ActionInfo to create the Object Node from
* @param paBrowsePath The browsepath to the Object Struct
* @param paStructType The Struct Type
* @param paMemberActionInfos The vector in which the ActionInfos of the members should be added.
* @return e_InitOk if initialization was successful, e_InitTerminated otherwise
*/
forte::com_infra::EComResponse initializeMemberAction(CActionInfo& paActionInfo, std::string &paBrowsePath, CIEC_STRUCT &paStructType);
forte::com_infra::EComResponse initializeMemberAction(CActionInfo& paActionInfo, std::string &paBrowsePath, CIEC_STRUCT &paStructType, std::vector<std::shared_ptr<CActionInfo>> &paMemberActionInfos);

/**
* Check if OPC UA namespace is given by the Resource configuration.
Expand Down
21 changes: 10 additions & 11 deletions src/com/opc_ua/struct_action_info.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Primetals Technologies Austria GmbH
* Copyright (c) 2025 Primetals Technologies Austria GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -8,29 +8,28 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alois Zoitl - initial implementation
* Markus Meingast - initial implementation
*******************************************************************************/

#pragma once

#include "opcua_action_info.h"
#include "struct_member_action_info.h"
#include "opcua_layer.h"
#include "opcua_objectstruct_helper.h"

class CStructMemberActionInfo : public CActionInfo {
class CStructActionInfo : public CStructMemberActionInfo {
public:

explicit CStructMemberActionInfo(COPC_UA_ObjectStruct_Helper &paStructHelper, COPC_UA_Layer &paLayer, UA_ActionType paAction, const std::string &paEndpoint):
CActionInfo(paLayer, paAction, paEndpoint), mStructHelper(paStructHelper){
explicit CStructActionInfo(COPC_UA_ObjectStruct_Helper &paStructHelper, COPC_UA_Layer &paLayer, UA_ActionType paAction, const std::string &paEndpoint):
CStructMemberActionInfo(paStructHelper, paLayer, paAction, paEndpoint) {
}

const CIEC_ANY *const *getDataToSend() override {
mMemberArr[0] = mStructHelper.getStructMember(*this, true);
return mMemberArr;
void addMemberActionInfos(std::vector<std::shared_ptr<CActionInfo>> paActionInfos) {
mStructMemberActionInfos.insert(mStructMemberActionInfos.end(), paActionInfos.begin(), paActionInfos.end());
}

private:
CIEC_ANY const* mMemberArr[1];

COPC_UA_ObjectStruct_Helper &mStructHelper;
std::vector<std::shared_ptr<CActionInfo>> mStructMemberActionInfos;

};
36 changes: 36 additions & 0 deletions src/com/opc_ua/struct_member_action_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2023 Primetals Technologies Austria GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alois Zoitl - initial implementation
*******************************************************************************/

#pragma once

#include "opcua_action_info.h"
#include "opcua_layer.h"
#include "opcua_objectstruct_helper.h"

class CStructMemberActionInfo : public CActionInfo {
public:

explicit CStructMemberActionInfo(COPC_UA_ObjectStruct_Helper &paStructHelper, COPC_UA_Layer &paLayer, UA_ActionType paAction, const std::string &paEndpoint):
CActionInfo(paLayer, paAction, paEndpoint), mStructHelper(paStructHelper){
}

const CIEC_ANY *const *getDataToSend() override {
mMemberArr[0] = mStructHelper.getStructMember(*this, true);
return mMemberArr;
}

private:
CIEC_ANY const* mMemberArr[1];

COPC_UA_ObjectStruct_Helper &mStructHelper;
};

0 comments on commit 25d5fb0

Please sign in to comment.