ua_nodestore.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef UA_NODESTORE_H_
  2. #define UA_NODESTORE_H_
  3. #include "ua_types_generated.h"
  4. #include "ua_nodes.h"
  5. /**
  6. * @ingroup server
  7. *
  8. * @defgroup nodestore NodeStore
  9. *
  10. * @brief Stores the nodes in the address space. Internally, it is based on a
  11. * hash-map that maps nodes to their nodeid.
  12. *
  13. * Nodes need to be allocated on the heap before adding them to the nodestore
  14. * with. When adding, the node is copied to a new (managed) location in the
  15. * nodestore and the original memory is freed. The nodes in the nodestore are
  16. * immutable. To change the content of a node, it needs to be replaced as a
  17. * whole.
  18. *
  19. * Every node you _get from the nodestore needs to be _released when it is no
  20. * longer needed. In the background, reference counting is used to know if
  21. * somebody still uses the node in multi-threaded environments.
  22. *
  23. * @{
  24. */
  25. struct UA_NodeStore;
  26. typedef struct UA_NodeStore UA_NodeStore;
  27. /** Create a new nodestore */
  28. UA_NodeStore * UA_NodeStore_new(void);
  29. /** Delete the nodestore and all nodes in it */
  30. void UA_NodeStore_delete(UA_NodeStore *ns);
  31. /**
  32. * Inserts a new node into the nodestore. If the nodeid is zero, then a fresh
  33. * numeric nodeid from nodestore 1 is assigned. The memory of the original node
  34. * is freed and the content is moved to a managed (immutable) node. If inserted
  35. * is not NULL, then a pointer to the managed node is returned (and must be
  36. * released).
  37. */
  38. UA_StatusCode UA_NodeStore_insert(UA_NodeStore *ns, UA_Node *node, const UA_Node **inserted);
  39. /**
  40. * Replace an existing node in the nodestore. If the node was already replaced,
  41. * UA_STATUSCODE_BADINTERNALERROR is returned. If inserted is not NULL, a
  42. * pointer to the managed (immutable) node is returned.
  43. */
  44. UA_StatusCode UA_NodeStore_replace(UA_NodeStore *ns, const UA_Node *oldNode, UA_Node *node, const UA_Node **inserted);
  45. /**
  46. * Remove a node from the nodestore. Always succeeds, even if the node was not
  47. * found.
  48. */
  49. UA_StatusCode UA_NodeStore_remove(UA_NodeStore *ns, const UA_NodeId *nodeid);
  50. /**
  51. * Retrieve a managed node (read-only) from the nodestore. Nodes are reference-
  52. * counted (for garbage collection) and immutable. They can only be replaced
  53. * entirely. After the node is no longer used, it needs to be released to decrease
  54. * the reference count.
  55. */
  56. const UA_Node * UA_NodeStore_get(const UA_NodeStore *ns, const UA_NodeId *nodeid);
  57. /**
  58. * Release a managed node. Do never call this with a node that isn't managed by a
  59. * nodestore.
  60. */
  61. void UA_NodeStore_release(const UA_Node *managed);
  62. /**
  63. * A function that can be evaluated on all entries in a nodestore via
  64. * UA_NodeStore_iterate. Note that the visitor is read-only on the nodes.
  65. */
  66. typedef void (*UA_NodeStore_nodeVisitor)(const UA_Node *node);
  67. /** Iterate over all nodes in a nodestore. */
  68. void UA_NodeStore_iterate(const UA_NodeStore *ns, UA_NodeStore_nodeVisitor visitor);
  69. /** @} */
  70. #endif /* UA_NODESTORE_H_ */