ua_nodestore.h 3.6 KB

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