Elektra
0.9.11
|
Constructs a class KDB. More...
#include <kdb.hpp>
Public Member Functions | |
KDB () | |
Constructs a class KDB. More... | |
KDB (Key &errorKey) | |
Constructs a class KDB. More... | |
KDB (KeySet &contract) | |
Constructs a class KDB. More... | |
KDB (KeySet &contract, Key &errorKey) | |
Constructs a class KDB. More... | |
virtual void | open (Key &errorKey) |
Open the database. More... | |
virtual void | open (KeySet &contract, Key &errorKey) |
Open the database. More... | |
virtual void | close () throw () |
Close the database. More... | |
virtual void | close (Key &errorKey) throw () |
Close the database. More... | |
virtual int | get (KeySet &returned, std::string const &keyname) |
Get all keys below keyname inside returned. More... | |
virtual int | get (KeySet &returned, Key &parentKey) |
Get all keys below parentKey inside returned. More... | |
virtual int | set (KeySet &returned, std::string const &keyname) |
Set all keys below keyname. More... | |
virtual int | set (KeySet &returned, Key &parentKey) |
Set all keys below parentKey. More... | |
Constructs a class KDB.
KDBException | if database could not be opened |
Opens the session with the Key database.
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the Key database (KDB), you must not forget to call kdbClose() to free resources.
The method will bootstrap itself in the following way. The first step is to open the default backend. With it system:/elektra/mountpoints
will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the contract
is processed. Finally, the libraries for backends will be loaded and with it the KDB
data structure will be initialized.
The pointer to the KDB
structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.
Get a KDB
handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:
You don't need kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects.
contract | the contract that should be ensured before opening the KDB all data is copied and the KeySet can safely be used for e.g. kdbGet() later |
errorKey | the key which holds errors and warnings which were issued |
NULL | on failure |
Access to the key database.
|
inline |
Constructs a class KDB.
KDBException | if database could not be opened |
Opens the session with the Key database.
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the Key database (KDB), you must not forget to call kdbClose() to free resources.
The method will bootstrap itself in the following way. The first step is to open the default backend. With it system:/elektra/mountpoints
will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the contract
is processed. Finally, the libraries for backends will be loaded and with it the KDB
data structure will be initialized.
The pointer to the KDB
structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.
Get a KDB
handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:
You don't need kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects.
contract | the contract that should be ensured before opening the KDB all data is copied and the KeySet can safely be used for e.g. kdbGet() later |
errorKey | the key which holds errors and warnings which were issued |
NULL | on failure |
|
inlineexplicit |
Constructs a class KDB.
errorKey | is useful if you want to get the warnings in the successful case, when no exception is thrown. |
KDBException | if database could not be opened |
Opens the session with the Key database.
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the Key database (KDB), you must not forget to call kdbClose() to free resources.
The method will bootstrap itself in the following way. The first step is to open the default backend. With it system:/elektra/mountpoints
will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the contract
is processed. Finally, the libraries for backends will be loaded and with it the KDB
data structure will be initialized.
The pointer to the KDB
structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.
Get a KDB
handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:
You don't need kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects.
contract | the contract that should be ensured before opening the KDB all data is copied and the KeySet can safely be used for e.g. kdbGet() later |
errorKey | the key which holds errors and warnings which were issued |
NULL | on failure |
|
inlineexplicit |
Constructs a class KDB.
contract | the contract that should be ensured |
errorKey | is useful if you want to get the warnings in the successful case, when no exception is thrown. |
KDBException | if database could not be opened |
Opens the session with the Key database.
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the Key database (KDB), you must not forget to call kdbClose() to free resources.
The method will bootstrap itself in the following way. The first step is to open the default backend. With it system:/elektra/mountpoints
will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the contract
is processed. Finally, the libraries for backends will be loaded and with it the KDB
data structure will be initialized.
The pointer to the KDB
structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.
Get a KDB
handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:
You don't need kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects.
contract | the contract that should be ensured before opening the KDB all data is copied and the KeySet can safely be used for e.g. kdbGet() later |
errorKey | the key which holds errors and warnings which were issued |
NULL | on failure |
Constructs a class KDB.
contract | the contract that should be ensured |
errorKey | is useful if you want to get the warnings in the successful case, when no exception is thrown. |
KDBException | if database could not be opened |
Opens the session with the Key database.
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the Key database (KDB), you must not forget to call kdbClose() to free resources.
The method will bootstrap itself in the following way. The first step is to open the default backend. With it system:/elektra/mountpoints
will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the contract
is processed. Finally, the libraries for backends will be loaded and with it the KDB
data structure will be initialized.
The pointer to the KDB
structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.
Get a KDB
handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:
You don't need kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects.
contract | the contract that should be ensured before opening the KDB all data is copied and the KeySet can safely be used for e.g. kdbGet() later |
errorKey | the key which holds errors and warnings which were issued |
NULL | on failure |
|
inlinevirtual |
Close the database.
The return value does not matter because its only a null pointer check.
Closes the session with the Key database.
This is the counterpart of kdbOpen().
You must call this method when you are finished working with the Key database. You can manipulate Key and KeySet objects also after kdbClose(), but you must not use any kdb*() call afterwards.
The handle
parameter will be finalized and all resources associated to it will be freed. After a kdbClose(), the handle
cannot be used anymore.
handle | contains internal information of opened key database |
errorKey | the key which holds error/warning information |
0 | on success |
-1 | on NULL pointer |
|
inlinevirtual |
Close the database.
The return value does not matter because its only a null pointer check.
errorKey | is useful if you want to get the warnings |
Closes the session with the Key database.
This is the counterpart of kdbOpen().
You must call this method when you are finished working with the Key database. You can manipulate Key and KeySet objects also after kdbClose(), but you must not use any kdb*() call afterwards.
The handle
parameter will be finalized and all resources associated to it will be freed. After a kdbClose(), the handle
cannot be used anymore.
handle | contains internal information of opened key database |
errorKey | the key which holds error/warning information |
0 | on success |
-1 | on NULL pointer |
Get all keys below parentKey inside returned.
Retrieve Keys from a Key database in an atomic and universal way.
handle
must be passed as returned from kdbOpen(). returned
KeySet must be a valid KeySet, e.g. constructed with ksNew(). parentKey
Key must be a valid Key, e.g. constructed with keyNew().If you pass NULL on any parameter, kdbGet() will fail immediately without doing anything.
The returned KeySet ks
may already contain some keys, e.g. from previous kdbGet() calls. The newly retrieved Keys will be appended using ksAppendKey().
If not done earlier, kdbGet() will fully retrieve all keys under the parentKey
folder recursively (See Optimization below when it will not be done). Cascading Keys (starting with /) will retrieve the same path in all namespaces. /
will retrieve all Keys in handle
.
It is recommended to use the most specific parentKey
possible. (e.g. using system:/
is rarely the most specific)
proc:/
keys, must be passed to calls of kdbSet(), otherwise they will be lost. This stems from the fact that the user has the only copy of the whole configuration and backends only write configuration that was passed to them. For example, if you kdbGet() "system:/mountpoint/interest" you will not only get all Keys below system:/mountpoint/interest, but also all Keys below system:/mountpoint (if system:/mountpoint is a mountpoint as the name suggests, but system:/mountpoint/interest is not a mountpoint). Make sure to not touch or remove Keys outside the Keys of interest, because others may need them!When a backend fails kdbGet() will return -1 with all error and warning information in the parentKey
. The parameter returned
will not be changed.
It is your responsibility to save the original KeySet if you need it afterwards.
If you want to be sure to get a fresh KeySet again, you need to open a second handle to the Key database using kdbOpen().
handle | contains internal information of opened key database |
parentKey | Keys below parentKey will be retrieved from handle . It is also used to add warnings and set error information. |
ks | the (pre-initialized) KeySet returned with all keys found will not be changed on error or if no update is required |
1 | if the Keys were retrieved successfully. There might be warnings attached to the parentKey! Depending on your use case, you might need to treat them as errors! |
0 | if there was no update - no changes are made to the KeySet then. There might be warnings attached to the parentKey! Depending on your use case, you might need to treat them as erorrs! |
-1 | on failure - no changes are made to the KeySet then |
returned | the keyset where the keys will be in |
parentKey | the parentKey of returned |
0 | if no key was updated |
1 | if user or system keys were updated |
2 | if user and system keys were updated |
KDBException | if there were problems with the database |
Reimplemented in kdb::tools::merging::MergingKDB.
|
inlinevirtual |
Get all keys below keyname inside returned.
Retrieve Keys from a Key database in an atomic and universal way.
handle
must be passed as returned from kdbOpen(). returned
KeySet must be a valid KeySet, e.g. constructed with ksNew(). parentKey
Key must be a valid Key, e.g. constructed with keyNew().If you pass NULL on any parameter, kdbGet() will fail immediately without doing anything.
The returned KeySet ks
may already contain some keys, e.g. from previous kdbGet() calls. The newly retrieved Keys will be appended using ksAppendKey().
If not done earlier, kdbGet() will fully retrieve all keys under the parentKey
folder recursively (See Optimization below when it will not be done). Cascading Keys (starting with /) will retrieve the same path in all namespaces. /
will retrieve all Keys in handle
.
It is recommended to use the most specific parentKey
possible. (e.g. using system:/
is rarely the most specific)
proc:/
keys, must be passed to calls of kdbSet(), otherwise they will be lost. This stems from the fact that the user has the only copy of the whole configuration and backends only write configuration that was passed to them. For example, if you kdbGet() "system:/mountpoint/interest" you will not only get all Keys below system:/mountpoint/interest, but also all Keys below system:/mountpoint (if system:/mountpoint is a mountpoint as the name suggests, but system:/mountpoint/interest is not a mountpoint). Make sure to not touch or remove Keys outside the Keys of interest, because others may need them!When a backend fails kdbGet() will return -1 with all error and warning information in the parentKey
. The parameter returned
will not be changed.
It is your responsibility to save the original KeySet if you need it afterwards.
If you want to be sure to get a fresh KeySet again, you need to open a second handle to the Key database using kdbOpen().
handle | contains internal information of opened key database |
parentKey | Keys below parentKey will be retrieved from handle . It is also used to add warnings and set error information. |
ks | the (pre-initialized) KeySet returned with all keys found will not be changed on error or if no update is required |
1 | if the Keys were retrieved successfully. There might be warnings attached to the parentKey! Depending on your use case, you might need to treat them as errors! |
0 | if there was no update - no changes are made to the KeySet then. There might be warnings attached to the parentKey! Depending on your use case, you might need to treat them as erorrs! |
-1 | on failure - no changes are made to the KeySet then |
returned | the keyset where the keys will be in |
keyname | the root keyname which should be used to get keys below it |
0 | if no key was updated |
1 | if user or system keys were updated |
2 | if user and system keys were updated |
KDBException | if there were problems with the database |
Reimplemented in kdb::tools::merging::MergingKDB.
|
inlinevirtual |
Open the database.
errorKey | is useful if you want to get the warnings in the successful case, when no exception is thrown. |
Opens the session with the Key database.
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the Key database (KDB), you must not forget to call kdbClose() to free resources.
The method will bootstrap itself in the following way. The first step is to open the default backend. With it system:/elektra/mountpoints
will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the contract
is processed. Finally, the libraries for backends will be loaded and with it the KDB
data structure will be initialized.
The pointer to the KDB
structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.
Get a KDB
handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:
You don't need kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects.
contract | the contract that should be ensured before opening the KDB all data is copied and the KeySet can safely be used for e.g. kdbGet() later |
errorKey | the key which holds errors and warnings which were issued |
NULL | on failure |
Open the database.
contract | the contract that should be ensured |
errorKey | is useful if you want to get the warnings in the successful case, when no exception is thrown. |
Opens the session with the Key database.
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the Key database (KDB), you must not forget to call kdbClose() to free resources.
The method will bootstrap itself in the following way. The first step is to open the default backend. With it system:/elektra/mountpoints
will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the contract
is processed. Finally, the libraries for backends will be loaded and with it the KDB
data structure will be initialized.
The pointer to the KDB
structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.
Get a KDB
handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:
You don't need kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects.
contract | the contract that should be ensured before opening the KDB all data is copied and the KeySet can safely be used for e.g. kdbGet() later |
errorKey | the key which holds errors and warnings which were issued |
NULL | on failure |
Set all keys below parentKey.
If the keyname of the parentKey is invalid (e.g. empty) all keys will be set.
Set Keys to a Key database in an atomic and universal way.
returned
KeySet must be a valid KeySet, e.g. constructed with ksNew(). parentKey
Key must be a valid Key, e.g. constructed with keyNew(). It must not have read-only name, value or metadata.If you pass NULL on any parameter, kdbSet() will fail immediately without doing anything.
With parentKey
you can specify which part of the given keyset is of interest for you. Then you promise to only modify or remove keys below this key. All others would be passed back as they were retrieved by kdbGet(). Cascading keys (starting with /) will set the path in all namespaces. /
will commit all keys. This parameter is an optimization toonly save keys of mountpoints affected by the specified parentKey
. This does not necessarily mean that only changes to keys below that parentKey
are saved. Meta-names in parentKey
will be rejected (error C01320). Empty/Invalid Keys will also be rejected (error C01320).
parentKey == NULL
or parentKey
has read-only metadata, kdbSet() will immediately return the error code -1. In all other error cases the following happens:
In case of errors you should present the error message to the user and let the user decide what to do. Possible solutions are:
showElektraErrorDialog() and doElektraMerge() need to be implemented by the user of Elektra. For doElektraMerge a 3-way merge algorithm exists in libelektra-tools.
handle | contains internal information of opened key database |
ks | a KeySet which should contain changed keys, otherwise nothing is done |
parentKey | Keys below parentKey will be set to handle . It is also used to add warnings and set error information. |
1 | on success |
0 | if nothing had to be done, no changes in KDB |
-1 | on failure, no changes in KDB, an error will be set on parentKey if possible (see "Errors" above) |
handle
0 | if no key was updated |
1 | if user or system keys were updated |
2 | if user and system keys were updated |
returned | the keyset where the keys are passed to the user |
parentKey | the parentKey of returned |
KDBException | if there were problems with the database |
|
inlinevirtual |
Set all keys below keyname.
If the keyname of the parentKey is invalid (e.g. empty) all keys will be set.
Set Keys to a Key database in an atomic and universal way.
returned
KeySet must be a valid KeySet, e.g. constructed with ksNew(). parentKey
Key must be a valid Key, e.g. constructed with keyNew(). It must not have read-only name, value or metadata.If you pass NULL on any parameter, kdbSet() will fail immediately without doing anything.
With parentKey
you can specify which part of the given keyset is of interest for you. Then you promise to only modify or remove keys below this key. All others would be passed back as they were retrieved by kdbGet(). Cascading keys (starting with /) will set the path in all namespaces. /
will commit all keys. This parameter is an optimization toonly save keys of mountpoints affected by the specified parentKey
. This does not necessarily mean that only changes to keys below that parentKey
are saved. Meta-names in parentKey
will be rejected (error C01320). Empty/Invalid Keys will also be rejected (error C01320).
parentKey == NULL
or parentKey
has read-only metadata, kdbSet() will immediately return the error code -1. In all other error cases the following happens:
In case of errors you should present the error message to the user and let the user decide what to do. Possible solutions are:
showElektraErrorDialog() and doElektraMerge() need to be implemented by the user of Elektra. For doElektraMerge a 3-way merge algorithm exists in libelektra-tools.
handle | contains internal information of opened key database |
ks | a KeySet which should contain changed keys, otherwise nothing is done |
parentKey | Keys below parentKey will be set to handle . It is also used to add warnings and set error information. |
1 | on success |
0 | if nothing had to be done, no changes in KDB |
-1 | on failure, no changes in KDB, an error will be set on parentKey if possible (see "Errors" above) |
handle
0 | if no key was updated |
1 | if user or system keys were updated |
2 | if user and system keys were updated |
returned | the keyset where the keys will be in |
keyname | the keyname below the names should be set |
KDBException | if there were problems with the database |