Config Tree Transactions

This topic summarizes how to create read and write transactions to manage a target's configuration database (config tree).

There are also pre-built Config Tree APIs and a target config tool.

Read from own Tree

By default, every app gets read access to their own tree.

This code sample shows how an app can read a value from its own tree:

bool myBoolVal = le_cfg_GetBool(iteratorRef, "isBoolSet", false);
 
if (myBoolVal)
{
LE_INFO("The test value was set.");
}
else
{
LE_INFO("The test value was not set.");
}

This code tries to read a value from the tree named, myApp. If the value /test/isBoolSet was previously written to the tree, that value will be returned. Otherwise, the default value false is returned.

Write to Tree

Before you can write to a tree, you need to run as a user with the correct permissions. Permission settings are handled slightly differently, instead of writing under apps in the system tree, you write permission settings under the user's branch.

Processes running under the root user or those with the same user ID as the config tree process aren't restricted by permissions.

To create permissions, as the root user on the target console run config set using the write option:

$ config set /apps/myApp/configLimits/acl/myApp write

The permissions are added to the system tree under /apps/myApp/configLimits/acl/myApp.

Once the permissions are set, you can add a write function like this:

Two Apps One Tree

You may need to have one app read and another app read and write from a common tree.

To set permissions for two apps, as the root user on the target console run config set using the common option:

$ config set /apps/readerApp/configLimits/acl/common read
$ config set /apps/writerApp/configLimits/acl/common write

Granting write permission on a tree also gives read permission.

Once the permissions are set, you need to create a read to the tree name that includes the iterator path common: like this:

le_cfg_IteratorRef_t iteratorRef = le_cfg_CreateReadTxn("common:/test");
bool myBoolVal = le_cfg_GetBool(iteratorRef, "isBoolSet", false);
 
if (myBoolVal)
{
LE_INFO("The test value was set.");
}
else
{
LE_INFO("The test value was not set.");
}

A write also needs the tree name to include the iterator path common: like this:

le_cfg_IteratorRef_t iteratorRef = le_cfg_CreateWriteTxn("common:/test");
le_cfg_SetBool(iteratorRef, "isBoolSet", true);

Read Any Tree

You can create read access to any tree, but typically you won't want it to run as a root process.

This code sample shows a supervisorApp with read access to any tree:

$ config set /apps/supervisorApp/configLimits/allAccess read

If you don't specify a tree name, the read will be created on the user's default tree: the tree with the same name as the app.

Write Process Any Tree

You may need to create a write for a process to any tree for a process that isn't part of app. This code sample uses the user name instead of the app name:

$ config set /users/testUser/configLimits/allAccess write