regify utility  2.0.0-0
kvstore.h
1 /*
2  * Copyright regify
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
45 #ifndef REGIFY_UTIL_KVSTORE_H
46 #define REGIFY_UTIL_KVSTORE_H
47 /* Only need to export C interface if used by C++ source code */
48 #ifdef __cplusplus
49 extern "C" {
50 #endif /* __cplusplus */
54 struct KvStore_;
55 
64 typedef int32_t (*kvset) (struct KvStore_* kvs, const char* key,
65  const char* val, rusize len);
66 
77 typedef int32_t (*kvget) (struct KvStore_* kvs, const char* key,
78  char** val, rusize* len);
79 
88 typedef int32_t (*kvlist) (struct KvStore_* kvs, const char* key,
89  ruList* list);
90 
96 typedef struct KvStore_ {
98  // internal
99  ru_uint type;
100  ruFreeFunc ctxFree;
109  void* ctx;
111 
117 RUAPI KvStore* ruNewStore(void);
118 
123 RUAPI void ruFreeStore(void* obj);
124 
130 RUAPI int32_t ruValidStore(void* obj);
131 
135 typedef void* ruFileStore;
136 
144 RUAPI KvStore* ruNewFileStore (const char *folderPath, int32_t* code);
145 
155 RUAPI int32_t ruFileStoreSet (KvStore *kvs, const char* key, const char *val, rusize len);
156 
166 RUAPI int32_t ruFileStoreGet (KvStore *kvs, const char* key, char **val, rusize* len);
167 
176 RUAPI int32_t ruFileStoreList (KvStore *kvs, const char* key, ruList* result);
177 
181 typedef void* ruNullStore;
182 
188 RUAPI KvStore* ruNewNullStore(void);
189 
198 RUAPI int32_t ruNullStoreSet (KvStore *kvs, const char* key, const char *val, rusize len);
199 
208 RUAPI int32_t ruNullStoreGet (KvStore *kvs, const char* key, char **val, rusize* len);
209 
217 RUAPI int32_t ruNullStoreList (KvStore *kvs, const char* key, ruList* list);
218 
222 #ifdef __cplusplus
223 }
224 #endif /* __cplusplus */
225 #endif //REGIFY_UTIL_KVSTORE_H
RUAPI KvStore * ruNewStore(void)
Returns a generic KvStore interface. This function is mainly used by those implementing the KvStore i...
void * ruNullStore
Opaque pointer to a Null KvStore interface.
Definition: kvstore.h:181
void * ruFileStore
Opaque pointer to a File based KvStore interface.
Definition: kvstore.h:135
int32_t(* kvget)(struct KvStore_ *kvs, const char *key, char **val, rusize *len)
KvStore getter function interface.
Definition: kvstore.h:77
RUAPI int32_t ruFileStoreList(KvStore *kvs, const char *key, ruList *result)
Returns a list of keys under the given key.
int32_t(* kvlist)(struct KvStore_ *kvs, const char *key, ruList *list)
KvStore list function interface.
Definition: kvstore.h:88
RUAPI KvStore * ruNewFileStore(const char *folderPath, int32_t *code)
Returns a newly created file system based KvStore object. If there is already store data in the given...
RUAPI int32_t ruNullStoreList(KvStore *kvs, const char *key, ruList *list)
Returns a list of items under given key.
RUAPI void ruFreeStore(void *obj)
Public function to free the given KvStore object.
int32_t(* kvset)(struct KvStore_ *kvs, const char *key, const char *val, rusize len)
KvStore setter function interface.
Definition: kvstore.h:64
struct KvStore_ KvStore
The key/value store interface type. This object holds the kvget, kvlist and kvset methods of an imple...
RUAPI int32_t ruFileStoreGet(KvStore *kvs, const char *key, char **val, rusize *len)
Get the value of key from the given FileStore.
RUAPI int32_t ruValidStore(void *obj)
Checks given object to be a valid KvStore object.
RUAPI KvStore * ruNewNullStore(void)
Returns a newly created NULL based KvStore interface. This keystore silently ignores setters and neve...
RUAPI int32_t ruFileStoreSet(KvStore *kvs, const char *key, const char *val, rusize len)
Set the value of key in the given FileStore.
RUAPI int32_t ruNullStoreGet(KvStore *kvs, const char *key, char **val, rusize *len)
Get the value of key from the given KvStore.
RUAPI int32_t ruNullStoreSet(KvStore *kvs, const char *key, const char *val, rusize len)
Set the value of key in the given FileStore.
void * ruList
Opaque pointer to list object. See List Collection.
Definition: list.h:103
void(* ruFreeFunc)(ptr o)
Signature of a generic free function.
Definition: regify-util.h:363
uintptr_t ru_uint
A pointer sized unsigned integer type for collections like ruMap or ruList.
Definition: regify-util.h:333
size_t rusize
Abstracted version of size_t.
Definition: regify-util.h:338
The key/value store interface type. This object holds the kvget, kvlist and kvset methods of an imple...
Definition: kvstore.h:96
void * ctx
A user defined context that will be passed to all given methods.
Definition: kvstore.h:109
kvlist list
The method that will be called to list data keys.
Definition: kvstore.h:107
kvget get
The method that will be called to retrieve data.
Definition: kvstore.h:105
kvset set
The method that will be called to set data.
Definition: kvstore.h:103