objdb.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (c) 2006 MontaVista Software, Inc.
  3. * Copyright (c) 2007-2009 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef OBJDB_H_DEFINED
  36. #define OBJDB_H_DEFINED
  37. #define OBJECT_PARENT_HANDLE 0xFFFFFFFF00000000ULL
  38. #include <stdio.h>
  39. #include <corosync/hdb.h>
  40. typedef enum {
  41. OBJECT_TRACK_DEPTH_ONE,
  42. OBJECT_TRACK_DEPTH_RECURSIVE
  43. } object_track_depth_t;
  44. typedef enum {
  45. OBJECT_KEY_CREATED,
  46. OBJECT_KEY_REPLACED,
  47. OBJECT_KEY_DELETED
  48. } object_change_type_t;
  49. typedef enum {
  50. OBJDB_RELOAD_NOTIFY_START,
  51. OBJDB_RELOAD_NOTIFY_END,
  52. OBJDB_RELOAD_NOTIFY_FAILED
  53. } objdb_reload_notify_type_t;
  54. typedef void (*object_key_change_notify_fn_t)(
  55. object_change_type_t change_type,
  56. hdb_handle_t parent_object_handle,
  57. hdb_handle_t object_handle,
  58. const void *object_name_pt, size_t object_name_len,
  59. const void *key_name_pt, size_t key_len,
  60. const void *key_value_pt, size_t key_value_len,
  61. void *priv_data_pt);
  62. typedef void (*object_create_notify_fn_t) (unsigned int parent_object_handle,
  63. hdb_handle_t object_handle,
  64. const void *name_pt, size_t name_len,
  65. void *priv_data_pt);
  66. typedef void (*object_destroy_notify_fn_t) (unsigned int parent_object_handle,
  67. const void *name_pt,
  68. size_t name_len,
  69. void *priv_data_pt);
  70. typedef void (*object_reload_notify_fn_t) (objdb_reload_notify_type_t, int flush,
  71. void *priv_data_pt);
  72. struct object_valid {
  73. char *object_name;
  74. size_t object_len;
  75. };
  76. struct object_key_valid {
  77. char *key_name;
  78. size_t key_len;
  79. int (*validate_callback) (const void *key, size_t key_len,
  80. const void *value, size_t value_len);
  81. };
  82. struct objdb_iface_ver0 {
  83. int (*objdb_init) (void);
  84. int (*object_create) (
  85. hdb_handle_t parent_object_handle,
  86. hdb_handle_t *object_handle,
  87. const void *object_name,
  88. size_t object_name_len);
  89. int (*object_priv_set) (
  90. hdb_handle_t object_handle,
  91. void *priv);
  92. int (*object_key_create) (
  93. hdb_handle_t object_handle,
  94. const void *key_name,
  95. size_t key_len,
  96. const void *value,
  97. size_t value_len);
  98. int (*object_destroy) (
  99. hdb_handle_t object_handle);
  100. int (*object_valid_set) (
  101. hdb_handle_t object_handle,
  102. struct object_valid *object_valid_list,
  103. size_t object_valid_list_entries);
  104. int (*object_key_valid_set) (
  105. hdb_handle_t object_handle,
  106. struct object_key_valid *object_key_valid_list,
  107. size_t object_key_valid_list_entries);
  108. int (*object_find_create) (
  109. hdb_handle_t parent_object_handle,
  110. const void *object_name,
  111. size_t object_name_len,
  112. hdb_handle_t *object_find_handle);
  113. int (*object_find_next) (
  114. hdb_handle_t object_find_handle,
  115. hdb_handle_t *object_handle);
  116. int (*object_find_destroy) (
  117. hdb_handle_t object_find_handle);
  118. int (*object_key_get) (
  119. hdb_handle_t object_handle,
  120. const void *key_name,
  121. size_t key_len,
  122. void **value,
  123. size_t *value_len);
  124. int (*object_priv_get) (
  125. hdb_handle_t jobject_handle,
  126. void **priv);
  127. int (*object_key_replace) (
  128. hdb_handle_t object_handle,
  129. const void *key_name,
  130. size_t key_len,
  131. const void *new_value,
  132. size_t new_value_len);
  133. int (*object_key_delete) (
  134. hdb_handle_t object_handle,
  135. const void *key_name,
  136. size_t key_len);
  137. int (*object_iter_reset) (
  138. hdb_handle_t parent_object_handle);
  139. int (*object_iter) (
  140. hdb_handle_t parent_object_handle,
  141. void **object_name,
  142. size_t *name_len,
  143. hdb_handle_t *object_handle);
  144. int (*object_key_iter_reset) (
  145. hdb_handle_t object_handle);
  146. int (*object_key_iter) (
  147. hdb_handle_t parent_object_handle,
  148. void **key_name,
  149. size_t *key_len,
  150. void **value,
  151. size_t *value_len);
  152. int (*object_parent_get) (
  153. hdb_handle_t object_handle,
  154. hdb_handle_t *parent_handle);
  155. int (*object_name_get) (
  156. hdb_handle_t object_handle,
  157. char *object_name,
  158. size_t *object_name_len);
  159. int (*object_dump) (
  160. hdb_handle_t object_handle,
  161. FILE *file);
  162. int (*object_key_iter_from) (
  163. hdb_handle_t parent_object_handle,
  164. hdb_handle_t start_pos,
  165. void **key_name,
  166. size_t *key_len,
  167. void **value,
  168. size_t *value_len);
  169. int (*object_track_start) (
  170. hdb_handle_t object_handle,
  171. object_track_depth_t depth,
  172. object_key_change_notify_fn_t key_change_notify_fn,
  173. object_create_notify_fn_t object_create_notify_fn,
  174. object_destroy_notify_fn_t object_destroy_notify_fn,
  175. object_reload_notify_fn_t object_reload_notify_fn,
  176. void * priv_data_pt);
  177. void (*object_track_stop) (
  178. object_key_change_notify_fn_t key_change_notify_fn,
  179. object_create_notify_fn_t object_create_notify_fn,
  180. object_destroy_notify_fn_t object_destroy_notify_fn,
  181. object_reload_notify_fn_t object_reload_notify_fn,
  182. void * priv_data_pt);
  183. int (*object_write_config) (const char **error_string);
  184. int (*object_reload_config) (
  185. int flush,
  186. const char **error_string);
  187. int (*object_key_increment) (
  188. hdb_handle_t object_handle,
  189. const void *key_name,
  190. size_t key_len,
  191. unsigned int *value);
  192. int (*object_key_decrement) (
  193. hdb_handle_t object_handle,
  194. const void *key_name,
  195. size_t key_len,
  196. unsigned int *value);
  197. };
  198. #endif /* OBJDB_H_DEFINED */