数据通信
通过 xplugin::xPluginInterface()(原始类:InterfaceManager)访问。详细签名见 接口说明。
插件间通信
- commandCustomData接口用于控制器侧自定义插件通信,返回 QJsonArray(元素为各插件名与键值 JSON)。
// 自定义控制器插件名称 "ControllerPluginName"
// 读
auto arr = xplugin::xPluginInterface().commandCustomData(
this, "ControllerPluginName", "key");
// 写 key-val
xplugin::xPluginInterface().commandCustomData(
this, "ControllerPluginName", "key", "value");
// 写 JSON 对象 / 数组
xplugin::xPluginInterface().commandCustomData(
this, "ControllerPluginName", QJsonObject{{"k", "v"}});
- 协议设计可与控制器插件约定 JSON 结构;控制器册参见 客户端交互。
xservice 读写与订阅
auto &iface = xplugin::xPluginInterface();
QJsonValue v = iface.getXServiceData("project.tasks_pointer");
iface.setXServiceData("some.key", QVariant(1));
iface.connectXServiceData(PLUGIN_NAME, "project.tasks_pointer",
[](const QVariant &data) { /* 变化回调 */ },
""); // 可选 key,与 pluginName+serviceKey 组成唯一 id
iface.disconnectXServiceData(PLUGIN_NAME, "project.tasks_pointer");
- commandXServiceData:异步操作接口
- execCommandXServiceData:同步操作接口并返回 QJsonValue
RC 接口请求
auto &iface = xplugin::xPluginInterface();
iface.rcRequest("module", "command", QJsonValue());
QJsonValue result = iface.rcExecRequest("module", "command", QJsonValue(), true, 1600);
iface.rcRequestFullCommand("full.path.command", QJsonValue());
- 默认超时:异步 4800 ms,同步 1600 ms。
网络状态
方式一:Qt 信号
connect(&xplugin::xPluginInterface(), &xplugin::InterfaceManager::sigNetworkConnect,
this, &MyClass::onConnected);
方式二:回调注册
auto &iface = xplugin::xPluginInterface();
QString id = iface.connectNetworkStatus(true, PLUGIN_NAME, this, [](){});
iface.disconnectNetworkStatus(true, PLUGIN_NAME, id);
方式三:事件总线 — NetworkConnected / NetworkDisconnected,见 事件系统。