Skip to content

Commit

Permalink
[Fabric-Sync] Cleanup pass through APIs (#36604)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored Nov 22, 2024
1 parent d1600cc commit 403d595
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 146 deletions.
75 changes: 0 additions & 75 deletions examples/fabric-sync/admin/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,81 +212,6 @@ void DeviceManager::OpenRemoteDeviceCommissioningWindow(EndpointId remoteEndpoin
}
}

CHIP_ERROR DeviceManager::PairRemoteFabricBridge(NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp,
uint16_t deviceRemotePort)
{
CHIP_ERROR err = PairingManager::Instance().PairDevice(nodeId, setupPINCode, deviceRemoteIp, deviceRemotePort);

if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified,
"Failed to pair remote fabric bridge: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
ChipLogValueX64(nodeId), err.Format());
return err;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceManager::PairRemoteDevice(NodeId nodeId, const char * payload)
{
CHIP_ERROR err = PairingManager::Instance().PairDeviceWithCode(nodeId, payload);

if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to pair device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
ChipLogValueX64(nodeId), err.Format());
return err;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceManager::PairRemoteDevice(NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp,
uint16_t deviceRemotePort)
{
CHIP_ERROR err = PairingManager::Instance().PairDevice(nodeId, setupPINCode, deviceRemoteIp, deviceRemotePort);

if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to pair device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
ChipLogValueX64(nodeId), err.Format());
return err;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceManager::UnpairRemoteFabricBridge()
{
if (mRemoteBridgeNodeId == kUndefinedNodeId)
{
ChipLogError(NotSpecified, "Remote bridge node ID is undefined; cannot unpair device.");
return CHIP_ERROR_INCORRECT_STATE;
}

CHIP_ERROR err = PairingManager::Instance().UnpairDevice(mRemoteBridgeNodeId);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to unpair remote bridge device " ChipLogFormatX64, ChipLogValueX64(mRemoteBridgeNodeId));
return err;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceManager::UnpairRemoteDevice(NodeId nodeId)
{
CHIP_ERROR err = PairingManager::Instance().UnpairDevice(nodeId);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to unpair remote device " ChipLogFormatX64, ChipLogValueX64(nodeId));
return err;
}

return CHIP_NO_ERROR;
}

