配置管理器 API 参考

本节记录配置管理器 API。

配置核心

typedef struct config_namespace *config_ns_handle_t

Namespace handle type.

config_status_t config_open_namespace(const char *name, config_ns_handle_t *handle)

Open a namespace.

参数:
  • name -- [in] Namespace name

  • handle -- [out] Pointer to store the namespace handle

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_close_namespace(config_ns_handle_t handle)

Close a namespace.

参数:

handle -- [in] Namespace handle

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_erase_namespace(const char *name)

Erase all keys in a namespace.

参数:

name -- [in] Namespace name

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_set_i32(config_ns_handle_t ns, const char *key, int32_t value)

Set a 32-bit signed integer in namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • value -- [in] Value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_get_i32(config_ns_handle_t ns, const char *key, int32_t *value, int32_t default_val)

Get a 32-bit signed integer from namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_set_u32(config_ns_handle_t ns, const char *key, uint32_t value)

Set a 32-bit unsigned integer in namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • value -- [in] Value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_get_u32(config_ns_handle_t ns, const char *key, uint32_t *value, uint32_t default_val)

Get a 32-bit unsigned integer from namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_set_str(config_ns_handle_t ns, const char *key, const char *value)

Set a string in namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • value -- [in] String value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_get_str(config_ns_handle_t ns, const char *key, char *buffer, size_t buf_size)

Get a string from namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • buffer -- [out] Buffer to store the string

  • buf_size -- [in] Size of the buffer

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_set_bool(config_ns_handle_t ns, const char *key, bool value)

Set a boolean in namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • value -- [in] Boolean value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_get_bool(config_ns_handle_t ns, const char *key, bool *value, bool default_val)

Get a boolean from namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_exists(config_ns_handle_t ns, const char *key, bool *exists)

Check if a key exists in namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

  • exists -- [out] Pointer to store the result

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_delete(config_ns_handle_t ns, const char *key)

Delete a key from namespace.

参数:
  • ns -- [in] Namespace handle

  • key -- [in] Configuration key

返回值:

CONFIG_OK on success, error code otherwise

typedef void (*config_change_cb_t)(const char *key, config_type_t type, const void *old_value, const void *new_value, void *user_data)

Configuration change callback function type.

Param key:

[in] Key that changed

Param type:

[in] Value type

Param old_value:

[in] Previous value (may be NULL)

Param new_value:

[in] New value

Param user_data:

[in] User-provided context

typedef struct config_callback *config_cb_handle_t

Callback handle type.

config_status_t config_register_callback(const char *key, config_change_cb_t callback, void *user_data, config_cb_handle_t *handle)

Register a callback for a specific key.

参数:
  • key -- [in] Configuration key to watch

  • callback -- [in] Callback function

  • user_data -- [in] User-provided context

  • handle -- [out] Pointer to store the callback handle

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_register_wildcard_callback(config_change_cb_t callback, void *user_data, config_cb_handle_t *handle)

Register a wildcard callback for all key changes.

参数:
  • callback -- [in] Callback function

  • user_data -- [in] User-provided context

  • handle -- [out] Pointer to store the callback handle

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_unregister_callback(config_cb_handle_t handle)

Unregister a callback.

参数:

handle -- [in] Callback handle

返回值:

CONFIG_OK on success, error code otherwise

typedef bool (*config_iterate_cb_t)(const config_entry_info_t *info, void *user_data)

Iteration callback function type.

Param info:

[in] Entry information

Param user_data:

[in] User-provided context

Return:

true to continue iteration, false to stop

config_status_t config_exists(const char *key, bool *exists)

Check if a key exists.

参数:
  • key -- [in] Configuration key

  • exists -- [out] Pointer to store the result

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_type(const char *key, config_type_t *type)

Get the type of a stored value.

参数:
  • key -- [in] Configuration key

  • type -- [out] Pointer to store the type

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_delete(const char *key)

Delete a configuration key.

参数:

key -- [in] Configuration key

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_count(size_t *count)

Get the number of stored keys.

参数:

count -- [out] Pointer to store the count

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_iterate(config_iterate_cb_t callback, void *user_data)

Iterate over all configuration entries.

