Skip to content

Commit d117c5d

Browse files
yufengwangcadiogopintodsr
authored andcommitted
[Fabric Bridge] Overwrite the default implementation of Administrator Commissioning C… (project-chip#33909)
* Overwrite the default implementation of Administrator Commissioning Cluster * Address review comments
1 parent 0e674ad commit d117c5d

File tree

1 file changed

+56
-0
lines changed
  • examples/fabric-bridge-app/linux

1 file changed

+56
-0
lines changed

examples/fabric-bridge-app/linux/main.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636

3737
using namespace chip;
3838

39+
using namespace chip::app;
40+
using namespace chip::app::Clusters;
41+
using namespace chip::app::Clusters::AdministratorCommissioning;
42+
3943
#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
4044
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
4145
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)
@@ -97,10 +101,62 @@ void AttemptRpcClientConnect(System::Layer * systemLayer, void * appState)
97101
}
98102
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
99103

104+
class AdministratorCommissioningCommandHandler : public CommandHandlerInterface
105+
{
106+
public:
107+
// Register for the AdministratorCommissioning cluster on all endpoints.
108+
AdministratorCommissioningCommandHandler() :
109+
CommandHandlerInterface(Optional<EndpointId>::Missing(), AdministratorCommissioning::Id)
110+
{}
111+
112+
void InvokeCommand(HandlerContext & handlerContext) override;
113+
};
114+
115+
void AdministratorCommissioningCommandHandler::InvokeCommand(HandlerContext & handlerContext)
116+
{
117+
using Protocols::InteractionModel::Status;
118+
119+
EndpointId endpointId = handlerContext.mRequestPath.mEndpointId;
120+
ChipLogProgress(NotSpecified, "Received command to open commissioning window on Endpoind: %d", endpointId);
121+
122+
if (handlerContext.mRequestPath.mCommandId != Commands::OpenCommissioningWindow::Id || endpointId == kRootEndpointId)
123+
{
124+
// Proceed with default handling in Administrator Commissioning Server
125+
return;
126+
}
127+
128+
handlerContext.SetCommandHandled();
129+
Status status = Status::Success;
130+
131+
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
132+
Device * device = DeviceMgr().GetDevice(endpointId);
133+
134+
// TODO: issues:#33784, need to make OpenCommissioningWindow synchronous
135+
if (device != nullptr && OpenCommissioningWindow(device->GetNodeId()) == CHIP_NO_ERROR)
136+
{
137+
ChipLogProgress(NotSpecified, "Commissioning window is now open");
138+
}
139+
else
140+
{
141+
status = Status::Failure;
142+
ChipLogProgress(NotSpecified, "Commissioning window is failed to open");
143+
}
144+
#else
145+
status = Status::Failure;
146+
ChipLogProgress(NotSpecified, "Commissioning window failed to open: PW_RPC_FABRIC_BRIDGE_SERVICE not defined");
147+
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
148+
149+
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, status);
150+
}
151+
152+
AdministratorCommissioningCommandHandler gAdministratorCommissioningCommandHandler;
153+
100154
} // namespace
101155

102156
void ApplicationInit()
103157
{
158+
InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gAdministratorCommissioningCommandHandler);
159+
104160
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
105161
InitRpcServer(kFabricBridgeServerPort);
106162
AttemptRpcClientConnect(&DeviceLayer::SystemLayer(), nullptr);

0 commit comments

Comments
 (0)