Event System
Client plugins use xplugin::xPluginEvent() with the unified event bus (XPluginEventSystem), complementing signals such as InterfaceManager::sigNetworkConnect: suitable for cross-module, custom-type, filtered, and one-shot subscriptions.
Subscribe Example
- Subscribe method
QString subId = xplugin::xPluginEvent().subscribe(
xplugin::XPluginEventType::RCPowerStatusChange,
[](const xplugin::XPluginEvent& e) {
// e.data(), e.source()
},
PLUGIN_NAME,
this // auto-unsubscribe when context is destroyed
);
- Common built-in types (see xpluginevent.h):
| Type | Value | Meaning |
|---|---|---|
| NetworkConnected | 0x2001 | Network connected |
| NetworkDisconnected | 0x2002 | Network disconnected |
| XServiceDataChange | 0x3001 | xservice node changed |
| RCPowerStatusChange | 0x4001 | Power-on state changed |
| RCRunModelChange | 0x4011 | Manual/auto mode switch |
| RCRunStart / RCRunStop | 0x4021 / 0x4022 | Program run start/stop |
| RCBeforeRunStart / RCBeforeRunStop | 0x4023 / 0x4024 | Hooks before run start/stop |
- User-defined events start from UserEventStart (0x8000); use registerCustomEventType("MyEvent") to allocate a type.
Publish
xplugin::xPluginEvent().publish(
xplugin::XPluginEventType::UserEventStart + 1,
QVariant("payload"),
PLUGIN_NAME);
Unsubscribe
| Method | Purpose |
|---|---|
| unsubscribe(subscriptionId) | By ID |
| unsubscribeByPlugin(PLUGIN_NAME) | All subscriptions for plugin |
| unsubscribeByType(type) | All subscriptions for type |
| unsubscribeByTypeAndPlugin(PLUGIN_NAME, type) | Plugin + type |
- On plugin
detach(), cancel all subscriptions for this plugin to avoid dangling callbacks.