feat(events): 添加传输策略事件支持
添加了新的 transport_policy_event 事件类型,用于管理 HID 传输策略和蓝牙配置文件策略。该事件包含源模式、HID 传输策 略和蓝牙配置文件策略三个枚举值,并提供了相应的提交函数 和日志记录功能。 BREAKING CHANGE: 将原有的 mode_switch_event 替换为更具体的 transport_policy_event,相关模块需要更新以使用新的事件类 型。
This commit is contained in:
78
src/events/transport_policy_event.c
Normal file
78
src/events/transport_policy_event.c
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "transport_policy_event.h"
|
||||
|
||||
static const char *source_mode_name(enum mode_switch_mode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case MODE_SWITCH_USB:
|
||||
return "USB";
|
||||
case MODE_SWITCH_BLE:
|
||||
return "BLE";
|
||||
case MODE_SWITCH_24G:
|
||||
return "24G";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *hid_transport_policy_name(enum hid_transport_policy transport)
|
||||
{
|
||||
switch (transport) {
|
||||
case HID_TRANSPORT_POLICY_NONE:
|
||||
return "none";
|
||||
case HID_TRANSPORT_POLICY_USB:
|
||||
return "usb";
|
||||
case HID_TRANSPORT_POLICY_BLE:
|
||||
return "ble";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *ble_profile_policy_name(enum ble_profile_policy profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case BLE_PROFILE_POLICY_NONE:
|
||||
return "none";
|
||||
case BLE_PROFILE_POLICY_GENERAL:
|
||||
return "general";
|
||||
case BLE_PROFILE_POLICY_DONGLE:
|
||||
return "dongle";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static void log_transport_policy_event(const struct app_event_header *aeh)
|
||||
{
|
||||
const struct transport_policy_event *event =
|
||||
cast_transport_policy_event(aeh);
|
||||
|
||||
APP_EVENT_MANAGER_LOG(aeh, "source:%s hid:%s ble:%s",
|
||||
source_mode_name(event->source_mode),
|
||||
hid_transport_policy_name(event->hid_transport),
|
||||
ble_profile_policy_name(event->ble_profile));
|
||||
}
|
||||
|
||||
static void profile_transport_policy_event(struct log_event_buf *buf,
|
||||
const struct app_event_header *aeh)
|
||||
{
|
||||
const struct transport_policy_event *event =
|
||||
cast_transport_policy_event(aeh);
|
||||
|
||||
nrf_profiler_log_encode_uint8(buf, event->source_mode);
|
||||
nrf_profiler_log_encode_uint8(buf, event->hid_transport);
|
||||
nrf_profiler_log_encode_uint8(buf, event->ble_profile);
|
||||
}
|
||||
|
||||
APP_EVENT_INFO_DEFINE(transport_policy_event,
|
||||
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U8,
|
||||
NRF_PROFILER_ARG_U8),
|
||||
ENCODE("source_mode", "hid_transport", "ble_profile"),
|
||||
profile_transport_policy_event);
|
||||
|
||||
APP_EVENT_TYPE_DEFINE(transport_policy_event,
|
||||
log_transport_policy_event,
|
||||
&transport_policy_event_info,
|
||||
APP_EVENT_FLAGS_CREATE(
|
||||
IF_ENABLED(CONFIG_BRIDGE_LOG_TRANSPORT_POLICY_EVENT,
|
||||
(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE))));
|
||||
Reference in New Issue
Block a user