confdb.h 8.1 KB

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