confdb.h 7.9 KB

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