Skip to content

Commit

Permalink
Cleanup AutoSync command (#36128)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored Oct 17, 2024
1 parent c0c674c commit ed7ef1b
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 60 deletions.
1 change: 0 additions & 1 deletion examples/fabric-admin/commands/fabric-sync/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void registerCommandsFabricSync(Commands & commands, CredentialIssuerCommands *
make_unique<FabricSyncAddLocalBridgeCommand>(credsIssuerConfig),
make_unique<FabricSyncRemoveLocalBridgeCommand>(credsIssuerConfig),
make_unique<FabricSyncDeviceCommand>(credsIssuerConfig),
make_unique<FabricAutoSyncCommand>(credsIssuerConfig),
};

commands.RegisterCommandSet(clusterName, clusterCommands, "Commands for fabric synchronization.");
Expand Down
12 changes: 0 additions & 12 deletions examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,3 @@ CHIP_ERROR FabricSyncDeviceCommand::RunCommand(EndpointId remoteId)

return CHIP_NO_ERROR;
}

CHIP_ERROR FabricAutoSyncCommand::RunCommand(bool enableAutoSync)
{
DeviceMgr().EnableAutoSync(enableAutoSync);

// print to console
fprintf(stderr, "Auto Fabric Sync is %s.\n", enableAutoSync ? "enabled" : "disabled");
fprintf(stderr,
"WARNING: The auto-sync command is currently under development and may contain bugs. Use it at your own risk.\n");

return CHIP_NO_ERROR;
}
19 changes: 0 additions & 19 deletions examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,3 @@ class FabricSyncDeviceCommand : public CHIPCommand, public CommissioningWindowDe

CHIP_ERROR RunCommand(chip::EndpointId remoteId);
};

class FabricAutoSyncCommand : public CHIPCommand
{
public:
FabricAutoSyncCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("enable-auto-sync", credIssuerCommands)
{
AddArgument("state", 0, 1, &mEnableAutoSync, "Set to true to enable auto Fabric Sync, false to disable.");
}

/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override { return RunCommand(mEnableAutoSync); }

chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }

private:
bool mEnableAutoSync;

CHIP_ERROR RunCommand(bool enableAutoSync);
};
21 changes: 0 additions & 21 deletions examples/fabric-admin/device_manager/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,6 @@ void DeviceManager::HandleAttributePartsListUpdate(TLV::TLVReader & data)
{
// print to console
fprintf(stderr, "A new device is added on Endpoint: %u\n", endpoint);

if (mAutoSyncEnabled)
{
StringBuilder<kMaxCommandSize> commandBuilder;
commandBuilder.Add("fabricsync sync-device ");
commandBuilder.AddFormat("%d", endpoint);
PushCommand(commandBuilder.c_str());
}
}

// Process removed endpoints
Expand All @@ -373,19 +365,6 @@ void DeviceManager::HandleAttributePartsListUpdate(TLV::TLVReader & data)
ChipLogProgress(NotSpecified, "No device on Endpoint: %u", endpoint);
continue;
}

if (mAutoSyncEnabled)
{
NodeId nodeId = device->GetNodeId();
if (PairingManager::Instance().UnpairDevice(nodeId) != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to unpair device " ChipLogFormatX64, ChipLogValueX64(nodeId));
}
else
{
PairingManager::Instance().SetPairingDelegate(this);
}
}
}
}

Expand Down
9 changes: 2 additions & 7 deletions examples/fabric-admin/device_manager/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,10 @@ class DeviceManager : public PairingDelegate
void SetLocalBridgeSetupPinCode(uint32_t pinCode) { mLocalBridgeSetupPinCode = pinCode; }
void SetLocalBridgeNodeId(chip::NodeId nodeId) { mLocalBridgeNodeId = nodeId; }

bool IsAutoSyncEnabled() const { return mAutoSyncEnabled; }

bool IsFabricSyncReady() const { return mRemoteBridgeNodeId != chip::kUndefinedNodeId; }

bool IsLocalBridgeReady() const { return mLocalBridgeNodeId != chip::kUndefinedNodeId; }

void EnableAutoSync(bool state) { mAutoSyncEnabled = state; }

void AddSyncedDevice(const Device & device);

void RemoveSyncedDevice(chip::NodeId nodeId);
Expand Down Expand Up @@ -208,9 +204,8 @@ class DeviceManager : public PairingDelegate
chip::NodeId mLocalBridgeNodeId = chip::kUndefinedNodeId;

std::set<Device> mSyncedDevices;
bool mAutoSyncEnabled = false;
bool mInitialized = false;
uint64_t mRequestId = 0;
bool mInitialized = false;
uint64_t mRequestId = 0;

BridgeSubscription mBridgeSubscriber;
FabricSyncGetter mFabricSyncGetter;
Expand Down

0 comments on commit ed7ef1b

Please sign in to comment.