ua_nodes.h 13 KB

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