Skip to main content

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):
TypeValueMeaning
NetworkConnected0x2001Network connected
NetworkDisconnected0x2002Network disconnected
XServiceDataChange0x3001xservice node changed
RCPowerStatusChange0x4001Power-on state changed
RCRunModelChange0x4011Manual/auto mode switch
RCRunStart / RCRunStop0x4021 / 0x4022Program run start/stop
RCBeforeRunStart / RCBeforeRunStop0x4023 / 0x4024Hooks 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);
tips: For thread-sensitive scenarios, use publishAsync

Unsubscribe

MethodPurpose
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.