![]() |
BSB Developer Docs
|
Type-safe settings storage with JSON persistence and versioned migrations. More...
#include <furi.h>#include <cjson/cJSON.h>Go to the source code of this file.
Data Structures | |
| struct | SettingProviderSetting |
| Setting descriptor. More... | |
| struct | SettingProviderBoolInterface |
| Boolean interface - stores as JSON true/false. More... | |
| struct | SettingProviderIntInterface |
| Integer interface with optional validation. More... | |
| struct | SettingProviderFloatInterface |
| Float interface with optional validation. More... | |
| struct | SettingProviderStringInterface |
| String interface with optional validation. More... | |
| struct | SettingProviderCustomInterface |
| Custom type interface with string serialization. More... | |
| struct | SettingProviderEnumInterface |
| Enum interface - stores integer as string from map. More... | |
| struct | SettingProviderUnionInterface |
| Union interface - stores tagged union with discriminator. More... | |
| struct | SettingProviderStructInterface |
| Struct interface - stores nested object with multiple fields. More... | |
| struct | SettingProviderRawInterface |
| Raw interface with direct cJSON serialization. More... | |
| struct | SettingProviderMigration |
| Migration structure for version upgrades. More... | |
Typedefs | |
| typedef struct SettingProvider | SettingProvider |
| Opaque settings provider handle. | |
Functions | |
| SettingProvider * | setting_provider_alloc (const char *file_path, int settings_version, const SettingProviderMigration *migrations, size_t migrations_count) |
| Allocate a settings provider. | |
| void | setting_provider_free (SettingProvider *instance) |
| Free settings setting provider instance. | |
| bool | setting_provider_save (SettingProvider *instance, const SettingProviderSetting *setting, const void *value) |
| Save a setting value. | |
| bool | setting_provider_load (SettingProvider *instance, const SettingProviderSetting *setting, void *value) |
| Load a setting value. | |
| bool | setting_provider_reset (SettingProvider *instance, const SettingProviderSetting *setting, void *value) |
| Reset setting to default value. | |
| bool | setting_provider_validate (const SettingProviderSetting *setting, const void *value) |
| Validate a value against a setting's constraints. | |
| bool | setting_provider_load_document (SettingProvider *instance, const SettingProviderSetting *setting, const char *data, size_t size, void *value) |
| Load values from a settings document. | |
| bool | setting_provider_save_document (SettingProvider *instance, const SettingProviderSetting *setting, const void *value, FuriString *data) |
| Save values into a settings document. | |
Type-safe settings storage with JSON persistence and versioned migrations.
Supported setting data types.
| SettingProvider * setting_provider_alloc | ( | const char * | file_path, |
| int | settings_version, | ||
| const SettingProviderMigration * | migrations, | ||
| size_t | migrations_count ) |
Allocate a settings provider.
| [in] | file_path | Path to JSON settings file |
| [in] | settings_version | Current version (must be > 0, used for migrations) |
| [in] | migrations | Array of migration callbacks, or NULL if no migrations needed |
| [in] | migrations_count | Number of entries in migrations array |
| void setting_provider_free | ( | SettingProvider * | instance | ) |
Free settings setting provider instance.
| [in] | instance | Instance to be freed |
| bool setting_provider_load | ( | SettingProvider * | instance, |
| const SettingProviderSetting * | setting, | ||
| void * | value ) |
Load a setting value.
Loads the value from JSON storage. If the setting is not present in storage, the default value from the interface is used and saved.
| [in] | instance | Setting provider instance |
| [in] | setting | Setting descriptor |
| [out] | value | Output buffer (must match expected type/size) |
| bool setting_provider_load_document | ( | SettingProvider * | instance, |
| const SettingProviderSetting * | setting, | ||
| const char * | data, | ||
| size_t | size, | ||
| void * | value ) |
Load values from a settings document.
Strict document load: the document must carry a current or migratable version and every field of the setting subtree, all valid. On failure the value buffer may be partially overwritten with defaults.
| [in] | instance | Setting provider instance |
| [in] | setting | Setting descriptor |
| [in] | data | Document data to load from |
| [in] | size | Length of the document data |
| [out] | value | Output buffer (must match expected type/size) |
| bool setting_provider_reset | ( | SettingProvider * | instance, |
| const SettingProviderSetting * | setting, | ||
| void * | value ) |
Reset setting to default value.
Writes the default value to storage and optionally returns it in the output buffer.
| [in] | instance | Setting provider instance |
| [in] | setting | Setting descriptor |
| [out] | value | Output buffer for default value, or NULL if not needed |
| bool setting_provider_save | ( | SettingProvider * | instance, |
| const SettingProviderSetting * | setting, | ||
| const void * | value ) |
Save a setting value.
Validates the value before saving.
| [in] | instance | Setting provider instance |
| [in] | setting | Setting descriptor |
| [in] | value | Pointer to value (type must match setting->type) |
| bool setting_provider_save_document | ( | SettingProvider * | instance, |
| const SettingProviderSetting * | setting, | ||
| const void * | value, | ||
| FuriString * | data ) |
Save values into a settings document.
Builds the settings document for the setting subtree with the instance version, without touching storage.
| [in] | instance | Setting provider instance |
| [in] | setting | Setting descriptor |
| [in] | value | Pointer to value to save |
| [out] | data | Serialized document data |
| bool setting_provider_validate | ( | const SettingProviderSetting * | setting, |
| const void * | value ) |
Validate a value against a setting's constraints.
| [in] | setting | Setting descriptor |
| [in] | value | Pointer to value to validate |