Skip to content

Commit 403d595

Browse files
authored
[Fabric-Sync] Cleanup pass through APIs (#36604)
1 parent d1600cc commit 403d595

10 files changed

Lines changed: 36 additions & 146 deletions

examples/fabric-sync/admin/DeviceManager.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -212,81 +212,6 @@ void DeviceManager::OpenRemoteDeviceCommissioningWindow(EndpointId remoteEndpoin
212212
}
213213
}
214214

215-
CHIP_ERROR DeviceManager::PairRemoteFabricBridge(NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp,
216-
uint16_t deviceRemotePort)
217-
{
218-
CHIP_ERROR err = PairingManager::Instance().PairDevice(nodeId, setupPINCode, deviceRemoteIp, deviceRemotePort);
219-
220-
if (err != CHIP_NO_ERROR)
221-
{
222-
ChipLogError(NotSpecified,
223-
"Failed to pair remote fabric bridge: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
224-
ChipLogValueX64(nodeId), err.Format());
225-
return err;
226-
}
227-
228-
return CHIP_NO_ERROR;
229-
}
230-
231-
CHIP_ERROR DeviceManager::PairRemoteDevice(NodeId nodeId, const char * payload)
232-
{
233-
CHIP_ERROR err = PairingManager::Instance().PairDeviceWithCode(nodeId, payload);
234-
235-
if (err != CHIP_NO_ERROR)
236-
{
237-
ChipLogError(NotSpecified, "Failed to pair device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
238-
ChipLogValueX64(nodeId), err.Format());
239-
return err;
240-
}
241-
242-
return CHIP_NO_ERROR;
243-
}
244-
245-
CHIP_ERROR DeviceManager::PairRemoteDevice(NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp,
246-
uint16_t deviceRemotePort)
247-
{
248-
CHIP_ERROR err = PairingManager::Instance().PairDevice(nodeId, setupPINCode, deviceRemoteIp, deviceRemotePort);
249-
250-
if (err != CHIP_NO_ERROR)
251-
{
252-
ChipLogError(NotSpecified, "Failed to pair device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
253-
ChipLogValueX64(nodeId), err.Format());
254-
return err;
255-
}
256-
257-
return CHIP_NO_ERROR;
258-
}
259-
260-
CHIP_ERROR DeviceManager::UnpairRemoteFabricBridge()
261-
{
262-
if (mRemoteBridgeNodeId == kUndefinedNodeId)
263-
{
264-
ChipLogError(NotSpecified, "Remote bridge node ID is undefined; cannot unpair device.");
265-
return CHIP_ERROR_INCORRECT_STATE;
266-
}
267-
268-
CHIP_ERROR err = PairingManager::Instance().UnpairDevice(mRemoteBridgeNodeId);
269-
if (err != CHIP_NO_ERROR)
270-
{
271-
ChipLogError(NotSpecified, "Failed to unpair remote bridge device " ChipLogFormatX64, ChipLogValueX64(mRemoteBridgeNodeId));
272-
return err;
273-
}
274-
275-
return CHIP_NO_ERROR;
276-
}
277-
278-
CHIP_ERROR DeviceManager::UnpairRemoteDevice(NodeId nodeId)
279-
{
280-
CHIP_ERROR err = PairingManager::Instance().UnpairDevice(nodeId);
281-
if (err != CHIP_NO_ERROR)
282-
{
283-
ChipLogError(NotSpecified, "Failed to unpair remote device " ChipLogFormatX64, ChipLogValueX64(nodeId));
284-
return err;
285-
}
286-
287-
return CHIP_NO_ERROR;
288-
}
289-
290215
void DeviceManager::SubscribeRemoteFabricBridge()
291216
{
292217
ChipLogProgress(NotSpecified, "Start subscription to the remote bridge.");

examples/fabric-sync/admin/DeviceManager.h

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -140,71 +140,6 @@ class DeviceManager
140140
*/
141141
void OpenRemoteDeviceCommissioningWindow(chip::EndpointId remoteEndpointId);
142142

143-
/**
144-
* @brief Pair a remote fabric bridge with a given node ID.
145-
*
146-
* This function initiates the pairing process for a remote fabric bridge using the specified parameters.
147-
148-
* @param nodeId The user-defined ID for the node being commissioned. It doesn’t need to be the same ID,
149-
* as for the first fabric.
150-
* @param setupPINCode The setup PIN code used to authenticate the pairing process.
151-
* @param deviceRemoteIp The IP address of the remote device that is being paired as part of the fabric bridge.
152-
* @param deviceRemotePort The secured device port of the remote device that is being paired as part of the fabric bridge.
153-
*
154-
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
155-
*/
156-
CHIP_ERROR PairRemoteFabricBridge(chip::NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp,
157-
uint16_t deviceRemotePort);
158-
159-
/**
160-
* @brief Pair a remote Matter device to the current fabric.
161-
*
162-
* This function initiates the pairing process for a remote device using the specified parameters.
163-
164-
* @param nodeId The user-defined ID for the node being commissioned. It doesn’t need to be the same ID,
165-
* as for the first fabric.
166-
* @param payload The the QR code payload or a manual pairing code generated by the first commissioner
167-
* instance when opened commissioning window.
168-
*
169-
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
170-
*/
171-
CHIP_ERROR PairRemoteDevice(chip::NodeId nodeId, const char * payload);
172-
173-
/**
174-
* @brief Pair a remote Matter device to the current fabric.
175-
*
176-
* This function initiates the pairing process for a remote device using the specified parameters.
177-
178-
* @param nodeId The user-defined ID for the node being commissioned. It doesn’t need to be the same ID,
179-
* as for the first fabric.
180-
* @param setupPINCode The setup PIN code used to authenticate the pairing process.
181-
* @param deviceRemoteIp The IP address of the remote device that is being paired as part of the fabric bridge.
182-
* @param deviceRemotePort The secured device port of the remote device that is being paired as part of the fabric bridge.
183-
*
184-
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
185-
*/
186-
CHIP_ERROR PairRemoteDevice(chip::NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp, uint16_t deviceRemotePort);
187-
188-
/**
189-
* @brief Unpair the remote Matter fabric bridge.
190-
*
191-
* This function initiates the unpairing process for the remote Matter fabric bridge from the current fabric.
192-
*
193-
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
194-
*/
195-
CHIP_ERROR UnpairRemoteFabricBridge();
196-
197-
/**
198-
* @brief Unpair a specific remote Matter device from the current fabric.
199-
*
200-
* This function removes a specific remote device, identified by the node ID, from the fabric.
201-
*
202-
* @param nodeId The user-defined ID of the node that is being unpaired.
203-
*
204-
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
205-
*/
206-
CHIP_ERROR UnpairRemoteDevice(chip::NodeId nodeId);
207-
208143
void SubscribeRemoteFabricBridge();
209144

210145
void ReadSupportedDeviceCategories();

examples/fabric-sync/admin/FabricAdmin.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ FabricAdmin::CommissionRemoteBridge(Controller::CommissioningWindowPasscodeParam
115115
usleep(kCommissionPrepareTimeMs * 1000);
116116

117117
PairingManager::Instance().SetPairingDelegate(this);
118-
DeviceManager::Instance().PairRemoteDevice(mNodeId, code.c_str());
118+
err = PairingManager::Instance().PairDeviceWithCode(mNodeId, code.c_str());
119+
if (err != CHIP_NO_ERROR)
120+
{
121+
ChipLogError(NotSpecified,
122+
"Failed to commission remote bridge device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
123+
ChipLogValueX64(mNodeId), err.Format());
124+
}
119125
}
120126
else
121127
{

examples/fabric-sync/admin/PairingManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ CHIP_ERROR PairingManager::PairDevice(chip::NodeId nodeId, uint32_t setupPINCode
636636

637637
CHIP_ERROR PairingManager::UnpairDevice(NodeId nodeId)
638638
{
639+
if (nodeId == kUndefinedNodeId)
640+
{
641+
ChipLogError(NotSpecified, "node ID is undefined; cannot unpair device.");
642+
return CHIP_ERROR_INCORRECT_STATE;
643+
}
644+
639645
return DeviceLayer::SystemLayer().ScheduleLambda([nodeId]() {
640646
PairingManager & self = PairingManager::Instance();
641647

examples/fabric-sync/bridge/include/FabricAdminDelegate.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ class FabricAdminDelegate
6161
virtual CHIP_ERROR CommissionRemoteBridge(chip::Controller::CommissioningWindowPasscodeParams params, chip::VendorId vendorId,
6262
uint16_t productId) = 0;
6363

64+
/**
65+
* Sends a request to keep a device active for a specified duration.
66+
*
67+
* @param ScopedNodeId Identifies the target node within the fabric.
68+
* @param StayActiveDurationMs The duration for which the device should stay active.
69+
* @param TimeoutMs Timeout for the operation.
70+
*
71+
* @return CHIP_ERROR An error code indicating the success or failure of the
72+
* operation.
73+
* - CHIP_NO_ERROR: Request processed successfully.
74+
* - CHIP_ERROR_INTERNAL: An internal error occurred during the preparation or sending
75+
* of the command.
76+
*/
6477
virtual CHIP_ERROR KeepActive(chip::ScopedNodeId scopedNodeId, uint32_t stayActiveDurationMs, uint32_t timeoutMs) = 0;
6578
};
6679

examples/fabric-sync/shell/AddBridgeCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CHIP_ERROR AddBridgeCommand::RunCommand()
8888
ChipLogProgress(NotSpecified, "Running AddBridgeCommand with Node ID: %lu, PIN Code: %u, Address: %s, Port: %u", mBridgeNodeId,
8989
mSetupPINCode, mRemoteAddr, mRemotePort);
9090

91-
return admin::DeviceManager::Instance().PairRemoteFabricBridge(mBridgeNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
91+
return admin::PairingManager::Instance().PairDevice(mBridgeNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
9292
}
9393

9494
} // namespace commands

examples/fabric-sync/shell/AddDeviceCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ CHIP_ERROR AddDeviceCommand::RunCommand()
7676

7777
admin::PairingManager::Instance().SetPairingDelegate(this);
7878

79-
return admin::DeviceManager::Instance().PairRemoteDevice(mNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
79+
return admin::PairingManager::Instance().PairDevice(mNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
8080
}
8181

8282
} // namespace commands

examples/fabric-sync/shell/RemoveBridgeCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ CHIP_ERROR RemoveBridgeCommand::RunCommand()
6666

6767
admin::PairingManager::Instance().SetPairingDelegate(this);
6868

69-
return admin::DeviceManager::Instance().UnpairRemoteFabricBridge();
69+
return admin::PairingManager::Instance().UnpairDevice(bridgeNodeId);
7070
}
7171

7272
} // namespace commands

examples/fabric-sync/shell/RemoveDeviceCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CHIP_ERROR RemoveDeviceCommand::RunCommand()
6363

6464
ChipLogProgress(NotSpecified, "Running RemoveDeviceCommand with Node ID: %lu", mNodeId);
6565

66-
return admin::DeviceManager::Instance().UnpairRemoteDevice(mNodeId);
66+
return admin::PairingManager::Instance().UnpairDevice(mNodeId);
6767
}
6868

6969
} // namespace commands

examples/fabric-sync/shell/SyncDeviceCommand.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ void SyncDeviceCommand::OnCommissioningWindowOpened(NodeId deviceId, CHIP_ERROR
5353

5454
usleep(kCommissionPrepareTimeMs * 1000);
5555

56-
admin::DeviceManager::Instance().PairRemoteDevice(nodeId, payloadBuffer);
56+
error = admin::PairingManager::Instance().PairDeviceWithCode(nodeId, payloadBuffer);
57+
if (error != CHIP_NO_ERROR)
58+
{
59+
ChipLogError(NotSpecified, "Failed to sync device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
60+
ChipLogValueX64(nodeId), err.Format());
61+
}
5762
}
5863
else
5964
{

0 commit comments

Comments
 (0)