|
26 | 26 | using namespace chip;
|
27 | 27 | using namespace chip::app::Clusters;
|
28 | 28 |
|
29 |
| -namespace { |
30 |
| - |
31 |
| -// Constants |
32 |
| -constexpr uint32_t kSyncPrepareTimeMs = 1000; |
33 |
| - |
34 |
| -} // namespace |
35 |
| - |
36 | 29 | // Define the static member
|
37 | 30 | DeviceManager DeviceManager::sInstance;
|
38 | 31 |
|
39 | 32 | void DeviceManager::Init()
|
40 | 33 | {
|
41 |
| - // TODO: Init mLastUsedNodeId from chip config file |
| 34 | + // TODO: (#34113) Init mLastUsedNodeId from chip config file |
42 | 35 | mLastUsedNodeId = 1;
|
43 | 36 | }
|
44 | 37 |
|
@@ -93,19 +86,18 @@ Device * DeviceManager::FindDeviceByNode(NodeId nodeId)
|
93 | 86 | void DeviceManager::RemoveSyncedDevice(NodeId nodeId)
|
94 | 87 | {
|
95 | 88 | Device * device = FindDeviceByNode(nodeId);
|
96 |
| - if (device != nullptr) |
97 |
| - { |
98 |
| - mSyncedDevices.erase(*device); |
99 |
| - ChipLogProgress(NotSpecified, "Removed synced device: NodeId:" ChipLogFormatX64 ", EndpointId %u", |
100 |
| - ChipLogValueX64(device->GetNodeId()), device->GetEndpointId()); |
101 |
| - } |
102 |
| - else |
| 89 | + if (device == nullptr) |
103 | 90 | {
|
104 | 91 | ChipLogProgress(NotSpecified, "No device found with NodeId:" ChipLogFormatX64, ChipLogValueX64(nodeId));
|
| 92 | + return; |
105 | 93 | }
|
| 94 | + |
| 95 | + mSyncedDevices.erase(*device); |
| 96 | + ChipLogProgress(NotSpecified, "Removed synced device: NodeId:" ChipLogFormatX64 ", EndpointId %u", |
| 97 | + ChipLogValueX64(device->GetNodeId()), device->GetEndpointId()); |
106 | 98 | }
|
107 | 99 |
|
108 |
| -void DeviceManager::HanldeAttributeChange(const app::ConcreteDataAttributePath & path, TLV::TLVReader * data) |
| 100 | +void DeviceManager::HandleAttributeChange(const app::ConcreteDataAttributePath & path, TLV::TLVReader * data) |
109 | 101 | {
|
110 | 102 | if (path.mClusterId != Descriptor::Id || path.mAttributeId != Descriptor::Attributes::PartsList::Id)
|
111 | 103 | {
|
@@ -140,10 +132,15 @@ void DeviceManager::HanldeAttributeChange(const app::ConcreteDataAttributePath &
|
140 | 132 | return;
|
141 | 133 | }
|
142 | 134 |
|
143 |
| - // Compare newEndpoints with mSyncedEndpoints to determine added and removed endpoints |
| 135 | + // Compare newEndpoints with mSyncedDevices to determine added and removed endpoints |
144 | 136 | std::vector<EndpointId> addedEndpoints;
|
145 | 137 | std::vector<EndpointId> removedEndpoints;
|
146 | 138 |
|
| 139 | + // Note: We're using vectors and manual searches instead of set operations |
| 140 | + // because we need to work with the Device objects in mSyncedDevices, |
| 141 | + // not just their EndpointIds. This approach allows us to access the full |
| 142 | + // Device information when processing changes. |
| 143 | + |
147 | 144 | // Find added endpoints
|
148 | 145 | for (const auto & endpoint : newEndpoints)
|
149 | 146 | {
|
@@ -172,8 +169,6 @@ void DeviceManager::HanldeAttributeChange(const app::ConcreteDataAttributePath &
|
172 | 169 | {
|
173 | 170 | char command[64];
|
174 | 171 | snprintf(command, sizeof(command), "fabricsync sync-device %d", endpoint);
|
175 |
| - |
176 |
| - usleep(kSyncPrepareTimeMs * 1000); |
177 | 172 | PushCommand(command);
|
178 | 173 | }
|
179 | 174 | }
|
@@ -205,8 +200,6 @@ void DeviceManager::HanldeAttributeChange(const app::ConcreteDataAttributePath &
|
205 | 200 | }
|
206 | 201 |
|
207 | 202 | pairingCommand->RegisterPairingDelegate(this);
|
208 |
| - |
209 |
| - usleep(kSyncPrepareTimeMs * 1000); |
210 | 203 | PushCommand(command);
|
211 | 204 | }
|
212 | 205 | }
|
|
0 commit comments