BSB Developer Docs
Loading...
Searching...
No Matches
setting_provider.h File Reference

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.
 

Enumerations

enum  SettingProviderSettingType {
  SettingProviderSettingTypeBool , SettingProviderSettingTypeInt , SettingProviderSettingTypeFloat , SettingProviderSettingTypeString ,
  SettingProviderSettingTypeCustom , SettingProviderSettingTypeEnum , SettingProviderSettingTypeUnion , SettingProviderSettingTypeStruct ,
  SettingProviderSettingTypeRaw , SettingProviderSettingTypesCount
}
 Supported setting data types. More...
 

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.
 

Detailed Description

Type-safe settings storage with JSON persistence and versioned migrations.

Enumeration Type Documentation

◆ SettingProviderSettingType

Supported setting data types.

Enumerator
SettingProviderSettingTypeBool 

Boolean value (JSON true/false)

SettingProviderSettingTypeInt 

Signed integer value.

SettingProviderSettingTypeFloat 

Floating-point value.

SettingProviderSettingTypeString 

Null-terminated C string.

SettingProviderSettingTypeCustom 

User-defined with serialize/deserialize callbacks.

SettingProviderSettingTypeEnum 

Enum mapped to string names.

SettingProviderSettingTypeUnion 

Tagged union with discriminator.

SettingProviderSettingTypeStruct 

Nested structure with inner settings.

SettingProviderSettingTypeRaw 

Raw data with direct cJSON serialization.

SettingProviderSettingTypesCount 

Sentinel value, do not use.

Function Documentation

◆ setting_provider_alloc()

SettingProvider * setting_provider_alloc ( const char * file_path,
int settings_version,
const SettingProviderMigration * migrations,
size_t migrations_count )

Allocate a settings provider.

Parameters
[in]file_pathPath to JSON settings file
[in]settings_versionCurrent version (must be > 0, used for migrations)
[in]migrationsArray of migration callbacks, or NULL if no migrations needed
[in]migrations_countNumber of entries in migrations array
Returns
Allocated setting provider instance

◆ setting_provider_free()

void setting_provider_free ( SettingProvider * instance)

Free settings setting provider instance.

Parameters
[in]instanceInstance to be freed

◆ setting_provider_load()

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.

Parameters
[in]instanceSetting provider instance
[in]settingSetting descriptor
[out]valueOutput buffer (must match expected type/size)
Returns
true on success, false on parse error

◆ setting_provider_load_document()

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.

Parameters
[in]instanceSetting provider instance
[in]settingSetting descriptor
[in]dataDocument data to load from
[in]sizeLength of the document data
[out]valueOutput buffer (must match expected type/size)
Returns
true on success, false on an invalid document

◆ setting_provider_reset()

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.

Parameters
[in]instanceSetting provider instance
[in]settingSetting descriptor
[out]valueOutput buffer for default value, or NULL if not needed
Returns
true on success, false on write error

◆ setting_provider_save()

bool setting_provider_save ( SettingProvider * instance,
const SettingProviderSetting * setting,
const void * value )

Save a setting value.

Validates the value before saving.

Parameters
[in]instanceSetting provider instance
[in]settingSetting descriptor
[in]valuePointer to value (type must match setting->type)
Returns
true on success, false if validation failed or write error

◆ setting_provider_save_document()

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.

Parameters
[in]instanceSetting provider instance
[in]settingSetting descriptor
[in]valuePointer to value to save
[out]dataSerialized document data
Returns
true on success, false when a value fails to serialize

◆ setting_provider_validate()

bool setting_provider_validate ( const SettingProviderSetting * setting,
const void * value )

Validate a value against a setting's constraints.

Parameters
[in]settingSetting descriptor
[in]valuePointer to value to validate
Returns
true if value is valid or no validation is defined