ua_nodes.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef UA_NODES_H_
  5. #define UA_NODES_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #include "ua_server.h"
  10. /**
  11. * .. _information-modelling:
  12. *
  13. * Information Modelling
  14. * =====================
  15. *
  16. * Information modelling in OPC UA combines concepts from object-orientation and
  17. * semantic modelling. At the core, an OPC UA information model is a graph made
  18. * up of
  19. *
  20. * - Nodes: There are eight possible Node types (variable, object, method, ...)
  21. * - References: Typed and directed relations between two nodes
  22. *
  23. * Every node is identified by a unique (within the server) :ref:`nodeid`.
  24. * Reference are triples of the form ``(source-nodeid, referencetype-nodeid,
  25. * target-nodeid)``. An example reference between nodes is a
  26. * ``hasTypeDefinition`` reference between a Variable and its VariableType. Some
  27. * ReferenceTypes are *hierarchic* and must not form *directed loops*. See the
  28. * section on :ref:`ReferenceTypes <referencetypenode>` for more details on
  29. * possible references and their semantics.
  30. *
  31. * The structures defined in this section are *not user-facing*. The interaction
  32. * with the information model is possible only via the OPC UA :ref:`services`.
  33. * Still, we reproduce how nodes are represented internally so that users may
  34. * have a clear mental model.
  35. *
  36. * Base Node Attributes
  37. * --------------------
  38. *
  39. * Nodes contain attributes according to their node type. The base node
  40. * attributes are common to all node types. In the OPC UA :ref:`services`,
  41. * attributes are referred to via the :ref:`nodeid` of the containing node and
  42. * an integer :ref:`attribute-id`.
  43. *
  44. * Internally, open62541 uses ``UA_Node`` in places where the exact node type is
  45. * not known or not important. The ``nodeClass`` attribute is used to ensure the
  46. * correctness of casting from ``UA_Node`` to a specific node type. */
  47. /* List of reference targets with the same reference type and direction */
  48. typedef struct {
  49. UA_NodeId referenceTypeId;
  50. UA_Boolean isInverse;
  51. size_t targetIdsSize;
  52. UA_ExpandedNodeId *targetIds;
  53. } UA_NodeReferenceKind;
  54. #define UA_NODE_BASEATTRIBUTES \
  55. UA_NodeId nodeId; \
  56. UA_NodeClass nodeClass; \
  57. UA_QualifiedName browseName; \
  58. UA_LocalizedText displayName; \
  59. UA_LocalizedText description; \
  60. UA_UInt32 writeMask; \
  61. size_t referencesSize; \
  62. UA_NodeReferenceKind *references;
  63. typedef struct {
  64. UA_NODE_BASEATTRIBUTES
  65. } UA_Node;
  66. /**
  67. * VariableNode
  68. * ------------
  69. *
  70. * Variables store values in a :ref:`datavalue` together with
  71. * metadata for introspection. Most notably, the attributes data type, value
  72. * rank and array dimensions constrain the possible values the variable can take
  73. * on.
  74. *
  75. * Variables come in two flavours: properties and datavariables. Properties are
  76. * related to a parent with a ``hasProperty`` reference and may not have child
  77. * nodes themselves. Datavariables may contain properties (``hasProperty``) and
  78. * also datavariables (``hasComponents``).
  79. *
  80. * All variables are instances of some :ref:`variabletypenode` in return
  81. * constraining the possible data type, value rank and array dimensions
  82. * attributes.
  83. *
  84. * Data Type
  85. * ^^^^^^^^^
  86. *
  87. * The (scalar) data type of the variable is constrained to be of a specific
  88. * type or one of its children in the type hierarchy. The data type is given as
  89. * a NodeId pointing to a :ref:`datatypenode` in the type hierarchy. See the
  90. * Section :ref:`datatypenode` for more details.
  91. *
  92. * If the data type attribute points to ``UInt32``, then the value attribute
  93. * must be of that exact type since ``UInt32`` does not have children in the
  94. * type hierarchy. If the data type attribute points ``Number``, then the type
  95. * of the value attribute may still be ``UInt32``, but also ``Float`` or
  96. * ``Byte``.
  97. *
  98. * Consistency between the data type attribute in the variable and its
  99. * :ref:`VariableTypeNode` is ensured.
  100. *
  101. * Value Rank
  102. * ^^^^^^^^^^
  103. *
  104. * This attribute indicates whether the value attribute of the variable is an
  105. * array and how many dimensions the array has. It may have the following
  106. * values:
  107. *
  108. * - ``n >= 1``: the value is an array with the specified number of dimensions
  109. * - ``n = 0``: the value is an array with one or more dimensions
  110. * - ``n = -1``: the value is a scalar
  111. * - ``n = -2``: the value can be a scalar or an array with any number of dimensions
  112. * - ``n = -3``: the value can be a scalar or a one dimensional array
  113. *
  114. * Consistency between the value rank attribute in the variable and its
  115. * :ref:`variabletypenode` is ensured.
  116. *
  117. * Array Dimensions
  118. * ^^^^^^^^^^^^^^^^
  119. *
  120. * If the value rank permits the value to be a (multi-dimensional) array, the
  121. * exact length in each dimensions can be further constrained with this
  122. * attribute.
  123. *
  124. * - For positive lengths, the variable value is guaranteed to be of the same
  125. * length in this dimension.
  126. * - The dimension length zero is a wildcard and the actual value may have any
  127. * length in this dimension.
  128. *
  129. * Consistency between the array dimensions attribute in the variable and its
  130. * :ref:`variabletypenode` is ensured. */
  131. /* Indicates whether a variable contains data inline or whether it points to an
  132. * external data source */
  133. typedef enum {
  134. UA_VALUESOURCE_DATA,
  135. UA_VALUESOURCE_DATASOURCE
  136. } UA_ValueSource;
  137. #define UA_NODE_VARIABLEATTRIBUTES \
  138. /* Constraints on possible values */ \
  139. UA_NodeId dataType; \
  140. UA_Int32 valueRank; \
  141. size_t arrayDimensionsSize; \
  142. UA_UInt32 *arrayDimensions; \
  143. \
  144. /* The current value */ \
  145. UA_ValueSource valueSource; \
  146. union { \
  147. struct { \
  148. UA_DataValue value; \
  149. UA_ValueCallback callback; \
  150. } data; \
  151. UA_DataSource dataSource; \
  152. } value;
  153. typedef struct {
  154. UA_NODE_BASEATTRIBUTES
  155. UA_NODE_VARIABLEATTRIBUTES
  156. UA_Byte accessLevel;
  157. UA_Double minimumSamplingInterval;
  158. UA_Boolean historizing; /* currently unsupported */
  159. } UA_VariableNode;
  160. /**
  161. * .. _variabletypenode:
  162. *
  163. * VariableTypeNode
  164. * ----------------
  165. *
  166. * VariableTypes are used to provide type definitions for variables.
  167. * VariableTypes constrain the data type, value rank and array dimensions
  168. * attributes of variable instances. Furthermore, instantiating from a specific
  169. * variable type may provide semantic information. For example, an instance from
  170. * ``MotorTemperatureVariableType`` is more meaningful than a float variable
  171. * instantiated from ``BaseDataVariable``. */
  172. typedef struct {
  173. UA_NODE_BASEATTRIBUTES
  174. UA_NODE_VARIABLEATTRIBUTES
  175. UA_Boolean isAbstract;
  176. } UA_VariableTypeNode;
  177. /**
  178. * .. _methodnode:
  179. *
  180. * MethodNode
  181. * ----------
  182. *
  183. * Methods define callable functions and are invoked using the :ref:`Call
  184. * <method-services>` service. MethodNodes may have special properties (variable
  185. * childen with a ``hasProperty`` reference) with the :ref:`qualifiedname` ``(0,
  186. * "InputArguments")`` and ``(0, "OutputArguments")``. The input and output
  187. * arguments are both described via an array of ``UA_Argument``. While the Call
  188. * service uses a generic array of :ref:`variant` for input and output, the
  189. * actual argument values are checked to match the signature of the MethodNode.
  190. *
  191. * Note that the same MethodNode may be referenced from several objects (and
  192. * object types). For this, the NodeId of the method *and of the object
  193. * providing context* is part of a Call request message.
  194. */
  195. typedef struct {
  196. UA_NODE_BASEATTRIBUTES
  197. UA_Boolean executable;
  198. /* Members specific to open62541 */
  199. void *methodHandle;
  200. UA_MethodCallback attachedMethod;
  201. } UA_MethodNode;
  202. /**
  203. * ObjectNode
  204. * ----------
  205. *
  206. * Objects are used to represent systems, system components, real-world objects
  207. * and software objects. Objects are instances of an :ref:`object
  208. * type<objecttypenode>` and may contain variables, methods and further
  209. * objects. */
  210. typedef struct {
  211. UA_NODE_BASEATTRIBUTES
  212. UA_Byte eventNotifier;
  213. /* Members specific to open62541 */
  214. void *instanceHandle;
  215. } UA_ObjectNode;
  216. /**
  217. * .. _objecttypenode:
  218. *
  219. * ObjectTypeNode
  220. * --------------
  221. *
  222. * ObjectTypes provide definitions for Objects. Abstract objects cannot be
  223. * instantiated. See :ref:`object-lifecycle` for the use of constructor and
  224. * destructor callbacks. */
  225. typedef struct {
  226. UA_NODE_BASEATTRIBUTES
  227. UA_Boolean isAbstract;
  228. /* Members specific to open62541 */
  229. UA_ObjectLifecycleManagement lifecycleManagement;
  230. } UA_ObjectTypeNode;
  231. /**
  232. * .. _referencetypenode:
  233. *
  234. * ReferenceTypeNode
  235. * -----------------
  236. *
  237. * Each reference between two nodes is typed with a ReferenceType that gives
  238. * meaning to the relation. The OPC UA standard defines a set of ReferenceTypes
  239. * as a mandatory part of OPC UA information models.
  240. *
  241. * - Abstract ReferenceTypes cannot be used in actual references and are only
  242. * used to structure the ReferenceTypes hierarchy
  243. * - Symmetric references have the same meaning from the perspective of the
  244. * source and target node
  245. *
  246. * The figure below shows the hierarchy of the standard ReferenceTypes (arrows
  247. * indicate a ``hasSubType`` relation). Refer to Part 3 of the OPC UA
  248. * specification for the full semantics of each ReferenceType.
  249. *
  250. * .. graphviz::
  251. *
  252. * digraph tree {
  253. *
  254. * node [height=0, shape=box, fillcolor="#E5E5E5", concentrate=true]
  255. *
  256. * references [label="References\n(Abstract, Symmetric)"]
  257. * hierarchical_references [label="HierarchicalReferences\n(Abstract)"]
  258. * references -> hierarchical_references
  259. *
  260. * nonhierarchical_references [label="NonHierarchicalReferences\n(Abstract, Symmetric)"]
  261. * references -> nonhierarchical_references
  262. *
  263. * haschild [label="HasChild\n(Abstract)"]
  264. * hierarchical_references -> haschild
  265. *
  266. * aggregates [label="Aggregates\n(Abstract)"]
  267. * haschild -> aggregates
  268. *
  269. * organizes [label="Organizes"]
  270. * hierarchical_references -> organizes
  271. *
  272. * hascomponent [label="HasComponent"]
  273. * aggregates -> hascomponent
  274. *
  275. * hasorderedcomponent [label="HasOrderedComponent"]
  276. * hascomponent -> hasorderedcomponent
  277. *
  278. * hasproperty [label="HasProperty"]
  279. * aggregates -> hasproperty
  280. *
  281. * hassubtype [label="HasSubtype"]
  282. * haschild -> hassubtype
  283. *
  284. * hasmodellingrule [label="HasModellingRule"]
  285. * nonhierarchical_references -> hasmodellingrule
  286. *
  287. * hastypedefinition [label="HasTypeDefinition"]
  288. * nonhierarchical_references -> hastypedefinition
  289. *
  290. * hasencoding [label="HasEncoding"]
  291. * nonhierarchical_references -> hasencoding
  292. *
  293. * hasdescription [label="HasDescription"]
  294. * nonhierarchical_references -> hasdescription
  295. *
  296. * haseventsource [label="HasEventSource"]
  297. * hierarchical_references -> haseventsource
  298. *
  299. * hasnotifier [label="HasNotifier"]
  300. * hierarchical_references -> hasnotifier
  301. *
  302. * generatesevent [label="GeneratesEvent"]
  303. * nonhierarchical_references -> generatesevent
  304. *
  305. * alwaysgeneratesevent [label="AlwaysGeneratesEvent"]
  306. * generatesevent -> alwaysgeneratesevent
  307. *
  308. * {rank=same hierarchical_references nonhierarchical_references}
  309. * {rank=same generatesevent haseventsource hasmodellingrule
  310. * hasencoding hassubtype}
  311. * {rank=same alwaysgeneratesevent hasproperty}
  312. *
  313. * }
  314. *
  315. * The ReferenceType hierarchy can be extended with user-defined ReferenceTypes.
  316. * Many Companion Specifications for OPC UA define new ReferenceTypes to be used
  317. * in their domain of interest.
  318. *
  319. * For the following example of custom ReferenceTypes, we attempt to model the
  320. * structure of a technical system. For this, we introduce two custom
  321. * ReferenceTypes. First, the hierarchical ``contains`` ReferenceType indicates
  322. * that a system (represented by an OPC UA object) contains a component (or
  323. * subsystem). This gives rise to a tree-structure of containment relations. For
  324. * example, the motor (object) is contained in the car and the crankshaft is
  325. * contained in the motor. Second, the symmetric ``connectedTo`` ReferenceType
  326. * indicates that two components are connected. For example, the motor's
  327. * crankshaft is connected to the gear box. Connections are independent of the
  328. * containment hierarchy and can induce a general graph-structure. Further
  329. * subtypes of ``connectedTo`` could be used to differentiate between physical,
  330. * electrical and information related connections. A client can then learn the
  331. * layout of a (physical) system represented in an OPC UA information model
  332. * based on a common understanding of just two custom reference types. */
  333. typedef struct {
  334. UA_NODE_BASEATTRIBUTES
  335. UA_Boolean isAbstract;
  336. UA_Boolean symmetric;
  337. UA_LocalizedText inverseName;
  338. } UA_ReferenceTypeNode;
  339. /**
  340. * .. _datatypenode:
  341. *
  342. * DataTypeNode
  343. * ------------
  344. *
  345. * DataTypes represent simple and structured data types. DataTypes may contain
  346. * arrays. But they always describe the structure of a single instance. In
  347. * open62541, DataTypeNodes in the information model hierarchy are matched to
  348. * ``UA_DataType`` type descriptions for :ref:`generic-types` via their NodeId.
  349. *
  350. * Abstract DataTypes (e.g. ``Number``) cannot be the type of actual values.
  351. * They are used to constrain values to possible child DataTypes (e.g.
  352. * ``UInt32``). */
  353. typedef struct {
  354. UA_NODE_BASEATTRIBUTES
  355. UA_Boolean isAbstract;
  356. } UA_DataTypeNode;
  357. /**
  358. * ViewNode
  359. * --------
  360. *
  361. * Each View defines a subset of the Nodes in the AddressSpace. Views can be
  362. * used when browsing an information model to focus on a subset of nodes and
  363. * references only. ViewNodes can be created and be interacted with. But their
  364. * use in the :ref:`Browse<view-services>` service is currently unsupported in
  365. * open62541. */
  366. typedef struct {
  367. UA_NODE_BASEATTRIBUTES
  368. UA_Byte eventNotifier;
  369. UA_Boolean containsNoLoops;
  370. } UA_ViewNode;
  371. #ifdef __cplusplus
  372. } // extern "C"
  373. #endif
  374. #endif /* UA_NODES_H_ */