confdb.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Copyright (c) 2008 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfi@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef COROSYNC_CONFDB_H_DEFINED
  35. #define COROSYNC_CONFDB_H_DEFINED
  36. #include <corosync/corotypes.h>
  37. #include <corosync/hdb.h>
  38. /**
  39. * @addtogroup confdb_corosync
  40. *
  41. * @{
  42. */
  43. typedef uint64_t confdb_handle_t;
  44. #define OBJECT_PARENT_HANDLE 0xFFFFFFFF00000000ULL
  45. typedef enum {
  46. CONFDB_TRACK_DEPTH_ONE,
  47. CONFDB_TRACK_DEPTH_RECURSIVE
  48. } confdb_track_depth_t;
  49. typedef enum {
  50. OBJECT_KEY_CREATED,
  51. OBJECT_KEY_REPLACED,
  52. OBJECT_KEY_DELETED
  53. } confdb_change_type_t;
  54. typedef void (*confdb_key_change_notify_fn_t) (
  55. confdb_handle_t handle,
  56. confdb_change_type_t change_type,
  57. hdb_handle_t parent_object_handle,
  58. hdb_handle_t object_handle,
  59. void *object_name,
  60. int object_name_len,
  61. void *key_name,
  62. int key_name_len,
  63. void *key_value,
  64. int key_value_len);
  65. typedef void (*confdb_object_create_notify_fn_t) (
  66. confdb_handle_t handle,
  67. hdb_handle_t parent_object_handle,
  68. hdb_handle_t object_handle,
  69. uint8_t *name_pt,
  70. int name_len);
  71. typedef void (*confdb_object_delete_notify_fn_t) (
  72. confdb_handle_t handle,
  73. hdb_handle_t parent_object_handle,
  74. uint8_t *name_pt,
  75. int name_len);
  76. typedef struct {
  77. confdb_object_create_notify_fn_t confdb_object_create_change_notify_fn;
  78. confdb_object_delete_notify_fn_t confdb_object_delete_change_notify_fn;
  79. confdb_key_change_notify_fn_t confdb_key_change_notify_fn;
  80. } confdb_callbacks_t;
  81. /** @} */
  82. /*
  83. * Create a new confdb connection
  84. */
  85. cs_error_t confdb_initialize (
  86. confdb_handle_t *handle,
  87. confdb_callbacks_t *callbacks);
  88. /*
  89. * Close the confdb handle
  90. */
  91. cs_error_t confdb_finalize (
  92. confdb_handle_t handle);
  93. /*
  94. * Write back the configuration
  95. */
  96. cs_error_t confdb_write (
  97. confdb_handle_t handle,
  98. char *error_text);
  99. /*
  100. * Reload the configuration
  101. */
  102. cs_error_t confdb_reload (
  103. confdb_handle_t handle,
  104. int flush,
  105. char *error_text);
  106. /*
  107. * Get a file descriptor on which to poll. confdb_handle_t is NOT a
  108. * file descriptor and may not be used directly.
  109. */
  110. cs_error_t confdb_fd_get (
  111. confdb_handle_t handle,
  112. int *fd);
  113. /*
  114. * Dispatch configuration changes
  115. */
  116. cs_error_t confdb_dispatch (
  117. confdb_handle_t handle,
  118. cs_dispatch_flags_t dispatch_types);
  119. /*
  120. * Change notification
  121. */
  122. cs_error_t confdb_track_changes (
  123. confdb_handle_t handle,
  124. hdb_handle_t object_handle,
  125. unsigned int flags);
  126. cs_error_t confdb_stop_track_changes (
  127. confdb_handle_t handle);
  128. /*
  129. * Manipulate objects
  130. */
  131. cs_error_t confdb_object_create (
  132. confdb_handle_t handle,
  133. hdb_handle_t parent_object_handle,
  134. const void *object_name,
  135. int object_name_len,
  136. hdb_handle_t *object_handle);
  137. cs_error_t confdb_object_destroy (
  138. confdb_handle_t handle,
  139. hdb_handle_t object_handle);
  140. cs_error_t confdb_object_parent_get (
  141. confdb_handle_t handle,
  142. hdb_handle_t object_handle,
  143. hdb_handle_t *parent_object_handle);
  144. /*
  145. * Manipulate keys
  146. */
  147. cs_error_t confdb_key_create (
  148. confdb_handle_t handle,
  149. hdb_handle_t parent_object_handle,
  150. const void *key_name,
  151. int key_name_len,
  152. const void *value,
  153. int value_len);
  154. cs_error_t confdb_key_delete (
  155. confdb_handle_t handle,
  156. hdb_handle_t parent_object_handle,
  157. const void *key_name,
  158. int key_name_len,
  159. const void *value,
  160. int value_len);
  161. /*
  162. * Key queries
  163. */
  164. cs_error_t confdb_key_get (
  165. confdb_handle_t handle,
  166. hdb_handle_t parent_object_handle,
  167. const void *key_name,
  168. int key_name_len,
  169. void *value,
  170. int *value_len);
  171. cs_error_t confdb_key_replace (
  172. confdb_handle_t handle,
  173. hdb_handle_t parent_object_handle,
  174. const void *key_name,
  175. int key_name_len,
  176. const void *old_value,
  177. int old_value_len,
  178. const void *new_value,
  179. int new_value_len);
  180. cs_error_t confdb_key_increment (
  181. confdb_handle_t handle,
  182. hdb_handle_t parent_object_handle,
  183. const void *key_name,
  184. int key_name_len,
  185. unsigned int *value);
  186. cs_error_t confdb_key_decrement (
  187. confdb_handle_t handle,
  188. hdb_handle_t parent_object_handle,
  189. const void *key_name,
  190. int key_name_len,
  191. unsigned int *value);
  192. /*
  193. * Object queries
  194. * "find" loops through all objects of a given name and is also
  195. * a quick way of finding a specific object,
  196. * "iter" returns each object in sequence.
  197. */
  198. cs_error_t confdb_object_find_start (
  199. confdb_handle_t handle,
  200. hdb_handle_t parent_object_handle);
  201. cs_error_t confdb_object_find (
  202. confdb_handle_t handle,
  203. hdb_handle_t parent_object_handle,
  204. const void *object_name,
  205. int object_name_len,
  206. hdb_handle_t *object_handle);
  207. cs_error_t confdb_object_find_destroy(
  208. confdb_handle_t handle,
  209. hdb_handle_t parent_object_handle);
  210. cs_error_t confdb_object_iter_start (
  211. confdb_handle_t handle,
  212. hdb_handle_t parent_object_handle);
  213. cs_error_t confdb_object_iter (
  214. confdb_handle_t handle,
  215. hdb_handle_t parent_object_handle,
  216. hdb_handle_t *object_handle,
  217. void *object_name,
  218. int *object_name_len);
  219. cs_error_t confdb_object_iter_destroy(
  220. confdb_handle_t handle,
  221. hdb_handle_t parent_object_handle);
  222. /*
  223. * Key iterator
  224. */
  225. cs_error_t confdb_key_iter_start (
  226. confdb_handle_t handle,
  227. hdb_handle_t object_handle);
  228. cs_error_t confdb_key_iter (
  229. confdb_handle_t handle,
  230. hdb_handle_t parent_object_handle,
  231. void *key_name,
  232. int *key_name_len,
  233. void *value,
  234. int *value_len);
  235. /*
  236. * Get/set context variable
  237. */
  238. cs_error_t confdb_context_get (
  239. confdb_handle_t handle,
  240. const void **context);
  241. cs_error_t confdb_context_set (
  242. confdb_handle_t handle,
  243. const void *context);
  244. #endif /* COROSYNC_CONFDB_H_DEFINED */