ua_server_internal.h 6.0 KB

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