lordgamez commented on code in PR #2287:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2287#discussion_r4514208792


##########
extensions/opc/src/OPCCommon.cpp:
##########
@@ -464,6 +470,90 @@ UA_StatusCode 
Client::translateBrowsePathsToNodeIdsRequest(const std::string& pa
   }
 }
 
+std::expected<NodeId, UA_StatusCode> Client::findChild(const UA_NodeId& 
parent_node_id, std::string_view browse_name,
+    UA_UInt16 browse_name_namespace_index, UA_UInt32 ref_type_id) {
+  std::string name(browse_name);
+  UA_RelativePathElement element;
+  UA_RelativePathElement_init(&element);
+  element.referenceTypeId = UA_NODEID_NUMERIC(0, ref_type_id);
+  element.includeSubtypes = true;
+  element.targetName = UA_QUALIFIEDNAME(browse_name_namespace_index, 
name.data());
+
+  UA_BrowsePath browse_path;
+  UA_BrowsePath_init(&browse_path);
+  browse_path.startingNode = parent_node_id;
+  browse_path.relativePath.elements = &element;
+  browse_path.relativePath.elementsSize = 1;
+
+  UA_TranslateBrowsePathsToNodeIdsRequest request;
+  UA_TranslateBrowsePathsToNodeIdsRequest_init(&request);
+  request.browsePaths = &browse_path;
+  request.browsePathsSize = 1;
+
+  UA_TranslateBrowsePathsToNodeIdsResponse response = 
UA_Client_Service_translateBrowsePathsToNodeIds(client_, request);
+  const auto guard = gsl::finally([&response]() { 
UA_TranslateBrowsePathsToNodeIdsResponse_clear(&response); });
+
+  if (response.responseHeader.serviceResult != UA_STATUSCODE_GOOD) {
+    return std::unexpected{response.responseHeader.serviceResult};
+  }
+  if (response.resultsSize != 1) {
+    return std::unexpected{UA_STATUSCODE_BADUNEXPECTEDERROR};
+  }
+  if (response.results[0].statusCode != UA_STATUSCODE_GOOD) {
+    return std::unexpected{response.results[0].statusCode};
+  }
+  if (response.results[0].targetsSize < 1) {
+    return std::unexpected{UA_STATUSCODE_BADNOMATCH};
+  }

Review Comment:
   We can ignore multiple path matches as we did before, this is not scope of 
this PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to