ua_nodestore.h 3.4 KB

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