Skip to content

Commit 12484a9

Browse files
authored
Put fabric sync logic into namespace admin (#36361)
1 parent 9c389ba commit 12484a9

29 files changed

+113
-16
lines changed

examples/fabric-admin/commands/common/CHIPCommand.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
182182
mCredIssuerCmds->SetCredentialIssuerOption(CredentialIssuerCommands::CredentialIssuerOptions::kAllowTestCdSigningKey,
183183
allowTestCdSigningKey);
184184

185-
ReturnLogErrorOnFailure(PairingManager::Instance().Init(&CurrentCommissioner(), mCredIssuerCmds));
185+
ReturnLogErrorOnFailure(admin::PairingManager::Instance().Init(&CurrentCommissioner(), mCredIssuerCmds));
186186

187187
return CHIP_NO_ERROR;
188188
}

examples/fabric-admin/commands/fabric-sync/Commands.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ void registerCommandsFabricSync(Commands & commands, CredentialIssuerCommands *
2626
const char * clusterName = "FabricSync";
2727

2828
commands_list clusterCommands = {
29-
make_unique<FabricSyncAddBridgeCommand>(credsIssuerConfig),
30-
make_unique<FabricSyncRemoveBridgeCommand>(credsIssuerConfig),
31-
make_unique<FabricSyncAddLocalBridgeCommand>(credsIssuerConfig),
32-
make_unique<FabricSyncRemoveLocalBridgeCommand>(credsIssuerConfig),
33-
make_unique<FabricSyncDeviceCommand>(credsIssuerConfig),
29+
make_unique<admin::FabricSyncAddBridgeCommand>(credsIssuerConfig),
30+
make_unique<admin::FabricSyncRemoveBridgeCommand>(credsIssuerConfig),
31+
make_unique<admin::FabricSyncAddLocalBridgeCommand>(credsIssuerConfig),
32+
make_unique<admin::FabricSyncRemoveLocalBridgeCommand>(credsIssuerConfig),
33+
make_unique<admin::FabricSyncDeviceCommand>(credsIssuerConfig),
3434
};
3535

3636
commands.RegisterCommandSet(clusterName, clusterCommands, "Commands for fabric synchronization.");

examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
using namespace ::chip;
3232

33+
namespace admin {
34+
3335
void FabricSyncAddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err)
3436
{
3537
if (mBridgeNodeId != deviceId)
@@ -305,3 +307,5 @@ CHIP_ERROR FabricSyncDeviceCommand::RunCommand(EndpointId remoteId)
305307

306308
return CHIP_NO_ERROR;
307309
}
310+
311+
} // namespace admin

examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <commands/common/CHIPCommand.h>
2222
#include <device_manager/PairingManager.h>
2323

24+
namespace admin {
25+
2426
// Constants
2527
constexpr uint32_t kCommissionPrepareTimeMs = 500;
2628

@@ -136,3 +138,5 @@ class FabricSyncDeviceCommand : public CHIPCommand, public CommissioningWindowDe
136138

137139
CHIP_ERROR RunCommand(chip::EndpointId remoteId);
138140
};
141+
142+
} // namespace admin

