Skip to content

refactor: switch treeland IPC to Qt Remote Objects#96

Open
zccrs wants to merge 1 commit into
linuxdeepin:masterfrom
zccrs:qremoteobject-treeland-ipc
Open

refactor: switch treeland IPC to Qt Remote Objects#96
zccrs wants to merge 1 commit into
linuxdeepin:masterfrom
zccrs:qremoteobject-treeland-ipc

Conversation

@zccrs

@zccrs zccrs commented Jun 2, 2026

Copy link
Copy Markdown
Member

Summary

  • replace the treeland Wayland client IPC in ddm with a Qt Remote Objects replica
  • remove the generated treeland-ddm Wayland client protocol from ddm
  • keep dde-seatd control socket handling unchanged

Testing

  • cmake --build build

@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 @zccrs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zccrs

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

@zccrs zccrs force-pushed the qremoteobject-treeland-ipc branch 3 times, most recently from 9c5c73a to 38f5a23 Compare June 3, 2026 02:47
@zccrs zccrs requested a review from Copilot June 3, 2026 02:48

Copilot AI 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.

Pull request overview

Refactors ddm’s Treeland IPC from a generated Wayland client protocol to a Qt Remote Objects (QtRO) replica, aligning the daemon-side connector with Qt’s IPC stack and removing the build-time Wayland-client codegen dependency.

ddm 与 Treeland 的 IPC 进行重构:从原先生成的 Wayland client 协议切换为 Qt Remote Objects(QtRO)replica,使 daemon 侧连接器改用 Qt 的 IPC 机制,并移除构建期的 Wayland-client 协议代码生成依赖。

Changes:

  • Introduces a QtRO replica definition (treelandddmremote.rep) and switches TreelandConnector to call into the generated TreelandDDMRemoteReplica.
  • Removes Wayland client protocol code generation/linkage from CMake and adds Qt6 RemoteObjects dependency.
  • Updates distro/CI dependencies to include Qt Remote Objects (Debian Build-Depends, Arch workflow).

变更点:

  • 新增 QtRO replica 定义(treelandddmremote.rep),并让 TreelandConnector 通过生成的 TreelandDDMRemoteReplica 发起调用。
  • 从 CMake 中移除 Wayland client 协议生成/链接,并新增 Qt6 RemoteObjects 依赖。
  • 更新发行版/CI 依赖(Debian Build-Depends、Arch workflow)以包含 Qt Remote Objects。

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/daemon/treelandddmremote.rep Adds Qt Remote Objects replica interface for Treeland control methods.
src/daemon/TreelandConnector.h Updates connector interface/members for QtRO + local socket usage.
src/daemon/TreelandConnector.cpp Replaces Wayland IPC calls with QtRO replica acquisition and invocation logic.
src/daemon/CMakeLists.txt Hooks qt_add_repc_replicas() and links Qt6::RemoteObjects; removes Wayland-generated source.
CMakeLists.txt Drops Wayland client/TreelandProtocols discovery; adds Qt6 RemoteObjects requirement.
debian/control Adds qt6-remoteobjects-dev to Build-Depends.
.github/workflows/ddm-archlinux-build.yml Installs Qt Remote Objects dependency for Arch CI build.
Comments suppressed due to low confidence (1)

src/daemon/TreelandConnector.h:43

  • Include guards need to be closed at the end of the header (#endif).

建议:在文件末尾补上 #endif,与文件开头的 #ifndef/#define 成对。

};
}

Comment thread src/daemon/TreelandConnector.cpp Outdated
Comment thread src/daemon/TreelandConnector.cpp
Comment thread src/daemon/TreelandConnector.cpp Outdated
Comment thread src/daemon/TreelandConnector.h Outdated
Comment thread src/daemon/TreelandConnector.h Outdated
Comment thread .github/workflows/ddm-archlinux-build.yml Outdated
Comment thread debian/control Outdated
Comment thread src/daemon/TreelandConnector.cpp Outdated
Comment thread src/daemon/treelandddmremote.rep Outdated
Comment thread src/daemon/treelandddmremote.rep Outdated
@zccrs zccrs force-pushed the qremoteobject-treeland-ipc branch from 38f5a23 to d13b4bb Compare June 3, 2026 04:04
@zccrs

zccrs commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

已按这轮 review 收口:

  • TreelandConnector 里重复实现的 dde-seatd control socket / grouped-VT 逻辑已全部删除,VT 事件统一回到现有 DdeSeatdControl + SeatManager::handleVtChanged()
  • treelandddmremote.rep 已删掉未再使用的 activateSession/deactivateSession/enableRender/disableRender,两端接口只保留当前实际使用的 switchToGreeter/switchToUser
  • TreelandConnector.h 已改为 #pragma once,空的 setSignalHandler() 和未使用的 grouped-VT 包装接口一并移除。
  • debian/control、Arch/Deepin CI 中残留的 libwayland-dev / treeland-protocols 构建依赖已删除;本分支当前已不再使用这些构建输入。

之前 Copilot 提到的同步 control-socket I/O、协议版本、getpwnam()、TOCTOU 等问题,都是基于那套已经删掉的重复实现,当前 head 已不再适用。#endif 那条也是误报:这里现在用的是 #pragma once

@zccrs zccrs force-pushed the qremoteobject-treeland-ipc branch from d13b4bb to 40ceee2 Compare June 3, 2026 10:36
Comment thread src/daemon/TreelandConnector.cpp Outdated
Comment thread src/daemon/TreelandConnector.cpp Outdated
Comment thread src/daemon/SocketServer.cpp Outdated

connect(socket, &QLocalSocket::disconnected, socket, &QLocalSocket::deleteLater);
connect(socket, &QLocalSocket::disconnected, this, [this] {
Q_EMIT disconnected();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

这样就不用写成一个lambda了,直接链接就行

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

已处理:去掉了这里的 lambda,QLocalSocket::disconnected 现在直接连接到 deleteLater();同时不再额外通过 SocketServer::disconnected 做日志胶水。

Comment thread src/daemon/SocketServer.cpp Outdated
void SocketServer::login(QString user, QString password, int sessionType, QString sessionFile) {
qDebug() << "Message received from greeter: Login";
Session session(static_cast<Session::Type>(sessionType), sessionFile);
Q_EMIT loginRequested(user, password, session);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

不要搞这种设计呀,不能直接调用实现方的 login 方法吗?不要用这种发出信号,再在外面做一个胶水层的方式,多此一举。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

已处理:SocketServer 现在持有对应的 Display,远端 login/logout/lock/unlock/connectGreeter 请求会直接调用实现方方法,不再先发 loginRequested 等信号再由外层胶水转发。

Comment thread src/daemon/greeterddmremote.rep Outdated
// SPDX-License-Identifier: GPL-2.0-or-later

class GreeterDDMRemote {
PROP(QString hostName)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

这些属性是不是应该声明为只读的?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

已处理:这些属性已改成 SOURCEONLYSETTER。这样 ddm source 侧仍可更新属性值,但 replica/greeter 侧只能读取和订阅变更,语义上是远端只读。

Comment thread src/daemon/SocketServer.cpp Outdated
@zccrs zccrs force-pushed the qremoteobject-treeland-ipc branch 7 times, most recently from f308bc0 to 1ca093d Compare June 4, 2026 08:37
@deepin-bot

deepin-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.3.5
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #100

Comment thread src/daemon/Display.cpp Outdated
Comment thread src/daemon/Display.cpp Outdated
Comment thread src/daemon/Display.cpp
Comment thread src/daemon/SocketServer.cpp Outdated
Comment thread src/daemon/SocketServer.cpp Outdated
Comment thread src/daemon/SocketServer.cpp
Comment thread src/daemon/SocketServer.cpp Outdated
@zccrs zccrs force-pushed the qremoteobject-treeland-ipc branch 6 times, most recently from 63e12e6 to 94014e1 Compare June 8, 2026 03:44
@zccrs zccrs force-pushed the qremoteobject-treeland-ipc branch 4 times, most recently from 20ccead to 1e654d8 Compare June 8, 2026 05:44
Replace the greeter IPC bridge with Qt Remote Objects endpoints.
Use DDMRemote and TreelandRemote as cross-process call contracts.

将 greeter IPC 桥接改为 Qt Remote Objects 端点。
使用 DDMRemote 和 TreelandRemote 作为跨进程调用契约。

Log: 切换 Treeland 与 DDM 的 IPC 到 Qt Remote Objects
Influence: 规范远程对象和 socket 命名,影响 DDM 与 Treeland 的登录/切换通信。
@zccrs zccrs force-pushed the qremoteobject-treeland-ipc branch from 1e654d8 to c8cc950 Compare June 8, 2026 06:25
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查报告

总体概述

这次代码更新主要涉及显示管理器(DDM)的重构,从基于Wayland原生协议通信转向使用Qt的远程对象框架(QtRO)进行进程间通信。重构旨在提高代码的可维护性和安全性。

主要变更

  1. 通信机制改变

    • 从直接使用Wayland协议和本地套接字转向Qt Remote Objects (QtRO)
    • 新增了ddmremote.reptreelandremote.rep定义远程对象接口
  2. 依赖关系调整

    • 移除了对treeland-protocols-git的源码构建依赖
    • 添加了qt6-remoteobjects作为新的依赖
  3. 架构优化

    • 简化了Display类中的socket连接管理
    • 改进了会话状态跟踪机制
    • 优化了电源管理功能的实现

详细分析

1. 代码质量

优点

  • 代码结构更加清晰,职责分离更好
  • 使用QtRO替代了直接的套接字通信,提高了抽象层次
  • 错误处理更加完善

需要改进的地方

  • Display.cpp中的onTreelandLockStateChanged方法过于复杂,建议拆分为更小的函数
  • PowerManager.cpp中的能力检查逻辑可以进一步封装

2. 性能考虑

优点

  • 使用QtRO可能比直接套接字通信有更好的性能
  • 减少了不必要的数据拷贝

潜在问题

  • 远程对象调用可能引入额外的延迟,需要确保关键路径的性能
  • watchUserSession方法中的异步调用可能导致竞态条件

3. 安全性

优点

  • 移除了直接处理Wayland协议的代码,减少了潜在的安全风险
  • 使用QtRO提供了更好的访问控制机制

需要注意的地方

  • SocketServer::start()方法中的套接字名称生成需要确保唯一性
  • 用户认证相关的逻辑需要特别注意安全性

具体建议

  1. Display.cpp改进

    // 当前代码
    void Display::onTreelandLockStateChanged(bool locked) {
        m_treelandLocked = locked;
        if (m_activeTreelandSessionId <= 0)
            return;
        // ... 长段代码
    }
    
    // 建议拆分为
    void Display::onTreelandLockStateChanged(bool locked) {
        m_treelandLocked = locked;
        if (m_activeTreelandSessionId <= 0)
            return;
        updateLockState(locked);
    }
    
    void Display::updateLockState(bool locked) {
        OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(),
                                                   Logind::managerPath(),
                                                   QDBusConnection::systemBus());
        if (locked)
            manager.LockSession(QString::number(m_activeTreelandSessionId));
        else
            manager.UnlockSession(QString::number(m_activeTreelandSessionId));
    }
  2. PowerManager.cpp改进

    // 当前代码
    bool PowerManager::canPowerOff() const {
        for (PowerManagerBackend *backend: m_backends) {
            if (backend->canPowerOff())
                return true;
        }
        return false;
    }
    
    // 建议添加缓存
    void PowerManager::updateCapabilities() {
        m_capabilities = Capability::None;
        for (PowerManagerBackend *backend : m_backends) {
            m_capabilities |= backend->capabilities();
        }
    }
  3. 安全性增强

    • SocketServer::start()中添加套接字权限检查
    • 在认证相关方法中添加输入验证

总结

这次重构整体上是积极的,提高了代码的可维护性和安全性。主要改进了进程间通信机制,简化了复杂的会话管理逻辑。建议关注性能影响,并进一步完善错误处理和安全性验证。

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.

3 participants