参数:
  • callback -- [in] Iteration callback

  • user_data -- [in] User-provided context

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_ns_iterate(config_ns_handle_t ns, config_iterate_cb_t callback, void *user_data)

Iterate over entries in a namespace.

参数:
  • ns -- [in] Namespace handle

  • callback -- [in] Iteration callback

  • user_data -- [in] User-provided context

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_init(const config_manager_config_t *config)

Initialize the Config Manager.

参数:

config -- [in] Configuration structure, or NULL for defaults

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_deinit(void)

Deinitialize the Config Manager.

注意

Releases all resources

返回值:

CONFIG_OK on success, error code otherwise

bool config_is_initialized(void)

Check if Config Manager is initialized.

返回值:

true if initialized, false otherwise

config_status_t config_set_backend(const config_backend_t *backend)

Set the storage backend.

参数:

backend -- [in] Pointer to backend structure

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_commit(void)

Commit pending changes to storage.

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_load(void)

Load configurations from storage.

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_i32(const char *key, int32_t value)

Set a 32-bit signed integer value.

参数:
  • key -- [in] Configuration key

  • value -- [in] Value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_i32(const char *key, int32_t *value, int32_t default_val)

Get a 32-bit signed integer value.

参数:
  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_u32(const char *key, uint32_t value)

Set a 32-bit unsigned integer value.

参数:
  • key -- [in] Configuration key

  • value -- [in] Value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_u32(const char *key, uint32_t *value, uint32_t default_val)

Get a 32-bit unsigned integer value.

参数:
  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_i64(const char *key, int64_t value)

Set a 64-bit signed integer value.

参数:
  • key -- [in] Configuration key

  • value -- [in] Value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_i64(const char *key, int64_t *value, int64_t default_val)

Get a 64-bit signed integer value.

参数:
  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_float(const char *key, float value)

Set a float value.

参数:
  • key -- [in] Configuration key

  • value -- [in] Value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_float(const char *key, float *value, float default_val)

Get a float value.

参数:
  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_bool(const char *key, bool value)

Set a boolean value.

参数:
  • key -- [in] Configuration key

  • value -- [in] Value to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_bool(const char *key, bool *value, bool default_val)

Get a boolean value.

参数:
  • key -- [in] Configuration key

  • value -- [out] Pointer to store the value

  • default_val -- [in] Default value if key not found

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_str(const char *key, const char *value)

Set a string value.

参数:
  • key -- [in] Configuration key

  • value -- [in] Null-terminated string to store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_str(const char *key, char *buffer, size_t buf_size)

Get a string value.

参数:
  • key -- [in] Configuration key

  • buffer -- [out] Buffer to store the string

  • buf_size -- [in] Size of the buffer

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_str_len(const char *key, size_t *len)

Get the length of a stored string.

参数:
  • key -- [in] Configuration key

  • len -- [out] Pointer to store the length (excluding null terminator)

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_blob(const char *key, const void *data, size_t size)

Set a binary blob value.

参数:
  • key -- [in] Configuration key

  • data -- [in] Binary data to store

  • size -- [in] Size of the data

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_blob(const char *key, void *buffer, size_t buf_size, size_t *actual_size)

Get a binary blob value.

参数:
  • key -- [in] Configuration key

  • buffer -- [out] Buffer to store the data

  • buf_size -- [in] Size of the buffer

  • actual_size -- [out] Actual size of the data (optional, can be NULL)

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_blob_len(const char *key, size_t *len)

Get the size of a stored blob.

参数:
  • key -- [in] Configuration key

  • len -- [out] Pointer to store the size

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_default_i32(const char *key, int32_t value)

Set default value for a 32-bit signed integer.

参数:
  • key -- [in] Configuration key

  • value -- [in] Default value

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_default_u32(const char *key, uint32_t value)

Set default value for a 32-bit unsigned integer.

参数:
  • key -- [in] Configuration key

  • value -- [in] Default value

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_default_i64(const char *key, int64_t value)

Set default value for a 64-bit signed integer.

参数:
  • key -- [in] Configuration key

  • value -- [in] Default value

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_default_float(const char *key, float value)

Set default value for a float.

