Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <opc/ua/services/services.h>
00023 #include <opc/ua/protocol/object_ids.h>
00024
00025 namespace OpcUa
00026 {
00027 namespace Model
00028 {
00029
00030 class Reference;
00031 class Variable;
00032
00033 class Node
00034 {
00035 public:
00036 Node(NodeId id, Services::SharedPtr services);
00037
00038 NodeId GetId() const;
00039
00040
00041 QualifiedName GetBrowseName() const;
00042 LocalizedText GetDisplayName() const;
00043
00044 std::vector<Reference> GetReferencies() const;
00045
00046 public:
00047 Services::SharedPtr GetServices() const
00048 {
00049 return OpcUaServices;
00050 }
00051
00052 protected:
00053 Node(Services::SharedPtr services);
00054
00055 protected:
00056 NodeId Id;
00057 QualifiedName BrowseName;
00058 LocalizedText DisplayName;
00059 Services::SharedPtr OpcUaServices;
00060 };
00061
00062
00063 class ReferenceType : public Node
00064 {
00065 public:
00066 ReferenceType(NodeId typeId, Services::SharedPtr services);
00067
00068 ReferenceType Parent() const;
00069
00070 QualifiedName Name() const;
00071 QualifiedName InverseName() const;
00072 };
00073
00074 class Reference
00075 {
00076 public:
00077 ReferenceType Type();
00078
00079 Node Source() const;
00080 Node Target() const;
00081 };
00082
00083 class DataType : public Node
00084 {
00085 public:
00086 DataType(NodeId typeId, Services::SharedPtr services);
00087
00088 bool IsAbstrasct() const;
00089 DataType Parent() const;
00090
00091 std::vector<DataType> SubTypes() const;
00092
00093 private:
00094 bool IsAbstract = false;
00095 NodeId ParentTypeId;
00096 };
00097
00098 class VariableType : public Node
00099 {
00100 public:
00101 VariableType(NodeId typeId, Services::SharedPtr services);
00102
00103
00104 VariableType(Services::SharedPtr services, const NodeId& typeId);
00105
00106 bool IsBase() const;
00107 bool IsAbstract() const;
00108 VariableType Parent() const;
00109 std::vector<VariableType> SubTypes() const;
00110
00111 DataType ValueType() const;
00112
00113 DataValue GetDefaultValue() const;
00114 void SetDefaultValue(const DataValue& value);
00115
00116 std::vector<Variable> GetVariables() const;
00117 Variable GetVariable(const QualifiedName& name) const;
00118 Variable GetVariable(const RelativePath& path) const;
00119
00120 private:
00121 bool Abstract = false;
00122 DataValue DefaultValue;
00123 NodeId ValueTypeId;
00124 NodeId ParentTypeId;
00125 };
00126
00127
00128 class Variable : public Node
00129 {
00130 public:
00131 Variable(NodeId variableId, Services::SharedPtr services);
00132
00133 VariableType GetType() const;
00134
00135 DataValue GetValue() const;
00136 void SetValue(const Variant& value);
00137 void SetValue(const DataValue& value);
00138 VariantType GetDataType() const;
00139
00140 std::vector<Variable> Variables() const;
00141 Variable GetVariable(const QualifiedName& name) const;
00142 Variable GetVariable(const std::vector<QualifiedName>& path) const;
00143
00144 private:
00145 friend class Object;
00146
00147 Variable(Services::SharedPtr services)
00148 : Node(services)
00149 {
00150 }
00151
00152 private:
00153 NodeId TypeId;
00154 VariantType DataType = VariantType::NUL;
00155 };
00156
00157
00158 class Object;
00159
00160 class ObjectType : public Node
00161 {
00162 public:
00163 ObjectType(NodeId objectId, Services::SharedPtr services);
00164
00165 bool IsBase() const;
00166 bool IsAbstract() const;
00167
00168 std::vector<Variable> Variables() const;
00169 std::vector<Object> Objects() const;
00170
00171 std::vector<ObjectType> SubTypes() const;
00172
00173 ObjectType Parent() const;
00174
00175 private:
00176 bool Abstract = false;
00177 NodeId ParentTypeId;
00178 };
00179
00180
00181 class Object : public Node
00182 {
00183 public:
00184 Object(NodeId objectId, Services::SharedPtr services);
00185 Object(Object&& object);
00186 Object(const Object& object);
00187
00188 ObjectType GetType() const;
00189
00191 std::vector<Variable> GetVariables() const;
00193 Variable GetVariable(const QualifiedName& name) const;
00195 Variable GetVariable(const RelativePath& path) const;
00196
00204 Variable CreateVariable(const QualifiedName& browseName, const Variant& value);
00205 Variable CreateVariable(const NodeId& newVariableId, const QualifiedName& browseName, const Variant& value);
00206 Variable CreateVariable(const QualifiedName& browseName, const VariableType& type);
00207 Variable CreateVariable(const NodeId& newVariableId, const QualifiedName& browseName, const VariableType& type);
00208
00209 std::vector<Object> GetObjects() const;
00210 Object GetObject(const QualifiedName& name) const;
00211 Object GetObject(const RelativePath& name) const;
00212
00213 Object CreateObject(const ObjectType& type, const QualifiedName& browseName);
00214 Object CreateObject(const NodeId& newNodeId, const ObjectType& nodeType, const QualifiedName& browseName);
00215 Object CreateObject(const ObjectType& type, const QualifiedName& browseName, const std::string& displayName);
00216 Object CreateObject(const NodeId& newNodeId, const ObjectType& type, const QualifiedName& browseName, const std::string& displayName);
00217
00218 private:
00219 Object CreateObject(const NodeId& newNodeId, const NodeId& parentNode, const NodeId& typeId, const QualifiedName& browseName, const std::string& displayName);
00220 Variable CreateVariable(const NodeId& newNodeId, const NodeId& parentNode, const NodeId& typeId, const QualifiedName& browseName, const std::string& displayName);
00221
00222 NodeId InstantiateType(const NodeId& newNodeId, const NodeId& parentNode, const NodeId& typeId, NodeClass nodeClass, const QualifiedName& browseName, const std::string& displayName);
00223 std::vector<ReferenceDescription> BrowseObjectsAndVariables(const NodeId& id);
00224
00225 std::map<NodeId, std::vector<ReferenceDescription>> CopyObjectsAndVariables(const NodeId& targetNode, const std::vector<ReferenceDescription>& refs);
00226 AddNodesItem CreateVariableCopy(const NodeId& parentId, const ReferenceDescription& ref);
00227 AddNodesItem CreateObjectCopy(const NodeId& parentId, const ReferenceDescription& ref);
00228
00229 private:
00230 explicit Object(Services::SharedPtr services);
00231 };
00232
00233 class Server
00234 {
00235 public:
00236 Server(Services::SharedPtr services);
00237
00238 Object RootObject() const;
00239 Object GetObject(const NodeId& id) const;
00240 ObjectType GetObjectType(const NodeId& typeId) const;
00241
00242 public:
00243 Services::SharedPtr GetServices() const;
00244
00245 private:
00246 Services::SharedPtr Connection;
00247 };
00248
00249 }
00250 }