node.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  *   Copyright (C) 2014-2014 Olivier Roulet-Dubonnet          *
00003  *   olivier.roulet@gmail.com          *
00004  *                      *
00005  *   This library is free software; you can redistribute it and/or modify   *
00006  *   it under the terms of the GNU Lesser General Public License as      *
00007  *   published by the Free Software Foundation; version 3 of the License.   *
00008  *                      *
00009  *   This library is distributed in the hope that it will be useful,      *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of      *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *
00012  *   GNU Lesser General Public License for more details.        *
00013  *                      *
00014  *   You should have received a copy of the GNU Lesser General Public License *
00015  *   along with this library; if not, write to the          *
00016  *   Free Software Foundation, Inc.,              *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.        *
00018  ******************************************************************************/
00019 
00020 #pragma once
00021 
00022 #include <opc/ua/services/services.h>
00023 
00024 #include <sstream>
00025 
00026 
00027 namespace OpcUa
00028 {
00029 
00030   class NodeNotFoundException : public std::runtime_error 
00031   {
00032     public:
00033       NodeNotFoundException() : std::runtime_error("NodeNotFoundException") { }
00034   };
00035 
00041 
00042   class Node
00043   {
00044   public:
00045     // Creating Root Node.
00046     explicit Node(Services::SharedPtr srv);
00047     Node(Services::SharedPtr srv, const NodeId& id);
00048     Node(const Node& other); 
00049     Node(){}
00050 
00051     NodeId GetId() const;
00052 
00053     QualifiedName GetBrowseName() const;
00054     //void SetBrowseName(const QualifiedName& name) const;
00055 
00058     std::vector<Node> GetChildren(const OpcUa::ReferenceId& refid) const;
00059 
00062     std::vector<Node> GetChildren() const;
00063 
00064     //The GetChildNode methods return a node defined by its path from the node. A path is defined by
00065     // a sequence of browse name(QualifiedName). A browse name is either defined through a qualifiedname object
00066     // or a string of format namespace:browsename. If a namespace is not specified it is assumed to be
00067     //the same as the parent
00068     Node GetChild(const std::vector<OpcUa::QualifiedName>& path) const;
00069     Node GetChild(const std::vector<std::string>& path) const;
00070     Node GetChild(const std::string& browsename) const ;
00071 
00072     std::vector<Node> GetProperties() const {return GetChildren(OpcUa::ReferenceId::HasProperty);}
00073     std::vector<Node> GetVariables() const {return GetChildren(OpcUa::ReferenceId::HasComponent);} //Not correct should filter by variable type
00074 
00075     
00076 
00077     //TODO: How to get References?
00078 
00079     //The Read and Write methods read or write attributes of the node
00080     //FIXME: add possibility to read and write several nodes at once
00081     DataValue GetAttribute(const AttributeId attr) const;
00082     void SetAttribute(AttributeId attr, const DataValue &dval) const;
00083     //std::vector<StatusCode> WriteAttrs(OpcUa::AttributeId attr, const Variant &val);
00084     
00085     //Helper method to get/set VALUE attribute of a node (Not all nodes support VALUE attribute)
00086     Variant GetValue() const;
00087     DataValue GetDataValue() const;
00088     void SetValue(const Variant& val) const;
00089     void SetValue(const DataValue& dval) const;
00090 
00091     Variant GetDataType() const;
00092 
00093     // CallMethod
00094     std::vector<Variant> CallMethod(NodeId methodId, std::vector<Variant> inputArguments) const;
00095     std::vector<std::vector<Variant>> CallMethods(std::vector<NodeId> methodIds, std::vector<std::vector<Variant>> inputArguments) const;
00096 
00097     //OpcUa low level methods to to modify address space model
00098     std::vector<AddNodesResult> AddNodes(std::vector<AddNodesItem> items) const;
00099     std::vector<StatusCode> AddReferences(std::vector<AddReferencesItem> items) const;
00100 
00101 
00102     //Helper classes to modify address space model
00103     Node AddFolder(const NodeId& folderId, const QualifiedName& browseName) const;
00104     Node AddFolder(const std::string& nodeid, const std::string& browseName) const; 
00105     Node AddFolder(uint32_t namespaceidx, const std::string& browseName) const;
00106 
00107     Node AddObject(const NodeId& folderId, const QualifiedName& browseName) const;
00108     Node AddObject(const std::string& nodeid, const std::string& browseName) const; 
00109     Node AddObject(uint32_t namespaceidx, const std::string& browseName) const;
00110 
00111     Node AddVariable(const NodeId& variableId, const QualifiedName& browsename, const Variant& val) const;
00112     Node AddVariable(uint32_t namespaceidx, const std::string& BrowseName, const Variant& val) const;
00113     Node AddVariable(const std::string& nodeId, const std::string& browseName, const Variant& val) const; 
00114 
00115     Node AddProperty(const NodeId& propertyId, const QualifiedName& browsename, const Variant& val) const;
00116     Node AddProperty(const std::string& nodeid, const std::string& browseName, const Variant& val) const;
00117     Node AddProperty(uint32_t namespaceidx, const std::string& browseName, const Variant& val) const;
00118 
00119     Node AddMethod(const NodeId& variableId, const QualifiedName& browsename, std::function<std::vector<OpcUa::Variant> (std::vector<OpcUa::Variant> arguments)> method) const;
00120     Node AddMethod(uint32_t namespaceidx, const std::string& BrowseName, std::function<std::vector<OpcUa::Variant> (std::vector<OpcUa::Variant> arguments)> method) const;
00121     Node AddMethod(const std::string& nodeId, const std::string& browseName, std::function<std::vector<OpcUa::Variant> (std::vector<OpcUa::Variant> arguments)> method) const; 
00122 
00123     std::string ToString() const;
00124 
00125     bool operator==(Node const& x) const { return Id == x.Id; }
00126     bool operator!=(Node const& x) const { return Id != x.Id; }
00127 
00128     //FIXME: I need this to create a copy for python binding, another way?
00129     OpcUa::Services::SharedPtr GetServices() const {return Server;}
00130 
00131   protected:
00132     OpcUa::Services::SharedPtr Server;
00133     NodeId Id;
00134   };
00135 
00136 
00137   std::ostream& operator<<(std::ostream& os, const Node& node);
00138 
00139   //FIXME: The following methods should be moved somewhere else!!!
00140 
00141   ObjectId VariantTypeToDataType(VariantType vt);
00142 
00143 
00144 } // namespace OpcUa
00145 


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:56