confdb.h 6.5 KB

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