参数:
  • key -- [in] Configuration key

  • value -- [in] Default value

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_default_bool(const char *key, bool value)

Set default value for a boolean.

参数:
  • key -- [in] Configuration key

  • value -- [in] Default value

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_default_str(const char *key, const char *value)

Set default value for a string.

参数:
  • key -- [in] Configuration key

  • value -- [in] Default string value

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_reset_to_default(const char *key)

Reset a key to its default value.

参数:

key -- [in] Configuration key

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_reset_all_to_defaults(void)

Reset all keys to their default values.

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_register_defaults(const config_default_t *defaults, size_t count)

Register multiple default values.

参数:
  • defaults -- [in] Array of default value definitions

  • count -- [in] Number of defaults

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_export_size(config_format_t format, config_export_flags_t flags, size_t *size)

Get the required buffer size for export.

参数:
  • format -- [in] Export format

  • flags -- [in] Export flags

  • size -- [out] Pointer to store the required size

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_export(config_format_t format, config_export_flags_t flags, void *buffer, size_t buf_size, size_t *actual_size)

Export all configurations.

参数:
  • format -- [in] Export format

  • flags -- [in] Export flags

  • buffer -- [out] Buffer to store exported data

  • buf_size -- [in] Size of the buffer

  • actual_size -- [out] Actual size of exported data

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_export_namespace(const char *ns_name, config_format_t format, config_export_flags_t flags, void *buffer, size_t buf_size, size_t *actual_size)

Export configurations from a specific namespace.

参数:
  • ns_name -- [in] Namespace name

  • format -- [in] Export format

  • flags -- [in] Export flags

  • buffer -- [out] Buffer to store exported data

  • buf_size -- [in] Size of the buffer

  • actual_size -- [out] Actual size of exported data

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_import(config_format_t format, config_import_flags_t flags, const void *data, size_t size)

Import configurations.

参数:
  • format -- [in] Import format

  • flags -- [in] Import flags

  • data -- [in] Data to import

  • size -- [in] Size of the data

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_import_namespace(const char *ns_name, config_format_t format, config_import_flags_t flags, const void *data, size_t size)

Import configurations to a specific namespace.

参数:
  • ns_name -- [in] Namespace name

  • format -- [in] Import format

  • flags -- [in] Import flags

  • data -- [in] Data to import

  • size -- [in] Size of the data

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_encryption_key(const uint8_t *key, size_t key_len, config_crypto_algo_t algo)

Set the encryption key.

参数:
  • key -- [in] Encryption key

  • key_len -- [in] Key length in bytes

  • algo -- [in] Encryption algorithm

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_clear_encryption_key(void)

Clear the encryption key.

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_str_encrypted(const char *key, const char *value)

Set an encrypted string value.

参数:
  • key -- [in] Configuration key

  • value -- [in] String value to encrypt and store

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_set_blob_encrypted(const char *key, const void *data, size_t size)

Set an encrypted blob value.

参数:
  • key -- [in] Configuration key

  • data -- [in] Data to encrypt and store

  • size -- [in] Size of the data

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_is_encrypted(const char *key, bool *encrypted)

Check if a key is encrypted.

参数:
  • key -- [in] Configuration key

  • encrypted -- [out] Pointer to store the result

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_rotate_encryption_key(const uint8_t *new_key, size_t key_len, config_crypto_algo_t algo)

Rotate the encryption key.

注意

Re-encrypts all encrypted keys with the new key

参数:
  • new_key -- [in] New encryption key

  • key_len -- [in] Key length in bytes

  • algo -- [in] Encryption algorithm

返回值:

CONFIG_OK on success, error code otherwise

config_status_t config_get_last_error(void)

Get the last error code.

返回值:

Last error code

const char *config_error_to_str(config_status_t status)

Convert error code to string.

参数:

status -- [in] Error code

返回值:

Error string

CONFIG_MANAGER_CONFIG_DEFAULT

Default configuration initializer.

struct config_manager_config_t
#include <config.h>

Config Manager configuration structure.

Public Members

uint16_t max_keys

Maximum key count (32-256)

uint8_t max_key_len

Maximum key length (16-64)

uint16_t max_value_size

