confdb.h 7.1 KB

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