Skip to content

feat(factory): upgrade DccFactory to v2.0 with lifecycle and DBus data channel#3228

Open
caixr23 wants to merge 1 commit into
linuxdeepin:masterfrom
caixr23:dcc-v2
Open

feat(factory): upgrade DccFactory to v2.0 with lifecycle and DBus data channel#3228
caixr23 wants to merge 1 commit into
linuxdeepin:masterfrom
caixr23:dcc-v2

Conversation

@caixr23

@caixr23 caixr23 commented May 13, 2026

Copy link
Copy Markdown
Contributor
  1. Rename DccFactory to DccFactory_20, bump IID to v2.0
  2. Add registerType() for QML type registration in main thread
  3. Add active() for post-creation activation in main thread
  4. Add get/set virtual methods for DBus-triggered data access in worker thread
  5. Add DCC_FULL_FACTORY_CLASS macro with singleton create and full lifecycle delegation to classname::registerType/active/get/set
  6. Preserve v1.0 interface in dccfactoryold.h for backward compatibility
  7. Wire DBus get/set slots in ControlCenterDBusAdaptor and DccManager (async dispatch pending)
  8. Migrate DefAppModel plugin as first v2.0 adopter, move qmlRegisterType into static registerType()

Influence:

  1. Verify existing v1.0 plugins still load via old interface
  2. Verify DefAppModel QML types register correctly on startup

feat(factory): 升级 DccFactory 至 v2.0,支持生命周期管理与 DBus 数据通道

  1. 将 DccFactory 重命名为 DccFactory_20,IID 升级为 v2.0
  2. 新增 registerType() 用于在主线程中注册 QML 类型
  3. 新增 active() 用于在主线程中执行创建后激活
  4. 新增 get/set 虚函数用于在子线程中响应 DBus 数据请求
  5. 新增 DCC_FULL_FACTORY_CLASS 宏,支持单例创建及完整生命周期 委托至 classname::registerType/active/get/set
  6. 在 dccfactoryold.h 中保留 v1.0 接口以向后兼容
  7. 在 ControlCenterDBusAdaptor 和 DccManager 中接入 DBus get/set (异步分发待实现)
  8. 迁移 DefAppModel 插件作为首个 v2.0 适配示例,将 qmlRegisterType 移入静态 registerType()

Influence:

  1. 验证已有的 v1.0 插件仍能通过旧接口正常加载
  2. 验证 DefAppModel 的 QML 类型在启动时正确注册

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @caixr23, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Comment thread include/dccfactory.h
class DccObject;

class DccFactory : public QObject
class DccFactory_20 : public QObject

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

保留DccFactory名,旧插件处理会不会冲突

Comment thread include/dccfactory.h
}; \
}

#define DCC_FULL_FACTORY_CLASS(classname) \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

命名带版本号可以不冲突 DCC_FACTORY_V20_CLASS

Comment thread include/dccfactory.h
Q_SIGNALS:
// 模块中有设置项变化时,发出该信号
// 命名valuesChanged() 待定
void propertiesChanged(const QVariantMap &properties);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

信号命名问题,数据类型用QString(json)还是QVariantMap,get/set的类型要不要统一?
信号是否有依赖插件是否实现

@deepin-bot

deepin-bot Bot commented May 16, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.86
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3238

@deepin-bot

deepin-bot Bot commented May 20, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.87
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3245

@deepin-bot

deepin-bot Bot commented May 22, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.88
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3251

@deepin-bot

deepin-bot Bot commented May 25, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.89
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3253

@deepin-bot

deepin-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.90
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3279

@deepin-bot

deepin-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.91
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3281

…a channel

1. Rename DccFactory to DccFactory_20, bump IID to v2.0
2. Add registerType() for QML type registration in main thread
3. Add active() for post-creation activation in main thread
4. Add get/set virtual methods for DBus-triggered data access in
   worker thread
5. Add DCC_FULL_FACTORY_CLASS macro with singleton create and full
   lifecycle delegation to classname::registerType/active/get/set
6. Preserve v1.0 interface in dccfactoryold.h for backward
   compatibility
7. Wire DBus get/set slots in ControlCenterDBusAdaptor and DccManager
   (async dispatch pending)
8. Migrate DefAppModel plugin as first v2.0 adopter, move
   qmlRegisterType into static registerType()

Influence:
1. Verify existing v1.0 plugins still load via old interface
2. Verify DefAppModel QML types register correctly on startup

feat(factory): 升级 DccFactory 至 v2.0,支持生命周期管理与 DBus 数据通道

1. 将 DccFactory 重命名为 DccFactory_20,IID 升级为 v2.0
2. 新增 registerType() 用于在主线程中注册 QML 类型
3. 新增 active() 用于在主线程中执行创建后激活
4. 新增 get/set 虚函数用于在子线程中响应 DBus 数据请求
5. 新增 DCC_FULL_FACTORY_CLASS 宏,支持单例创建及完整生命周期
   委托至 classname::registerType/active/get/set
