nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches

◆ GEN_CONFIG_EVENT_HANDLERS

#define GEN_CONFIG_EVENT_HANDLERS (   mod_name,
  opt_descr,
  config_set_fn,
  config_fetch_fn 
)

#include <applications/nrf_desktop/src/events/config_event.h>

Value:
BUILD_ASSERT(ARRAY_SIZE(opt_descr) > 0); \
BUILD_ASSERT(ARRAY_SIZE(opt_descr) <= OPT_FIELD_MASK); \
if (IS_ENABLED(CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE) && is_config_event(aeh)) { \
static const uint8_t module_id_in_section \
__attribute__((__section__("config_channel_modules"))) = 0; \
uint8_t config_module_id = \
&module_id_in_section - (uint8_t *)__start_config_channel_modules; \
static uint8_t cur_opt_descr; \
\
struct config_event *event = cast_config_event(aeh); \
\
uint8_t rsp_data_buf[CONFIG_CHANNEL_FETCHED_DATA_MAX_SIZE]; \
size_t rsp_data_size = 0; \
bool consume = false; \
\
/* Not for us. */ \
if (event->recipient != CFG_CHAN_RECIPIENT_LOCAL) { \
return false; \
} \
\
if (event->status == CONFIG_STATUS_SET) { \
if (MOD_FIELD_GET(event->event_id) == config_module_id) { \
BUILD_ASSERT(config_set_fn != NULL); \
(*config_set_fn)(OPT_ID_GET(OPT_FIELD_GET(event->event_id)), \
event->dyndata.data, \
event->dyndata.size); \
consume = true; \
} \
} else if (event->status == CONFIG_STATUS_FETCH) { \
if (MOD_FIELD_GET(event->event_id) == config_module_id) { \
if (OPT_FIELD_GET(event->event_id) == MODULE_OPT_MODULE_DESCR) {\
if (cur_opt_descr < ARRAY_SIZE(opt_descr) + 1) { \
const char *data_ptr; \
\
if (cur_opt_descr == 0) { \
data_ptr = mod_name; \
} else { \
data_ptr = opt_descr[cur_opt_descr - 1];\
} \
rsp_data_size = strlen(data_ptr); \
__ASSERT_NO_MSG(rsp_data_size <= \
sizeof(rsp_data_buf)); \
strncpy((char *) rsp_data_buf, data_ptr, \
rsp_data_size); \
cur_opt_descr++; \
} else { \
rsp_data_size = sizeof(uint8_t); \
rsp_data_buf[0] = MODULE_DESCR_END_CHAR; \
cur_opt_descr = 0; \
} \
} else { \
BUILD_ASSERT(config_fetch_fn != NULL); \
(*config_fetch_fn)(OPT_ID_GET( \
OPT_FIELD_GET(event->event_id)), \
rsp_data_buf, \
&rsp_data_size); \
} \
consume = true; \
} \
} \
\
if (consume) { \
struct config_event *rsp = new_config_event(rsp_data_size); \
\
rsp->transport_id = event->transport_id; \
rsp->recipient = event->recipient; \
rsp->event_id = event->event_id; \
rsp->status = CONFIG_STATUS_SUCCESS; \
rsp->is_request = false; \
\
if (rsp_data_size > 0) { \
memcpy(rsp->dyndata.data, rsp_data_buf, rsp_data_size); \
} \
\
APP_EVENT_SUBMIT(rsp); \
} \
\
return consume; \
}
#define CFG_CHAN_RECIPIENT_LOCAL
Definition: config_event.h:79
#define OPT_ID_GET(opt_field)
Definition: config_event.h:67
#define CONFIG_CHANNEL_FETCHED_DATA_MAX_SIZE
Definition: config_event.h:51
#define MOD_FIELD_GET(event_id)
Definition: config_event.h:59
#define MODULE_OPT_MODULE_DESCR
Definition: config_event.h:70
#define MODULE_DESCR_END_CHAR
Definition: config_event.h:73
#define OPT_FIELD_MASK
Definition: config_event.h:63
#define OPT_FIELD_GET(event_id)
Definition: config_event.h:65
bool is_request
Definition: config_event.h:88
uint8_t status
Definition: config_event.h:93
uint8_t recipient
Definition: config_event.h:92
uint16_t transport_id
Definition: config_event.h:87
uint8_t event_id
Definition: config_event.h:91
struct event_dyndata dyndata
Definition: config_event.h:94
Configuration channel event. Used to forward configuration channel request/response.
Definition: config_event.h:84