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


##########
extensions/opc/include/OPCCommon.h:
##########
@@ -58,6 +58,43 @@ enum class OPCNodeDataType{
   String
 };
 
+// RAII owner for a UA_NodeId that calls UA_NodeId_clear to free node id 
allocation
+class NodeId {
+ public:
+  NodeId() = default;
+  explicit NodeId(UA_NodeId id) noexcept : id_(id) {}  // takes ownership of 
an already-built node id
+  NodeId(const NodeId&) = delete;
+  NodeId& operator=(const NodeId&) = delete;
+  NodeId(NodeId&& other) noexcept : id_(other.id_) { other.id_ = 
UA_NODEID_NULL; }
+  NodeId& operator=(NodeId&& other) noexcept {
+    if (this != &other) {
+      UA_NodeId_clear(&id_);
+      id_ = other.id_;
+      other.id_ = UA_NODEID_NULL;
+    }
+    return *this;
+  }
+  ~NodeId() noexcept { UA_NodeId_clear(&id_); }
+
+  static NodeId copyOf(const UA_NodeId& id) {
+    NodeId result;
+    UA_NodeId_copy(&id, &result.id_);
+    return result;
+  }
+
+  operator const UA_NodeId&() const noexcept { return id_; }  // 
NOLINT(google-explicit-constructor) implicit passthrough to the C API is 
intended
+  [[nodiscard]] const UA_NodeId& get() const noexcept { return id_; }
+
+  // Returns a pointer to the (cleared) node id for an open62541 out-parameter 
to write a freshly created node id into.
+  UA_NodeId* receive() noexcept {
+    UA_NodeId_clear(&id_);
+    return &id_;
+  }

Review Comment:
   This is already handled in the OPC UA client code in 
`src/client/ua_client_highlevel.c`. We are using this value as the out 
parameter of the add node operation, and the add node only touches the out 
parameter if the internal call succeeds otherwise it remains untouched:
   ```
   /* Move the id of the created node */
   retval = response.results[0].statusCode;
   if(retval == UA_STATUSCODE_GOOD && outNewNodeId) {
       *outNewNodeId = response.results[0].addedNodeId;
       UA_NodeId_init(&response.results[0].addedNodeId);
   }
   ```



-- 
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