# softbus_daemon API 接口表 本文档汇总 `src/api/ipc_dbus` 当前对外接口,分为: - D-Bus 直接方法 - `executeCommand` JSON 命令接口 ## 1) D-Bus 服务基础信息 | 项目 | 值 | |---|---| | Service | `com.softbus.Daemon` | | ObjectPath | `/com/softbus/Daemon` | | Interface | `com.softbus.Daemon` | | 适配类 | `IpcDBus` | ## 2) D-Bus 方法表(IpcDBus) | 方法 | 入参 | 返回 | 说明 | |---|---|---|---| | `isRunning()` | 无 | `bool` | 核心服务是否初始化完成 | | `ping()` | 无 | `QString` | 健康探针,固定返回 `pong` | | `getVersion()` | 无 | `QString` | 进程版本号 | | `getStatus()` | 无 | `QString(JSON)` | 返回服务状态(pid/role/running/timestamp 等) | | `getPid()` | 无 | `qint64` | 返回守护进程 PID | | `shutdown()` | 无 | `void` | 关闭 CoreService 并退出进程 | | `reloadConfig()` | 无 | `bool` | 预留,当前为占位实现 | | `executeCommand(requestJson)` | `QString(JSON)` | `QString(JSON)` | 统一 JSON 命令入口 | ## 3) executeCommand 协议 ### 3.1 请求格式 ```json { "id": "req-001", "action": "add_filter", "params": {} } ``` ### 3.2 响应格式 ```json { "id": "req-001", "code": 0, "message": "ok", "data": {} } ``` ## 4) action 路由表(CommandDispatcher) | action | params 关键字段 | 成功 code | 失败 code | 说明 | |---|---|---:|---:|---| | `add_filter` | `id`, `endpoint?`, `deviceId?`, `stableKey?`, `condition?` | `0` | `4001` | 添加过滤规则 | | `remove_filter` | `id` | `0` | `4041` | 删除过滤规则 | | `add_transform_rule` | `id`, `endpoint?`, `deviceId?`, `stableKey?`, `scale?`, `offset?`, `unit?` | `0` | `4002` | 添加转换规则 | | `remove_transform_rule` | `id` | `0` | `4042` | 删除转换规则 | | `list_rules` | 无 | `0` | - | 返回规则计数状态 | | `get_status` | 无 | `0` | - | 返回规则计数状态 | | 其他未知 action | - | - | `4040` | 未知动作 | ## 5) 通用错误码约定(当前实现) | code | message | 说明 | |---:|---|---| | `0` | `ok` | 成功 | | `4000` | `invalid_json` | 请求 JSON 无法解析或非对象 | | `4001` | `invalid_filter_rule` | 过滤规则参数非法 | | `4002` | `invalid_transform_rule` | 转换规则参数非法 | | `4003` | `invalid_action` | action 为空或分发器不可用 | | `4040` | `unknown_action` | action 未注册 | | `4041` | `filter_not_found` | 删除过滤规则时未找到 | | `4042` | `transform_rule_not_found` | 删除转换规则时未找到 | ## 6) 维护建议 - 新增 action 时,同时更新: - `CommandDispatcher::dispatch(...)` - 本文档第 4 节 action 表 - 若扩展返回结构,保持 `code/message/data` 三元组不变,避免客户端兼容性问题。