ua_nodestore.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef UA_NODESTORE_H_
  5. #define UA_NODESTORE_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #include "ua_nodes.h"
  10. /**
  11. * Nodestore
  12. * ---------
  13. * Stores nodes that can be indexed by their NodeId. Internally, it is based on
  14. * a hash-map implementation. */
  15. struct UA_NodeStore;
  16. typedef struct UA_NodeStore UA_NodeStore;
  17. /**
  18. * Nodestore Lifecycle
  19. * ^^^^^^^^^^^^^^^^^^^ */
  20. /* Create a new nodestore */
  21. UA_NodeStore * UA_NodeStore_new(void);
  22. /* Delete the nodestore and all nodes in it. Do not call from a read-side
  23. critical section (multithreading). */
  24. void UA_NodeStore_delete(UA_NodeStore *ns);
  25. /**
  26. * Node Lifecycle
  27. * ^^^^^^^^^^^^^^
  28. *
  29. * The following definitions are used to create empty nodes of the different
  30. * node types. The memory is managed by the nodestore. Therefore, the node has
  31. * to be removed via a special deleteNode function. (If the new node is not
  32. * added to the nodestore.) */
  33. /* Create an editable node of the given NodeClass. */
  34. UA_Node * UA_NodeStore_newNode(UA_NodeClass nodeClass);
  35. #define UA_NodeStore_newObjectNode() \
  36. (UA_ObjectNode*)UA_NodeStore_newNode(UA_NODECLASS_OBJECT)
  37. #define UA_NodeStore_newVariableNode() \
  38. (UA_VariableNode*)UA_NodeStore_newNode(UA_NODECLASS_VARIABLE)
  39. #define UA_NodeStore_newMethodNode() \
  40. (UA_MethodNode*)UA_NodeStore_newNode(UA_NODECLASS_METHOD)
  41. #define UA_NodeStore_newObjectTypeNode() \
  42. (UA_ObjectTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_OBJECTTYPE)
  43. #define UA_NodeStore_newVariableTypeNode() \
  44. (UA_VariableTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_VARIABLETYPE)
  45. #define UA_NodeStore_newReferenceTypeNode() \
  46. (UA_ReferenceTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_REFERENCETYPE)
  47. #define UA_NodeStore_newDataTypeNode() \
  48. (UA_DataTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_DATATYPE)
  49. #define UA_NodeStore_newViewNode() \
  50. (UA_ViewNode*)UA_NodeStore_newNode(UA_NODECLASS_VIEW)
  51. /* Delete an editable node. */
  52. void UA_NodeStore_deleteNode(UA_Node *node);
  53. /**
  54. * Insert / Get / Replace / Remove
  55. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  56. /* Inserts a new node into the nodestore. If the nodeid is zero, then a fresh
  57. * numeric nodeid from namespace 1 is assigned. If insertion fails, the node is
  58. * deleted. */
  59. UA_StatusCode UA_NodeStore_insert(UA_NodeStore *ns, UA_Node *node);
  60. /* The returned node is immutable. */
  61. const UA_Node * UA_NodeStore_get(UA_NodeStore *ns, const UA_NodeId *nodeid);
  62. /* Returns an editable copy of a node (needs to be deleted with the deleteNode
  63. function or inserted / replaced into the nodestore). */
  64. UA_Node * UA_NodeStore_getCopy(UA_NodeStore *ns, const UA_NodeId *nodeid);
  65. /* To replace a node, get an editable copy of the node, edit and replace with
  66. * this function. If the node was already replaced since the copy was made,
  67. * UA_STATUSCODE_BADINTERNALERROR is returned. If the nodeid is not found,
  68. * UA_STATUSCODE_BADNODEIDUNKNOWN is returned. In both error cases, the editable
  69. * node is deleted. */
  70. UA_StatusCode UA_NodeStore_replace(UA_NodeStore *ns, UA_Node *node);
  71. /* Remove a node in the nodestore. */
  72. UA_StatusCode UA_NodeStore_remove(UA_NodeStore *ns, const UA_NodeId *nodeid);
  73. /**
  74. * Iteration
  75. * ^^^^^^^^^
  76. * The following definitions are used to call a callback for every node in the
  77. * nodestore. */
  78. typedef void (*UA_NodeStore_nodeVisitor)(const UA_Node *node);
  79. void UA_NodeStore_iterate(UA_NodeStore *ns, UA_NodeStore_nodeVisitor visitor);
  80. #ifdef __cplusplus
  81. } // extern "C"
  82. #endif
  83. #endif /* UA_NODESTORE_H_ */