nmdb: Add LevelDB support
[nmdb.git] / nmdb / be.h
blob802b9bcead9ff6439498a2369579738fbf12143e
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_LEVELDB,
35 BE_NULL,
38 /* Generic opener that knows about all the backends */
39 struct db_conn *db_open(enum backend_type type, const char *name, int flags);
41 /* Returns the backend type for the given name. */
42 enum backend_type be_type_from_str(const char *name);
44 /* Returns the backend name for the given type. */
45 const char *be_str_from_type(enum backend_type type);
47 /* String containing a list of all supported backends */
48 #if BE_ENABLE_QDBM
49 #define _QDBM_SUPP "qdbm "
50 #else
51 #define _QDBM_SUPP ""
52 #endif
54 #if BE_ENABLE_BDB
55 #define _BDB_SUPP "bdb "
56 #else
57 #define _BDB_SUPP ""
58 #endif
60 #if BE_ENABLE_TC
61 #define _TC_SUPP "tc "
62 #else
63 #define _TC_SUPP ""
64 #endif
66 #if BE_ENABLE_TDB
67 #define _TDB_SUPP "tdb "
68 #else
69 #define _TDB_SUPP ""
70 #endif
72 #if BE_ENABLE_LEVELDB
73 #define _LEVELDB_SUPP "leveldb "
74 #else
75 #define _LEVELDB_SUPP ""
76 #endif
78 #if BE_ENABLE_NULL
79 #define _NULL_SUPP "null "
80 #else
81 #define _NULL_SUPP ""
82 #endif
84 #define SUPPORTED_BE \
85 _QDBM_SUPP _BDB_SUPP _TC_SUPP _TDB_SUPP _LEVELDB_SUPP _NULL_SUPP
88 /* Default backend */
89 #if BE_ENABLE_TDB
90 #define DEFAULT_BE BE_TDB
91 #define DEFAULT_BE_NAME "tdb"
92 #elif BE_ENABLE_TC
93 #define DEFAULT_BE BE_TC
94 #define DEFAULT_BE_NAME "tc"
95 #elif BE_ENABLE_QDBM
96 #define DEFAULT_BE BE_QDBM
97 #define DEFAULT_BE_NAME "qdbm"
98 #elif BE_ENABLE_BDB
99 #define DEFAULT_BE BE_BDB
100 #define DEFAULT_BE_NAME "bdb"
101 #elif BE_ENABLE_LEVELDB
102 #define DEFAULT_BE BE_LEVELDB
103 #define DEFAULT_BE_NAME "leveldb"
104 #elif BE_ENABLE_NULL
105 #warning "using null backend as the default"
106 #define DEFAULT_BE BE_NULL
107 #define DEFAULT_BE_NAME "null"
108 #else
109 #error "no backend available"
110 #endif
113 #endif