hdb.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2011 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef HDB_H_DEFINED
  36. #define HDB_H_DEFINED
  37. #ifndef _GNU_SOURCE
  38. #define _GNU_SOURCE
  39. #endif
  40. #include <errno.h>
  41. #include <assert.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <pthread.h>
  45. #include <stdint.h>
  46. #include <inttypes.h>
  47. #include <qb/qbhdb.h>
  48. typedef qb_handle_t hdb_handle_t;
  49. /*
  50. * Formatting for string printing on 32/64 bit systems
  51. */
  52. #define HDB_D_FORMAT QB_HDB_D_FORMAT
  53. #define HDB_X_FORMAT QB_HDB_X_FORMAT
  54. #define hdb_handle_database qb_hdb
  55. /**
  56. * @brief hdb_database_lock
  57. * @param mutex
  58. */
  59. static inline void hdb_database_lock (pthread_mutex_t *mutex)
  60. {
  61. pthread_mutex_lock (mutex);
  62. }
  63. /**
  64. * @brief hdb_database_unlock
  65. * @param mutex
  66. */
  67. static inline void hdb_database_unlock (pthread_mutex_t *mutex)
  68. {
  69. pthread_mutex_unlock (mutex);
  70. }
  71. /**
  72. * @brief hdb_database_lock_init
  73. * @param mutex
  74. */
  75. static inline void hdb_database_lock_init (pthread_mutex_t *mutex)
  76. {
  77. pthread_mutex_init (mutex, NULL);
  78. }
  79. /**
  80. * @brief hdb_database_lock_destroy
  81. * @param mutex
  82. */
  83. static inline void hdb_database_lock_destroy (pthread_mutex_t *mutex)
  84. {
  85. pthread_mutex_destroy (mutex);
  86. }
  87. #define DECLARE_HDB_DATABASE QB_HDB_DECLARE
  88. /**
  89. * @brief hdb_create
  90. * @param handle_database
  91. */
  92. static inline void hdb_create (
  93. struct hdb_handle_database *handle_database)
  94. {
  95. qb_hdb_create (handle_database);
  96. }
  97. /**
  98. * @brief hdb_destroy
  99. * @param handle_database
  100. */
  101. static inline void hdb_destroy (
  102. struct hdb_handle_database *handle_database)
  103. {
  104. qb_hdb_destroy (handle_database);
  105. }
  106. /**
  107. * @brief hdb_handle_create
  108. * @param handle_database
  109. * @param instance_size
  110. * @param handle_id_out
  111. * @return
  112. */
  113. static inline int hdb_handle_create (
  114. struct hdb_handle_database *handle_database,
  115. int instance_size,
  116. hdb_handle_t *handle_id_out)
  117. {
  118. return (qb_hdb_handle_create (handle_database, instance_size,
  119. handle_id_out));
  120. }
  121. /**
  122. * @brief hdb_handle_get
  123. * @param handle_database
  124. * @param handle_in
  125. * @param instance
  126. * @return
  127. */
  128. static inline int hdb_handle_get (
  129. struct hdb_handle_database *handle_database,
  130. hdb_handle_t handle_in,
  131. void **instance)
  132. {
  133. return (qb_hdb_handle_get (handle_database, handle_in, instance));
  134. }
  135. /**
  136. * @brief hdb_handle_get_always
  137. * @param handle_database
  138. * @param handle_in
  139. * @param instance
  140. * @return
  141. */
  142. static inline int hdb_handle_get_always (
  143. struct hdb_handle_database *handle_database,
  144. hdb_handle_t handle_in,
  145. void **instance)
  146. {
  147. return (qb_hdb_handle_get_always (handle_database, handle_in, instance));
  148. }
  149. /**
  150. * @brief hdb_handle_put
  151. * @param handle_database
  152. * @param handle_in
  153. * @return
  154. */
  155. static inline int hdb_handle_put (
  156. struct hdb_handle_database *handle_database,
  157. hdb_handle_t handle_in)
  158. {
  159. return (qb_hdb_handle_put (handle_database, handle_in));
  160. }
  161. /**
  162. * @brief hdb_handle_destroy
  163. * @param handle_database
  164. * @param handle_in
  165. * @return
  166. */
  167. static inline int hdb_handle_destroy (
  168. struct hdb_handle_database *handle_database,
  169. hdb_handle_t handle_in)
  170. {
  171. return (qb_hdb_handle_destroy (handle_database, handle_in));
  172. }
  173. /**
  174. * @brief hdb_handle_refcount_get
  175. * @param handle_database
  176. * @param handle_in
  177. * @return
  178. */
  179. static inline int hdb_handle_refcount_get (
  180. struct hdb_handle_database *handle_database,
  181. hdb_handle_t handle_in)
  182. {
  183. return (qb_hdb_handle_refcount_get (handle_database, handle_in));
  184. }
  185. /**
  186. * @brief hdb_iterator_reset
  187. * @param handle_database
  188. */
  189. static inline void hdb_iterator_reset (
  190. struct hdb_handle_database *handle_database)
  191. {
  192. qb_hdb_iterator_reset (handle_database);
  193. }
  194. /**
  195. * @brief hdb_iterator_next
  196. * @param handle_database
  197. * @param instance
  198. * @param handle
  199. * @return
  200. */
  201. static inline int hdb_iterator_next (
  202. struct hdb_handle_database *handle_database,
  203. void **instance,
  204. hdb_handle_t *handle)
  205. {
  206. return (qb_hdb_iterator_next (handle_database, instance, handle));
  207. }
  208. /**
  209. * @brief hdb_base_convert
  210. * @param handle
  211. * @return
  212. */
  213. static inline unsigned int hdb_base_convert (hdb_handle_t handle)
  214. {
  215. return (qb_hdb_base_convert (handle));
  216. }
  217. /**
  218. * @brief hdb_nocheck_convert
  219. * @param handle
  220. * @return
  221. */
  222. static inline unsigned long long hdb_nocheck_convert (unsigned int handle)
  223. {
  224. return (qb_hdb_nocheck_convert (handle));
  225. }
  226. #endif /* HDB_H_DEFINED */