ua_namespace.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef __NAMESPACE_H__
  2. #define __NAMESPACE_H__
  3. #include "ua_types.h"
  4. #include "ua_types_generated.h"
  5. #include "util/ua_list.h"
  6. #ifdef MULTITHREADING
  7. #define _XOPEN_SOURCE 500
  8. #define __USE_UNIX98
  9. #include <pthread.h>
  10. #endif
  11. /** @brief Namespace entries point to an UA_Node. But the actual data structure
  12. is opaque outside of ua_namespace.c */
  13. typedef struct Namespace_Entry {
  14. UA_UInt64 status; /* 2 bits status | 14 bits checkout count | 48 bits timestamp */
  15. const UA_Node *node; /* Nodes are immutable. It is not recommended to change nodes in place */
  16. } Namespace_Entry;
  17. /** @brief Namespace datastructure. It mainly serves as a hashmap to UA_Nodes. */
  18. typedef struct Namespace {
  19. UA_UInt32 namespaceId;
  20. Namespace_Entry *entries;
  21. UA_UInt32 size;
  22. UA_UInt32 count;
  23. UA_UInt32 sizePrimeIndex; /* Current size, as an index into the table of primes. */
  24. } Namespace;
  25. /** Namespace locks indicate that a thread currently operates on an entry. */
  26. struct Namespace_Entry_Lock;
  27. typedef struct Namespace_Entry_Lock Namespace_Entry_Lock;
  28. /** @brief Release a lock on a namespace entry. */
  29. void Namespace_Entry_Lock_release(Namespace_Entry_Lock * lock);
  30. /** @brief Create a new namespace */
  31. UA_Int32 Namespace_new(Namespace ** result, UA_UInt32 size, UA_UInt32 namespaceId);
  32. /** @brief Delete all nodes in the namespace */
  33. void Namespace_empty(Namespace * ns);
  34. /** @brief Delete the namespace and all nodes in it */
  35. void Namespace_delete(Namespace * ns);
  36. /** @brief Insert a new node into the namespace. Abort an entry with the same
  37. NodeId is already present */
  38. UA_Int32 Namespace_insert(Namespace * ns, const UA_Node * node);
  39. /** @brief Insert a new node or replace an existing node if an entry has the same NodeId. */
  40. UA_Int32 Namespace_insertOrReplace(Namespace * ns, const UA_Node * node);
  41. /** @brief Find an unused (numeric) NodeId in the namespace and insert the node.
  42. The node is modified to contain the new nodeid after insertion. */
  43. UA_Int32 Namespace_insertUnique(Namespace * ns, UA_Node * node);
  44. /** @brief Remove a node from the namespace */
  45. UA_Int32 Namespace_remove(Namespace * ns, const UA_NodeId * nodeid);
  46. /** @brief Tests whether the namespace contains an entry for a given NodeId */
  47. UA_Int32 Namespace_contains(const Namespace * ns, const UA_NodeId * nodeid);
  48. /** @brief Retrieve a node (read-only) from the namespace. Nodes are identified
  49. by their NodeId. After the Node is no longer used, the lock needs to be
  50. released. */
  51. UA_Int32 Namespace_get(const Namespace *ns, const UA_NodeId * nodeid, const UA_Node **result,
  52. Namespace_Entry_Lock ** lock);
  53. /** @brief A function that can be evaluated on all entries in a namespace via Namespace_iterate */
  54. typedef void (*Namespace_nodeVisitor) (const UA_Node *node);
  55. /** @brief Iterate over all nodes in a namespace */
  56. UA_Int32 Namespace_iterate(const Namespace * ns, Namespace_nodeVisitor visitor);
  57. #endif /* __NAMESPACE_H */