ua_server_internal.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #ifndef UA_SERVER_INTERNAL_H_
  2. #define UA_SERVER_INTERNAL_H_
  3. #include "ua_util.h"
  4. #include "ua_server.h"
  5. #include "ua_server_external_ns.h"
  6. #include "ua_connection_internal.h"
  7. #include "ua_session_manager.h"
  8. #include "ua_securechannel_manager.h"
  9. #include "ua_nodestore.h"
  10. #define ANONYMOUS_POLICY "open62541-anonymous-policy"
  11. #define USERNAME_POLICY "open62541-username-policy"
  12. #ifdef UA_ENABLE_EXTERNAL_NAMESPACES
  13. /** Mapping of namespace-id and url to an external nodestore. For namespaces
  14. that have no mapping defined, the internal nodestore is used by default. */
  15. typedef struct UA_ExternalNamespace {
  16. UA_UInt16 index;
  17. UA_String url;
  18. UA_ExternalNodeStore externalNodeStore;
  19. } UA_ExternalNamespace;
  20. #endif
  21. #ifdef UA_ENABLE_MULTITHREADING
  22. typedef struct {
  23. UA_Server *server;
  24. pthread_t thr;
  25. UA_UInt32 counter;
  26. volatile UA_Boolean running;
  27. char padding[64 - sizeof(void*) - sizeof(pthread_t) -
  28. sizeof(UA_UInt32) - sizeof(UA_Boolean)]; // separate cache lines
  29. } UA_Worker;
  30. #endif
  31. #if defined(UA_ENABLE_METHODCALLS) && defined(UA_ENABLE_SUBSCRIPTIONS)
  32. /* Internally used context to a session 'context' of the current mehtod call */
  33. extern UA_THREAD_LOCAL UA_Session* methodCallSession;
  34. #endif
  35. struct UA_Server {
  36. /* Meta */
  37. UA_DateTime startTime;
  38. size_t endpointDescriptionsSize;
  39. UA_EndpointDescription *endpointDescriptions;
  40. /* Security */
  41. UA_SecureChannelManager secureChannelManager;
  42. UA_SessionManager sessionManager;
  43. /* Address Space */
  44. UA_NodeStore *nodestore;
  45. size_t namespacesSize;
  46. UA_String *namespaces;
  47. #ifdef UA_ENABLE_EXTERNAL_NAMESPACES
  48. size_t externalNamespacesSize;
  49. UA_ExternalNamespace *externalNamespaces;
  50. #endif
  51. /* Jobs with a repetition interval */
  52. LIST_HEAD(RepeatedJobsList, RepeatedJob) repeatedJobs;
  53. #ifdef UA_ENABLE_MULTITHREADING
  54. /* Dispatch queue head for the worker threads (the tail should not be in the same cache line) */
  55. struct cds_wfcq_head dispatchQueue_head;
  56. UA_Worker *workers; /* there are nThread workers in a running server */
  57. struct cds_lfs_stack mainLoopJobs; /* Work that shall be executed only in the main loop and not
  58. by worker threads */
  59. struct DelayedJobs *delayedJobs;
  60. pthread_cond_t dispatchQueue_condition; /* so the workers don't spin if the queue is empty */
  61. struct cds_wfcq_tail dispatchQueue_tail; /* Dispatch queue tail for the worker threads */
  62. #endif
  63. /* Config is the last element so that MSVC allows the usernamePasswordLogins
  64. field with zero-sized array */
  65. UA_ServerConfig config;
  66. };
  67. /*****************/
  68. /* Node Handling */
  69. /*****************/
  70. void UA_Node_deleteMembersAnyNodeClass(UA_Node *node);
  71. UA_StatusCode UA_Node_copyAnyNodeClass(const UA_Node *src, UA_Node *dst);
  72. typedef UA_StatusCode (*UA_EditNodeCallback)(UA_Server*, UA_Session*, UA_Node*, const void*);
  73. /* Calls callback on the node. In the multithreaded case, the node is copied before and replaced in
  74. the nodestore. */
  75. UA_StatusCode UA_Server_editNode(UA_Server *server, UA_Session *session, const UA_NodeId *nodeId,
  76. UA_EditNodeCallback callback, const void *data);
  77. void UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection, const UA_ByteString *msg);
  78. UA_StatusCode UA_Server_delayedCallback(UA_Server *server, UA_ServerCallback callback, void *data);
  79. UA_StatusCode UA_Server_delayedFree(UA_Server *server, void *data);
  80. void UA_Server_deleteAllRepeatedJobs(UA_Server *server);
  81. /* Add an existing node. The node is assumed to be "finished", i.e. no
  82. * instantiation from inheritance is necessary. Instantiationcallback and
  83. * addedNodeId may be NULL. */
  84. UA_StatusCode
  85. Service_AddNodes_existing(UA_Server *server, UA_Session *session, UA_Node *node,
  86. const UA_NodeId *parentNodeId,
  87. const UA_NodeId *referenceTypeId,
  88. const UA_NodeId *typeDefinition,
  89. UA_InstantiationCallback *instantiationCallback,
  90. UA_NodeId *addedNodeId);
  91. /*********************/
  92. /* Utility Functions */
  93. /*********************/
  94. UA_StatusCode
  95. parse_numericrange(const UA_String *str, UA_NumericRange *range);
  96. UA_Boolean
  97. UA_Node_hasSubTypeOrInstances(const UA_Node *node);
  98. const UA_VariableTypeNode *
  99. getVariableNodeType(UA_Server *server, const UA_VariableNode *node);
  100. const UA_ObjectTypeNode *
  101. getObjectNodeType(UA_Server *server, const UA_ObjectNode *node);
  102. UA_StatusCode
  103. getTypeHierarchy(UA_NodeStore *ns, const UA_NodeId *root,
  104. UA_NodeId **reftypes, size_t *reftypes_count);
  105. UA_StatusCode
  106. isNodeInTree(UA_NodeStore *ns, const UA_NodeId *rootNode,
  107. const UA_NodeId *nodeToFind, const UA_NodeId *referenceTypeIds,
  108. size_t referenceTypeIdsSize, UA_Boolean *found);
  109. const UA_Node *
  110. getNodeType(UA_Server *server, const UA_Node *node);
  111. /***************************************/
  112. /* Check Information Model Consistency */
  113. /***************************************/
  114. UA_StatusCode
  115. UA_VariableNode_setArrayDimensions(UA_Server *server, UA_VariableNode *node,
  116. const UA_VariableTypeNode *vt,
  117. size_t arrayDimensionsSize, UA_UInt32 *arrayDimensions);
  118. UA_StatusCode
  119. UA_VariableNode_setValueRank(UA_Server *server, UA_VariableNode *node,
  120. const UA_VariableTypeNode *vt,
  121. const UA_Int32 valueRank);
  122. UA_StatusCode
  123. UA_VariableNode_setDataType(UA_Server *server, UA_VariableNode *node,
  124. const UA_VariableTypeNode *vt,
  125. const UA_NodeId *dataType);
  126. UA_StatusCode
  127. UA_VariableNode_setValue(UA_Server *server, UA_VariableNode *node,
  128. const UA_DataValue *value, const UA_String *indexRange);
  129. UA_StatusCode
  130. UA_Variant_matchVariableDefinition(UA_Server *server, const UA_NodeId *variableDataTypeId,
  131. UA_Int32 variableValueRank, size_t variableArrayDimensionsSize,
  132. const UA_UInt32 *variableArrayDimensions, const UA_Variant *value,
  133. const UA_NumericRange *range, UA_Variant *equivalent);
  134. /*******************/
  135. /* Single-Services */
  136. /*******************/
  137. /* Some services take an array of "independent" requests. The single-services
  138. are stored here to keep ua_services.h clean for documentation purposes. */
  139. UA_StatusCode
  140. Service_AddReferences_single(UA_Server *server, UA_Session *session,
  141. const UA_AddReferencesItem *item);
  142. UA_StatusCode
  143. Service_DeleteNodes_single(UA_Server *server, UA_Session *session,
  144. const UA_NodeId *nodeId, UA_Boolean deleteReferences);
  145. UA_StatusCode
  146. Service_DeleteReferences_single(UA_Server *server, UA_Session *session,
  147. const UA_DeleteReferencesItem *item);
  148. void Service_Browse_single(UA_Server *server, UA_Session *session,
  149. struct ContinuationPointEntry *cp,
  150. const UA_BrowseDescription *descr,
  151. UA_UInt32 maxrefs, UA_BrowseResult *result);
  152. void
  153. Service_TranslateBrowsePathsToNodeIds_single(UA_Server *server, UA_Session *session,
  154. const UA_BrowsePath *path,
  155. UA_BrowsePathResult *result);
  156. void Service_Read_single(UA_Server *server, UA_Session *session,
  157. UA_TimestampsToReturn timestamps,
  158. const UA_ReadValueId *id, UA_DataValue *v);
  159. UA_StatusCode Service_Write_single(UA_Server *server, UA_Session *session,
  160. const UA_WriteValue *wvalue);
  161. void Service_Call_single(UA_Server *server, UA_Session *session,
  162. const UA_CallMethodRequest *request,
  163. UA_CallMethodResult *result);
  164. #endif /* UA_SERVER_INTERNAL_H_ */