hdb.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. static inline void hdb_database_lock (pthread_mutex_t *mutex)
  56. {
  57. pthread_mutex_lock (mutex);
  58. }
  59. static inline void hdb_database_unlock (pthread_mutex_t *mutex)
  60. {
  61. pthread_mutex_unlock (mutex);
  62. }
  63. static inline void hdb_database_lock_init (pthread_mutex_t *mutex)
  64. {
  65. pthread_mutex_init (mutex, NULL);
  66. }
  67. static inline void hdb_database_lock_destroy (pthread_mutex_t *mutex)
  68. {
  69. pthread_mutex_destroy (mutex);
  70. }
  71. #define DECLARE_HDB_DATABASE QB_HDB_DECLARE
  72. static inline void hdb_create (
  73. struct hdb_handle_database *handle_database)
  74. {
  75. qb_hdb_create (handle_database);
  76. }
  77. static inline void hdb_destroy (
  78. struct hdb_handle_database *handle_database)
  79. {
  80. qb_hdb_destroy (handle_database);
  81. }
  82. static inline int hdb_handle_create (
  83. struct hdb_handle_database *handle_database,
  84. int instance_size,
  85. hdb_handle_t *handle_id_out)
  86. {
  87. return (qb_hdb_handle_create (handle_database, instance_size,
  88. handle_id_out));
  89. }
  90. static inline int hdb_handle_get (
  91. struct hdb_handle_database *handle_database,
  92. hdb_handle_t handle_in,
  93. void **instance)
  94. {
  95. return (qb_hdb_handle_get (handle_database, handle_in, instance));
  96. }
  97. static inline int hdb_handle_get_always (
  98. struct hdb_handle_database *handle_database,
  99. hdb_handle_t handle_in,
  100. void **instance)
  101. {
  102. return (qb_hdb_handle_get_always (handle_database, handle_in, instance));
  103. }
  104. static inline int hdb_handle_put (
  105. struct hdb_handle_database *handle_database,
  106. hdb_handle_t handle_in)
  107. {
  108. return (qb_hdb_handle_put (handle_database, handle_in));
  109. }
  110. static inline int hdb_handle_destroy (
  111. struct hdb_handle_database *handle_database,
  112. hdb_handle_t handle_in)
  113. {
  114. return (qb_hdb_handle_destroy (handle_database, handle_in));
  115. }
  116. static inline int hdb_handle_refcount_get (
  117. struct hdb_handle_database *handle_database,
  118. hdb_handle_t handle_in)
  119. {
  120. return (qb_hdb_handle_refcount_get (handle_database, handle_in));
  121. }
  122. static inline void hdb_iterator_reset (
  123. struct hdb_handle_database *handle_database)
  124. {
  125. qb_hdb_iterator_reset (handle_database);
  126. }
  127. static inline int hdb_iterator_next (
  128. struct hdb_handle_database *handle_database,
  129. void **instance,
  130. hdb_handle_t *handle)
  131. {
  132. return (qb_hdb_iterator_next (handle_database, instance, handle));
  133. }
  134. static inline unsigned int hdb_base_convert (hdb_handle_t handle)
  135. {
  136. return (qb_hdb_base_convert (handle));
  137. }
  138. static inline unsigned long long hdb_nocheck_convert (unsigned int handle)
  139. {
  140. return (qb_hdb_nocheck_convert (handle));
  141. }
  142. #endif /* HDB_H_DEFINED */