ua_nodestore.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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() \
  34. (UA_ObjectNode*)UA_NodeStore_newNode(UA_NODECLASS_OBJECT)
  35. #define UA_NodeStore_newVariableNode() \
  36. (UA_VariableNode*)UA_NodeStore_newNode(UA_NODECLASS_VARIABLE)
  37. #define UA_NodeStore_newMethodNode() \
  38. (UA_MethodNode*)UA_NodeStore_newNode(UA_NODECLASS_METHOD)
  39. #define UA_NodeStore_newObjectTypeNode() \
  40. (UA_ObjectTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_OBJECTTYPE)
  41. #define UA_NodeStore_newVariableTypeNode() \
  42. (UA_VariableTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_VARIABLETYPE)
  43. #define UA_NodeStore_newReferenceTypeNode() \
  44. (UA_ReferenceTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_REFERENCETYPE)
  45. #define UA_NodeStore_newDataTypeNode() \
  46. (UA_DataTypeNode*)UA_NodeStore_newNode(UA_NODECLASS_DATATYPE)
  47. #define UA_NodeStore_newViewNode() \
  48. (UA_ViewNode*)UA_NodeStore_newNode(UA_NODECLASS_VIEW)
  49. /* Delete an editable node. */
  50. void UA_NodeStore_deleteNode(UA_Node *node);
  51. /**
  52. * Insert / Get / Replace / Remove
  53. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  54. /* Inserts a new node into the nodestore. If the nodeid is zero, then a fresh
  55. * numeric nodeid from namespace 1 is assigned. If insertion fails, the node is
  56. * deleted. */
  57. UA_StatusCode UA_NodeStore_insert(UA_NodeStore *ns, UA_Node *node);
  58. /* The returned node is immutable. */
  59. const UA_Node * UA_NodeStore_get(UA_NodeStore *ns, const UA_NodeId *nodeid);
  60. /* Returns an editable copy of a node (needs to be deleted with the deleteNode
  61. function or inserted / replaced into the nodestore). */
  62. UA_Node * UA_NodeStore_getCopy(UA_NodeStore *ns, const UA_NodeId *nodeid);
  63. /* To replace a node, get an editable copy of the node, edit and replace with
  64. * this function. If the node was already replaced since the copy was made,
  65. * UA_STATUSCODE_BADINTERNALERROR is returned. If the nodeid is not found,
  66. * UA_STATUSCODE_BADNODEIDUNKNOWN is returned. In both error cases, the editable
  67. * node is deleted. */
  68. UA_StatusCode UA_NodeStore_replace(UA_NodeStore *ns, UA_Node *node);
  69. /* Remove a node in the nodestore. */
  70. UA_StatusCode UA_NodeStore_remove(UA_NodeStore *ns, const UA_NodeId *nodeid);
  71. /**
  72. * Iteration
  73. * ^^^^^^^^^
  74. * The following definitions are used to call a callback for every node in the
  75. * nodestore. */
  76. typedef void (*UA_NodeStore_nodeVisitor)(const UA_Node *node);
  77. void UA_NodeStore_iterate(UA_NodeStore *ns, UA_NodeStore_nodeVisitor visitor);
  78. #ifdef __cplusplus
  79. } // extern "C"
  80. #endif
  81. #endif /* UA_NODESTORE_H_ */