confdb.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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.
  134. *
  135. * confdb_handle_t is NOT a file descriptor and may not be used directly.
  136. */
  137. cs_error_t confdb_fd_get (
  138. confdb_handle_t handle,
  139. int *fd);
  140. /**
  141. * Dispatch configuration changes
  142. */
  143. cs_error_t confdb_dispatch (
  144. confdb_handle_t handle,
  145. cs_dispatch_flags_t dispatch_types);
  146. /**
  147. * Change notification
  148. */
  149. cs_error_t confdb_track_changes (
  150. confdb_handle_t handle,
  151. hdb_handle_t object_handle,
  152. unsigned int flags);
  153. cs_error_t confdb_stop_track_changes (
  154. confdb_handle_t handle);
  155. /**
  156. * Manipulate objects
  157. */
  158. cs_error_t confdb_object_create (
  159. confdb_handle_t handle,
  160. hdb_handle_t parent_object_handle,
  161. const void *object_name,
  162. size_t object_name_len,
  163. hdb_handle_t *object_handle);
  164. cs_error_t confdb_object_destroy (
  165. confdb_handle_t handle,
  166. hdb_handle_t object_handle);
  167. cs_error_t confdb_object_parent_get (
  168. confdb_handle_t handle,
  169. hdb_handle_t object_handle,
  170. hdb_handle_t *parent_object_handle);
  171. cs_error_t confdb_object_name_get (
  172. confdb_handle_t handle,
  173. hdb_handle_t object_handle,
  174. char *object_name,
  175. size_t *object_name_len);
  176. /**
  177. * Manipulate keys
  178. */
  179. cs_error_t confdb_key_create (
  180. confdb_handle_t handle,
  181. hdb_handle_t parent_object_handle,
  182. const void *key_name,
  183. size_t key_name_len,
  184. const void *value,
  185. size_t value_len);
  186. cs_error_t confdb_key_create_typed (
  187. confdb_handle_t handle,
  188. hdb_handle_t parent_object_handle,
  189. const char *key_name,
  190. const void *value,
  191. size_t value_len,
  192. confdb_value_types_t type);
  193. cs_error_t confdb_key_delete (
  194. confdb_handle_t handle,
  195. hdb_handle_t parent_object_handle,
  196. const void *key_name,
  197. size_t key_name_len,
  198. const void *value,
  199. size_t value_len);
  200. /**
  201. * Key queries
  202. */
  203. cs_error_t confdb_key_get (
  204. confdb_handle_t handle,
  205. hdb_handle_t parent_object_handle,
  206. const void *key_name,
  207. size_t key_name_len,
  208. void *value,
  209. size_t *value_len);
  210. cs_error_t confdb_key_get_typed (
  211. confdb_handle_t handle,
  212. hdb_handle_t parent_object_handle,
  213. const char *key_name,
  214. void *value,
  215. size_t *value_len,
  216. confdb_value_types_t *type);
  217. cs_error_t confdb_key_replace (
  218. confdb_handle_t handle,
  219. hdb_handle_t parent_object_handle,
  220. const void *key_name,
  221. size_t key_name_len,
  222. const void *old_value,
  223. size_t old_value_len,
  224. const void *new_value,
  225. size_t new_value_len);
  226. cs_error_t confdb_key_increment (
  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. cs_error_t confdb_key_decrement (
  233. confdb_handle_t handle,
  234. hdb_handle_t parent_object_handle,
  235. const void *key_name,
  236. size_t key_name_len,
  237. unsigned int *value);
  238. /**
  239. * Object queries
  240. *
  241. * "find" loops through all objects of a given name and is also
  242. * a quick way of finding a specific object,
  243. *
  244. * "iter" returns each object in sequence.
  245. */
  246. cs_error_t confdb_object_find_start (
  247. confdb_handle_t handle,
  248. hdb_handle_t parent_object_handle);
  249. cs_error_t confdb_object_find (
  250. confdb_handle_t handle,
  251. hdb_handle_t parent_object_handle,
  252. const void *object_name,
  253. size_t object_name_len,
  254. hdb_handle_t *object_handle);
  255. cs_error_t confdb_object_find_destroy(
  256. confdb_handle_t handle,
  257. hdb_handle_t parent_object_handle);
  258. cs_error_t confdb_object_iter_start (
  259. confdb_handle_t handle,
  260. hdb_handle_t parent_object_handle);
  261. cs_error_t confdb_object_iter (
  262. confdb_handle_t handle,
  263. hdb_handle_t parent_object_handle,
  264. hdb_handle_t *object_handle,
  265. void *object_name,
  266. size_t *object_name_len);
  267. cs_error_t confdb_object_iter_destroy(
  268. confdb_handle_t handle,
  269. hdb_handle_t parent_object_handle);
  270. /**
  271. * Key iterator
  272. */
  273. cs_error_t confdb_key_iter_start (
  274. confdb_handle_t handle,
  275. hdb_handle_t object_handle);
  276. cs_error_t confdb_key_iter (
  277. confdb_handle_t handle,
  278. hdb_handle_t parent_object_handle,
  279. void *key_name,
  280. size_t *key_name_len,
  281. void *value,
  282. size_t *value_len);
  283. cs_error_t confdb_key_iter_typed (
  284. confdb_handle_t handle,
  285. hdb_handle_t parent_object_handle,
  286. char *key_name,
  287. void *value,
  288. size_t *value_len,
  289. confdb_value_types_t *type);
  290. /**
  291. * Get context variable
  292. */
  293. cs_error_t confdb_context_get (
  294. confdb_handle_t handle,
  295. const void **context);
  296. /**
  297. * Set context variable
  298. */
  299. cs_error_t confdb_context_set (
  300. confdb_handle_t handle,
  301. const void *context);
  302. #ifdef __cplusplus
  303. }
  304. #endif
  305. #endif /* COROSYNC_CONFDB_H_DEFINED */