From f45cbaa40d82dcd01de86f7e98b8560452ee2693 Mon Sep 17 00:00:00 2001 From: Markus Meingast Date: Wed, 20 Mar 2024 10:17:27 +0100 Subject: [PATCH 1/4] Add AddWatches Method to OPC UA MGR --- src/stdfblib/ita/OPCUA_MGR.cpp | 53 ++++++++++++++++++++++++++++++++-- src/stdfblib/ita/OPCUA_MGR.h | 23 +++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/stdfblib/ita/OPCUA_MGR.cpp b/src/stdfblib/ita/OPCUA_MGR.cpp index 61cf9d44d..d3dd9702e 100644 --- a/src/stdfblib/ita/OPCUA_MGR.cpp +++ b/src/stdfblib/ita/OPCUA_MGR.cpp @@ -177,6 +177,17 @@ char OPCUA_MGR::smDeleteConnArg2Description[] = "{SubApp.FbName.PortName}"; char OPCUA_MGR::smDeleteConnAttrDisplayName[] = "Delete Connection"; char OPCUA_MGR::smDeleteConnAttrDescription[] = "Delete Connection"; +#ifdef FORTE_SUPPORT_MONITORING + +/* Add Watch */ +char OPCUA_MGR::smAddWatchMethodName[] = "addWatch"; +char OPCUA_MGR::smAddWatchArgName[] = "FB Port"; +char OPCUA_MGR::smAddWatchArgDescription[] = "Fully qualified name of FB Port"; +char OPCUA_MGR::smAddWatchAttrDisplayName[] = "Add Watch"; +char OPCUA_MGR::smAddWatchAttrDescription[] = "Add Watch"; + +#endif // FORTE_SUPPORT_MONITORING + /* Initialize UA Status Codes */ const std::map OPCUA_MGR::scResponseMap = { {EMGMResponse::Ready, UA_STATUSCODE_GOOD}, @@ -284,6 +295,9 @@ EMGMResponse OPCUA_MGR::createIEC61499ResourceObjectType(UA_Server* paServer) { if (addKillFBMethod(paServer) != EMGMResponse::Ready) return eRetVal; if (addDeleteFBMethod(paServer) != EMGMResponse::Ready) return eRetVal; if (addDeleteConnectionMethod(paServer) != EMGMResponse::Ready) return eRetVal; +#ifdef FORTE_SUPPORT_MONITORING + if (addAddWatchMethod(paServer) != EMGMResponse::Ready) return eRetVal; +#endif // FORTE_SUPPORT_MONITORING return EMGMResponse::Ready; } @@ -949,6 +963,41 @@ UA_StatusCode OPCUA_MGR::onDeleteConnection(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } +/* FORTE Monitoring */ +#ifdef FORTE_SUPPORT_MONITORING + +EMGMResponse OPCUA_MGR::addAddWatchMethod(UA_Server* paServer) { + UA_Argument inputArgument; + initArgument(inputArgument, UA_TYPES_STRING, smAddWatchArgName, smAddWatchArgDescription); + + UA_MethodAttributes addWatchAttr = createAttribute(smAddWatchAttrDisplayName, smAddWatchAttrDescription); + return addMethodNode(paServer, smAddWatchMethodName, mResourceTypeId, addWatchAttr, &inputArgument, 1, nullptr, 0, &onAddWatch); +} + +UA_StatusCode OPCUA_MGR::onAddWatch(UA_Server*, + const UA_NodeId*, void*, + const UA_NodeId*, void* methodContext, + const UA_NodeId*, void* objectContext, + size_t, const UA_Variant* input, + size_t, UA_Variant*) { + if (methodContext != nullptr) { + EMGMResponse eRetVal = EMGMResponse::UnsupportedType; + std::string destination; + destination = getInputValue(*static_cast(input[0].data)); + std::vector fullFbName; + parseDestinationName(destination, fullFbName); + + const char* resourceName = static_cast(objectContext); + OPCUA_MGR* uaMGR = static_cast(methodContext); + uaMGR->setMGMCommand(EMGMCommandType::MonitoringAddWatch, CStringDictionary::getInstance().insert(resourceName), nullptr, fullFbName); + eRetVal = uaMGR->mUaDevice.executeMGMCommand(uaMGR->mCommand); + return scResponseMap.find(eRetVal)->second; + } + return UA_STATUSCODE_BADUNKNOWNRESPONSE; +} + +#endif // FORTE_SUPPORT_MONITORING + /* Helpers */ EMGMResponse OPCUA_MGR::addMethodNode(UA_Server* paServer, char* paMethodNodeName, UA_NodeId paParentNodeId, UA_MethodAttributes paAttr, @@ -1016,7 +1065,7 @@ void OPCUA_MGR::setMGMCommand(EMGMCommandType paCMD, CStringDictionary::TStringI mCommand.mSecondParam.pushBack(CStringDictionary::getInstance().insert(paSecondParam)); } if (paAdditionalParams != nullptr) { - mCommand.mAdditionalParams.fromString(paAdditionalParams); + mCommand.mAdditionalParams = CIEC_STRING(paAdditionalParams); } } @@ -1037,7 +1086,7 @@ void OPCUA_MGR::setMGMCommand(EMGMCommandType paCMD, CStringDictionary::TStringI } } if (paAdditionalParams != nullptr) { - mCommand.mAdditionalParams.fromString(paAdditionalParams); + mCommand.mAdditionalParams = CIEC_STRING(paAdditionalParams); } } diff --git a/src/stdfblib/ita/OPCUA_MGR.h b/src/stdfblib/ita/OPCUA_MGR.h index 8a524d89b..7eae1019b 100644 --- a/src/stdfblib/ita/OPCUA_MGR.h +++ b/src/stdfblib/ita/OPCUA_MGR.h @@ -191,6 +191,18 @@ class OPCUA_MGR { static char smDeleteConnAttrDisplayName[]; static char smDeleteConnAttrDescription[]; +/* FORTE Monitoring */ +#ifdef FORTE_SUPPORT_MONITORING + + /* Add Watch */ + static char smAddWatchMethodName[]; + static char smAddWatchArgName[]; + static char smAddWatchArgDescription[]; + static char smAddWatchAttrDisplayName[]; + static char smAddWatchAttrDescription[]; + +#endif // FORTE_SUPPORT_MONITORING + static const std::map scResponseMap; static const UA_UInt16 smNamespaces[]; @@ -393,6 +405,17 @@ class OPCUA_MGR { size_t inputSize, const UA_Variant* input, size_t outputSize, UA_Variant* output); +/* FORTE Monitoring */ + +#ifdef FORTE_SUPPORT_MONITORING + EMGMResponse addAddWatchMethod(UA_Server* paServer); + static UA_StatusCode onAddWatch(UA_Server* server, + const UA_NodeId* sessionId, void* sessionHandle, + const UA_NodeId* methodId, void* methodContext, + const UA_NodeId* objectId, void* objectContext, + size_t inputSize, const UA_Variant* input, + size_t outputSize, UA_Variant* output); +#endif // FORTE_SUPPORT_MONITORING /* Helpers */ EMGMResponse addMethodNode(UA_Server* paServer, char* paMethodName, UA_NodeId paParentNodeId, From 5897ed563a852bfaaf8fead71329a0cf3165d7ea Mon Sep 17 00:00:00 2001 From: Markus Meingast Date: Wed, 20 Mar 2024 10:42:16 +0100 Subject: [PATCH 2/4] Add ReadWatches Method to OPC UA MGR --- src/stdfblib/ita/OPCUA_MGR.cpp | 42 ++++++++++++++++++++++++++++++++++ src/stdfblib/ita/OPCUA_MGR.h | 20 +++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/stdfblib/ita/OPCUA_MGR.cpp b/src/stdfblib/ita/OPCUA_MGR.cpp index d3dd9702e..c444599e6 100644 --- a/src/stdfblib/ita/OPCUA_MGR.cpp +++ b/src/stdfblib/ita/OPCUA_MGR.cpp @@ -186,6 +186,13 @@ char OPCUA_MGR::smAddWatchArgDescription[] = "Fully qualified name of FB Port"; char OPCUA_MGR::smAddWatchAttrDisplayName[] = "Add Watch"; char OPCUA_MGR::smAddWatchAttrDescription[] = "Add Watch"; +/* Read Watches */ +char OPCUA_MGR::smReadWatchesMethodName[] = "readWatches"; +char OPCUA_MGR::smReadWatchesOutArgName[] = "Response"; +char OPCUA_MGR::smReadWatchesOutArgDescription[] = "Read Response"; +char OPCUA_MGR::smReadWatchesDisplayName[] = "Read Watches"; +char OPCUA_MGR::smReadWatchesDescription[] = "Read Watches"; + #endif // FORTE_SUPPORT_MONITORING /* Initialize UA Status Codes */ @@ -246,6 +253,9 @@ EMGMResponse OPCUA_MGR::createIEC61499MgmtObject(UA_Server* paServer) { if (addKillDeviceMethod(paServer) != EMGMResponse::Ready) return eRetVal; if (addKillResourceMethod(paServer) != EMGMResponse::Ready) return eRetVal; if (addDeleteResourceMethod(paServer) != EMGMResponse::Ready) return eRetVal; +#ifdef FORTE_SUPPORT_MONITORING + if (addReadWatchesMethod(paServer) != EMGMResponse::Ready) return eRetVal; +#endif // FORTE_SUPPORT_MONITORING return addMgmtObjectInstance(); } @@ -996,6 +1006,36 @@ UA_StatusCode OPCUA_MGR::onAddWatch(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } +EMGMResponse OPCUA_MGR::addReadWatchesMethod(UA_Server* paServer) { + UA_Argument outputArgument; + initArgument(outputArgument, UA_TYPES_STRING, smReadWatchesOutArgName, smReadWatchesOutArgDescription); + UA_MethodAttributes readWatchesAttr = createAttribute(smReadWatchesDisplayName, smReadWatchesDescription); + return addMethodNode(paServer, smReadWatchesMethodName, mMgmtTypeId, readWatchesAttr, nullptr, 0, &outputArgument, 1, &onReadWatches); +} + +UA_StatusCode OPCUA_MGR::onReadWatches(UA_Server*, + const UA_NodeId*, void*, + const UA_NodeId*, void* methodContext, + const UA_NodeId*, void*, + size_t, const UA_Variant*, + size_t, UA_Variant* output) { + if (methodContext != nullptr) { + EMGMResponse eRetVal = EMGMResponse::UnsupportedType; + OPCUA_MGR* uaMGR = static_cast(methodContext); + uaMGR->setMGMCommand(EMGMCommandType::MonitoringReadWatches, CStringDictionary::scmInvalidStringId, nullptr, nullptr, nullptr); + eRetVal = uaMGR->mUaDevice.executeMGMCommand(uaMGR->mCommand); + int status = scResponseMap.find(eRetVal)->second; + if (status != UA_STATUSCODE_GOOD) { + return status; + } + UA_String uaResp = UA_String_fromChars(uaMGR->mCommand.mMonitorResponse.c_str()); + status = UA_Variant_setScalarCopy(output, &uaResp, &UA_TYPES[UA_TYPES_STRING]); + UA_String_clear(&uaResp); + return status; + } + return UA_STATUSCODE_BADUNKNOWNRESPONSE; +} + #endif // FORTE_SUPPORT_MONITORING /* Helpers */ @@ -1050,7 +1090,9 @@ void OPCUA_MGR::clearMGMCommand() { mCommand.mFirstParam.clear(); mCommand.mSecondParam.clear(); mCommand.mAdditionalParams.clear(); +#ifdef FORTE_SUPPORT_MONITORING mCommand.mMonitorResponse.clear(); +#endif // FORTE_SUPPORT_MONITORING } void OPCUA_MGR::setMGMCommand(EMGMCommandType paCMD, CStringDictionary::TStringId paDestination, diff --git a/src/stdfblib/ita/OPCUA_MGR.h b/src/stdfblib/ita/OPCUA_MGR.h index 7eae1019b..0ea85ace8 100644 --- a/src/stdfblib/ita/OPCUA_MGR.h +++ b/src/stdfblib/ita/OPCUA_MGR.h @@ -201,6 +201,13 @@ class OPCUA_MGR { static char smAddWatchAttrDisplayName[]; static char smAddWatchAttrDescription[]; + /* Read Watches */ + static char smReadWatchesMethodName[]; + static char smReadWatchesDisplayName[]; + static char smReadWatchesDescription[]; + static char smReadWatchesOutArgName[]; + static char smReadWatchesOutArgDescription[]; + #endif // FORTE_SUPPORT_MONITORING static const std::map scResponseMap; @@ -408,14 +415,25 @@ class OPCUA_MGR { /* FORTE Monitoring */ #ifdef FORTE_SUPPORT_MONITORING + EMGMResponse addAddWatchMethod(UA_Server* paServer); static UA_StatusCode onAddWatch(UA_Server* server, const UA_NodeId* sessionId, void* sessionHandle, const UA_NodeId* methodId, void* methodContext, const UA_NodeId* objectId, void* objectContext, size_t inputSize, const UA_Variant* input, - size_t outputSize, UA_Variant* output); + size_t outputSize, UA_Variant* output); + + EMGMResponse addReadWatchesMethod(UA_Server* paServer); + static UA_StatusCode onReadWatches(UA_Server* server, + const UA_NodeId* sessionId, void* sessionHandle, + const UA_NodeId* methodId, void* methodContext, + const UA_NodeId* objectId, void* objectContext, + size_t inputSize, const UA_Variant* input, + size_t outputSize, UA_Variant* output); + #endif // FORTE_SUPPORT_MONITORING + /* Helpers */ EMGMResponse addMethodNode(UA_Server* paServer, char* paMethodName, UA_NodeId paParentNodeId, From c64d718fc44d7edbc9aab364d9aacf532856bbc3 Mon Sep 17 00:00:00 2001 From: Markus Meingast Date: Wed, 20 Mar 2024 12:39:40 +0100 Subject: [PATCH 3/4] Add RemoveWatches Method to OPC UA MGR --- src/stdfblib/ita/OPCUA_MGR.cpp | 38 ++++++++++++++++++++++++++++++++++ src/stdfblib/ita/OPCUA_MGR.h | 15 ++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/stdfblib/ita/OPCUA_MGR.cpp b/src/stdfblib/ita/OPCUA_MGR.cpp index c444599e6..1ee84dde8 100644 --- a/src/stdfblib/ita/OPCUA_MGR.cpp +++ b/src/stdfblib/ita/OPCUA_MGR.cpp @@ -193,6 +193,13 @@ char OPCUA_MGR::smReadWatchesOutArgDescription[] = "Read Response"; char OPCUA_MGR::smReadWatchesDisplayName[] = "Read Watches"; char OPCUA_MGR::smReadWatchesDescription[] = "Read Watches"; +/* Remove Watch */ +char OPCUA_MGR::smRemoveWatchMethodName[] = "removeWatch"; +char OPCUA_MGR::smRemoveWatchArgName[] = "FB Port"; +char OPCUA_MGR::smRemoveWatchArgDescription[] = "Fully qualified name of FB Port"; +char OPCUA_MGR::smRemoveWatchAttrDisplayName[] = "Remove Watch"; +char OPCUA_MGR::smRemoveWatchAttrDescription[] = "Remove Watch"; + #endif // FORTE_SUPPORT_MONITORING /* Initialize UA Status Codes */ @@ -307,6 +314,7 @@ EMGMResponse OPCUA_MGR::createIEC61499ResourceObjectType(UA_Server* paServer) { if (addDeleteConnectionMethod(paServer) != EMGMResponse::Ready) return eRetVal; #ifdef FORTE_SUPPORT_MONITORING if (addAddWatchMethod(paServer) != EMGMResponse::Ready) return eRetVal; + if (addRemoveWatchMethod(paServer) != EMGMResponse::Ready) return eRetVal; #endif // FORTE_SUPPORT_MONITORING return EMGMResponse::Ready; } @@ -1036,6 +1044,36 @@ UA_StatusCode OPCUA_MGR::onReadWatches(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } +EMGMResponse OPCUA_MGR::addRemoveWatchMethod(UA_Server* paServer) { + UA_Argument inputArgument; + initArgument(inputArgument, UA_TYPES_STRING, smRemoveWatchArgName, smRemoveWatchArgDescription); + + UA_MethodAttributes removeWatchAttr = createAttribute(smRemoveWatchAttrDisplayName, smRemoveWatchAttrDescription); + return addMethodNode(paServer, smRemoveWatchMethodName, mResourceTypeId, removeWatchAttr, &inputArgument, 1, nullptr, 0, &onRemoveWatch); +} + +UA_StatusCode OPCUA_MGR::onRemoveWatch(UA_Server*, + const UA_NodeId*, void*, + const UA_NodeId*, void* methodContext, + const UA_NodeId*, void* objectContext, + size_t, const UA_Variant* input, + size_t, UA_Variant*) { + if (methodContext != nullptr) { + EMGMResponse eRetVal = EMGMResponse::UnsupportedType; + std::string destination; + destination = getInputValue(*static_cast(input[0].data)); + std::vector fullFbName; + parseDestinationName(destination, fullFbName); + + const char* resourceName = static_cast(objectContext); + OPCUA_MGR* uaMGR = static_cast(methodContext); + uaMGR->setMGMCommand(EMGMCommandType::MonitoringRemoveWatch, CStringDictionary::getInstance().insert(resourceName), nullptr, fullFbName); + eRetVal = uaMGR->mUaDevice.executeMGMCommand(uaMGR->mCommand); + return scResponseMap.find(eRetVal)->second; + } + return UA_STATUSCODE_BADUNKNOWNRESPONSE; +} + #endif // FORTE_SUPPORT_MONITORING /* Helpers */ diff --git a/src/stdfblib/ita/OPCUA_MGR.h b/src/stdfblib/ita/OPCUA_MGR.h index 0ea85ace8..508db7572 100644 --- a/src/stdfblib/ita/OPCUA_MGR.h +++ b/src/stdfblib/ita/OPCUA_MGR.h @@ -208,6 +208,13 @@ class OPCUA_MGR { static char smReadWatchesOutArgName[]; static char smReadWatchesOutArgDescription[]; + /* Remove Watch */ + static char smRemoveWatchMethodName[]; + static char smRemoveWatchArgName[]; + static char smRemoveWatchArgDescription[]; + static char smRemoveWatchAttrDisplayName[]; + static char smRemoveWatchAttrDescription[]; + #endif // FORTE_SUPPORT_MONITORING static const std::map scResponseMap; @@ -432,6 +439,14 @@ class OPCUA_MGR { size_t inputSize, const UA_Variant* input, size_t outputSize, UA_Variant* output); + EMGMResponse addRemoveWatchMethod(UA_Server* paServer); + static UA_StatusCode onRemoveWatch(UA_Server* server, + const UA_NodeId* sessionId, void* sessionHandle, + const UA_NodeId* methodId, void* methodContext, + const UA_NodeId* objectId, void* objectContext, + size_t inputSize, const UA_Variant* input, + size_t outputSize, UA_Variant* output); + #endif // FORTE_SUPPORT_MONITORING /* Helpers */ From 6cb8f2e794e11664966be7f3a9f60e0514796280 Mon Sep 17 00:00:00 2001 From: Markus Meingast Date: Wed, 27 Mar 2024 11:39:57 +0100 Subject: [PATCH 4/4] Set callback input value strings to const --- src/stdfblib/ita/OPCUA_MGR.cpp | 84 +++++++++++++--------------------- src/stdfblib/ita/OPCUA_MGR.h | 2 +- 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/stdfblib/ita/OPCUA_MGR.cpp b/src/stdfblib/ita/OPCUA_MGR.cpp index 1ee84dde8..969fb36ed 100644 --- a/src/stdfblib/ita/OPCUA_MGR.cpp +++ b/src/stdfblib/ita/OPCUA_MGR.cpp @@ -386,8 +386,8 @@ UA_StatusCode OPCUA_MGR::onCreateResource(UA_Server*, if (!methodContext) { return UA_STATUSCODE_BADUNKNOWNRESPONSE; } - std::string resourceName = getInputValue(*static_cast(input[0].data)); - std::string resType = getInputValue(*static_cast(input[1].data)); + const std::string resourceName(getInputValue(*static_cast(input[0].data))); + const std::string resType(getInputValue(*static_cast(input[1].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::CreateFBInstance, CStringDictionary::scmInvalidStringId, nullptr, resourceName.c_str(), resType.c_str()); @@ -432,10 +432,8 @@ UA_StatusCode OPCUA_MGR::onCreateFB(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); - std::string fbTypeStr; - fbTypeStr = getInputValue(*static_cast(input[1].data)); + const std::string destination(getInputValue(*static_cast(input[0].data))); + const std::string fbTypeStr(getInputValue(*static_cast(input[1].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -467,10 +465,8 @@ UA_StatusCode OPCUA_MGR::onCreateConnection(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string source; - source = getInputValue(*static_cast(input[0].data)); - std::string destination; - destination = getInputValue(*static_cast(input[1].data)); + const std::string source(getInputValue(*static_cast(input[0].data))); + const std::string destination(getInputValue(*static_cast(input[1].data))); std::vector sourceFullName; std::vector destinationFullName; @@ -500,7 +496,7 @@ UA_StatusCode OPCUA_MGR::onWriteDevice(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string writeValue = getInputValue(*static_cast(input[0].data)); + const std::string writeValue(getInputValue(*static_cast(input[0].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::Write, CStringDictionary::scmInvalidStringId, writeValue.c_str(), nullptr, nullptr); @@ -527,8 +523,8 @@ UA_StatusCode OPCUA_MGR::onWriteResource(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string resourceName = getInputValue(*static_cast(input[0].data)); - std::string writeValue = getInputValue(*static_cast(input[1].data)); + const std::string resourceName(getInputValue(*static_cast(input[0].data))); + const std::string writeValue(getInputValue(*static_cast(input[1].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::Write, CStringDictionary::getInstance().insert(resourceName.c_str()), writeValue.c_str(), nullptr, nullptr); @@ -557,9 +553,8 @@ UA_StatusCode OPCUA_MGR::onWriteFB(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); - std::string writeValue = getInputValue(*static_cast(input[1].data)); + const std::string destination(getInputValue(*static_cast(input[0].data))); + const std::string writeValue(getInputValue(*static_cast(input[1].data))); std::vector writeDestination; parseDestinationName(destination, writeDestination); @@ -609,8 +604,7 @@ UA_StatusCode OPCUA_MGR::onStartResource(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - /* Resource Name */ - std::string resourceName = getInputValue(*static_cast(input[0].data)); + const std::string resourceName(getInputValue(*static_cast(input[0].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::Start, CStringDictionary::getInstance().insert(resourceName.c_str()), nullptr, nullptr, nullptr); eRetVal = uaMGR->mUaDevice.executeMGMCommand(uaMGR->mCommand); @@ -633,9 +627,7 @@ UA_StatusCode OPCUA_MGR::onStartFB(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); - /* e.g. SubApp1.FB1*/ + const std::string destination(getInputValue(*static_cast(input[0].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -685,7 +677,7 @@ UA_StatusCode OPCUA_MGR::onStopResource(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string resourceName = getInputValue(*static_cast(input[0].data)); + const std::string resourceName(getInputValue(*static_cast(input[0].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::Stop, CStringDictionary::scmInvalidStringId, nullptr, resourceName.c_str(), nullptr); eRetVal = uaMGR->mUaDevice.executeMGMCommand(uaMGR->mCommand); @@ -710,9 +702,7 @@ UA_StatusCode OPCUA_MGR::onStopFB(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); - /* e.g. SubApp1.FB1*/ + const std::string destination(getInputValue(*static_cast(input[0].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -762,7 +752,7 @@ UA_StatusCode OPCUA_MGR::onResetResource(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string resourceName = getInputValue(*static_cast(input[0].data)); + const std::string resourceName(getInputValue(*static_cast(input[0].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::Reset, CStringDictionary::scmInvalidStringId, nullptr, resourceName.c_str(), nullptr); eRetVal = uaMGR->mUaDevice.executeMGMCommand(uaMGR->mCommand); @@ -787,9 +777,7 @@ UA_StatusCode OPCUA_MGR::onResetFB(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); - /* e.g. SubApp1.FB1*/ + const std::string destination(getInputValue(*static_cast(input[0].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -839,7 +827,7 @@ UA_StatusCode OPCUA_MGR::onKillResource(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string resourceName = getInputValue(*static_cast(input[0].data)); + const std::string resourceName(getInputValue(*static_cast(input[0].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::Kill, CStringDictionary::scmInvalidStringId, nullptr, resourceName.c_str(), nullptr); eRetVal = uaMGR->mUaDevice.executeMGMCommand(uaMGR->mCommand); @@ -864,9 +852,7 @@ UA_StatusCode OPCUA_MGR::onKillFB(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); - /* e.g. SubApp1.FB1*/ + const std::string destination(getInputValue(*static_cast(input[0].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -897,8 +883,7 @@ UA_StatusCode OPCUA_MGR::onDeleteResource(UA_Server*, return UA_STATUSCODE_BADUNKNOWNRESPONSE; } EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - /* Resource Name */ - std::string resourceName = getInputValue(*static_cast(input[0].data)); + const std::string resourceName(getInputValue(*static_cast(input[0].data))); OPCUA_MGR* uaMGR = static_cast(methodContext); uaMGR->setMGMCommand(EMGMCommandType::DeleteFBInstance, CStringDictionary::scmInvalidStringId, nullptr, resourceName.c_str(), nullptr); @@ -930,9 +915,7 @@ UA_StatusCode OPCUA_MGR::onDeleteFB(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); - /* e.g. SubApp1.FB1*/ + const std::string destination(getInputValue(*static_cast(input[0].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -963,10 +946,8 @@ UA_StatusCode OPCUA_MGR::onDeleteConnection(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string source; - source = getInputValue(*static_cast(input[0].data)); - std::string destination; - destination = getInputValue(*static_cast(input[1].data)); + const std::string source(getInputValue(*static_cast(input[0].data))); + const std::string destination(getInputValue(*static_cast(input[1].data))); std::vector sourceFullName; std::vector destinationFullName; parseDestinationName(source, sourceFullName); @@ -1000,8 +981,7 @@ UA_StatusCode OPCUA_MGR::onAddWatch(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); + const std::string destination(getInputValue(*static_cast(input[0].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -1060,8 +1040,7 @@ UA_StatusCode OPCUA_MGR::onRemoveWatch(UA_Server*, size_t, UA_Variant*) { if (methodContext != nullptr) { EMGMResponse eRetVal = EMGMResponse::UnsupportedType; - std::string destination; - destination = getInputValue(*static_cast(input[0].data)); + const std::string destination(getInputValue(*static_cast(input[0].data))); std::vector fullFbName; parseDestinationName(destination, fullFbName); @@ -1178,12 +1157,13 @@ std::string OPCUA_MGR::getInputValue(UA_String paInput) { return inputNameStr.substr(0, paInput.length); } -void OPCUA_MGR::parseDestinationName(std::string& paDestination, std::vector& paFbName) { - size_t index = paDestination.find_first_of("."); +void OPCUA_MGR::parseDestinationName(const std::string& paDestination, std::vector& paFbName) { + std::string dst(paDestination); + size_t index = dst.find_first_of("."); while (index != std::string::npos) { - paFbName.push_back(paDestination.substr(0, index)); - paDestination = paDestination.substr(paFbName.back().length() + 1); - index = paDestination.find_first_of("."); + paFbName.push_back(dst.substr(0, index)); + dst = dst.substr(paFbName.back().length() + 1); + index = dst.find_first_of("."); } - paFbName.push_back(paDestination.substr(0, index)); + paFbName.push_back(dst.substr(0, index)); } \ No newline at end of file diff --git a/src/stdfblib/ita/OPCUA_MGR.h b/src/stdfblib/ita/OPCUA_MGR.h index 508db7572..2a6d1fd63 100644 --- a/src/stdfblib/ita/OPCUA_MGR.h +++ b/src/stdfblib/ita/OPCUA_MGR.h @@ -473,5 +473,5 @@ class OPCUA_MGR { static std::string getInputValue(UA_String paInput); - static void parseDestinationName(std::string& paDestination, std::vector& paTarget); + static void parseDestinationName(const std::string& paDestination, std::vector& paTarget); }; \ No newline at end of file