confdb.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. /**
  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. const void *object_name,
  60. size_t object_name_len,
  61. const void *key_name,
  62. size_t key_name_len,
  63. const void *key_value,
  64. size_t 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. const void *name_pt,
  70. size_t name_len);
  71. typedef void (*confdb_object_delete_notify_fn_t) (
  72. confdb_handle_t handle,
  73. hdb_handle_t parent_object_handle,
  74. const void *name_pt,
  75. size_t 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. size_t errbuf_len);
  100. /*
  101. * Reload the configuration
  102. */
  103. cs_error_t confdb_reload (
  104. confdb_handle_t handle,
  105. int flush,
  106. char *error_text,
  107. size_t errbuf_len);
  108. /*
  109. * Get a file descriptor on which to poll. confdb_handle_t is NOT a
  110. * file descriptor and may not be used directly.
  111. */
  112. cs_error_t confdb_fd_get (
  113. confdb_handle_t handle,
  114. int *fd);
  115. /*
  116. * Dispatch configuration changes
  117. */
  118. cs_error_t confdb_dispatch (
  119. confdb_handle_t handle,
  120. cs_dispatch_flags_t dispatch_types);
  121. /*
  122. * Change notification
  123. */
  124. cs_error_t confdb_track_changes (
  125. confdb_handle_t handle,
  126. hdb_handle_t object_handle,
  127. unsigned int flags);
  128. cs_error_t confdb_stop_track_changes (
  129. confdb_handle_t handle);
  130. /*
  131. * Manipulate objects
  132. */
  133. cs_error_t confdb_object_create (
  134. confdb_handle_t handle,
  135. hdb_handle_t parent_object_handle,
  136. const void *object_name,
  137. int object_name_len,
  138. hdb_handle_t *object_handle);
  139. cs_error_t confdb_object_destroy (
  140. confdb_handle_t handle,
  141. hdb_handle_t object_handle);
  142. cs_error_t confdb_object_parent_get (
  143. confdb_handle_t handle,
  144. hdb_handle_t object_handle,
  145. hdb_handle_t *parent_object_handle);
  146. /*
  147. * Manipulate keys
  148. */
  149. cs_error_t confdb_key_create (
  150. confdb_handle_t handle,
  151. hdb_handle_t parent_object_handle,
  152. const void *key_name,
  153. int key_name_len,
  154. const void *value,
  155. int value_len);
  156. cs_error_t confdb_key_delete (
  157. confdb_handle_t handle,
  158. hdb_handle_t parent_object_handle,
  159. const void *key_name,
  160. int key_name_len,
  161. const void *value,
  162. int value_len);
  163. /*
  164. * Key queries
  165. */
  166. cs_error_t confdb_key_get (
  167. confdb_handle_t handle,
  168. hdb_handle_t parent_object_handle,
  169. const void *key_name,
  170. int key_name_len,
  171. void *value,
  172. int *value_len);
  173. cs_error_t confdb_key_replace (
  174. confdb_handle_t handle,
  175. hdb_handle_t parent_object_handle,
  176. const void *key_name,
  177. int key_name_len,
  178. const void *old_value,
  179. int old_value_len,
  180. const void *new_value,
  181. int new_value_len);
  182. cs_error_t confdb_key_increment (
  183. confdb_handle_t handle,
  184. hdb_handle_t parent_object_handle,
  185. const void *key_name,
  186. int key_name_len,
  187. unsigned int *value);
  188. cs_error_t confdb_key_decrement (
  189. confdb_handle_t handle,
  190. hdb_handle_t parent_object_handle,
  191. const void *key_name,
  192. int key_name_len,
  193. unsigned int *value);
  194. /*
  195. * Object queries
  196. * "find" loops through all objects of a given name and is also
  197. * a quick way of finding a specific object,
  198. * "iter" returns each object in sequence.
  199. */
  200. cs_error_t confdb_object_find_start (
  201. confdb_handle_t handle,
  202. hdb_handle_t parent_object_handle);
  203. cs_error_t confdb_object_find (
  204. confdb_handle_t handle,
  205. hdb_handle_t parent_object_handle,
  206. const void *object_name,
  207. int object_name_len,
  208. hdb_handle_t *object_handle);
  209. cs_error_t confdb_object_find_destroy(
  210. confdb_handle_t handle,
  211. hdb_handle_t parent_object_handle);
  212. cs_error_t confdb_object_iter_start (
  213. confdb_handle_t handle,
  214. hdb_handle_t parent_object_handle);
  215. cs_error_t confdb_object_iter (
  216. confdb_handle_t handle,
  217. hdb_handle_t parent_object_handle,
  218. hdb_handle_t *object_handle,
  219. void *object_name,
  220. int *object_name_len);
  221. cs_error_t confdb_object_iter_destroy(
  222. confdb_handle_t handle,
  223. hdb_handle_t parent_object_handle);
  224. /*
  225. * Key iterator
  226. */
  227. cs_error_t confdb_key_iter_start (
  228. confdb_handle_t handle,
  229. hdb_handle_t object_handle);
  230. cs_error_t confdb_key_iter (
  231. confdb_handle_t handle,
  232. hdb_handle_t parent_object_handle,
  233. void *key_name,
  234. int *key_name_len,
  235. void *value,
  236. int *value_len);
  237. /*
  238. * Get/set context variable
  239. */
  240. cs_error_t confdb_context_get (
  241. confdb_handle_t handle,
  242. const void **context);
  243. cs_error_t confdb_context_set (
  244. confdb_handle_t handle,
  245. const void *context);
  246. #endif /* COROSYNC_CONFDB_H_DEFINED */