refactor: extract access point lookup and state handler - #626
Conversation
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
Reviewer's GuideRefactors 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 handlingsequenceDiagram
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()
Flow diagram for SSID-based access point lookupflowchart 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"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>| connect(conn.data(), &NetworkManager::Connection::unsavedChanged, this, [this] { | ||
| Q_EMIT activeConnectionChanged(); | ||
| }, Qt::UniqueConnection); |
There was a problem hiding this comment.
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.
Influence:
refactor: 提取访问点查找和状态处理逻辑
Influence:
修复在无线网络时候,重启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:
Enhancements: