The configuration tree API allows applications to read and write their specific configuration. Each application is given an isolated tree. The system utilities store their configuration in the "root" tree.
Paths in the tree look like traditional Unix style paths and take the form of:
The path root is the root of the tree where the application has been given access. If the application has permission to access another tree, the path can also include the name of the other tree, followed by a colon.
In this case, a value named "value" is read from the tree named, "secondTree."
The tree is broken down into stems and leaves. A stem is a node that has at least one child node. While a leaf has no children, but may hold a value.
The configuration tree supports string, signed integer, boolean, floating point, and empty values. Storing anything more complex is encouraged to use stems and leafs to enhance readablity and debug-ablity. This also sidesteps nasty cross platform alignment issues.
The configuration tree makes use of simple transactions for working with its data. Both read and write transactions are supported. You want to use read transactions when to ensure you can atomically read multiple values from your configuration while keeping consistency with third parties trying to write data.
To prevent any single client from locking out other clients, read and write transactions have their own configurable timeout.
During a write transaction, both reading and writing are allowed. If you write a value during a transaction and read from that value again, you will get the same value you wrote. Third party clients will continue to see the old value. It's not until you commit your transaction that third parties will begin to see your updated value.
During read transactions, writes are not permitted and are thrown away.
Transactions are started by creating an iterator. Either a read or write iterator can be created. To end the transaction, you can either delete the iterator, cancelling the transaction. Or, in the case of write transactions, you can commit the iterator.
You can have multiple read transactions against the tree. They won't block other transactions from being creating. A read transaction won't block creating a write transaction either. A read transaction only blocks a write transaction from being comitted to the tree.
A write transaction in progress will also block creating another write transaction. If a write transaction is in progress when the request for another write transaction comes in, the secondary request will be blocked. This secondary request will remain blocked until the first transaction has been comitted or has timed out.
This code example will iterate a given node and print it's contents:
Consider the following example, the caller wants to update the devices IP address. It does so in a transaction so that the data is written atomiclly.
It's possible to ignore iterators and transactions entirely (e.g., if all you need to do is read or write some simple values in the tree).
The non-transactional reads and writes work almost identically to the transactional versions. They just don't explictly take an iterator object. The "quick" functions internally use an implicit transaction. This implicit transaction wraps one get or set, and does not protect your code from other activity in the system.
Because these functions don't take an explicit transaction, they can't work with relative paths. If a relative path is given, the path will be considered relative to the tree's root.
Translating the last examples to their "quick" counterparts, you have the following code. Because each read is independant, there is no guarantee of consistency between them. If another process changes one of the values while you read/write the other, the two values could be read out of sync.
Copyright (C) Sierra Wireless, Inc. 2014. Use of this work is subject to license.