ua_nodestore.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* For multithreading, nodes in the nodestore are immutable */
  26. #ifdef UA_ENABLE_MULTITHREADING
  27. # define UA_MT_CONST const
  28. #else
  29. # define UA_MT_CONST
  30. #endif
  31. struct UA_NodeStore;
  32. typedef struct UA_NodeStore UA_NodeStore;
  33. /** Create a new nodestore */
  34. UA_NodeStore * UA_NodeStore_new(void);
  35. /** Delete the nodestore and all nodes in it. Do not call from a read-side
  36. critical section (multithreading). */
  37. void UA_NodeStore_delete(UA_NodeStore *ns);
  38. /**
  39. * Inserts a new node into the nodestore. If the nodeid is zero, then a fresh
  40. * numeric nodeid from nodestore 1 is assigned. The memory of the original node
  41. * is freed and the content is moved to a managed (immutable) node. If inserted
  42. * is not NULL, then a pointer to the managed node is returned (and must be
  43. * released).
  44. */
  45. UA_StatusCode UA_NodeStore_insert(UA_NodeStore *ns, UA_Node *node, UA_MT_CONST UA_Node **inserted);
  46. /**
  47. * Replace an existing node in the nodestore. If the node was already replaced,
  48. * UA_STATUSCODE_BADINTERNALERROR is returned. A pointer to the inserted node is
  49. * returned. It is important that oldNode is not used afterwards in the same
  50. * thread.
  51. */
  52. UA_StatusCode UA_NodeStore_replace(UA_NodeStore *ns, UA_MT_CONST UA_Node *oldNode,
  53. UA_Node *node, UA_MT_CONST UA_Node **inserted);
  54. /**
  55. * Remove a node from the nodestore. Always succeeds, even if the node was not
  56. * found.
  57. */
  58. UA_StatusCode UA_NodeStore_remove(UA_NodeStore *ns, const UA_NodeId *nodeid);
  59. /**
  60. * Retrieve a managed node (read-only) from the nodestore. Nodes are reference-
  61. * counted (for garbage collection) and immutable. They can only be replaced
  62. * entirely. After the node is no longer used, it needs to be released to decrease
  63. * the reference count.
  64. */
  65. UA_MT_CONST UA_Node * UA_NodeStore_get(const UA_NodeStore *ns, const UA_NodeId *nodeid);
  66. /**
  67. * A function that can be evaluated on all entries in a nodestore via
  68. * UA_NodeStore_iterate. Note that the visitor is read-only on the nodes.
  69. */
  70. typedef void (*UA_NodeStore_nodeVisitor)(const UA_Node *node);
  71. /** Iterate over all nodes in a nodestore. */
  72. void UA_NodeStore_iterate(const UA_NodeStore *ns, UA_NodeStore_nodeVisitor visitor);
  73. /** @} */
  74. #endif /* UA_NODESTORE_H_ */