Maximum value size (64-1024)

uint8_t max_namespaces

Maximum namespace count

uint8_t max_callbacks

Maximum callback count

bool auto_commit

Auto-commit mode

struct config_default_t
#include <config.h>

Default value definition structure.

Public Members

const char *key

Configuration key

config_type_t type

Value type

int32_t i32_val

32-bit signed integer

uint32_t u32_val

32-bit unsigned integer

int64_t i64_val

64-bit signed integer

float float_val

Float value

bool bool_val

Boolean value

const char *str_val

String value

union config_default_t value

Default value

struct config_entry_info_t
#include <config.h>

Configuration entry information.

Public Members

char key[32]

Configuration key

config_type_t type

Value type

uint16_t value_size

Value size in bytes

uint8_t flags

Entry flags

配置定义

CONFIG_DEFAULT_MAX_KEYS

Default configuration values.

CONFIG_DEFAULT_MAX_KEY_LEN
CONFIG_DEFAULT_MAX_VALUE_SIZE
CONFIG_DEFAULT_MAX_NAMESPACES
CONFIG_DEFAULT_MAX_CALLBACKS
CONFIG_DEFAULT_MAX_DEFAULTS
CONFIG_MAX_NS_NAME_LEN
CONFIG_MIN_MAX_KEYS

Configuration limits.

CONFIG_MAX_MAX_KEYS
CONFIG_MIN_MAX_KEY_LEN
CONFIG_MAX_MAX_KEY_LEN
CONFIG_MIN_MAX_VALUE_SIZE
CONFIG_MAX_MAX_VALUE_SIZE
enum config_status_t

Config Manager status codes.

Values:

enumerator CONFIG_OK

Operation successful

enumerator CONFIG_ERROR

Generic error

enumerator CONFIG_ERROR_INVALID_PARAM

Invalid parameter

enumerator CONFIG_ERROR_NOT_INIT

Not initialized

enumerator CONFIG_ERROR_ALREADY_INIT

Already initialized

enumerator CONFIG_ERROR_NO_MEMORY

Out of memory

enumerator CONFIG_ERROR_NOT_FOUND

Key not found

enumerator CONFIG_ERROR_ALREADY_EXISTS

Key already exists

enumerator CONFIG_ERROR_TYPE_MISMATCH

Type mismatch

enumerator CONFIG_ERROR_KEY_TOO_LONG

Key name too long

enumerator CONFIG_ERROR_VALUE_TOO_LARGE

Value size too large

enumerator CONFIG_ERROR_BUFFER_TOO_SMALL

Buffer too small

enumerator CONFIG_ERROR_NO_SPACE

Storage space full

enumerator CONFIG_ERROR_NVS_READ

NVS read failure

enumerator CONFIG_ERROR_NVS_WRITE

NVS write failure

enumerator CONFIG_ERROR_INVALID_FORMAT

Invalid format

enumerator CONFIG_ERROR_NO_ENCRYPTION_KEY

Encryption key not set

enumerator CONFIG_ERROR_CRYPTO_FAILED

Encryption/decryption failed

enumerator CONFIG_ERROR_NO_BACKEND

Backend not set

enum config_type_t

Config data types.

Values:

enumerator CONFIG_TYPE_I32

32-bit signed integer

enumerator CONFIG_TYPE_U32

32-bit unsigned integer

enumerator CONFIG_TYPE_I64

64-bit signed integer

enumerator CONFIG_TYPE_FLOAT

Single precision float

enumerator CONFIG_TYPE_BOOL

Boolean

enumerator CONFIG_TYPE_STRING

Null-terminated string

enumerator CONFIG_TYPE_BLOB

Binary data

enum config_flags_t

Config entry flags.

Values:

enumerator CONFIG_FLAG_NONE

No flags

enumerator CONFIG_FLAG_ENCRYPTED

Value is encrypted

enumerator CONFIG_FLAG_READONLY

Read-only configuration

enumerator CONFIG_FLAG_PERSISTENT

Requires persistence

enum config_format_t

Export format types.

Values:

enumerator CONFIG_FORMAT_JSON

JSON format

enumerator CONFIG_FORMAT_BINARY

