confdb.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 OPENAIS_CONFDB_H_DEFINED
  35. #define OPENAIS_CONFDB_H_DEFINED
  36. /**
  37. * @addtogroup confdb_openais
  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. * Get a file descriptor on which to poll. confdb_handle_t is NOT a
  119. * file descriptor and may not be used directly.
  120. */
  121. confdb_error_t confdb_fd_get (
  122. confdb_handle_t handle,
  123. int *fd);
  124. /*
  125. * Dispatch configuration changes
  126. */
  127. confdb_error_t confdb_dispatch (
  128. confdb_handle_t handle,
  129. confdb_dispatch_t dispatch_types);
  130. /*
  131. * Change notification
  132. */
  133. confdb_error_t confdb_track_changes (
  134. confdb_handle_t handle,
  135. unsigned int object_handle,
  136. unsigned int flags);
  137. confdb_error_t confdb_stop_track_changes (
  138. confdb_handle_t handle);
  139. /*
  140. * Manipulate objects
  141. */
  142. confdb_error_t confdb_object_create (
  143. confdb_handle_t handle,
  144. unsigned int parent_object_handle,
  145. void *object_name,
  146. int object_name_len,
  147. unsigned int *object_handle);
  148. confdb_error_t confdb_object_destroy (
  149. confdb_handle_t handle,
  150. unsigned int object_handle);
  151. confdb_error_t confdb_object_parent_get (
  152. confdb_handle_t handle,
  153. unsigned int object_handle,
  154. unsigned int *parent_object_handle);
  155. /*
  156. * Manipulate keys
  157. */
  158. confdb_error_t confdb_key_create (
  159. confdb_handle_t handle,
  160. unsigned int parent_object_handle,
  161. void *key_name,
  162. int key_name_len,
  163. void *value,
  164. int value_len);
  165. confdb_error_t confdb_key_delete (
  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. /*
  173. * Key queries
  174. */
  175. confdb_error_t confdb_key_get (
  176. confdb_handle_t handle,
  177. unsigned int parent_object_handle,
  178. void *key_name,
  179. int key_name_len,
  180. void *value,
  181. int *value_len);
  182. confdb_error_t confdb_key_replace (
  183. confdb_handle_t handle,
  184. unsigned int parent_object_handle,
  185. void *key_name,
  186. int key_name_len,
  187. void *old_value,
  188. int old_value_len,
  189. void *new_value,
  190. int new_value_len);
  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. confdb_error_t confdb_object_find_start (
  198. confdb_handle_t handle,
  199. unsigned int parent_object_handle);
  200. confdb_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. confdb_error_t confdb_object_iter_start (
  207. confdb_handle_t handle,
  208. unsigned int parent_object_handle);
  209. confdb_error_t confdb_object_iter (
  210. confdb_handle_t handle,
  211. unsigned int parent_object_handle,
  212. unsigned int *object_handle,
  213. void *object_name,
  214. int *object_name_len);
  215. /*
  216. * Key iterator
  217. */
  218. confdb_error_t confdb_key_iter_start (
  219. confdb_handle_t handle,
  220. unsigned int object_handle);
  221. confdb_error_t confdb_key_iter (
  222. confdb_handle_t handle,
  223. unsigned int parent_object_handle,
  224. void *key_name,
  225. int *key_name_len,
  226. void *value,
  227. int *value_len);
  228. #endif /* OPENAIS_CONFDB_H_DEFINED */