Skip to content

Commit

Permalink
Merge branch 'project-chip:master' into indirect_crl
Browse files Browse the repository at this point in the history
  • Loading branch information
bh3000 authored Nov 14, 2024
2 parents 83e687e + 73ff58f commit 1b306c5
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 115 deletions.
4 changes: 2 additions & 2 deletions examples/fabric-sync/admin/BridgeSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void BridgeSubscription::OnAttributeData(const ConcreteDataAttributePath & path,
return;
}

DeviceMgr().HandleAttributeData(path, *data);
DeviceManager::Instance().HandleAttributeData(path, *data);
}

void BridgeSubscription::OnEventData(const app::EventHeader & eventHeader, TLV::TLVReader * data, const app::StatusIB * status)
Expand All @@ -101,7 +101,7 @@ void BridgeSubscription::OnEventData(const app::EventHeader & eventHeader, TLV::
return;
}

DeviceMgr().HandleEventData(eventHeader, *data);
DeviceManager::Instance().HandleEventData(eventHeader, *data);
}

void BridgeSubscription::OnError(CHIP_ERROR error)
Expand Down
2 changes: 1 addition & 1 deletion examples/fabric-sync/admin/CommissionerControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void CommissionerControl::OnResponse(app::CommandSender * client, const app::Con

if (data != nullptr)
{
DeviceMgr().HandleCommandResponse(path, *data);
DeviceManager::Instance().HandleCommandResponse(path, *data);
}
}

Expand Down
3 changes: 0 additions & 3 deletions examples/fabric-sync/admin/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ constexpr EndpointId kAggregatorEndpointId = 1;

} // namespace

// Define the static member
DeviceManager DeviceManager::sInstance;

LinuxCommissionableDataProvider sCommissionableDataProvider;

void DeviceManager::Init()
Expand Down
25 changes: 6 additions & 19 deletions examples/fabric-sync/admin/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class DeviceManager
public:
DeviceManager() = default;

static DeviceManager & Instance()
{
static DeviceManager instance;
return instance;
}

void Init();

chip::NodeId GetNextAvailableNodeId();
Expand Down Expand Up @@ -170,8 +176,6 @@ class DeviceManager
SyncedDevice * FindDeviceByNode(chip::NodeId nodeId);

private:
friend DeviceManager & DeviceMgr();

void RequestCommissioningApproval();

void HandleReadSupportedDeviceCategories(chip::TLV::TLVReader & data);
Expand All @@ -184,8 +188,6 @@ class DeviceManager

void HandleReverseOpenCommissioningWindow(chip::TLV::TLVReader & data);

static DeviceManager sInstance;

chip::NodeId mLastUsedNodeId = 0;

// The Node ID of the remote bridge used for Fabric-Sync
Expand All @@ -201,19 +203,4 @@ class DeviceManager
FabricSyncGetter mFabricSyncGetter;
};

