MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / translateBrowsePathsToNodeIdsRequest

Method translateBrowsePathsToNodeIdsRequest

extensions/opc/src/opc.cpp:336–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334};
335
336UA_StatusCode Client::translateBrowsePathsToNodeIdsRequest(const std::string& path, std::vector<UA_NodeId>& foundNodeIDs, const std::shared_ptr<core::logging::Logger>& logger) {
337 logger->log_trace("Trying to find node id for %s", path.c_str());
338
339 auto tokens = utils::StringUtils::split(path, "/");
340 std::vector<UA_UInt32> ids;
341 for(size_t i = 0; i < tokens.size(); ++i) {
342 UA_UInt32 val = (i ==0) ? UA_NS0ID_ORGANIZES : UA_NS0ID_HASCOMPONENT;
343 ids.push_back(val);
344 }
345
346 UA_BrowsePath browsePath;
347 UA_BrowsePath_init(&browsePath);
348 browsePath.startingNode = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
349
350 browsePath.relativePath.elements = (UA_RelativePathElement*)UA_Array_new(tokens.size(), &UA_TYPES[UA_TYPES_RELATIVEPATHELEMENT]);
351 browsePath.relativePath.elementsSize = tokens.size();
352
353 for(size_t i = 0; i < tokens.size(); ++i) {
354 UA_RelativePathElement *elem = &browsePath.relativePath.elements[i];
355 elem->referenceTypeId = UA_NODEID_NUMERIC(0, ids[i]);
356 elem->targetName = UA_QUALIFIEDNAME_ALLOC(0, tokens[i].c_str());
357 }
358
359 UA_TranslateBrowsePathsToNodeIdsRequest request;
360 UA_TranslateBrowsePathsToNodeIdsRequest_init(&request);
361 request.browsePaths = &browsePath;
362 request.browsePathsSize = 1;
363
364 UA_TranslateBrowsePathsToNodeIdsResponse response = UA_Client_Service_translateBrowsePathsToNodeIds(client_, request);
365
366 const auto guard = gsl::finally([&browsePath]() {
367 UA_BrowsePath_deleteMembers(&browsePath);
368 });
369
370 if(response.resultsSize < 1) {
371 logger->log_warn("No node id in response for %s", path.c_str());
372 return UA_STATUSCODE_BADNODATAAVAILABLE;
373 }
374
375 bool foundData = false;
376
377 for(size_t i = 0; i < response.resultsSize; ++i) {
378 UA_BrowsePathResult res = response.results[i];
379 for(size_t j = 0; j < res.targetsSize; ++j) {
380 foundData = true;
381 UA_NodeId resultId;
382 UA_NodeId_copy(&res.targets[j].targetId.nodeId, &resultId);
383 foundNodeIDs.push_back(resultId);
384 std::string namespaceUri((char*)res.targets[j].targetId.namespaceUri.data, res.targets[j].targetId.namespaceUri.length);
385 }
386 }
387
388 UA_TranslateBrowsePathsToNodeIdsResponse_deleteMembers(&response);
389
390 if(foundData) {
391 logger->log_debug("Found %lu nodes for path %s", foundNodeIDs.size(), path.c_str());
392 return UA_STATUSCODE_GOOD;
393 } else {

Callers 2

onTriggerMethod · 0.80
onTriggerMethod · 0.80

Calls 5

log_traceMethod · 0.80
c_strMethod · 0.80
log_warnMethod · 0.80
log_debugMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected