[Fabric-Admin] Clean up pass through functions from Device Manager (#36614)
* [Fabric-Admin] Clean up pass through functions from Device Manager
* Restyled by clang-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp
index e8296fa..5940578 100644
--- a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp
+++ b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp
@@ -32,6 +32,13 @@
namespace admin {
+namespace {
+
+constexpr uint32_t kDefaultSetupPinCode = 20202021;
+constexpr uint16_t kDefaultLocalBridgePort = 5540;
+
+} // namespace
+
void FabricSyncAddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
{
if (mBridgeNodeId != deviceId)
@@ -92,10 +99,8 @@
mBridgeNodeId = remoteId;
- DeviceManager::Instance().PairRemoteFabricBridge(remoteId, mSetupPINCode, reinterpret_cast<const char *>(mRemoteAddr.data()),
- mRemotePort);
-
- return CHIP_NO_ERROR;
+ return PairingManager::Instance().PairDevice(remoteId, mSetupPINCode, reinterpret_cast<const char *>(mRemoteAddr.data()),
+ mRemotePort);
}
void FabricSyncRemoveBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)
@@ -135,9 +140,8 @@
mBridgeNodeId = bridgeNodeId;
PairingManager::Instance().SetPairingDelegate(this);
- DeviceManager::Instance().UnpairRemoteFabricBridge();
- return CHIP_NO_ERROR;
+ return PairingManager::Instance().UnpairDevice(bridgeNodeId);
}
void FabricSyncAddLocalBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
@@ -185,18 +189,10 @@
PairingManager::Instance().SetPairingDelegate(this);
mLocalBridgeNodeId = deviceId;
- if (mSetupPINCode.HasValue())
- {
- DeviceManager::Instance().SetLocalBridgeSetupPinCode(mSetupPINCode.Value());
- }
- if (mLocalPort.HasValue())
- {
- DeviceManager::Instance().SetLocalBridgePort(mLocalPort.Value());
- }
+ uint16_t localBridgePort = mLocalPort.ValueOr(kDefaultLocalBridgePort);
+ uint32_t localBridgeSetupPinCode = mSetupPINCode.ValueOr(kDefaultSetupPinCode);
- DeviceManager::Instance().PairLocalFabricBridge(deviceId);
-
- return CHIP_NO_ERROR;
+ return PairingManager::Instance().PairDevice(deviceId, localBridgeSetupPinCode, "::1", localBridgePort);
}
void FabricSyncRemoveLocalBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)
@@ -236,9 +232,8 @@
mLocalBridgeNodeId = bridgeNodeId;
PairingManager::Instance().SetPairingDelegate(this);
- DeviceManager::Instance().UnpairLocalFabricBridge();
- return CHIP_NO_ERROR;
+ return PairingManager::Instance().UnpairDevice(mLocalBridgeNodeId);
}
void FabricSyncDeviceCommand::OnCommissioningWindowOpened(NodeId deviceId, CHIP_ERROR err, SetupPayload payload)
@@ -259,7 +254,10 @@
usleep(kCommissionPrepareTimeMs * 1000);
- DeviceManager::Instance().PairRemoteDevice(nodeId, payloadBuffer);
+ if (PairingManager::Instance().PairDeviceWithCode(nodeId, payloadBuffer) != CHIP_NO_ERROR)
+ {
+ ChipLogError(NotSpecified, "Failed to sync device " ChipLogFormatX64, ChipLogValueX64(nodeId));
+ }
}
else
{
diff --git a/examples/fabric-admin/device_manager/DeviceManager.cpp b/examples/fabric-admin/device_manager/DeviceManager.cpp
index 41ee1f3..67c634b 100644
--- a/examples/fabric-admin/device_manager/DeviceManager.cpp
+++ b/examples/fabric-admin/device_manager/DeviceManager.cpp
@@ -39,6 +39,7 @@
constexpr uint16_t kWindowTimeout = 300;
constexpr uint16_t kIteration = 1000;
constexpr uint16_t kMaxDiscriminatorLength = 4095;
+constexpr uint16_t kResponseTimeoutSeconds = 30;
} // namespace
@@ -177,47 +178,6 @@
}
}
-void DeviceManager::PairRemoteFabricBridge(NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp,
- uint16_t deviceRemotePort)
-{
- if (PairingManager::Instance().PairDevice(nodeId, setupPINCode, deviceRemoteIp, deviceRemotePort) != CHIP_NO_ERROR)
- {
- ChipLogError(NotSpecified, "Failed to pair remote fabric bridge " ChipLogFormatX64, ChipLogValueX64(nodeId));
- }
-}
-
-void DeviceManager::PairRemoteDevice(NodeId nodeId, const char * payload)
-{
- if (PairingManager::Instance().PairDeviceWithCode(nodeId, payload) != CHIP_NO_ERROR)
- {
- ChipLogError(NotSpecified, "Failed to pair remote device " ChipLogFormatX64, ChipLogValueX64(nodeId));
- }
-}
-
-void DeviceManager::PairLocalFabricBridge(NodeId nodeId)
-{
- if (PairingManager::Instance().PairDevice(nodeId, mLocalBridgeSetupPinCode, "::1", mLocalBridgePort) != CHIP_NO_ERROR)
- {
- ChipLogError(NotSpecified, "Failed to pair local fabric bridge " ChipLogFormatX64, ChipLogValueX64(nodeId));
- }
-}
-
-void DeviceManager::UnpairRemoteFabricBridge()
-{
- if (PairingManager::Instance().UnpairDevice(mRemoteBridgeNodeId) != CHIP_NO_ERROR)
- {
- ChipLogError(NotSpecified, "Failed to unpair remote bridge device " ChipLogFormatX64, ChipLogValueX64(mRemoteBridgeNodeId));
- }
-}
-
-void DeviceManager::UnpairLocalFabricBridge()
-{
- if (PairingManager::Instance().UnpairDevice(mLocalBridgeNodeId) != CHIP_NO_ERROR)
- {
- ChipLogError(NotSpecified, "Failed to unpair local bridge device " ChipLogFormatX64, ChipLogValueX64(mLocalBridgeNodeId));
- }
-}
-
void DeviceManager::SubscribeRemoteFabricBridge()
{
ChipLogProgress(NotSpecified, "Start subscription to the remote bridge.");
diff --git a/examples/fabric-admin/device_manager/DeviceManager.h b/examples/fabric-admin/device_manager/DeviceManager.h
index 8c273ee..b326996 100644
--- a/examples/fabric-admin/device_manager/DeviceManager.h
+++ b/examples/fabric-admin/device_manager/DeviceManager.h
@@ -28,10 +28,6 @@
namespace admin {
-constexpr uint32_t kDefaultSetupPinCode = 20202021;
-constexpr uint16_t kDefaultLocalBridgePort = 5540;
-constexpr uint16_t kResponseTimeoutSeconds = 30;
-
class SyncedDevice
{
public:
@@ -73,8 +69,6 @@
void SetRemoteBridgeNodeId(chip::NodeId nodeId);
- void SetLocalBridgePort(uint16_t port) { mLocalBridgePort = port; }
- void SetLocalBridgeSetupPinCode(uint32_t pinCode) { mLocalBridgeSetupPinCode = pinCode; }
void SetLocalBridgeNodeId(chip::NodeId nodeId) { mLocalBridgeNodeId = nodeId; }
bool IsFabricSyncReady() const { return mRemoteBridgeNodeId != chip::kUndefinedNodeId; }
@@ -133,45 +127,6 @@
*/
void OpenRemoteDeviceCommissioningWindow(chip::EndpointId remoteEndpointId);
- /**
- * @brief Pair a remote fabric bridge with a given node ID.
- *
- * This function initiates the pairing process for a remote fabric bridge using the specified parameters.
-
- * @param nodeId The user-defined ID for the node being commissioned. It doesn’t need to be the same ID,
- * as for the first fabric.
- * @param setupPINCode The setup PIN code used to authenticate the pairing process.
- * @param deviceRemoteIp The IP address of the remote device that is being paired as part of the fabric bridge.
- * @param deviceRemotePort The secured device port of the remote device that is being paired as part of the fabric bridge.
- */
- void PairRemoteFabricBridge(chip::NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp, uint16_t deviceRemotePort);
-
- /**
- * @brief Pair a remote Matter device to the current fabric.
- *
- * This function initiates the pairing process for a remote device using the specified parameters.
-
- * @param nodeId The user-defined ID for the node being commissioned. It doesn’t need to be the same ID,
- * as for the first fabric.
- * @param payload The the QR code payload or a manual pairing code generated by the first commissioner
- * instance when opened commissioning window.
- */
- void PairRemoteDevice(chip::NodeId nodeId, const char * payload);
-
- /**
- * @brief Pair a local fabric bridge with a given node ID.
- *
- * This function initiates the pairing process for the local fabric bridge using the specified parameters.
-
- * @param nodeId The user-defined ID for the node being commissioned. It doesn’t need to be the same ID,
- * as for the first fabric.
- */
- void PairLocalFabricBridge(chip::NodeId nodeId);
-
- void UnpairRemoteFabricBridge();
-
- void UnpairLocalFabricBridge();
-
void SubscribeRemoteFabricBridge();
void ReadSupportedDeviceCategories();
@@ -204,8 +159,6 @@
// This represents the bridge on the other ecosystem.
chip::NodeId mRemoteBridgeNodeId = chip::kUndefinedNodeId;
- uint16_t mLocalBridgePort = kDefaultLocalBridgePort;
- uint32_t mLocalBridgeSetupPinCode = kDefaultSetupPinCode;
// The Node ID of the local bridge used for Fabric-Sync
// This represents the bridge within its own ecosystem.
chip::NodeId mLocalBridgeNodeId = chip::kUndefinedNodeId;
diff --git a/examples/fabric-admin/rpc/RpcServer.cpp b/examples/fabric-admin/rpc/RpcServer.cpp
index 06f7d82..a7c9259 100644
--- a/examples/fabric-admin/rpc/RpcServer.cpp
+++ b/examples/fabric-admin/rpc/RpcServer.cpp
@@ -179,7 +179,11 @@
// RequestCommissioningApproval, you need to wait for it to open a commissioning window on its bridge.
usleep(kCommissionPrepareTimeMs * 1000);
PairingManager::Instance().SetPairingDelegate(this);
- DeviceManager::Instance().PairRemoteDevice(mNodeId, code.c_str());
+
+ if (PairingManager::Instance().PairDeviceWithCode(mNodeId, code.c_str()) != CHIP_NO_ERROR)
+ {
+ ChipLogError(NotSpecified, "Failed to commission device " ChipLogFormatX64, ChipLogValueX64(mNodeId));
+ }
}
else
{