已创建新的分层目录结构:
src/common/dom/ - DOM模型定义src/common/types.h - 公共类型定义src/core/pal/ - 协议适配层src/core/dal/ - 数据抽象层src/core/sbl/ - 服务总线层src/api/ - 统一接口层src/common/dom/DomBase.h)src/core/pal/)src/core/dal/)src/core/sbl/)src/core/SoftBusCore.h/cpp)src/api/SoftBusAPI.h/cpp)已将所有新文件添加到CMakeLists.txt中。
docs/ARCHITECTURE.md - 架构说明文档docs/REFACTORING_GUIDE.md - 重构指南需要重构以下UI组件,移除直接Manager依赖:
SerialDockPage - 移除SerialManager成员,改用APISerialDataWidget - 移除setSerialManager,改用APIViewCan - 移除CanManager成员,改用API示例重构(见 docs/REFACTORING_GUIDE.md):
// 旧代码
connect(m_serialManager, &SerialManager::dataReceived, ...);
// 新代码
connect(SoftBusAPI::instance(), &SoftBusAPI::dataChanged, ...);
需要创建映射配置文件:
config/tag_mapping.json 示例文件需要更新 main.cpp:
#include "api/SoftBusAPI.h"
#include "core/SoftBusCore.h"
#include "core/pal/serial/SerialProtocolAdapter.h"
#include "serial_manager/serial_manager.h"
#include "soft_bus_core/soft_bus_core.h"
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
// 1. 初始化新的软总线API
SoftBusAPI* api = SoftBusAPI::instance();
api->initialize();
// 2. 创建旧的SoftBusCore(用于数据库兼容)
SoftBusCore* oldBusCore = new SoftBusCore();
oldBusCore->initDB("soft_bus_db");
// 3. 创建SerialManager(保持向后兼容)
SerialManager* serialManager = new SerialManager(oldBusCore);
// 4. 创建协议适配器并注册
SerialProtocolAdapter* serialAdapter = new SerialProtocolAdapter();
serialAdapter->setSerialManager(serialManager);
SoftBusCore::instance()->registerProtocolAdapter(serialAdapter);
// 5. 加载映射配置
SoftBusCore::instance()->getDataMapper()->loadProfile("config/tag_mapping.json");
// 6. 创建主窗口
MainWindow window;
window.show();
return app.exec();
}
// 在UI组件中
#include "api/SoftBusAPI.h"
// 订阅数据
SoftBusAPI::instance()->subscribe("*");
connect(SoftBusAPI::instance(), &SoftBusAPI::dataChanged,
this, &MyWidget::onDataChanged);
// 发送控制指令
SoftBusAPI::instance()->sendCommand("Pump.Main.Control", 1);