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
36 #ifndef HDB_H_DEFINED
37 #define HDB_H_DEFINED
38
39 #ifndef _GNU_SOURCE
40 #define _GNU_SOURCE
41 #endif
42
43 #include <errno.h>
44 #include <assert.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <pthread.h>
48 #include <stdint.h>
49 #include <inttypes.h>
50 #include <qb/qbhdb.h>
51
52 typedef qb_handle_t hdb_handle_t;
53
54 /*
55 * Formatting for string printing on 32/64 bit systems
56 */
57 #define HDB_D_FORMAT QB_HDB_D_FORMAT
58 #define HDB_X_FORMAT QB_HDB_X_FORMAT
59
60 #define hdb_handle_database qb_hdb
61
62 /**
63 * @brief hdb_database_lock
64 * @param mutex
65 */
hdb_database_lock(pthread_mutex_t * mutex)66 static inline void hdb_database_lock (pthread_mutex_t *mutex)
67 {
68 pthread_mutex_lock (mutex);
69 }
70
71 /**
72 * @brief hdb_database_unlock
73 * @param mutex
74 */
hdb_database_unlock(pthread_mutex_t * mutex)75 static inline void hdb_database_unlock (pthread_mutex_t *mutex)
76 {
77 pthread_mutex_unlock (mutex);
78 }
79
80 /**
81 * @brief hdb_database_lock_init
82 * @param mutex
83 */
hdb_database_lock_init(pthread_mutex_t * mutex)84 static inline void hdb_database_lock_init (pthread_mutex_t *mutex)
85 {
86 pthread_mutex_init (mutex, NULL);
87 }
88
89 /**
90 * @brief hdb_database_lock_destroy
91 * @param mutex
92 */
hdb_database_lock_destroy(pthread_mutex_t * mutex)93 static inline void hdb_database_lock_destroy (pthread_mutex_t *mutex)
94 {
95 pthread_mutex_destroy (mutex);
96 }
97
98 #define DECLARE_HDB_DATABASE QB_HDB_DECLARE
99
100 /**
101 * @brief hdb_create
102 * @param handle_database
103 */
hdb_create(struct hdb_handle_database * handle_database)104 static inline void hdb_create (
105 struct hdb_handle_database *handle_database)
106 {
107 qb_hdb_create (handle_database);
108 }
109
110 /**
111 * @brief hdb_destroy
112 * @param handle_database
113 */
hdb_destroy(struct hdb_handle_database * handle_database)114 static inline void hdb_destroy (
115 struct hdb_handle_database *handle_database)
116 {
117 qb_hdb_destroy (handle_database);
118 }
119
120 /**
121 * @brief hdb_handle_create
122 * @param handle_database
123 * @param instance_size
124 * @param handle_id_out
125 * @return
126 */
hdb_handle_create(struct hdb_handle_database * handle_database,int instance_size,hdb_handle_t * handle_id_out)127 static inline int hdb_handle_create (
128 struct hdb_handle_database *handle_database,
129 int instance_size,
130 hdb_handle_t *handle_id_out)
131 {
132 return (qb_hdb_handle_create (handle_database, instance_size,
133 handle_id_out));
134 }
135
136 /**
137 * @brief hdb_handle_get
138 * @param handle_database
139 * @param handle_in
140 * @param instance
141 * @return
142 */
hdb_handle_get(struct hdb_handle_database * handle_database,hdb_handle_t handle_in,void ** instance)143 static inline int hdb_handle_get (
144 struct hdb_handle_database *handle_database,
145 hdb_handle_t handle_in,
146 void **instance)
147 {
148 return (qb_hdb_handle_get (handle_database, handle_in, instance));
149 }
150
151 /**
152 * @brief hdb_handle_get_always
153 * @param handle_database
154 * @param handle_in
155 * @param instance
156 * @return
157 */
hdb_handle_get_always(struct hdb_handle_database * handle_database,hdb_handle_t handle_in,void ** instance)158 static inline int hdb_handle_get_always (
159 struct hdb_handle_database *handle_database,
160 hdb_handle_t handle_in,
161 void **instance)
162 {
163 return (qb_hdb_handle_get_always (handle_database, handle_in, instance));
164 }
165
166 /**
167 * @brief hdb_handle_put
168 * @param handle_database
169 * @param handle_in
170 * @return
171 */
hdb_handle_put(struct hdb_handle_database * handle_database,hdb_handle_t handle_in)172 static inline int hdb_handle_put (
173 struct hdb_handle_database *handle_database,
174 hdb_handle_t handle_in)
175 {
176 return (qb_hdb_handle_put (handle_database, handle_in));
177 }
178
179 /**
180 * @brief hdb_handle_destroy
181 * @param handle_database
182 * @param handle_in
183 * @return
184 */
hdb_handle_destroy(struct hdb_handle_database * handle_database,hdb_handle_t handle_in)185 static inline int hdb_handle_destroy (
186 struct hdb_handle_database *handle_database,
187 hdb_handle_t handle_in)
188 {
189 return (qb_hdb_handle_destroy (handle_database, handle_in));
190 }
191
192 /**
193 * @brief hdb_handle_refcount_get
194 * @param handle_database
195 * @param handle_in
196 * @return
197 */
hdb_handle_refcount_get(struct hdb_handle_database * handle_database,hdb_handle_t handle_in)198 static inline int hdb_handle_refcount_get (
199 struct hdb_handle_database *handle_database,
200 hdb_handle_t handle_in)
201 {
202 return (qb_hdb_handle_refcount_get (handle_database, handle_in));
203 }
204
205 /**
206 * @brief hdb_iterator_reset
207 * @param handle_database
208 */
hdb_iterator_reset(struct hdb_handle_database * handle_database)209 static inline void hdb_iterator_reset (
210 struct hdb_handle_database *handle_database)
211 {
212 qb_hdb_iterator_reset (handle_database);
213 }
214
215 /**
216 * @brief hdb_iterator_next
217 * @param handle_database
218 * @param instance
219 * @param handle
220 * @return
221 */
hdb_iterator_next(struct hdb_handle_database * handle_database,void ** instance,hdb_handle_t * handle)222 static inline int hdb_iterator_next (
223 struct hdb_handle_database *handle_database,
224 void **instance,
225 hdb_handle_t *handle)
226 {
227 return (qb_hdb_iterator_next (handle_database, instance, handle));
228 }
229
230 /**
231 * @brief hdb_base_convert
232 * @param handle
233 * @return
234 */
hdb_base_convert(hdb_handle_t handle)235 static inline unsigned int hdb_base_convert (hdb_handle_t handle)
236 {
237 return (qb_hdb_base_convert (handle));
238 }
239
240 /**
241 * @brief hdb_nocheck_convert
242 * @param handle
243 * @return
244 */
hdb_nocheck_convert(unsigned int handle)245 static inline unsigned long long hdb_nocheck_convert (unsigned int handle)
246 {
247 return (qb_hdb_nocheck_convert (handle));
248 }
249
250 #endif /* HDB_H_DEFINED */
251