subsys/settings: Update bluetooth module
Updated the bluetooth module to use static handlers. Removed the old bt specific static registration. The routine bt_settings_init() is still calling settings_init() which IMO is not needed anymore. Updates: changed SETTINGS_REGISTER_STATIC() to SETTINGS_STATIC_HANDLER_DEFINE() changed settings_handler_stat type to settings_handler_static type removed NULL declarations renamed bt_handler to bt_settingshandler, as bt_handler already exists. renamed all bt_XXX_handler to bt_xxx_settingshandler to avoid any overlap. changed SETTINGS_STATIC_HANDLER_DEFINE() to create variable names from _hname by just prepending them with settings_handler_. updated all bt_xxx_settings_handler to just bt_xxx. Signed-off-by: Laczen JMS <laczenjms@gmail.com>
This commit is contained in:
parent
c20ff1150f
commit
5f19c8160a
8 changed files with 32 additions and 89 deletions
|
@ -109,15 +109,6 @@
|
|||
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_SETTINGS)
|
||||
SECTION_DATA_PROLOGUE(_bt_settings_area,,SUBALIGN(4))
|
||||
{
|
||||
_bt_settings_start = .;
|
||||
KEEP(*(SORT_BY_NAME("._bt_settings_handler.static.*")))
|
||||
_bt_settings_end = .;
|
||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||
#endif
|
||||
|
||||
SECTION_DATA_PROLOGUE(log_const_sections,,)
|
||||
{
|
||||
__log_const_start = .;
|
||||
|
|
|
@ -150,17 +150,29 @@ struct settings_handler_static {
|
|||
};
|
||||
|
||||
/**
|
||||
* Register a static handler for settings items
|
||||
* Define a static handler for settings items
|
||||
*
|
||||
* @param _handler Structure containing registration info, this must be const
|
||||
* The handler name in ROM needs to be unique, it is generated from
|
||||
* _handler and the linenumber of SETTINGS_REGISTER_STATIC()
|
||||
* @param _hname handler name
|
||||
* @param _tree subtree name
|
||||
* @param _get get routine (can be NULL)
|
||||
* @param _set set routine (can be NULL)
|
||||
* @param _commit commit routine (can be NULL)
|
||||
* @param _export export routine (can be NULL)
|
||||
*
|
||||
* This createa a variable _hname prepended by settings_handler_.
|
||||
*
|
||||
*/
|
||||
#define SETTINGS_STATIC_HANDLER_DEFINE(_handler) \
|
||||
const Z_STRUCT_SECTION_ITERABLE(settings_handler_static, \
|
||||
_CONCAT(_handler, __LINE__))\
|
||||
= _handler
|
||||
|
||||
#define SETTINGS_STATIC_HANDLER_DEFINE(_hname, _tree, _get, _set, _commit, \
|
||||
_export) \
|
||||
const Z_STRUCT_SECTION_ITERABLE(settings_handler_static, \
|
||||
settings_handler_ ## _hname) = { \
|
||||
.name = _tree, \
|
||||
.h_get = _get, \
|
||||
.h_set = _set, \
|
||||
.h_commit = _commit, \
|
||||
.h_export = _export, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of settings and backend
|
||||
|
|
|
@ -3629,7 +3629,7 @@ static int ccc_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
|||
return 0;
|
||||
}
|
||||
|
||||
BT_SETTINGS_DEFINE(ccc, ccc_set, NULL, NULL);
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(bt_ccc, "bt/ccc", NULL, ccc_set, NULL, NULL);
|
||||
|
||||
#if defined(CONFIG_BT_GATT_CACHING)
|
||||
static int cf_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
||||
|
@ -3676,7 +3676,7 @@ static int cf_set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
|||
return 0;
|
||||
}
|
||||
|
||||
BT_SETTINGS_DEFINE(cf, cf_set, NULL, NULL);
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(bt_cf, "bt/cf", NULL, cf_set, NULL, NULL);
|
||||
|
||||
static u8_t stored_hash[16];
|
||||
|
||||
|
@ -3719,6 +3719,7 @@ static int db_hash_commit(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
BT_SETTINGS_DEFINE(hash, db_hash_set, db_hash_commit, NULL);
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(bt_hash, "bt/hash", NULL, db_hash_set,
|
||||
db_hash_commit, NULL);
|
||||
#endif /*CONFIG_BT_GATT_CACHING */
|
||||
#endif /* CONFIG_BT_SETTINGS */
|
||||
|
|
|
@ -365,5 +365,7 @@ static int keys_commit(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
BT_SETTINGS_DEFINE(keys, keys_set, keys_commit, NULL);
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(bt_keys, "bt/keys", NULL, keys_set, keys_commit,
|
||||
NULL);
|
||||
|
||||
#endif /* CONFIG_BT_SETTINGS */
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define LOG_MODULE_NAME bt_mesh_settings
|
||||
#include "common/log.h"
|
||||
|
||||
#include "../settings.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "crypto.h"
|
||||
|
@ -824,7 +823,8 @@ static int mesh_commit(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
BT_SETTINGS_DEFINE(mesh, mesh_set, mesh_commit, NULL);
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh, "bt/mesh", NULL, mesh_set, mesh_commit,
|
||||
NULL);
|
||||
|
||||
/* Pending flags that use K_NO_WAIT as the storage timeout */
|
||||
#define NO_WAIT_PENDING_BITS (BIT(BT_MESH_NET_PENDING) | \
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
#include "hci_core.h"
|
||||
#include "settings.h"
|
||||
|
||||
/* Linker-defined symbols bound to the bt_settings_handler structs */
|
||||
extern const struct bt_settings_handler _bt_settings_start[];
|
||||
extern const struct bt_settings_handler _bt_settings_end[];
|
||||
|
||||
void bt_settings_encode_key(char *path, size_t path_size, const char *subsys,
|
||||
bt_addr_le_t *addr, const char *key)
|
||||
{
|
||||
|
@ -90,7 +86,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
|||
void *cb_arg)
|
||||
{
|
||||
ssize_t len;
|
||||
const struct bt_settings_handler *h;
|
||||
const char *next;
|
||||
|
||||
if (!name) {
|
||||
|
@ -100,12 +95,6 @@ static int set(const char *name, size_t len_rd, settings_read_cb read_cb,
|
|||
|
||||
len = settings_name_next(name, &next);
|
||||
|
||||
for (h = _bt_settings_start; h < _bt_settings_end; h++) {
|
||||
if (!strncmp(name, h->name, len)) {
|
||||
return h->set(next, len_rd, read_cb, cb_arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!strncmp(name, "id", len)) {
|
||||
/* Any previously provided identities supersede flash */
|
||||
if (atomic_test_bit(bt_dev.flags, BT_DEV_PRESET_ID)) {
|
||||
|
@ -211,8 +200,6 @@ void bt_settings_save_id(void)
|
|||
|
||||
static int commit(void)
|
||||
{
|
||||
const struct bt_settings_handler *h;
|
||||
|
||||
BT_DBG("");
|
||||
|
||||
#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC)
|
||||
|
@ -234,36 +221,10 @@ static int commit(void)
|
|||
bt_finalize_init();
|
||||
}
|
||||
|
||||
for (h = _bt_settings_start; h < _bt_settings_end; h++) {
|
||||
if (h->commit) {
|
||||
h->commit();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int export(int (*export_func)(const char *name, const void *val,
|
||||
size_t val_len))
|
||||
|
||||
{
|
||||
const struct bt_settings_handler *h;
|
||||
|
||||
for (h = _bt_settings_start; h < _bt_settings_end; h++) {
|
||||
if (h->export) {
|
||||
h->export(export_func);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct settings_handler bt_settings = {
|
||||
.name = "bt",
|
||||
.h_set = set,
|
||||
.h_commit = commit,
|
||||
.h_export = export,
|
||||
};
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(bt, "bt", NULL, set, commit, NULL);
|
||||
|
||||
int bt_settings_init(void)
|
||||
{
|
||||
|
@ -277,11 +238,5 @@ int bt_settings_init(void)
|
|||
return err;
|
||||
}
|
||||
|
||||
err = settings_register(&bt_settings);
|
||||
if (err) {
|
||||
BT_ERR("settings_register failed (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,23 +4,6 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
struct bt_settings_handler {
|
||||
const char *name;
|
||||
int (*set)(const char *name, size_t len, settings_read_cb read_cb,
|
||||
void *cb_arg);
|
||||
int (*commit)(void);
|
||||
int (*export)(int (*func)(const char *name,
|
||||
const void *val, size_t val_len));
|
||||
};
|
||||
|
||||
#define BT_SETTINGS_DEFINE(_name, _set, _commit, _export) \
|
||||
const Z_STRUCT_SECTION_ITERABLE(bt_settings_handler, _name) = { \
|
||||
.name = STRINGIFY(_name), \
|
||||
.set = _set, \
|
||||
.commit = _commit, \
|
||||
.export = _export, \
|
||||
}
|
||||
|
||||
/* Max settings key length (with all components) */
|
||||
#define BT_SETTINGS_KEY_MAX 36
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include "../host/settings.h"
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_SERVICE)
|
||||
#define LOG_MODULE_NAME bt_dis
|
||||
#include "common/log.h"
|
||||
|
@ -235,5 +233,6 @@ static int dis_set(const char *name, size_t len_rd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
BT_SETTINGS_DEFINE(dis, dis_set, NULL, NULL);
|
||||
SETTINGS_STATIC_HANDLER_DEFINE(bt_dis, "bt/dis", NULL, dis_set, NULL, NULL);
|
||||
|
||||
#endif /* CONFIG_BT_GATT_DIS_SETTINGS && CONFIG_BT_SETTINGS*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue