ua_nodestore.h 2.7 KB

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