ua_server_internal.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. typedef UA_StatusCode (*UA_EditNodeCallback)(UA_Server*, UA_Session*, UA_Node*, const void*);
  68. /* Calls callback on the node. In the multithreaded case, the node is copied before and replaced in
  69. the nodestore. */
  70. UA_StatusCode UA_Server_editNode(UA_Server *server, UA_Session *session, const UA_NodeId *nodeId,
  71. UA_EditNodeCallback callback, const void *data);
  72. void UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection, const UA_ByteString *msg);
  73. UA_StatusCode UA_Server_delayedCallback(UA_Server *server, UA_ServerCallback callback, void *data);
  74. UA_StatusCode UA_Server_delayedFree(UA_Server *server, void *data);
  75. void UA_Server_deleteAllRepeatedJobs(UA_Server *server);
  76. /* Add an existing node. The node is assumed to be "finished", i.e. no
  77. * instantiation from inheritance is necessary. Instantiationcallback and
  78. * addedNodeId may be NULL. */
  79. UA_StatusCode
  80. Service_AddNodes_existing(UA_Server *server, UA_Session *session, UA_Node *node,
  81. const UA_NodeId *parentNodeId,
  82. const UA_NodeId *referenceTypeId,
  83. const UA_NodeId *typeDefinition,
  84. UA_InstantiationCallback *instantiationCallback,
  85. UA_NodeId *addedNodeId);
  86. /*********************/
  87. /* Utility Functions */
  88. /*********************/
  89. UA_StatusCode
  90. parse_numericrange(const UA_String *str, UA_NumericRange *range);
  91. UA_Boolean
  92. UA_Node_hasSubTypeOrInstances(const UA_Node *node);
  93. const UA_VariableTypeNode *
  94. getVariableNodeType(UA_Server *server, const UA_VariableNode *node);
  95. const UA_ObjectTypeNode *
  96. getObjectNodeType(UA_Server *server, const UA_ObjectNode *node);
  97. UA_StatusCode
  98. getTypeHierarchy(UA_NodeStore *ns, const UA_NodeId *root,
  99. UA_NodeId **reftypes, size_t *reftypes_count);
  100. UA_StatusCode
  101. isNodeInTree(UA_NodeStore *ns, const UA_NodeId *rootNode,
  102. const UA_NodeId *nodeToFind, const UA_NodeId *referenceTypeIds,
  103. size_t referenceTypeIdsSize, UA_Boolean *found);
  104. /***************************************/
  105. /* Check Information Model Consistency */
  106. /***************************************/
  107. UA_StatusCode
  108. UA_VariableNode_setArrayDimensions(UA_Server *server, UA_VariableNode *node,
  109. const UA_VariableTypeNode *vt,
  110. size_t arrayDimensionsSize, UA_UInt32 *arrayDimensions);
  111. UA_StatusCode
  112. UA_VariableNode_setValueRank(UA_Server *server, UA_VariableNode *node,
  113. const UA_VariableTypeNode *vt,
  114. const UA_Int32 valueRank);
  115. UA_StatusCode
  116. UA_VariableNode_setDataType(UA_Server *server, UA_VariableNode *node,
  117. const UA_VariableTypeNode *vt,
  118. const UA_NodeId *dataType);
  119. UA_StatusCode
  120. UA_VariableNode_setValue(UA_Server *server, UA_VariableNode *node,
  121. const UA_DataValue *value, const UA_String *indexRange);
  122. UA_StatusCode
  123. UA_Variant_matchVariableDefinition(UA_Server *server, const UA_NodeId *variableDataTypeId,
  124. UA_Int32 variableValueRank, size_t variableArrayDimensionsSize,
  125. const UA_UInt32 *variableArrayDimensions, const UA_Variant *value,
  126. const UA_NumericRange *range, UA_Variant *equivalent);
  127. #endif /* UA_SERVER_INTERNAL_H_ */