confdb.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Copyright (c) 2008, 2009 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. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. * @addtogroup confdb_corosync
  43. *
  44. * @{
  45. */
  46. typedef uint64_t confdb_handle_t;
  47. #define OBJECT_PARENT_HANDLE 0xFFFFFFFF00000000ULL
  48. typedef enum {
  49. CONFDB_TRACK_DEPTH_ONE,
  50. CONFDB_TRACK_DEPTH_RECURSIVE
  51. } confdb_track_depth_t;
  52. typedef enum {
  53. OBJECT_KEY_CREATED,
  54. OBJECT_KEY_REPLACED,
  55. OBJECT_KEY_DELETED
  56. } confdb_change_type_t;
  57. typedef void (*confdb_key_change_notify_fn_t) (
  58. confdb_handle_t handle,
  59. confdb_change_type_t change_type,
  60. hdb_handle_t parent_object_handle,
  61. hdb_handle_t object_handle,
  62. const void *object_name,
  63. size_t object_name_len,
  64. const void *key_name,
  65. size_t key_name_len,
  66. const void *key_value,
  67. size_t key_value_len);
  68. typedef void (*confdb_object_create_notify_fn_t) (
  69. confdb_handle_t handle,
  70. hdb_handle_t parent_object_handle,
  71. hdb_handle_t object_handle,
  72. const void *name_pt,
  73. size_t name_len);
  74. typedef void (*confdb_object_delete_notify_fn_t) (
  75. confdb_handle_t handle,
  76. hdb_handle_t parent_object_handle,
  77. const void *name_pt,
  78. size_t name_len);
  79. typedef struct {
  80. confdb_object_create_notify_fn_t confdb_object_create_change_notify_fn;
  81. confdb_object_delete_notify_fn_t confdb_object_delete_change_notify_fn;
  82. confdb_key_change_notify_fn_t confdb_key_change_notify_fn;
  83. } confdb_callbacks_t;
  84. /** @} */
  85. /*
  86. * Create a new confdb connection
  87. */
  88. cs_error_t confdb_initialize (
  89. confdb_handle_t *handle,
  90. confdb_callbacks_t *callbacks);
  91. /*
  92. * Close the confdb handle
  93. */
  94. cs_error_t confdb_finalize (
  95. confdb_handle_t handle);
  96. /*
  97. * Write back the configuration
  98. */
  99. cs_error_t confdb_write (
  100. confdb_handle_t handle,
  101. char *error_text,
  102. size_t errbuf_len);
  103. /*
  104. * Reload the configuration
  105. */
  106. cs_error_t confdb_reload (
  107. confdb_handle_t handle,
  108. int flush,
  109. char *error_text,
  110. size_t errbuf_len);
  111. /*
  112. * Get a file descriptor on which to poll. confdb_handle_t is NOT a
  113. * file descriptor and may not be used directly.
  114. */
  115. cs_error_t confdb_fd_get (
  116. confdb_handle_t handle,
  117. int *fd);
  118. /*
  119. * Dispatch configuration changes
  120. */
  121. cs_error_t confdb_dispatch (
  122. confdb_handle_t handle,
  123. cs_dispatch_flags_t dispatch_types);
  124. /*
  125. * Change notification
  126. */
  127. cs_error_t confdb_track_changes (
  128. confdb_handle_t handle,
  129. hdb_handle_t object_handle,
  130. unsigned int flags);
  131. cs_error_t confdb_stop_track_changes (
  132. confdb_handle_t handle);
  133. /*
  134. * Manipulate objects
  135. */
  136. cs_error_t confdb_object_create (
  137. confdb_handle_t handle,
  138. hdb_handle_t parent_object_handle,
  139. const void *object_name,
  140. size_t object_name_len,
  141. hdb_handle_t *object_handle);
  142. cs_error_t confdb_object_destroy (
  143. confdb_handle_t handle,
  144. hdb_handle_t object_handle);
  145. cs_error_t confdb_object_parent_get (
  146. confdb_handle_t handle,
  147. hdb_handle_t object_handle,
  148. hdb_handle_t *parent_object_handle);
  149. /*
  150. * Manipulate keys
  151. */
  152. cs_error_t confdb_key_create (
  153. confdb_handle_t handle,
  154. hdb_handle_t parent_object_handle,
  155. const void *key_name,
  156. size_t key_name_len,
  157. const void *value,
  158. size_t value_len);
  159. cs_error_t confdb_key_delete (
  160. confdb_handle_t handle,
  161. hdb_handle_t parent_object_handle,
  162. const void *key_name,
  163. size_t key_name_len,
  164. const void *value,
  165. size_t value_len);
  166. /*
  167. * Key queries
  168. */
  169. cs_error_t confdb_key_get (
  170. confdb_handle_t handle,
  171. hdb_handle_t parent_object_handle,
  172. const void *key_name,
  173. size_t key_name_len,
  174. void *value,
  175. size_t *value_len);
  176. cs_error_t confdb_key_replace (
  177. confdb_handle_t handle,
  178. hdb_handle_t parent_object_handle,
  179. const void *key_name,
  180. size_t key_name_len,
  181. const void *old_value,
  182. size_t old_value_len,
  183. const void *new_value,
  184. size_t new_value_len);
  185. cs_error_t confdb_key_increment (
  186. confdb_handle_t handle,
  187. hdb_handle_t parent_object_handle,
  188. const void *key_name,
  189. size_t key_name_len,
  190. unsigned int *value);
  191. cs_error_t confdb_key_decrement (
  192. confdb_handle_t handle,
  193. hdb_handle_t parent_object_handle,
  194. const void *key_name,
  195. size_t key_name_len,
  196. unsigned int *value);
  197. /*
  198. * Object queries
  199. * "find" loops through all objects of a given name and is also
  200. * a quick way of finding a specific object,
  201. * "iter" returns each object in sequence.
  202. */
  203. cs_error_t confdb_object_find_start (
  204. confdb_handle_t handle,
  205. hdb_handle_t parent_object_handle);
  206. cs_error_t confdb_object_find (
  207. confdb_handle_t handle,
  208. hdb_handle_t parent_object_handle,
  209. const void *object_name,
  210. size_t object_name_len,
  211. hdb_handle_t *object_handle);
  212. cs_error_t confdb_object_find_destroy(
  213. confdb_handle_t handle,
  214. hdb_handle_t parent_object_handle);
  215. cs_error_t confdb_object_iter_start (
  216. confdb_handle_t handle,
  217. hdb_handle_t parent_object_handle);
  218. cs_error_t confdb_object_iter (
  219. confdb_handle_t handle,
  220. hdb_handle_t parent_object_handle,
  221. hdb_handle_t *object_handle,
  222. void *object_name,
  223. size_t *object_name_len);
  224. cs_error_t confdb_object_iter_destroy(
  225. confdb_handle_t handle,
  226. hdb_handle_t parent_object_handle);
  227. /*
  228. * Key iterator
  229. */
  230. cs_error_t confdb_key_iter_start (
  231. confdb_handle_t handle,
  232. hdb_handle_t object_handle);
  233. cs_error_t confdb_key_iter (
  234. confdb_handle_t handle,
  235. hdb_handle_t parent_object_handle,
  236. void *key_name,
  237. size_t *key_name_len,
  238. void *value,
  239. size_t *value_len);
  240. /*
  241. * Get/set context variable
  242. */
  243. cs_error_t confdb_context_get (
  244. confdb_handle_t handle,
  245. const void **context);
  246. cs_error_t confdb_context_set (
  247. confdb_handle_t handle,
  248. const void *context);
  249. #ifdef __cplusplus
  250. }
  251. #endif
  252. #endif /* COROSYNC_CONFDB_H_DEFINED */