Skip to content

Commit

Permalink
[Fabric-Admin] Merge CommissioningDelegate and PairingDelegate (#36388)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Dec 12, 2024
1 parent 941b629 commit 2523969
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ CHIP_ERROR FabricSyncAddBridgeCommand::RunCommand(NodeId remoteId)
return CHIP_NO_ERROR;
}

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

mBridgeNodeId = remoteId;

Expand Down Expand Up @@ -180,7 +180,7 @@ CHIP_ERROR FabricSyncAddLocalBridgeCommand::RunCommand(NodeId deviceId)
return CHIP_NO_ERROR;
}

PairingManager::Instance().SetCommissioningDelegate(this);
PairingManager::Instance().SetPairingDelegate(this);
mLocalBridgeNodeId = deviceId;

if (mSetupPINCode.HasValue())
Expand Down Expand Up @@ -252,7 +252,7 @@ void FabricSyncDeviceCommand::OnCommissioningWindowOpened(NodeId deviceId, CHIP_
{
NodeId nodeId = DeviceMgr().GetNextAvailableNodeId();

PairingManager::Instance().SetCommissioningDelegate(this);
PairingManager::Instance().SetPairingDelegate(this);
mAssignedNodeId = nodeId;

usleep(kCommissionPrepareTimeMs * 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace admin {
// Constants
constexpr uint32_t kCommissionPrepareTimeMs = 500;

class FabricSyncAddBridgeCommand : public CHIPCommand, public CommissioningDelegate
class FabricSyncAddBridgeCommand : public CHIPCommand, public PairingDelegate
{
public:
FabricSyncAddBridgeCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("add-bridge", credIssuerCommands)
Expand Down Expand Up @@ -71,7 +71,7 @@ class FabricSyncRemoveBridgeCommand : public CHIPCommand, public PairingDelegate
chip::NodeId mBridgeNodeId;
};

class FabricSyncAddLocalBridgeCommand : public CHIPCommand, public CommissioningDelegate
class FabricSyncAddLocalBridgeCommand : public CHIPCommand, public PairingDelegate
{
public:
FabricSyncAddLocalBridgeCommand(CredentialIssuerCommands * credIssuerCommands) :
Expand Down Expand Up @@ -116,7 +116,7 @@ class FabricSyncRemoveLocalBridgeCommand : public CHIPCommand, public PairingDel
chip::NodeId mLocalBridgeNodeId;
};

class FabricSyncDeviceCommand : public CHIPCommand, public CommissioningWindowDelegate, public CommissioningDelegate
class FabricSyncDeviceCommand : public CHIPCommand, public CommissioningWindowDelegate, public PairingDelegate
{
public:
FabricSyncDeviceCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("sync-device", credIssuerCommands)
Expand Down
7 changes: 4 additions & 3 deletions examples/fabric-admin/device_manager/PairingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ void PairingManager::OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err)
ChipLogProgress(NotSpecified, "Device commissioning Failure: %s", ErrorStr(err));
}

if (mCommissioningDelegate)
if (mPairingDelegate)
{
mCommissioningDelegate->OnCommissioningComplete(nodeId, err);
SetCommissioningDelegate(nullptr);
mPairingDelegate->OnCommissioningComplete(nodeId, err);
SetPairingDelegate(nullptr);
}
}

Expand Down Expand Up @@ -555,6 +555,7 @@ void PairingManager::OnCurrentFabricRemove(void * context, NodeId nodeId, CHIP_E
if (self->mPairingDelegate)
{
self->mPairingDelegate->OnDeviceRemoved(nodeId, err);
self->SetPairingDelegate(nullptr);
}

#if defined(PW_RPC_ENABLED)
Expand Down
14 changes: 3 additions & 11 deletions examples/fabric-admin/device_manager/PairingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,12 @@ class CommissioningWindowDelegate
virtual ~CommissioningWindowDelegate() = default;
};

class CommissioningDelegate
{
public:
virtual void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR err) = 0;
virtual ~CommissioningDelegate() = default;
};

class PairingDelegate
{
public:
virtual void OnDeviceRemoved(chip::NodeId deviceId, CHIP_ERROR err) = 0;
virtual ~PairingDelegate() = default;
virtual void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR err) {}
virtual void OnDeviceRemoved(chip::NodeId deviceId, CHIP_ERROR err) {}
virtual ~PairingDelegate() = default;
};

/**
Expand Down Expand Up @@ -85,7 +79,6 @@ class PairingManager : public chip::Controller::DevicePairingDelegate,
CHIP_ERROR Init(chip::Controller::DeviceCommissioner * commissioner, CredentialIssuerCommands * credIssuerCmds);

void SetOpenCommissioningWindowDelegate(CommissioningWindowDelegate * delegate) { mCommissioningWindowDelegate = delegate; }
void SetCommissioningDelegate(CommissioningDelegate * delegate) { mCommissioningDelegate = delegate; }
void SetPairingDelegate(PairingDelegate * delegate) { mPairingDelegate = delegate; }
PairingDelegate * GetPairingDelegate() { return mPairingDelegate; }

Expand Down Expand Up @@ -181,7 +174,6 @@ class PairingManager : public chip::Controller::DevicePairingDelegate,
CredentialIssuerCommands * mCredIssuerCmds = nullptr;

CommissioningWindowDelegate * mCommissioningWindowDelegate = nullptr;
CommissioningDelegate * mCommissioningDelegate = nullptr;
PairingDelegate * mPairingDelegate = nullptr;

chip::NodeId mNodeId = chip::kUndefinedNodeId;
Expand Down

0 comments on commit 2523969

Please sign in to comment.