Config
The Config plugin provides a flexible interface for reading, writing, and managing configuration data in various types, including math types and Xml data. It is intended for applications that require storing, retrieving, or sharing runtime or persistent settings. The location of the configuration file is flexible; it can be stored alongside the application binary or within a system-specific configuration directory. The configuration can also operate in read-only mode, allowing the application to use predefined initial values.
note
To initialize Config plugin, the following global macros must be defined (shared with the Logger plugin):
- TS_APP_NAME - Specifies the configuration file name (e.g., "MyApplication")
- TS_APP_PATH - Specifies the system configuration directory (e.g., ".tellusim")
- TS_APP_VERSION - Specifies the application version (e.g., "1.0")
#include <system/config/include/TellusimConfig.h>
Example
// create local config (stored next to the application binary)
Config::Flags flags = Config::FlagNone;
flags |= Config::FlagLocal; // store config locally
Config config(flags);
// print config version
TS_LOGF(Message, "Version: %s\n", config.getVersion().get());
// increment and update counter value
uint32_t counter = config.getu32("counter", 0);
TS_LOGF(Message, "Counter: %u\n", counter);
config.set("counter", counter + 1);