Put the objects before the libraries when building
[nmdb.git] / nmdb / be.h
blob37a821032c4be246b2eedb3985076f6898630629
2 #ifndef _BE_H
3 #define _BE_H
5 #include <stddef.h> /* size_t */
7 struct db_conn {
8 /* This is where the backend sets a reference to the connection, which
9 * will be properly casted when needed */
10 void *conn;
12 /* Operations */
13 int (*set)(struct db_conn *db, const unsigned char *key, size_t ksize,
14 unsigned char *val, size_t vsize);
15 int (*get)(struct db_conn *db, const unsigned char *key, size_t ksize,
16 unsigned char *val, size_t *vsize);
17 int (*del)(struct db_conn *db, const unsigned char *key, size_t ksize);
18 int (*firstkey)(struct db_conn *db, unsigned char *key, size_t *ksize);
19 int (*nextkey)(struct db_conn *db,
20 const unsigned char *key, size_t ksize,
21 unsigned char *nextkey, size_t *nksize);
22 int (*close)(struct db_conn *db);
25 enum backend_type {
26 /* The first two are special, used to indicate unknown and unsupported
27 * backends */
28 BE_UNKNOWN = -2,
29 BE_UNSUPPORTED = -1,
30 BE_QDBM = 1,
31 BE_BDB,
32 BE_TC,
33 BE_TDB,
34 BE_NULL,
37 /* Generic opener that knows about all the backends */
38 struct db_conn *db_open(enum backend_type type, const char *name, int flags);
40 /* Returns the backend type for the given name. */
41 enum backend_type be_type_from_str(const char *name);
43 /* Returns the backend name for the given type. */
44 const char *be_str_from_type(enum backend_type type);
46 /* String containing a list of all supported backends */
47 #if BE_ENABLE_QDBM
48 #define _QDBM_SUPP "qdbm "
49 #else
50 #define _QDBM_SUPP ""
51 #endif
53 #if BE_ENABLE_BDB
54 #define _BDB_SUPP "bdb "
55 #else
56 #define _BDB_SUPP ""
57 #endif
59 #if BE_ENABLE_TC
60 #define _TC_SUPP "tc "
61 #else
62 #define _TC_SUPP ""
63 #endif
65 #if BE_ENABLE_TDB
66 #define _TDB_SUPP "tdb "
67 #else
68 #define _TDB_SUPP ""
69 #endif
71 #if BE_ENABLE_NULL
72 #define _NULL_SUPP "null "
73 #else
74 #define _NULL_SUPP ""
75 #endif
77 #define SUPPORTED_BE _QDBM_SUPP _BDB_SUPP _TC_SUPP _TDB_SUPP _NULL_SUPP
80 /* Default backend */
81 #if BE_ENABLE_TDB
82 #define DEFAULT_BE BE_TDB
83 #define DEFAULT_BE_NAME "tdb"
84 #elif BE_ENABLE_TC
85 #define DEFAULT_BE BE_TC
86 #define DEFAULT_BE_NAME "tc"
87 #elif BE_ENABLE_QDBM
88 #define DEFAULT_BE BE_QDBM
89 #define DEFAULT_BE_NAME "qdbm"
90 #elif BE_ENABLE_BDB
91 #define DEFAULT_BE BE_BDB
92 #define DEFAULT_BE_NAME "bdb"
93 #elif BE_ENABLE_NULL
94 #warning "using null backend as the default"
95 #define DEFAULT_BE BE_NULL
96 #define DEFAULT_BE_NAME "null"
97 #else
98 #error "no backend available"
99 #endif
102 #endif