void DeviceManager::SubscribeRemoteFabricBridge()
{
ChipLogProgress(NotSpecified, "Start subscription to the remote bridge.");
Expand Down
65 changes: 0 additions & 65 deletions examples/fabric-sync/admin/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,71 +140,6 @@ class DeviceManager
*/
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.
*
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
*/
CHIP_ERROR 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.
*
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
*/
CHIP_ERROR PairRemoteDevice(chip::NodeId nodeId, const char * payload);

/**
* @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 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.
*
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
*/
CHIP_ERROR PairRemoteDevice(chip::NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp, uint16_t deviceRemotePort);

/**
* @brief Unpair the remote Matter fabric bridge.
*
* This function initiates the unpairing process for the remote Matter fabric bridge from the current fabric.
*
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
*/
CHIP_ERROR UnpairRemoteFabricBridge();

/**
* @brief Unpair a specific remote Matter device from the current fabric.
*
* This function removes a specific remote device, identified by the node ID, from the fabric.
*
* @param nodeId The user-defined ID of the node that is being unpaired.
*
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success or an appropriate error code on failure.
*/
CHIP_ERROR UnpairRemoteDevice(chip::NodeId nodeId);

void SubscribeRemoteFabricBridge();

void ReadSupportedDeviceCategories();
Expand Down
8 changes: 7 additions & 1 deletion examples/fabric-sync/admin/FabricAdmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ FabricAdmin::CommissionRemoteBridge(Controller::CommissioningWindowPasscodeParam
usleep(kCommissionPrepareTimeMs * 1000);

PairingManager::Instance().SetPairingDelegate(this);
DeviceManager::Instance().PairRemoteDevice(mNodeId, code.c_str());
err = PairingManager::Instance().PairDeviceWithCode(mNodeId, code.c_str());
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified,
"Failed to commission remote bridge device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
ChipLogValueX64(mNodeId), err.Format());
}
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions examples/fabric-sync/admin/PairingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ CHIP_ERROR PairingManager::PairDevice(chip::NodeId nodeId, uint32_t setupPINCode

CHIP_ERROR PairingManager::UnpairDevice(NodeId nodeId)
{
if (nodeId == kUndefinedNodeId)
{
ChipLogError(NotSpecified, "node ID is undefined; cannot unpair device.");
return CHIP_ERROR_INCORRECT_STATE;
}

return DeviceLayer::SystemLayer().ScheduleLambda([nodeId]() {
PairingManager & self = PairingManager::Instance();

Expand Down
13 changes: 13 additions & 0 deletions examples/fabric-sync/bridge/include/FabricAdminDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ class FabricAdminDelegate
virtual CHIP_ERROR CommissionRemoteBridge(chip::Controller::CommissioningWindowPasscodeParams params, chip::VendorId vendorId,
uint16_t productId) = 0;

/**
* Sends a request to keep a device active for a specified duration.
*
* @param ScopedNodeId Identifies the target node within the fabric.
* @param StayActiveDurationMs The duration for which the device should stay active.
* @param TimeoutMs Timeout for the operation.
*
* @return CHIP_ERROR An error code indicating the success or failure of the
* operation.
* - CHIP_NO_ERROR: Request processed successfully.
* - CHIP_ERROR_INTERNAL: An internal error occurred during the preparation or sending
* of the command.
*/
virtual CHIP_ERROR KeepActive(chip::ScopedNodeId scopedNodeId, uint32_t stayActiveDurationMs, uint32_t timeoutMs) = 0;
};

Expand Down
2 changes: 1 addition & 1 deletion examples/fabric-sync/shell/AddBridgeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ CHIP_ERROR AddBridgeCommand::RunCommand()
ChipLogProgress(NotSpecified, "Running AddBridgeCommand with Node ID: %lu, PIN Code: %u, Address: %s, Port: %u", mBridgeNodeId,
mSetupPINCode, mRemoteAddr, mRemotePort);

return admin::DeviceManager::Instance().PairRemoteFabricBridge(mBridgeNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
return admin::PairingManager::Instance().PairDevice(mBridgeNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
}

} // namespace commands
2 changes: 1 addition & 1 deletion examples/fabric-sync/shell/AddDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CHIP_ERROR AddDeviceCommand::RunCommand()

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

return admin::DeviceManager::Instance().PairRemoteDevice(mNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
return admin::PairingManager::Instance().PairDevice(mNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
}

} // namespace commands
2 changes: 1 addition & 1 deletion examples/fabric-sync/shell/RemoveBridgeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CHIP_ERROR RemoveBridgeCommand::RunCommand()

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

return admin::DeviceManager::Instance().UnpairRemoteFabricBridge();
return admin::PairingManager::Instance().UnpairDevice(bridgeNodeId);
}

} // namespace commands
2 changes: 1 addition & 1 deletion examples/fabric-sync/shell/RemoveDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ CHIP_ERROR RemoveDeviceCommand::RunCommand()

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

return admin::DeviceManager::Instance().UnpairRemoteDevice(mNodeId);
return admin::PairingManager::Instance().UnpairDevice(mNodeId);
}

} // namespace commands
7 changes: 6 additions & 1 deletion examples/fabric-sync/shell/SyncDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ void SyncDeviceCommand::OnCommissioningWindowOpened(NodeId deviceId, CHIP_ERROR

usleep(kCommissionPrepareTimeMs * 1000);

admin::DeviceManager::Instance().PairRemoteDevice(nodeId, payloadBuffer);
error = admin::PairingManager::Instance().PairDeviceWithCode(nodeId, payloadBuffer);
if (error != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to sync device: Node ID " ChipLogFormatX64 " with error: %" CHIP_ERROR_FORMAT,
ChipLogValueX64(nodeId), err.Format());
}
}
else
{
Expand Down

0 comments on commit 403d595

Please sign in to comment.