examples/fabric-admin/commands/interactive/InteractiveCommands.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void ENFORCE_FORMAT(3, 0) LoggingCallback(const char * module, uint8_t category,
117117
#if defined(PW_RPC_ENABLED)
118118
void AttemptRpcClientConnect(System::Layer * systemLayer, void * appState)
119119
{
120-
if (StartRpcClient() == CHIP_NO_ERROR)
120+
if (admin::StartRpcClient() == CHIP_NO_ERROR)
121121
{
122122
// print to console
123123
fprintf(stderr, "Connected to Fabric-Bridge\n");
@@ -199,8 +199,8 @@ CHIP_ERROR InteractiveStartCommand::RunCommand()
199199
}
200200

201201
#if defined(PW_RPC_ENABLED)
202-
SetRpcRemoteServerPort(mFabricBridgeServerPort.Value());
203-
InitRpcServer(mLocalServerPort.Value());
202+
admin::SetRpcRemoteServerPort(mFabricBridgeServerPort.Value());
203+
admin::InitRpcServer(mLocalServerPort.Value());
204204
ChipLogProgress(NotSpecified, "PW_RPC initialized.");
205205
DeviceLayer::PlatformMgr().ScheduleWork(ExecuteDeferredConnect, 0);
206206
#endif

examples/fabric-admin/commands/pairing/PairingCommand.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void PairingCommand::OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err)
405405
fprintf(stderr, "New device with Node ID: 0x%lx has been successfully added.\n", nodeId);
406406
// CurrentCommissioner() has a lifetime that is the entire life of the application itself
407407
// so it is safe to provide to StartDeviceSynchronization.
408-
DeviceSynchronizer::Instance().StartDeviceSynchronization(&CurrentCommissioner(), mNodeId, mDeviceIsICD);
408+
admin::DeviceSynchronizer::Instance().StartDeviceSynchronization(&CurrentCommissioner(), mNodeId, mDeviceIsICD);
409409
}
410410
else
411411
{
@@ -542,7 +542,7 @@ void PairingCommand::OnCurrentFabricRemove(void * context, NodeId nodeId, CHIP_E
542542
#if defined(PW_RPC_ENABLED)
543543
app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(command->CurrentCommissioner().GetFabricIndex(), nodeId);
544544
ScopedNodeId scopedNodeId(nodeId, command->CurrentCommissioner().GetFabricIndex());
545-
RemoveSynchronizedDevice(scopedNodeId);
545+
admin::RemoveSynchronizedDevice(scopedNodeId);
546546
#endif
547547
}
548548
else

examples/fabric-admin/device_manager/BridgeSubscription.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
*/
1818

1919
#include "BridgeSubscription.h"
20-
#include <device_manager/DeviceManager.h>
20+
#include "DeviceManager.h"
2121

2222
using namespace ::chip;
2323
using namespace ::chip::app;
2424
using chip::app::ReadClient;
2525

26+
namespace admin {
27+
2628
namespace {
2729

2830
constexpr uint16_t kSubscribeMinInterval = 0;
@@ -157,3 +159,5 @@ void BridgeSubscription::OnDeviceConnectionFailure(const ScopedNodeId & peerId,
157159
ChipLogError(NotSpecified, "BridgeSubscription failed to connect to " ChipLogFormatX64, ChipLogValueX64(peerId.GetNodeId()));
158160
OnDone(nullptr);
159161
}
162+
163+
} // namespace admin

examples/fabric-admin/device_manager/BridgeSubscription.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <memory>
2525
#include <optional>
2626

27+
namespace admin {
28+
2729
/**
2830
* @brief Class used to subscribe to attributes and events from the remote bridged device.
2931
*
@@ -75,3 +77,5 @@ class BridgeSubscription : public chip::app::ReadClient::Callback
7577
chip::EndpointId mEndpointId;
7678
bool subscriptionStarted = false;
7779
};
80+
81+
} // namespace admin

examples/fabric-admin/device_manager/CommissionerControl.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "CommissionerControl.h"
2-
#include <device_manager/DeviceManager.h>
2+
#include "DeviceManager.h"
33

44
using namespace ::chip;
55

6+
namespace admin {
7+
68
void CommissionerControl::Init(Controller::DeviceCommissioner & commissioner, NodeId nodeId, EndpointId endpointId)
79
{
810
// Ensure that mCommissioner is not already initialized
@@ -102,6 +104,9 @@ void CommissionerControl::OnDone(app::CommandSender * client)
102104

103105
CHIP_ERROR CommissionerControl::SendCommandForType(CommandType commandType, DeviceProxy * device)
104106
{
107+
ChipLogProgress(AppServer, "Sending command with Endpoint ID: %d, Command Type: %d", mEndpointId,
108+
static_cast<int>(commandType));
109+
105110
switch (commandType)
106111
{
107112
case CommandType::kRequestCommissioningApproval:
@@ -139,3 +144,5 @@ void CommissionerControl::OnDeviceConnectionFailureFn(void * context, const Scop
139144
VerifyOrReturn(self != nullptr, ChipLogError(NotSpecified, "OnDeviceConnectedFn: context is null"));
140145
self->OnDone(nullptr);
141146
}
147+
148+
} // namespace admin

examples/fabric-admin/device_manager/CommissionerControl.h

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <app/CommandSender.h>
2222
#include <controller/CHIPDeviceController.h>
2323

24+
namespace admin {
25+
2426
/**
2527
* @class CommissionerControl
2628
* @brief This class handles sending CHIP commands related to commissioning, including sending
@@ -123,3 +125,5 @@ class CommissionerControl : public chip::app::CommandSender::Callback
123125
chip::app::Clusters::CommissionerControl::Commands::RequestCommissioningApproval::Type mRequestCommissioningApproval;
124126
chip::app::Clusters::CommissionerControl::Commands::CommissionNode::Type mCommissionNode;
125127
};
128+
129+
} // namespace admin

examples/fabric-admin/device_manager/DeviceManager.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
using namespace chip;
2929

30+
namespace admin {
31+
3032
namespace {
3133

3234
constexpr EndpointId kAggregatorEndpointId = 1;
@@ -465,3 +467,5 @@ void DeviceManager::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err)
465467
RemoveSyncedDevice(deviceId);
466468
ChipLogProgress(NotSpecified, "Synced device with NodeId:" ChipLogFormatX64 " has been removed.", ChipLogValueX64(deviceId));
467469
}
470+
471+
} // namespace admin

examples/fabric-admin/device_manager/DeviceManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <platform/CHIPDeviceLayer.h>
2727
#include <set>
2828

29+
namespace admin {
30+
2931
constexpr uint32_t kDefaultSetupPinCode = 20202021;
3032
constexpr uint16_t kDefaultLocalBridgePort = 5540;
3133
constexpr uint16_t kResponseTimeoutSeconds = 30;
@@ -226,3 +228,5 @@ inline DeviceManager & DeviceMgr()
226228
}
227229
return DeviceManager::sInstance;
228230
}
231+
232+
} // namespace admin

examples/fabric-admin/device_manager/DeviceSubscription.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ using namespace ::chip;
3333
using namespace ::chip::app;
3434
using chip::app::ReadClient;
3535

36+
namespace admin {
37+
3638
namespace {
3739

3840
void OnDeviceConnectedWrapper(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle)
@@ -281,3 +283,5 @@ void DeviceSubscription::StopSubscription()
281283
MoveToState(State::AwaitingDestruction);
282284
mOnDoneCallback(mScopedNodeId);
283285
}
286+
287+
} // namespace admin

examples/fabric-admin/device_manager/DeviceSubscription.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
#include <app/ReadClient.h>
2121
#include <controller/CHIPDeviceController.h>
2222
#include <lib/core/DataModelTypes.h>
23-
2423
#include <memory>
2524

2625
#if defined(PW_RPC_ENABLED)
2726
#include "fabric_bridge_service/fabric_bridge_service.pb.h"
2827
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
2928
#endif
3029

30+
namespace admin {
31+
3132
class DeviceSubscriptionManager;
3233

3334
/// Attribute subscription to attributes that are important to keep track and send to fabric-bridge
@@ -95,3 +96,5 @@ class DeviceSubscription : public chip::app::ReadClient::Callback
9596
bool mChangeDetected = false;
9697
State mState = State::Idle;
9798
};
99+
100+
} // namespace admin

examples/fabric-admin/device_manager/DeviceSubscriptionManager.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
using namespace ::chip;
3333
using namespace ::chip::app;
3434

35+
namespace admin {
36+
3537
DeviceSubscriptionManager & DeviceSubscriptionManager::Instance()
3638
{
3739
static DeviceSubscriptionManager instance;
@@ -78,3 +80,5 @@ void DeviceSubscriptionManager::DeviceSubscriptionTerminated(ScopedNodeId scoped
7880
VerifyOrDie(it != mDeviceSubscriptionMap.end());
7981
mDeviceSubscriptionMap.erase(scopedNodeId);
8082
}
83+
84+
} // namespace admin

examples/fabric-admin/device_manager/DeviceSubscriptionManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <memory>
2727

28+
namespace admin {
29+
2830
class DeviceSubscriptionManager
2931
{
3032
public:
@@ -52,3 +54,5 @@ class DeviceSubscriptionManager
5254

5355
std::unordered_map<chip::ScopedNodeId, std::unique_ptr<DeviceSubscription>, ScopedNodeIdHasher> mDeviceSubscriptionMap;
5456
};
57+
58+
} // namespace admin

examples/fabric-admin/device_manager/DeviceSynchronization.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ using namespace ::chip;
3535
using namespace ::chip::app;
3636
using chip::app::ReadClient;
3737

38+
namespace admin {
39+
3840
namespace {
3941

4042
void OnDeviceConnectedWrapper(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle)
@@ -324,3 +326,5 @@ const char * DeviceSynchronizer::GetStateStr() const
324326
}
325327
return "N/A";
326328
}
329+
330+
} // namespace admin

examples/fabric-admin/device_manager/DeviceSynchronization.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
#include <app/ReadClient.h>
2323
#include <controller/CHIPDeviceController.h>
2424
#include <lib/core/DataModelTypes.h>
25-
2625
#include <memory>
2726

2827
#if defined(PW_RPC_ENABLED)
2928
#include "fabric_bridge_service/fabric_bridge_service.pb.h"
3029
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
3130
#endif
3231

32+
namespace admin {
33+
3334
/// Ensures that device data is synchronized to the remote fabric bridge.
3435
///
3536
/// Includes a state machine that:
@@ -100,3 +101,5 @@ class DeviceSynchronizer : public chip::app::ReadClient::Callback
100101
#endif
101102
UniqueIdGetter mUniqueIdGetter;
102103
};
104+
105+
} // namespace admin

examples/fabric-admin/device_manager/FabricSyncGetter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ using namespace ::chip;
2222
using namespace ::chip::app;
2323
using chip::app::ReadClient;
2424

25+
namespace admin {
26+
2527
namespace {
2628

2729
void OnDeviceConnectedWrapper(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle)
@@ -119,3 +121,5 @@ void FabricSyncGetter::OnDeviceConnectionFailure(const ScopedNodeId & peerId, CH
119121

120122
OnDone(nullptr);
121123
}
124+
125+
} // namespace admin

examples/fabric-admin/device_manager/FabricSyncGetter.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <memory>
2525
#include <optional>
2626

27+
namespace admin {
28+
2729
/**
2830
* @brief Class used to get FabricSynchronization from SupportedDeviceCategories attribute of Commissioner Control Cluster.
2931
*
@@ -73,3 +75,5 @@ class FabricSyncGetter : public chip::app::ReadClient::Callback
7375
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
7476
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
7577
};
78+
79+
} // namespace admin

examples/fabric-admin/device_manager/PairingManager.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
using namespace ::chip;
3636
using namespace ::chip::Controller;
3737

38+
namespace admin {
39+
3840
namespace {
3941

4042
CHIP_ERROR GetPayload(const char * setUpCode, SetupPayload & payload)
@@ -655,3 +657,5 @@ CHIP_ERROR PairingManager::UnpairDevice(NodeId nodeId)
655657
}
656658
});
657659
}
660+
661+
} // namespace admin

examples/fabric-admin/device_manager/PairingManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <controller/CurrentFabricRemover.h>
2626
#include <crypto/CHIPCryptoPAL.h>
2727

28+
namespace admin {
29+
2830
// Constants
2931
constexpr uint16_t kMaxManualCodeLength = 22;
3032

@@ -214,3 +216,5 @@ class PairingManager : public chip::Controller::DevicePairingDelegate,
214216
chip::Platform::UniquePtr<chip::Controller::CurrentFabricRemover> mCurrentFabricRemover;
215217
chip::Callback::Callback<chip::Controller::OnCurrentFabricRemove> mCurrentFabricRemoveCallback;
216218
};
219+
220+
} // namespace admin

examples/fabric-admin/device_manager/UniqueIdGetter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ using namespace ::chip;
2222
using namespace ::chip::app;
2323
using chip::app::ReadClient;
2424

25+
namespace admin {
26+
2527
namespace {
2628

2729
void OnDeviceConnectedWrapper(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle)
@@ -139,3 +141,5 @@ void UniqueIdGetter::OnDeviceConnectionFailure(const ScopedNodeId & peerId, CHIP
139141

140142
OnDone(nullptr);
141143
}
144+
145+
} // namespace admin

examples/fabric-admin/device_manager/UniqueIdGetter.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <memory>
2525
#include <optional>
2626

27+
namespace admin {
28+
2729
/**
2830
* @brief Class used to get UniqueID from Bridged Device Basic Information Cluster
2931
*
@@ -73,3 +75,5 @@ class UniqueIdGetter : public chip::app::ReadClient::Callback
7375
char mUniqueId[33];
7476
chip::EndpointId mEndpointId;
7577
};
78+
79+
} // namespace admin

0 commit comments

Comments
 (0)