bakaid commented on a change in pull request #635: MINIFICPP-819 - OPC Unified Architecture Support URL: https://github.com/apache/nifi-minifi-cpp/pull/635#discussion_r330401847
########## File path: extensions/opc/include/opc.h ########## @@ -0,0 +1,152 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef NIFI_MINIFI_CPP_OPC_H +#define NIFI_MINIFI_CPP_OPC_H + +#include "open62541/client.h" +#include "open62541/client_highlevel.h" +#include "open62541/client_config_default.h" +#include "logging/Logger.h" +#include "Exception.h" + +#include <string> +#include <functional> + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace opc { + +class OPCException : public minifi::Exception { + public: + OPCException(ExceptionType type, std::string &&errorMsg) + : Exception(type, errorMsg) { + } +}; + +enum class OPCNodeIDType{ Path, Int, String }; + +enum class OPCNodeDataType{ Int64, UInt64, Int32, UInt32, Boolean, Float, Double, String }; + +struct NodeData; + +class Client; + +using nodeFoundCallBackFunc = bool(Client& client, const UA_ReferenceDescription*, const std::string&); + +class Client { + public: + bool isConnected(); + UA_StatusCode connect(const std::string& url, const std::string& username = "", const std::string& password = ""); + ~Client(); + NodeData getNodeData(const UA_ReferenceDescription *ref, const std::string& basePath = ""); + UA_ReferenceDescription * getNodeReference(UA_NodeId nodeId); + void traverse(UA_NodeId nodeId, std::function<nodeFoundCallBackFunc> cb, const std::string& basePath = "", uint32_t maxDepth = 0, bool fetchRoot = true); + bool exists(UA_NodeId nodeId); + UA_StatusCode translateBrowsePathsToNodeIdsRequest(const std::string& path, std::vector<UA_NodeId>& foundNodeIDs, const std::shared_ptr<core::logging::Logger>& logger); + + template<typename T> + UA_StatusCode update_node(const UA_NodeId nodeId, T value); + + template<typename T> + UA_StatusCode add_node(const UA_NodeId parentNodeId, const UA_NodeId targetNodeId, std::string browseName, T value, OPCNodeDataType dt, UA_NodeId *receivedNodeId); + + private: + Client (std::shared_ptr<core::logging::Logger> logger, const std::string& applicationURI, + const std::vector<char>& certBuffer, const std::vector<char>& keyBuffer, + const std::vector<std::vector<char>>& trustBuffers); + + UA_Client *client_; + std::shared_ptr<core::logging::Logger> logger_; + + friend std::unique_ptr<Client> createClient(std::shared_ptr<core::logging::Logger> logger, Review comment: I think this would be better as a public static member function: it would be more straightforward and you wouldn't need to friend it. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
