ua_server_internal.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. *
  5. * Copyright 2014-2018 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2014, 2017 (c) Florian Palm
  7. * Copyright 2015-2016 (c) Sten Grüner
  8. * Copyright 2015 (c) Chris Iatrou
  9. * Copyright 2015-2016 (c) Oleksiy Vasylyev
  10. * Copyright 2016-2017 (c) Stefan Profanter, fortiss GmbH
  11. * Copyright 2017 (c) Julian Grothoff
  12. */
  13. #ifndef UA_SERVER_INTERNAL_H_
  14. #define UA_SERVER_INTERNAL_H_
  15. #include <open62541/server.h>
  16. #include <open62541/server_config.h>
  17. #include <open62541/plugin/nodestore.h>
  18. #include "ua_connection_internal.h"
  19. #include "ua_securechannel_manager.h"
  20. #include "ua_session_manager.h"
  21. #include "ua_timer.h"
  22. #include "ua_util_internal.h"
  23. #include "ua_workqueue.h"
  24. _UA_BEGIN_DECLS
  25. #ifdef UA_ENABLE_PUBSUB
  26. #include "ua_pubsub_manager.h"
  27. #endif
  28. #ifdef UA_ENABLE_DISCOVERY
  29. #include "ua_discovery_manager.h"
  30. #endif
  31. #ifdef UA_ENABLE_SUBSCRIPTIONS
  32. #include "ua_subscription.h"
  33. typedef struct {
  34. UA_MonitoredItem monitoredItem;
  35. void *context;
  36. union {
  37. UA_Server_DataChangeNotificationCallback dataChangeCallback;
  38. /* UA_Server_EventNotificationCallback eventCallback; */
  39. } callback;
  40. } UA_LocalMonitoredItem;
  41. #endif
  42. struct UA_Server {
  43. /* Config */
  44. UA_ServerConfig config;
  45. UA_DateTime startTime;
  46. /* Nodestore */
  47. void *nsCtx;
  48. /* Security */
  49. UA_SecureChannelManager secureChannelManager;
  50. UA_SessionManager sessionManager;
  51. UA_Session adminSession; /* Local access to the services (for startup and
  52. * maintenance) uses this Session with all possible
  53. * access rights (Session Id: 1) */
  54. /* Namespaces */
  55. size_t namespacesSize;
  56. UA_String *namespaces;
  57. /* Callbacks with a repetition interval */
  58. UA_Timer timer;
  59. /* WorkQueue and worker threads */
  60. UA_WorkQueue workQueue;
  61. /* For bootstrapping, omit some consistency checks, creating a reference to
  62. * the parent and member instantiation */
  63. UA_Boolean bootstrapNS0;
  64. /* Discovery */
  65. #ifdef UA_ENABLE_DISCOVERY
  66. UA_DiscoveryManager discoveryManager;
  67. #endif
  68. /* DataChange Subscriptions */
  69. #ifdef UA_ENABLE_SUBSCRIPTIONS
  70. /* Num active subscriptions */
  71. UA_UInt32 numSubscriptions;
  72. /* Num active monitored items */
  73. UA_UInt32 numMonitoredItems;
  74. /* To be cast to UA_LocalMonitoredItem to get the callback and context */
  75. LIST_HEAD(LocalMonitoredItems, UA_MonitoredItem) localMonitoredItems;
  76. UA_UInt32 lastLocalMonitoredItemId;
  77. #endif
  78. /* Publish/Subscribe */
  79. #ifdef UA_ENABLE_PUBSUB
  80. UA_PubSubManager pubSubManager;
  81. #endif
  82. };
  83. /*****************/
  84. /* Node Handling */
  85. /*****************/
  86. /* Deletes references from the node which are not matching any type in the given
  87. * array. Could be used to e.g. delete all the references, except
  88. * 'HASMODELINGRULE' */
  89. void UA_Node_deleteReferencesSubset(UA_Node *node, size_t referencesSkipSize,
  90. UA_NodeId* referencesSkip);
  91. /* Calls the callback with the node retrieved from the nodestore on top of the
  92. * stack. Either a copy or the original node for in-situ editing. Depends on
  93. * multithreading and the nodestore.*/
  94. typedef UA_StatusCode (*UA_EditNodeCallback)(UA_Server*, UA_Session*,
  95. UA_Node *node, void*);
  96. UA_StatusCode UA_Server_editNode(UA_Server *server, UA_Session *session,
  97. const UA_NodeId *nodeId,
  98. UA_EditNodeCallback callback,
  99. void *data);
  100. /*********************/
  101. /* Utility Functions */
  102. /*********************/
  103. /* A few global NodeId definitions */
  104. extern const UA_NodeId subtypeId;
  105. extern const UA_NodeId hierarchicalReferences;
  106. UA_UInt16 addNamespace(UA_Server *server, const UA_String name);
  107. UA_Boolean
  108. UA_Node_hasSubTypeOrInstances(const UA_Node *node);
  109. /* Recursively searches "upwards" in the tree following specific reference types */
  110. UA_Boolean
  111. isNodeInTree(void *nsCtx, const UA_NodeId *leafNode,
  112. const UA_NodeId *nodeToFind, const UA_NodeId *referenceTypeIds,
  113. size_t referenceTypeIdsSize);
  114. /* Returns an array with the hierarchy of type nodes. The returned array starts
  115. * at the leaf and continues "upwards" or "downwards" in the hierarchy based on the
  116. * ``hasSubType`` references. Since multiple-inheritance is possible in general,
  117. * duplicate entries are removed.
  118. * The parameter `walkDownwards` indicates the direction of search.
  119. * If set to TRUE it will get all the subtypes of the given
  120. * leafType (including leafType).
  121. * If set to FALSE it will get all the parent types of the given
  122. * leafType (including leafType)*/
  123. UA_StatusCode
  124. getTypeHierarchy(void *nsCtx, const UA_NodeId *leafType,
  125. UA_NodeId **typeHierarchy, size_t *typeHierarchySize,
  126. UA_Boolean walkDownwards);
  127. /* Same as getTypeHierarchy but takes multiple leafTypes as parameter and returns
  128. * an combined list of all the found types for all the leaf types */
  129. UA_StatusCode
  130. getTypesHierarchy(void *nsCtx, const UA_NodeId *leafType, size_t leafTypeSize,
  131. UA_NodeId **typeHierarchy, size_t *typeHierarchySize,
  132. UA_Boolean walkDownwards);
  133. /* Returns the type node from the node on the stack top. The type node is pushed
  134. * on the stack and returned. */
  135. const UA_Node * getNodeType(UA_Server *server, const UA_Node *node);
  136. /* Write a node attribute with a defined session */
  137. UA_StatusCode
  138. UA_Server_writeWithSession(UA_Server *server, UA_Session *session,
  139. const UA_WriteValue *value);
  140. /* Many services come as an array of operations. This function generalizes the
  141. * processing of the operations. */
  142. typedef void (*UA_ServiceOperation)(UA_Server *server, UA_Session *session,
  143. void *context,
  144. const void *requestOperation,
  145. void *responseOperation);
  146. UA_StatusCode
  147. UA_Server_processServiceOperations(UA_Server *server, UA_Session *session,
  148. UA_ServiceOperation operationCallback,
  149. void *context,
  150. const size_t *requestOperations,
  151. const UA_DataType *requestOperationsType,
  152. size_t *responseOperations,
  153. const UA_DataType *responseOperationsType)
  154. UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  155. /***************************************/
  156. /* Check Information Model Consistency */
  157. /***************************************/
  158. /* Read a node attribute in the context of a "checked-out" node. So the
  159. * attribute will not be copied when possible. The variant then points into the
  160. * node and has UA_VARIANT_DATA_NODELETE set. */
  161. void
  162. ReadWithNode(const UA_Node *node, UA_Server *server, UA_Session *session,
  163. UA_TimestampsToReturn timestampsToReturn,
  164. const UA_ReadValueId *id, UA_DataValue *v);
  165. UA_StatusCode
  166. readValueAttribute(UA_Server *server, UA_Session *session,
  167. const UA_VariableNode *vn, UA_DataValue *v);
  168. /* Test whether the value matches a variable definition given by
  169. * - datatype
  170. * - valueranke
  171. * - array dimensions.
  172. * Sometimes it can be necessary to transform the content of the value, e.g.
  173. * byte array to bytestring or uint32 to some enum. If editableValue is non-NULL,
  174. * we try to create a matching variant that points to the original data. */
  175. UA_Boolean
  176. compatibleValue(UA_Server *server, UA_Session *session, const UA_NodeId *targetDataTypeId,
  177. UA_Int32 targetValueRank, size_t targetArrayDimensionsSize,
  178. const UA_UInt32 *targetArrayDimensions, const UA_Variant *value,
  179. const UA_NumericRange *range);
  180. UA_Boolean
  181. compatibleArrayDimensions(size_t constraintArrayDimensionsSize,
  182. const UA_UInt32 *constraintArrayDimensions,
  183. size_t testArrayDimensionsSize,
  184. const UA_UInt32 *testArrayDimensions);
  185. UA_Boolean
  186. compatibleValueArrayDimensions(const UA_Variant *value, size_t targetArrayDimensionsSize,
  187. const UA_UInt32 *targetArrayDimensions);
  188. UA_Boolean
  189. compatibleValueRankArrayDimensions(UA_Server *server, UA_Session *session,
  190. UA_Int32 valueRank, size_t arrayDimensionsSize);
  191. UA_Boolean
  192. compatibleDataType(UA_Server *server, const UA_NodeId *dataType,
  193. const UA_NodeId *constraintDataType, UA_Boolean isValue);
  194. UA_Boolean
  195. compatibleValueRanks(UA_Int32 valueRank, UA_Int32 constraintValueRank);
  196. void
  197. Operation_Browse(UA_Server *server, UA_Session *session, const UA_UInt32 *maxrefs,
  198. const UA_BrowseDescription *descr, UA_BrowseResult *result);
  199. UA_DataValue
  200. UA_Server_readWithSession(UA_Server *server, UA_Session *session,
  201. const UA_ReadValueId *item,
  202. UA_TimestampsToReturn timestampsToReturn);
  203. /*****************************/
  204. /* AddNodes Begin and Finish */
  205. /*****************************/
  206. /* Creates a new node in the nodestore. */
  207. UA_StatusCode
  208. AddNode_raw(UA_Server *server, UA_Session *session, void *nodeContext,
  209. const UA_AddNodesItem *item, UA_NodeId *outNewNodeId);
  210. /* Check the reference to the parent node; Add references. */
  211. UA_StatusCode
  212. AddNode_addRefs(UA_Server *server, UA_Session *session, const UA_NodeId *nodeId,
  213. const UA_NodeId *parentNodeId, const UA_NodeId *referenceTypeId,
  214. const UA_NodeId *typeDefinitionId);
  215. /* Type-check type-definition; Run the constructors */
  216. UA_StatusCode
  217. AddNode_finish(UA_Server *server, UA_Session *session, const UA_NodeId *nodeId);
  218. /**********************/
  219. /* Create Namespace 0 */
  220. /**********************/
  221. UA_StatusCode UA_Server_initNS0(UA_Server *server);
  222. _UA_END_DECLS
  223. #endif /* UA_SERVER_INTERNAL_H_ */