23struct PluginSubscription {
24 void* plugin =
nullptr;
25 uint32_t action_id = 0;
31constexpr size_t MAX_PLUGIN_SUBSCRIPTIONS = 16;
37bool s_core_subscribed =
false;
38uint8_t s_core_bus_id = 0;
40PluginSubscription* slotForId(uint32_t
id) {
41 return s_subs.
lookup(
static_cast<int>(
id));
47void update_long_press_defer() {
48 constexpr uint32_t kLongPressBit =
51 for (
auto& s : s_subs.
slots) {
52 if (s.used && (s.mask & kLongPressBit)) {
63 const uint32_t bit = 1u <<
static_cast<uint8_t
>(evt.
type);
64 for (
auto& s : s_subs.
slots) {
65 if (!s.used || (s.mask & bit) == 0)
continue;
70 static_cast<uint32_t
>(evt.
type),
85 PluginSubscription* slot = s_subs.
allocate(slot_id);
87 plg_log_warn(
"EventBus: plugin subscription table full");
91 slot->plugin = plugin;
92 slot->action_id = action_id;
93 slot->mask = event_mask;
95 if (!s_core_subscribed) {
97 s_core_subscribed =
true;
99 slot->bus_id = s_core_bus_id;
101 update_long_press_defer();
107 auto* slot = slotForId(subscription_id);
111 *slot = PluginSubscription{};
112 update_long_press_defer();
125 evt.
data.
value =
static_cast<uint8_t
>(module_event_subtype & 0xff);
Discovers, loads, runs and unloads WASM plugins on the badge.
Owned WAMR module instance + per-plugin state.
Fixed-capacity, 1-based slot table for host-API resources.
static EventBus & instance()
Returns singleton event-bus instance.
bool publish(const Event &event, bool fromISR=false)
Publishes an event to the queue.
uint8_t subscribe(EventHandler handler, uint32_t mask=0)
Subscribes an event handler with optional type mask.
static constexpr uint32_t DEFER_SRC_EVENT
plugin KEY_LONG_PRESS subscription
static PluginManager & instance() noexcept
void dispatchActionTo(Plugin *plugin, uint32_t action_id, uint32_t idx, uint32_t user_data)
int host_event_publish(uint32_t module_event_subtype, uint32_t value)
Publish an EVENT_MODULE_EVENT carrying subtype and value.
int host_event_unsubscribe(uint32_t subscription_id)
Cancel a subscription returned by host_event_subscribe.
int host_event_subscribe(uint32_t event_mask, uint32_t action_id)
Subscribe to one or more events.
CDC Badge OS plugin host API - canonical C ABI contract.
#define HOST_ERR_NO_CAPABILITY
#define HOST_ERR_NO_MEMORY
#define HOST_ERR_NOT_FOUND
void plg_log_warn(const char *msg)
void * plg_get_active_plugin(void)
IKeypad * getKeypadInstance()
Returns the singleton keypad service instance.
union cdc::core::Event::@234350273243204124075032151001065005273232113040 data
T * lookup(int id)
1-based lookup. Returns nullptr if id is out of range or slot unused.
T * allocate(int &out_id)