objdb.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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, int object_name_len,
  59. const void *key_name_pt, int key_len,
  60. const void *key_value_pt, int 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, int name_len,
  65. void *priv_data_pt);
  66. typedef void (*object_destroy_notify_fn_t) (unsigned int parent_object_handle,
  67. void *name_pt, int name_len,
  68. void *priv_data_pt);
  69. typedef void (*object_reload_notify_fn_t) (objdb_reload_notify_type_t, int flush,
  70. void *priv_data_pt);
  71. struct object_valid {
  72. char *object_name;
  73. int object_len;
  74. };
  75. struct object_key_valid {
  76. char *key_name;
  77. int key_len;
  78. int (*validate_callback) (const void *key, int key_len,
  79. const void *value, int value_len);
  80. };
  81. struct objdb_iface_ver0 {
  82. int (*objdb_init) (void);
  83. int (*object_create) (
  84. hdb_handle_t parent_object_handle,
  85. hdb_handle_t *object_handle,
  86. const void *object_name,
  87. unsigned int object_name_len);
  88. int (*object_priv_set) (
  89. hdb_handle_t object_handle,
  90. void *priv);
  91. int (*object_key_create) (
  92. hdb_handle_t object_handle,
  93. const void *key_name,
  94. int key_len,
  95. const void *value,
  96. int value_len);
  97. int (*object_destroy) (
  98. hdb_handle_t object_handle);
  99. int (*object_valid_set) (
  100. hdb_handle_t object_handle,
  101. struct object_valid *object_valid_list,
  102. unsigned int object_valid_list_entries);
  103. int (*object_key_valid_set) (
  104. hdb_handle_t object_handle,
  105. struct object_key_valid *object_key_valid_list,
  106. unsigned int object_key_valid_list_entries);
  107. int (*object_find_create) (
  108. hdb_handle_t parent_object_handle,
  109. const void *object_name,
  110. int object_name_len,
  111. hdb_handle_t *object_find_handle);
  112. int (*object_find_next) (
  113. hdb_handle_t object_find_handle,
  114. hdb_handle_t *object_handle);
  115. int (*object_find_destroy) (
  116. hdb_handle_t object_find_handle);
  117. int (*object_key_get) (
  118. hdb_handle_t object_handle,
  119. const void *key_name,
  120. int key_len,
  121. void **value,
  122. int *value_len);
  123. int (*object_priv_get) (
  124. hdb_handle_t jobject_handle,
  125. void **priv);
  126. int (*object_key_replace) (
  127. hdb_handle_t object_handle,
  128. const void *key_name,
  129. int key_len,
  130. const void *new_value,
  131. int new_value_len);
  132. int (*object_key_delete) (
  133. hdb_handle_t object_handle,
  134. const void *key_name,
  135. int key_len);
  136. int (*object_iter_reset) (
  137. hdb_handle_t parent_object_handle);
  138. int (*object_iter) (
  139. hdb_handle_t parent_object_handle,
  140. void **object_name,
  141. int *name_len,
  142. hdb_handle_t *object_handle);
  143. int (*object_key_iter_reset) (
  144. hdb_handle_t object_handle);
  145. int (*object_key_iter) (
  146. hdb_handle_t parent_object_handle,
  147. void **key_name,
  148. int *key_len,
  149. void **value,
  150. int *value_len);
  151. int (*object_parent_get) (
  152. hdb_handle_t object_handle,
  153. hdb_handle_t *parent_handle);
  154. int (*object_name_get) (
  155. hdb_handle_t object_handle,
  156. char *object_name,
  157. int *object_name_len);
  158. int (*object_dump) (
  159. hdb_handle_t object_handle,
  160. FILE *file);
  161. int (*object_key_iter_from) (
  162. hdb_handle_t parent_object_handle,
  163. hdb_handle_t start_pos,
  164. void **key_name,
  165. int *key_len,
  166. void **value,
  167. int *value_len);
  168. int (*object_track_start) (
  169. hdb_handle_t object_handle,
  170. object_track_depth_t depth,
  171. object_key_change_notify_fn_t key_change_notify_fn,
  172. object_create_notify_fn_t object_create_notify_fn,
  173. object_destroy_notify_fn_t object_destroy_notify_fn,
  174. object_reload_notify_fn_t object_reload_notify_fn,
  175. void * priv_data_pt);
  176. void (*object_track_stop) (
  177. object_key_change_notify_fn_t key_change_notify_fn,
  178. object_create_notify_fn_t object_create_notify_fn,
  179. object_destroy_notify_fn_t object_destroy_notify_fn,
  180. object_reload_notify_fn_t object_reload_notify_fn,
  181. void * priv_data_pt);
  182. int (*object_write_config) (const char **error_string);
  183. int (*object_reload_config) (
  184. int flush,
  185. const char **error_string);
  186. int (*object_key_increment) (
  187. hdb_handle_t object_handle,
  188. const void *key_name,
  189. int key_len,
  190. unsigned int *value);
  191. int (*object_key_decrement) (
  192. hdb_handle_t object_handle,
  193. const void *key_name,
  194. int key_len,
  195. unsigned int *value);
  196. };
  197. #endif /* OBJDB_H_DEFINED */