Compact binary format

enum config_export_flags_t

Export flags.

Values:

enumerator CONFIG_EXPORT_FLAG_NONE

No flags

enumerator CONFIG_EXPORT_FLAG_DECRYPT

Decrypt values on export

enumerator CONFIG_EXPORT_FLAG_PRETTY

Pretty print JSON

enum config_import_flags_t

Import flags.

Values:

enumerator CONFIG_IMPORT_FLAG_NONE

No flags

enumerator CONFIG_IMPORT_FLAG_CLEAR

Clear existing before import

enumerator CONFIG_IMPORT_FLAG_SKIP_ERRORS

Skip errors and continue

enum config_crypto_algo_t

Encryption algorithms.

Values:

enumerator CONFIG_CRYPTO_AES128

AES-128-CBC

enumerator CONFIG_CRYPTO_AES256

AES-256-CBC

CONFIG_IS_OK(status)

Check if status is OK.

参数:
  • status -- [in] Status to check

返回值:

true if OK, false otherwise

CONFIG_IS_ERROR(status)

Check if status is error.

参数:
  • status -- [in] Status to check

返回值:

true if error, false otherwise

CONFIG_RETURN_IF_ERROR(status)

Return if status is error.

参数:
  • status -- [in] Status to check

CONFIG_UNUSED(x)

Unused parameter macro.

参数:
  • x -- [in] Parameter to mark as unused

后端接口

typedef struct config_backend config_backend_t

Forward declaration of backend structure.

typedef config_status_t (*config_backend_init_fn)(void *ctx)

Backend initialization function type.

Param ctx:

[in] Backend context

Return:

CONFIG_OK on success, error code otherwise

typedef config_status_t (*config_backend_deinit_fn)(void *ctx)

Backend deinitialization function type.

Param ctx:

[in] Backend context

Return:

CONFIG_OK on success, error code otherwise

typedef config_status_t (*config_backend_read_fn)(void *ctx, const char *key, void *data, size_t *size)

Backend read function type.

Param ctx:

[in] Backend context

Param key:

[in] Key to read

Param data:

[out] Buffer to store data

Param size:

[inout] Input: buffer size, Output: actual data size

Return:

CONFIG_OK on success, error code otherwise

typedef config_status_t (*config_backend_write_fn)(void *ctx, const char *key, const void *data, size_t size)

Backend write function type.

Param ctx:

[in] Backend context

Param key:

[in] Key to write

Param data:

[in] Data to write

Param size:

[in] Data size

Return:

CONFIG_OK on success, error code otherwise

typedef config_status_t (*config_backend_erase_fn)(void *ctx, const char *key)

Backend erase function type.

Param ctx:

[in] Backend context

Param key:

[in] Key to erase

Return:

CONFIG_OK on success, error code otherwise

typedef config_status_t (*config_backend_erase_all_fn)(void *ctx)

Backend erase all function type.

Param ctx:

[in] Backend context

Return:

CONFIG_OK on success, error code otherwise

typedef config_status_t (*config_backend_commit_fn)(void *ctx)

Backend commit function type.

Param ctx:

[in] Backend context

Return:

CONFIG_OK on success, error code otherwise

struct config_backend
#include <config_backend.h>

Config backend structure.

Defines the interface for config storage backends. Each backend must implement at least read, write, and erase functions.

Public Members

const char *name

Backend name (must be unique)

config_backend_init_fn init

Initialization function (optional)

config_backend_deinit_fn deinit

Deinitialization function (optional)

config_backend_read_fn read

Read function (required)

config_backend_write_fn write

Write function (required)

config_backend_erase_fn erase

Erase function (required)

config_backend_erase_all_fn erase_all

Erase all function (optional)

config_backend_commit_fn commit

Commit function (optional)

void *ctx

Backend-specific context

RAM 后端

const config_backend_t *config_backend_ram_get(void)

Get the RAM backend instance.

注意

RAM backend is volatile - data is lost on reset

返回值:

Pointer to RAM backend structure

Flash 后端

const config_backend_t *config_backend_flash_get(void)

Get the Flash backend instance.

注意

Flash backend provides persistent storage

返回值:

Pointer to Flash backend structure