Functions | |
int | kdbGetValue (KDBHandle handle, const char *keyname, char *returned, size_t maxSize) |
A high-level method to get a key value, by key name. | |
int | kdbSetValue (KDBHandle handle, const char *keyname, const char *value) |
A high-level method to set a value to a key, by key name. | |
int | kdbGetValueByParent (KDBHandle handle, const char *parentName, const char *baseName, char *returned, size_t maxSize) |
Fill up the returned buffer with the value of a key, which name is the concatenation of parentName and baseName . | |
int | kdbSetValueByParent (KDBHandle handle, const char *parentName, const char *baseName, const char *value) |
Sets the provided value to the key whose name is the concatenation of parentName and baseName . | |
int | kdbGetKeyByParent (KDBHandle handle, const char *parentName, const char *baseName, Key *returned) |
Given a parent key name plus a basename, returns the key. | |
int | kdbGetKeyByParentKey (KDBHandle handle, const Key *parent, const char *baseName, Key *returned) |
Similar to previous, provided for convenience. | |
ssize_t | kdbGetChildKeys (KDBHandle handle, const char *parentName, KeySet *returned, unsigned long options) |
This method is similar and calls kdbGetKeyChildKeys(). | |
ssize_t | kdbGetRootKeys (KDBHandle handle, KeySet *returned) |
Returns a KeySet with all root keys currently recognized and present on the system. | |
int | kdbRemove (KDBHandle handle, const char *keyName) |
Remove a key by its name from the backend storage. |
To use them:
#include <kdb.h>
These methods are higher level. They use the above methods to do their job, and don't have to be reimplemented for a different backend.
Binding writers don't have to implement these functions, use features of the binding language instead. But you can use these functions as ideas what high level methods may be useful.
int kdbGetValue | ( | KDBHandle | handle, | |
const char * | keyname, | |||
char * | returned, | |||
size_t | maxSize | |||
) |
A high-level method to get a key value, by key name.
This method is valid only for string keys. You have to use other methods to get non-string keys.
keyname | the name of the key to receive the value | |
returned | a buffer to put the key value | |
maxSize | the size of the buffer |
-1 on failure and errno
is propagated
Definition at line 114 of file kdbhighlevel.c.
References kdbGetKey(), KEY_SWITCH_END, keyDel(), keyGetString(), and keyNew().
Referenced by kdbGetValueByParent().
int kdbSetValue | ( | KDBHandle | handle, | |
const char * | keyname, | |||
const char * | value | |||
) |
A high-level method to set a value to a key, by key name.
It will obviously check if key exists first, and keep its metadata. So you'll not loose the precious key comment.
This will set a text key. So if the key was previously a binary, etc key, it will be retyped as text.
keyname | the name of the key to receive the value | |
value | the value to be set |
-1 on failure and errno
is propagated KDB_RET_TYPEMISMATCH if key is a directory
Definition at line 145 of file kdbhighlevel.c.
References KDB_RET_TYPEMISMATCH, kdbGetKey(), kdbSetKey(), KEY_SWITCH_END, keyDel(), keyIsDir(), keyNew(), and keySetString().
Referenced by kdbSetValueByParent().
int kdbGetValueByParent | ( | KDBHandle | handle, | |
const char * | parentName, | |||
const char * | baseName, | |||
char * | returned, | |||
size_t | maxSize | |||
) |
Fill up the returned
buffer with the value of a key, which name is the concatenation of parentName
and baseName
.
char *parent="user/sw/MyApp"; char *keys[]={"key1","key2","key3"}; char buffer[150]; // a big buffer int c; for (c=0; c<3; c++) { kdbGetValueByParent(handle,parent,keys[c],buffer,sizeof(buffer)); // Do something with buffer.... }
parentName | the name of the parent key | |
baseName | the name of the child key | |
returned | pre-allocated buffer to be filled with key value | |
maxSize | size of the returned buffer |
-1 on failure and errno
is propagated
Definition at line 193 of file kdbhighlevel.c.
References kdbGetValue(), and strblen().
int kdbSetValueByParent | ( | KDBHandle | handle, | |
const char * | parentName, | |||
const char * | baseName, | |||
const char * | value | |||
) |
Sets the provided value
to the key whose name is the concatenation of parentName
and baseName
.
parentName | the name of the parent key | |
baseName | the name of the child key | |
value | the value to set |
-1 on failure and errno
is propagated
Definition at line 217 of file kdbhighlevel.c.
References kdbSetValue(), and strblen().
int kdbGetKeyByParent | ( | KDBHandle | handle, | |
const char * | parentName, | |||
const char * | baseName, | |||
Key * | returned | |||
) |
Given a parent key name plus a basename, returns the key.
So here you'll provide something like
system/sw/myApp
plus key1
to get system/sw/myApp/key1
user/sw/MyApp
plus dir1/key2
to get user/sw/MyApp/dir1/key2
parentName | parent key name | |
baseName | leaf or child name | |
returned | a pointer to an initialized key to be filled |
-1 on failure and errno
is propagated
Definition at line 245 of file kdbhighlevel.c.
References kdbGetKey(), keySetName(), and strblen().
int kdbGetKeyByParentKey | ( | KDBHandle | handle, | |
const Key * | parent, | |||
const char * | baseName, | |||
Key * | returned | |||
) |
Similar to previous, provided for convenience.
parent | pointer to the parent key |
errno
is set Definition at line 263 of file kdbhighlevel.c.
References kdbGetKey(), keyGetFullName(), keyGetFullNameSize(), keySetName(), and strblen().
ssize_t kdbGetChildKeys | ( | KDBHandle | handle, | |
const char * | parentName, | |||
KeySet * | returned, | |||
unsigned long | options | |||
) |
This method is similar and calls kdbGetKeyChildKeys().
It is provided for convenience.
Instead of passing the parentName with a key it directly uses a string.
-1 on failure and errno
is propagated from kdbGetKeyChildKeys()
Definition at line 290 of file kdbhighlevel.c.
References kdbGetKeyChildKeys(), KEY_SWITCH_END, keyDel(), and keyNew().
Referenced by commandEdit(), and commandList().
ssize_t kdbGetRootKeys | ( | KDBHandle | handle, | |
KeySet * | returned | |||
) |
Returns a KeySet with all root keys currently recognized and present on the system.
Currently, the system
and current user's user
keys are returned.
returned | the initialized KeySet to be filled |
-1 on failure and errno
is propagated
commandList() code in KeyDB :: Class Methods command for usage example
Definition at line 318 of file kdbhighlevel.c.
References _Key::flags, KEY_SWITCH_END, KEY_SWITCH_FLAG, KEY_SWITCH_NEEDSYNC, keyDel(), keyNew(), ksInsert(), and _KeySet::size.
Referenced by commandList().
int kdbRemove | ( | KDBHandle | handle, | |
const char * | keyName | |||
) |
Remove a key by its name from the backend storage.
This is a convenience to kdbRemoveKey().
keyName | the name of the key to be removed |
-1 on failure and errno
is propagated
Definition at line 350 of file kdbhighlevel.c.
References kdbRemoveKey(), KEY_SWITCH_END, keyDel(), keyNew(), and keySetName().
Referenced by commandEdit(), and commandRemove().