ua_nodes.h 15 KB

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