6. 在 dccfactoryold.h 中保留 v1.0 接口以向后兼容
7. 在 ControlCenterDBusAdaptor 和 DccManager 中接入 DBus get/set
   (异步分发待实现)
8. 迁移 DefAppModel 插件作为首个 v2.0 适配示例,将
   qmlRegisterType 移入静态 registerType()

Influence:
1. 验证已有的 v1.0 插件仍能通过旧接口正常加载
2. 验证 DefAppModel 的 QML 类型在启动时正确注册
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查意见

总体评价

这个diff展示了对DCC (Deepin Control Center)框架的重大重构,主要是从v1.0升级到v2.0版本。主要变化包括引入了新的工厂模式、DBus通信机制、以及插件加载策略的优化。整体架构设计合理,但存在一些需要注意的问题。

具体问题及建议

1. 代码质量问题

DccFactory接口变更

  • 问题: 将DccFactory重命名为DccFactory_20可能导致兼容性问题
  • 建议:
    • 添加版本检查机制
    • DccFactoryAdapter中增加更详细的日志记录,便于追踪兼容性问题

DBus接口实现

  • 问题: ControlCenterDBusAdaptor中新增的GetSet方法缺乏参数验证
  • 建议:
    QVariantMap ControlCenterDBusAdaptor::Get(const QString &module, const QVariantMap &param) {
        if (module.isEmpty()) {
            return QVariantMap{{"error", "Empty module name"}};
        }
        // 其他参数验证...
        return parent()->get(module, param);
    }

2. 代码性能问题

插件加载策略

  • 问题: DataRequestTask中的10秒超时可能不够灵活
  • 建议:
    // 在DccPluginManager中添加配置
    qint32 m_dataRequestTimeout = 10000; // 可配置的超时时间
    
    // 在DataRequestTask中使用配置
    timeout.setInterval(m_manager->dataRequestTimeout());

线程安全

  • 问题: DccFactoryAdapter中的setDataObject方法没有同步保护
  • 建议:
    void DccFactoryAdapter::setDataObject(QObject *data) {
        QMutexLocker locker(&m_dataMutex);
        m_data = data;
    }

3. 代码安全问题

DBus通信安全

  • 问题: DBus消息处理没有进行安全验证
  • 建议:
    void DccPluginManager::get(const QString &module, const QVariantMap &param, const QDBusMessage &message) {
        // 添加模块名称白校验
        static const QStringList allowedModules = {"display", "datetime", "defaultapp"};
        if (!allowedModules.contains(module)) {
            QDBusConnection::sessionBus().send(
                message.createErrorReply("org.deepin.dde.ControlCenter1.Error.InvalidModule",
                                       "Invalid module: " + module));
            return;
        }
        // 其他安全检查...
    }

内存管理

  • 问题: DccPluginLoader中的对象生命周期管理可能存在问题
  • 建议:
    • 添加对象引用计数
    • 实现更完善的资源清理机制

4. 架构设计建议

插件加载模式

  • 问题: OnlyDataFull两种模式切换可能造成状态不一致
  • 建议:
    • 添加状态转换验证
    • 实现更细粒度的加载控制

错误处理

  • 问题: 错误处理机制不够统一
  • 建议:
    enum class ErrorCode {
        Success = 0,
        InvalidParameter,
        ModuleNotFound,
        Timeout,
        // 其他错误码...
    };
    
    struct ErrorInfo {
        ErrorCode code;
        QString message;
    };

5. 其他建议

  1. 日志记录:

    • 增加更详细的日志记录,特别是状态转换和错误情况
    • 使用统一的日志格式和级别
  2. 单元测试:

    • 为新增的DBus接口和插件加载机制添加单元测试
    • 测试边界条件和异常情况
  3. 文档更新:

    • 更新开发者文档,说明v2.0的新特性
    • 提供迁移指南,帮助现有插件适配新版本
  4. 性能监控:

    • 添加性能监控点,特别是插件加载和DBus调用
    • 实现性能数据收集和分析机制

总结

这个重构版本引入了许多改进,特别是在架构设计和功能扩展方面。然而,需要注意兼容性、性能和安全性问题。建议在后续版本中:

  1. 完善错误处理机制
  2. 加强安全验证
  3. 优化性能瓶颈
  4. 提供更好的文档和迁移支持

@deepin-bot

deepin-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.92
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3292

@deepin-bot

deepin-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.93
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3293

@deepin-bot

deepin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.94
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3301

@deepin-bot

deepin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.95
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3305

@deepin-bot

deepin-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.96
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3314

@deepin-bot

deepin-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.97
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3322

@deepin-bot

deepin-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.98
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3328

@deepin-bot

deepin-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.99
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants