Skip to content

refactor: extract access point lookup and state handler - #626

Open
wjyrich wants to merge 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-376663
Open

refactor: extract access point lookup and state handler#626
wjyrich wants to merge 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-376663

Conversation

@wjyrich

@wjyrich wjyrich commented Sep 11, 2026

Copy link
Copy Markdown
Contributor
  1. Extract the findAccessPoints lambda from onActiveConnectionChanged into a private member function findAccessPoints for reuse
  2. Extract the stateChanged lambda handler into a dedicated slot onStateChanged
  3. Use Qt::UniqueConnection for signal connections to prevent duplicate connections
  4. Add forward declaration of AccessPointProxyNM in the header
  5. Improve null safety by consolidating connection checks in the new helper methods

Influence:

  1. Test wireless connection state changes and verify status updates propagate correctly
  2. Verify access point lookup matches correct SSID during connection activation
  3. Test that duplicate signal connections are prevented when active connection changes repeatedly
  4. Verify timestamp updates on connection activation
  5. Test unsaved connection save flow and secret handling for 8021x and wireless security settings
  6. Confirm no regressions in active connection changed signal emission

refactor: 提取访问点查找和状态处理逻辑

  1. 将 onActiveConnectionChanged 中的 findAccessPoints lambda 提取为私有 成员函数 findAccessPoints 以便复用
  2. 将 stateChanged lambda 处理程序提取为专用槽函数 onStateChanged
  3. 使用 Qt::UniqueConnection 防止信号重复连接
  4. 在头文件中添加 AccessPointProxyNM 的前向声明
  5. 通过在新辅助方法中整合连接检查来提高空指针安全性

Influence:

  1. 测试无线连接状态变化,验证状态更新正确传播
  2. 验证连接激活期间访问点查找能匹配正确的 SSID
  3. 测试当活动连接反复变化时能防止信号重复连接
  4. 验证连接激活时时间戳更新
  5. 测试未保存连接的保存流程以及 8021x 和无线安全设置的密钥处理
  6. 确认活动连接变化信号发射无回归问题

修复在无线网络时候,重启networkmanager导致内存泄露的问题,
历史提交 : http://gerrit.uniontech.com/c/dde-network-core/+/281742

PMS: BUG-376663

Summary by Sourcery

Refactor wireless active-connection handling to improve lifecycle safety and prevent duplicate signal connections.

Bug Fixes:

  • Prevent memory leaks and duplicate signal handling when NetworkManager wireless active connections change or restart.

Enhancements:

  • Extract access-point lookup and active-connection state processing into reusable class members with consolidated connection validation.
  • Preserve wireless status, timestamp, unsaved connection, secret handling, and active-connection notifications while making signal subscriptions unique.

1. Extract the findAccessPoints lambda from onActiveConnectionChanged
into a private member function findAccessPoints for reuse
2. Extract the stateChanged lambda handler into a dedicated slot
onStateChanged
3. Use Qt::UniqueConnection for signal connections to prevent duplicate
connections
4. Add forward declaration of AccessPointProxyNM in the header
5. Improve null safety by consolidating connection checks in the new
helper methods

Influence:
1. Test wireless connection state changes and verify status updates
propagate correctly
2. Verify access point lookup matches correct SSID during connection
activation
3. Test that duplicate signal connections are prevented when active
connection changes repeatedly
4. Verify timestamp updates on connection activation
5. Test unsaved connection save flow and secret handling for 8021x and
wireless security settings
6. Confirm no regressions in active connection changed signal emission

refactor: 提取访问点查找和状态处理逻辑

1. 将 onActiveConnectionChanged 中的 findAccessPoints lambda 提取为私有
成员函数 findAccessPoints 以便复用
2. 将 stateChanged lambda 处理程序提取为专用槽函数 onStateChanged
3. 使用 Qt::UniqueConnection 防止信号重复连接
4. 在头文件中添加 AccessPointProxyNM 的前向声明
5. 通过在新辅助方法中整合连接检查来提高空指针安全性

Influence:
1. 测试无线连接状态变化,验证状态更新正确传播
2. 验证连接激活期间访问点查找能匹配正确的 SSID
3. 测试当活动连接反复变化时能防止信号重复连接
4. 验证连接激活时时间戳更新
5. 测试未保存连接的保存流程以及 8021x 和无线安全设置的密钥处理
6. 确认活动连接变化信号发射无回归问题

修复在无线网络时候,重启networkmanager导致内存泄露的问题,
历史提交 : http://gerrit.uniontech.com/c/dde-network-core/+/281742

PMS: BUG-376663
@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors wireless active-connection handling by extracting SSID-based access-point lookup and state processing into reusable class methods, consolidating null checks, and making both relevant signal connections unique to avoid duplicate callbacks while retaining status, timestamp, secret, save, and notification behavior.

Sequence diagram for wireless active connection state handling

sequenceDiagram
    participant AC as ActiveConnection
    participant WDM as WirelessDeviceManagerRealize
    participant AP as AccessPointProxyNM
    participant Conn as Connection
    participant WC as WirelessConnection

    WDM->>AC: stateChanged(state)
    AC-->>WDM: onStateChanged(state)
    WDM->>WDM: findAccessPoints(activeConnection)
    WDM->>Conn: connection()
    WDM->>AP: updateStatus(convertStateFromNetworkManager(state))
    WDM->>Conn: setTimestamp(currentDateTime())
    WDM->>WC: updateTimeStamp(timestamp)
    WDM-->>WDM: activeConnectionChanged()
Loading

Flow diagram for SSID-based access point lookup

flowchart TD
    A["Active connection changed"] --> B["findAccessPoints(activeConnection)"]
    B --> C{"Connection and wireless setting available?"}
    C -- No --> D["Return nullptr"]
    C -- Yes --> E["Match wireless SSID against access point SSID"]
    E --> F{"Matching access point found?"}
    F -- No --> D
    F -- Yes --> G["Return AccessPointProxyNM"]
Loading

File-Level Changes

Change Details Files
Extract access-point matching into a reusable null-safe helper.
  • Move SSID-based lookup out of the active-connection change handler.
  • Validate the active connection, underlying connection, and wireless settings before searching.
  • Use the helper both during activation handling and state-change processing.
src/impl/networkmanager/devicemanagerrealize.cpp
src/impl/networkmanager/devicemanagerrealize.h
Move active connection state processing into a dedicated slot while preserving status and timestamp behavior.
  • Resolve the emitting active connection and update access-point status and associated connection timestamps.
  • Retain unsaved-connection saving and retrieval of 8021x or wireless-security secrets on activation.
  • Continue emitting activeConnectionChanged after state processing.
src/impl/networkmanager/devicemanagerrealize.cpp
src/impl/networkmanager/devicemanagerrealize.h
Prevent duplicate signal subscriptions during repeated active-connection changes.
  • Connect stateChanged to the dedicated slot with Qt::UniqueConnection.
  • Connect unsavedChanged with Qt::UniqueConnection.
src/impl/networkmanager/devicemanagerrealize.cpp
Update declarations to support the extracted implementation.
  • Add the state-change slot and access-point lookup helper declarations.
  • Forward-declare AccessPointProxyNM in the header.
src/impl/networkmanager/devicemanagerrealize.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/impl/networkmanager/devicemanagerrealize.cpp" line_range="1050-1052" />
<code_context>
-                        }
-                        conn->save();
-                    }
-                    connect(conn.data(), &NetworkManager::Connection::unsavedChanged, this, [this] {
-                        Q_EMIT activeConnectionChanged();
-                    });
</code_context>
<issue_to_address>
**issue (bug_risk):** `Qt::UniqueConnection` does not deduplicate connections whose receiver is a lambda/functor, so each activation that reaches this block creates another `unsavedChanged` subscription. When the connection remains unsaved and emits `unsavedChanged`, the lambda emits `activeConnectionChanged()` once per accumulated subscription.

**Triggers:** When the same unsaved connection reaches the Activated state more than once, or when saving fails and the connection remains unsaved.

**Suggested fix:** Replace the lambda with a dedicated slot or explicitly store and disconnect the `QMetaObject::Connection` before reconnecting.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +1050 to +1052
connect(conn.data(), &NetworkManager::Connection::unsavedChanged, this, [this] {
Q_EMIT activeConnectionChanged();
}, Qt::UniqueConnection);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Qt::UniqueConnection does not deduplicate connections whose receiver is a lambda/functor, so each activation that reaches this block creates another unsavedChanged subscription. When the connection remains unsaved and emits unsavedChanged, the lambda emits activeConnectionChanged() once per accumulated subscription.

Triggers: When the same unsaved connection reaches the Activated state more than once, or when saving fails and the connection remains unsaved.

Suggested fix: Replace the lambda with a dedicated slot or explicitly store and disconnect the QMetaObject::Connection before reconnecting.

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.

1 participant