/**
* Returns the public interface of the DeviceManager singleton object.
*
* Applications should use this to access features of the DeviceManager
* object.
*/
inline DeviceManager & DeviceMgr()
{
if (!DeviceManager::sInstance.mInitialized)
{
DeviceManager::sInstance.Init();
}
return DeviceManager::sInstance;
}

} // namespace admin
8 changes: 4 additions & 4 deletions examples/fabric-sync/admin/DeviceSynchronization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void DeviceSynchronizer::OnDone(app::ReadClient * apReadClient)
{
ChipLogProgress(NotSpecified, "Synchronization complete for NodeId:" ChipLogFormatX64, ChipLogValueX64(mNodeId));

if (mState == State::ReceivedResponse && !DeviceMgr().IsCurrentBridgeDevice(mNodeId))
if (mState == State::ReceivedResponse && !DeviceManager::Instance().IsCurrentBridgeDevice(mNodeId))
{
GetUniqueId();
if (mState == State::GettingUid)
Expand Down Expand Up @@ -229,15 +229,15 @@ void DeviceSynchronizer::GetUniqueId()
// If we have a UniqueId we can return leaving state in ReceivedResponse.
VerifyOrReturn(!mCurrentDeviceData.uniqueId.has_value(), ChipLogDetail(NotSpecified, "We already have UniqueId"));

auto * device = DeviceMgr().FindDeviceByNode(mNodeId);
auto * device = DeviceManager::Instance().FindDeviceByNode(mNodeId);
// If there is no associated remote Fabric Sync Aggregator there is no other place for us to try
// getting the UniqueId from and can return leaving the state in ReceivedResponse.
VerifyOrReturn(device, ChipLogDetail(NotSpecified, "No remote Fabric Sync Aggregator to get UniqueId from"));

// Because device is not-null we expect IsFabricSyncReady to be true. IsFabricSyncReady indicates we have a
// connection to the remote Fabric Sync Aggregator.
VerifyOrDie(DeviceMgr().IsFabricSyncReady());
auto remoteBridgeNodeId = DeviceMgr().GetRemoteBridgeNodeId();
VerifyOrDie(DeviceManager::Instance().IsFabricSyncReady());
auto remoteBridgeNodeId = DeviceManager::Instance().GetRemoteBridgeNodeId();
EndpointId remoteEndpointIdOfInterest = device->GetEndpointId();

ChipLogDetail(NotSpecified, "Attempting to get UniqueId from remote Fabric Sync Aggregator");
Expand Down
4 changes: 2 additions & 2 deletions examples/fabric-sync/admin/FabricAdmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ FabricAdmin::CommissionRemoteBridge(Controller::CommissioningWindowPasscodeParam

if (err == CHIP_NO_ERROR)
{
NodeId nodeId = DeviceMgr().GetNextAvailableNodeId();
NodeId nodeId = DeviceManager::Instance().GetNextAvailableNodeId();

// After responding with RequestCommissioningApproval to the node where the client initiated the
// RequestCommissioningApproval, you need to wait for it to open a commissioning window on its bridge.
usleep(kCommissionPrepareTimeMs * 1000);

DeviceMgr().PairRemoteDevice(nodeId, code.c_str());
DeviceManager::Instance().PairRemoteDevice(nodeId, code.c_str());
}
else
{
Expand Down
21 changes: 6 additions & 15 deletions examples/fabric-sync/bridge/include/BridgedDeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class BridgedDeviceManager
public:
BridgedDeviceManager() = default;

static BridgedDeviceManager & Instance()
{
static BridgedDeviceManager instance;
return instance;
}

/**
* @brief Initializes the BridgedDeviceManager.
*
Expand Down Expand Up @@ -111,29 +117,14 @@ class BridgedDeviceManager
BridgedDevice * GetDeviceByUniqueId(const std::string & id);

private:
friend BridgedDeviceManager & BridgeDeviceMgr();

/**
* Creates a new unique ID that is not used by any other mDevice
*/
std::string GenerateUniqueId();

static BridgedDeviceManager sInstance;

chip::EndpointId mCurrentEndpointId;
chip::EndpointId mFirstDynamicEndpointId;
std::unique_ptr<BridgedDevice> mDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
};

/**
* Returns the public interface of the BridgedDeviceManager singleton object.
*
* Applications should use this to access features of the BridgedDeviceManager
* object.
*/
inline BridgedDeviceManager & BridgeDeviceMgr()
{
return BridgedDeviceManager::sInstance;
}

} // namespace bridge
4 changes: 2 additions & 2 deletions examples/fabric-sync/bridge/src/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void BridgedDeviceInformationCommandHandler::InvokeCommand(HandlerContext & hand
return;
}

BridgedDevice * device = BridgeDeviceMgr().GetDevice(endpointId);
BridgedDevice * device = BridgedDeviceManager::Instance().GetDevice(endpointId);
if (device == nullptr || !device->IsIcd())
{
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::Failure);
Expand Down Expand Up @@ -125,7 +125,7 @@ CHIP_ERROR BridgeInit(FabricAdminDelegate * delegate)
CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(&gBridgedDeviceInformationCommandHandler);
AttributeAccessInterfaceRegistry::Instance().Register(&gBridgedDeviceBasicInformationAttributes);

BridgeDeviceMgr().Init();
BridgedDeviceManager::Instance().Init();
FabricBridge::Instance().SetDelegate(delegate);
ReturnErrorOnFailure(gBridgedAdministratorCommissioning.Init());
ReturnErrorOnFailure(CommissionerControlInit(delegate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CHIP_ERROR BridgedAdministratorCommissioning::Read(const ConcreteReadAttributePa
{
VerifyOrDie(aPath.mClusterId == Clusters::AdministratorCommissioning::Id);
EndpointId endpointId = aPath.mEndpointId;
BridgedDevice * device = BridgeDeviceMgr().GetDevice(endpointId);
BridgedDevice * device = BridgedDeviceManager::Instance().GetDevice(endpointId);

if (!device)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CHIP_ERROR BridgedDeviceBasicInformationImpl::Read(const ConcreteReadAttributePa
// Registration is done for the bridged device basic information only
VerifyOrDie(path.mClusterId == app::Clusters::BridgedDeviceBasicInformation::Id);

BridgedDevice * dev = BridgeDeviceMgr().GetDevice(path.mEndpointId);
BridgedDevice * dev = BridgedDeviceManager::Instance().GetDevice(path.mEndpointId);
VerifyOrReturnError(dev != nullptr, CHIP_ERROR_NOT_FOUND);

switch (path.mAttributeId)
Expand Down Expand Up @@ -93,7 +93,7 @@ CHIP_ERROR BridgedDeviceBasicInformationImpl::Write(const ConcreteDataAttributeP
{
VerifyOrDie(path.mClusterId == app::Clusters::BridgedDeviceBasicInformation::Id);

BridgedDevice * dev = BridgeDeviceMgr().GetDevice(path.mEndpointId);
BridgedDevice * dev = BridgedDeviceManager::Instance().GetDevice(path.mEndpointId);
VerifyOrReturnError(dev != nullptr, CHIP_ERROR_NOT_FOUND);

if (!dev->IsReachable())
Expand Down
3 changes: 0 additions & 3 deletions examples/fabric-sync/bridge/src/BridgedDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ const EmberAfDeviceType sBridgedDeviceTypes[] = { { DEVICE_TYPE_BRIDGED_NODE, DE

} // namespace

// Define the static member
BridgedDeviceManager BridgedDeviceManager::sInstance;

void BridgedDeviceManager::Init()
{
mFirstDynamicEndpointId = static_cast<chip::EndpointId>(
Expand Down
12 changes: 6 additions & 6 deletions examples/fabric-sync/bridge/src/FabricBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CHIP_ERROR FabricBridge::AddSynchronizedDevice(const SynchronizedDevice & data)
device->SetIcd(data.isIcd.value_or(false));

// Add the device to the bridge manager with a parent endpoint
auto result = BridgeDeviceMgr().AddDeviceEndpoint(std::move(device), /* parentEndpointId= */ 1);
auto result = BridgedDeviceManager::Instance().AddDeviceEndpoint(std::move(device), /* parentEndpointId= */ 1);
if (!result.has_value())
{
ChipLogError(NotSpecified, "Failed to add device with Id=[%d:0x" ChipLogFormatX64 "]", data.id.GetFabricIndex(),
Expand All @@ -112,7 +112,7 @@ CHIP_ERROR FabricBridge::AddSynchronizedDevice(const SynchronizedDevice & data)
}

// Retrieve and verify the added device by ScopedNodeId
BridgedDevice * addedDevice = BridgeDeviceMgr().GetDeviceByScopedNodeId(data.id);
BridgedDevice * addedDevice = BridgedDeviceManager::Instance().GetDeviceByScopedNodeId(data.id);
VerifyOrDie(addedDevice);

ChipLogProgress(NotSpecified, "Added device with Id=[%d:0x" ChipLogFormatX64 "]", data.id.GetFabricIndex(),
Expand All @@ -137,7 +137,7 @@ CHIP_ERROR FabricBridge::RemoveSynchronizedDevice(ScopedNodeId scopedNodeId)
ChipLogProgress(NotSpecified, "Received RemoveSynchronizedDevice: Id=[%d:" ChipLogFormatX64 "]", scopedNodeId.GetFabricIndex(),
ChipLogValueX64(scopedNodeId.GetNodeId()));

auto removedIdx = BridgeDeviceMgr().RemoveDeviceByScopedNodeId(scopedNodeId);
auto removedIdx = BridgedDeviceManager::Instance().RemoveDeviceByScopedNodeId(scopedNodeId);
if (!removedIdx.has_value())
{
ChipLogError(NotSpecified, "Failed to remove device with Id=[%d:0x" ChipLogFormatX64 "]", scopedNodeId.GetFabricIndex(),
Expand All @@ -153,7 +153,7 @@ CHIP_ERROR FabricBridge::ActiveChanged(ScopedNodeId scopedNodeId, uint32_t promi
ChipLogProgress(NotSpecified, "Received ActiveChanged: Id=[%d:" ChipLogFormatX64 "]", scopedNodeId.GetFabricIndex(),
ChipLogValueX64(scopedNodeId.GetNodeId()));

auto * device = BridgeDeviceMgr().GetDeviceByScopedNodeId(scopedNodeId);
auto * device = BridgedDeviceManager::Instance().GetDeviceByScopedNodeId(scopedNodeId);
if (device == nullptr)
{
ChipLogError(NotSpecified, "Could not find bridged device associated with Id=[%d:0x" ChipLogFormatX64 "]",
Expand All @@ -170,7 +170,7 @@ CHIP_ERROR FabricBridge::AdminCommissioningAttributeChanged(const AdministratorC
ChipLogProgress(NotSpecified, "Received CADMIN attribute change: Id=[%d:" ChipLogFormatX64 "]", data.id.GetFabricIndex(),
ChipLogValueX64(data.id.GetNodeId()));

auto * device = BridgeDeviceMgr().GetDeviceByScopedNodeId(data.id);
auto * device = BridgedDeviceManager::Instance().GetDeviceByScopedNodeId(data.id);
if (device == nullptr)
{
ChipLogError(NotSpecified, "Could not find bridged device associated with Id=[%d:0x" ChipLogFormatX64 "]",
Expand Down Expand Up @@ -207,7 +207,7 @@ CHIP_ERROR FabricBridge::DeviceReachableChanged(ScopedNodeId scopedNodeId, bool
ChipLogProgress(NotSpecified, "Received device reachable changed: Id=[%d:" ChipLogFormatX64 "]", scopedNodeId.GetFabricIndex(),
ChipLogValueX64(scopedNodeId.GetNodeId()));

auto * device = BridgeDeviceMgr().GetDeviceByScopedNodeId(scopedNodeId);
auto * device = BridgedDeviceManager::Instance().GetDeviceByScopedNodeId(scopedNodeId);
if (device == nullptr)
{
ChipLogError(NotSpecified, "Could not find bridged device associated with Id=[%d:0x" ChipLogFormatX64 "]",
Expand Down
12 changes: 6 additions & 6 deletions examples/fabric-sync/shell/AddBridgeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ void AddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)

if (err == CHIP_NO_ERROR)
{
admin::DeviceMgr().SetRemoteBridgeNodeId(mBridgeNodeId);
admin::DeviceManager::Instance().SetRemoteBridgeNodeId(mBridgeNodeId);

ChipLogProgress(NotSpecified, "Successfully paired bridge device: NodeId: " ChipLogFormatX64,
ChipLogValueX64(mBridgeNodeId));

admin::DeviceMgr().UpdateLastUsedNodeId(mBridgeNodeId);
admin::DeviceMgr().SubscribeRemoteFabricBridge();
admin::DeviceManager::Instance().UpdateLastUsedNodeId(mBridgeNodeId);
admin::DeviceManager::Instance().SubscribeRemoteFabricBridge();

// After successful commissioning of the Commissionee, initiate Reverse Commissioning
// via the Commissioner Control Cluster. However, we must first verify that the
// remote Fabric-Bridge supports Fabric Synchronization.
//
// Note: The Fabric-Admin MUST NOT send the RequestCommissioningApproval command
// if the remote Fabric-Bridge lacks Fabric Synchronization support.
DeviceLayer::SystemLayer().ScheduleLambda([]() { admin::DeviceMgr().ReadSupportedDeviceCategories(); });
DeviceLayer::SystemLayer().ScheduleLambda([]() { admin::DeviceManager::Instance().ReadSupportedDeviceCategories(); });
}
else
{
Expand All @@ -75,7 +75,7 @@ void AddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)

CHIP_ERROR AddBridgeCommand::RunCommand()
{
if (admin::DeviceMgr().IsFabricSyncReady())
if (admin::DeviceManager::Instance().IsFabricSyncReady())
{
// print to console
fprintf(stderr, "Remote Fabric Bridge has already been configured.\n");
Expand All @@ -87,7 +87,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::DeviceMgr().PairRemoteFabricBridge(mBridgeNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
return admin::DeviceManager::Instance().PairRemoteFabricBridge(mBridgeNodeId, mSetupPINCode, mRemoteAddr, mRemotePort);
}

} // namespace commands
6 changes: 3 additions & 3 deletions examples/fabric-sync/shell/AddDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void AddDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
{
ChipLogProgress(NotSpecified, "Successfully paired device: NodeId: " ChipLogFormatX64, ChipLogValueX64(mNodeId));

admin::DeviceMgr().UpdateLastUsedNodeId(mNodeId);
admin::DeviceManager::Instance().UpdateLastUsedNodeId(mNodeId);
}
else
{
Expand All @@ -64,7 +64,7 @@ void AddDeviceCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)

CHIP_ERROR AddDeviceCommand::RunCommand()
{
if (admin::DeviceMgr().IsCurrentBridgeDevice(mNodeId))
if (admin::DeviceManager::Instance().IsCurrentBridgeDevice(mNodeId))
{
// print to console
fprintf(stderr, "The specified node ID has been reserved by the Fabric Bridge.\n");
Expand All @@ -76,7 +76,7 @@ CHIP_ERROR AddDeviceCommand::RunCommand()

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

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

} // namespace commands
6 changes: 3 additions & 3 deletions examples/fabric-sync/shell/RemoveBridgeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void RemoveBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)

if (err == CHIP_NO_ERROR)
{
admin::DeviceMgr().SetRemoteBridgeNodeId(kUndefinedNodeId);
admin::DeviceManager::Instance().SetRemoteBridgeNodeId(kUndefinedNodeId);

// print to console
fprintf(stderr, "Successfully removed bridge device: NodeId: " ChipLogFormatX64 "\n", ChipLogValueX64(mBridgeNodeId));
Expand All @@ -51,7 +51,7 @@ void RemoveBridgeCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)

CHIP_ERROR RemoveBridgeCommand::RunCommand()
{
NodeId bridgeNodeId = admin::DeviceMgr().GetRemoteBridgeNodeId();
NodeId bridgeNodeId = admin::DeviceManager::Instance().GetRemoteBridgeNodeId();

if (bridgeNodeId == kUndefinedNodeId)
{
Expand All @@ -66,7 +66,7 @@ CHIP_ERROR RemoveBridgeCommand::RunCommand()

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

return admin::DeviceMgr().UnpairRemoteFabricBridge();
return admin::DeviceManager::Instance().UnpairRemoteFabricBridge();
}

} // namespace commands
4 changes: 2 additions & 2 deletions examples/fabric-sync/shell/RemoveDeviceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void RemoveDeviceCommand::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)

CHIP_ERROR RemoveDeviceCommand::RunCommand()
{
if (admin::DeviceMgr().IsCurrentBridgeDevice(mNodeId))
if (admin::DeviceManager::Instance().IsCurrentBridgeDevice(mNodeId))
{
// print to console
fprintf(stderr, "The specified node ID has been reserved by the Fabric Bridge.\n");
Expand All @@ -63,7 +63,7 @@ CHIP_ERROR RemoveDeviceCommand::RunCommand()

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

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

} // namespace commands
Loading

0 comments on commit 1b306c5

Please sign in to comment.