Skip to content

Commit

Permalink
Add a list of clusters that are fully implemented via CommandHandlerI…
Browse files Browse the repository at this point in the history
…nterface. (#25901)

* Add a list of clusters that are fully implemented via CommandHandlerInterface.

For those clusters, we can skip generating the static dispatch bits, since the
CommandHandlerInterface handles all the cluster commands.

* Address review comment.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 19, 2023
1 parent f6df07f commit 8814244
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 589 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1175,90 +1175,6 @@ void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandP

} // namespace ModeSelect

namespace NetworkCommissioning {

void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv)
{
CHIP_ERROR TLVError = CHIP_NO_ERROR;
bool wasHandled = false;
{
switch (aCommandPath.mCommandId)
{
case Commands::ScanNetworks::Id: {
Commands::ScanNetworks::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterScanNetworksCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::AddOrUpdateWiFiNetwork::Id: {
Commands::AddOrUpdateWiFiNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled =
emberAfNetworkCommissioningClusterAddOrUpdateWiFiNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::AddOrUpdateThreadNetwork::Id: {
Commands::AddOrUpdateThreadNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled =
emberAfNetworkCommissioningClusterAddOrUpdateThreadNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::RemoveNetwork::Id: {
Commands::RemoveNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterRemoveNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::ConnectNetwork::Id: {
Commands::ConnectNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterConnectNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::ReorderNetwork::Id: {
Commands::ReorderNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterReorderNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
default: {
// Unrecognized command ID, error status will apply.
apCommandObj->AddStatus(aCommandPath, Protocols::InteractionModel::Status::UnsupportedCommand);
ChipLogError(Zcl, "Unknown command " ChipLogFormatMEI " for cluster " ChipLogFormatMEI,
ChipLogValueMEI(aCommandPath.mCommandId), ChipLogValueMEI(aCommandPath.mClusterId));
return;
}
}
}

if (CHIP_NO_ERROR != TLVError || !wasHandled)
{
apCommandObj->AddStatus(aCommandPath, Protocols::InteractionModel::Status::InvalidCommand);
ChipLogProgress(Zcl, "Failed to dispatch command, TLVError=%" CHIP_ERROR_FORMAT, TLVError.Format());
}
}

} // namespace NetworkCommissioning

namespace OtaSoftwareUpdateRequestor {

void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv)
Expand Down Expand Up @@ -2102,9 +2018,6 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV:
case Clusters::ModeSelect::Id:
Clusters::ModeSelect::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
break;
case Clusters::NetworkCommissioning::Id:
Clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
break;
case Clusters::OtaSoftwareUpdateRequestor::Id:
Clusters::OtaSoftwareUpdateRequestor::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,90 +754,6 @@ void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandP

} // namespace LevelControl

namespace NetworkCommissioning {

void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv)
{
CHIP_ERROR TLVError = CHIP_NO_ERROR;
bool wasHandled = false;
{
switch (aCommandPath.mCommandId)
{
case Commands::ScanNetworks::Id: {
Commands::ScanNetworks::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterScanNetworksCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::AddOrUpdateWiFiNetwork::Id: {
Commands::AddOrUpdateWiFiNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled =
emberAfNetworkCommissioningClusterAddOrUpdateWiFiNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::AddOrUpdateThreadNetwork::Id: {
Commands::AddOrUpdateThreadNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled =
emberAfNetworkCommissioningClusterAddOrUpdateThreadNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::RemoveNetwork::Id: {
Commands::RemoveNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterRemoveNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::ConnectNetwork::Id: {
Commands::ConnectNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterConnectNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
case Commands::ReorderNetwork::Id: {
Commands::ReorderNetwork::DecodableType commandData;
TLVError = DataModel::Decode(aDataTlv, commandData);
if (TLVError == CHIP_NO_ERROR)
{
wasHandled = emberAfNetworkCommissioningClusterReorderNetworkCallback(apCommandObj, aCommandPath, commandData);
}
break;
}
default: {
// Unrecognized command ID, error status will apply.
apCommandObj->AddStatus(aCommandPath, Protocols::InteractionModel::Status::UnsupportedCommand);
ChipLogError(Zcl, "Unknown command " ChipLogFormatMEI " for cluster " ChipLogFormatMEI,
ChipLogValueMEI(aCommandPath.mCommandId), ChipLogValueMEI(aCommandPath.mClusterId));
return;
}
}
}

if (CHIP_NO_ERROR != TLVError || !wasHandled)
{
apCommandObj->AddStatus(aCommandPath, Protocols::InteractionModel::Status::InvalidCommand);
ChipLogProgress(Zcl, "Failed to dispatch command, TLVError=%" CHIP_ERROR_FORMAT, TLVError.Format());
}
}

} // namespace NetworkCommissioning

namespace OtaSoftwareUpdateRequestor {

void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & aDataTlv)
Expand Down Expand Up @@ -1208,9 +1124,6 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV:
case Clusters::LevelControl::Id:
Clusters::LevelControl::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
break;
case Clusters::NetworkCommissioning::Id:
Clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
break;
case Clusters::OtaSoftwareUpdateRequestor::Id:
Clusters::OtaSoftwareUpdateRequestor::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
break;
Expand Down
40 changes: 0 additions & 40 deletions src/app/clusters/network-commissioning/network-commissioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,46 +799,6 @@ DeviceLayer::NetworkCommissioning::NetworkIterator * NullNetworkDriver::GetNetwo
} // namespace app
} // namespace chip

// These functions are ember interfaces, they should never be implemented since all network commissioning cluster functions are
// implemented in NetworkCommissioning::Instance.
bool emberAfNetworkCommissioningClusterAddOrUpdateThreadNetworkCallback(
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::AddOrUpdateThreadNetwork::DecodableType & commandData)
{
return false;
}

bool emberAfNetworkCommissioningClusterAddOrUpdateWiFiNetworkCallback(
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::AddOrUpdateWiFiNetwork::DecodableType & commandData)
{
return false;
}

bool emberAfNetworkCommissioningClusterConnectNetworkCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::ConnectNetwork::DecodableType & commandData)
{
return false;
}

bool emberAfNetworkCommissioningClusterRemoveNetworkCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::RemoveNetwork::DecodableType & commandData)
{
return false;
}

bool emberAfNetworkCommissioningClusterScanNetworksCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::ScanNetworks::DecodableType & commandData)
{
return false;
}

bool emberAfNetworkCommissioningClusterReorderNetworkCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::ReorderNetwork::DecodableType & commandData)
{
return false;
}

void MatterNetworkCommissioningPluginServerInitCallback()
{
// Nothing to do, the server init routine will be done in Instance::Init()
Expand Down
6 changes: 6 additions & 0 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ DefineBitmaps:
- BarrierControlCapabilities
- BarrierControlSafetyStatus

CommandHandlerInterfaceOnlyClusters:
# List of clusters that are implemented entirely with
# CommandHandlerInterface and hence do not need generated command dispatch.
# This uses asUpperCamelCase versions of the cluster name.
- NetworkCommissioning

# We need a more configurable way of deciding which clusters have which init functions....
# See https://github.com/project-chip/connectedhomeip/issues/4369
ClustersWithInitFunctions:
Expand Down
8 changes: 3 additions & 5 deletions src/app/zap-templates/templates/app/callback.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,15 @@ void emberAf{{asUpperCamelCase label}}ClusterClientTickCallback(chip::EndpointId

{{#zcl_clusters}}
{{#zcl_commands}}
{{#if (isClient source)}}
{{#unless (isInConfigList (asUpperCamelCase parent.name) "CommandHandlerInterfaceOnlyClusters")}}
/**
* @brief {{parent.name}} Cluster {{name}} Command callback (from {{source}})
*/
{{#if (isServer source)}}
bool emberAf{{asUpperCamelCase parent.label}}Cluster{{asUpperCamelCase name}}Callback(chip::EndpointId endpoint,
chip::app::CommandSender * commandObj
{{#zcl_command_arguments}}, {{#if isArray}}{{asUnderlyingZclType type}}{{else}}{{#if_is_struct type}}{{zapTypeToDecodableClusterObjectType type ns=parent.parent.label}}{{else}}{{asUnderlyingZclType type}}{{/if_is_struct}}{{/if}} {{asSymbol label}}{{/zcl_command_arguments}});
{{else}}
bool emberAf{{asUpperCamelCase parent.label}}Cluster{{asUpperCamelCase name}}Callback(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::{{asUpperCamelCase parent.label}}::Commands::{{asUpperCamelCase name}}::DecodableType & commandData);
{{/unless}}
{{/if}}
{{/zcl_commands}}
{{/zcl_clusters}}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace app {
namespace Clusters {

{{#all_user_clusters_with_incoming_commands}}
{{#unless (isInConfigList (asUpperCamelCase clusterName) "CommandHandlerInterfaceOnlyClusters")}}
{{#if (isServer clusterSide)}}
namespace {{asUpperCamelCase clusterName}} {

Expand Down Expand Up @@ -60,6 +61,7 @@ void DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandP
}

{{/if}}
{{/unless}}
{{/all_user_clusters_with_incoming_commands}}

} // namespace Clusters
Expand All @@ -69,11 +71,13 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV:
switch (aCommandPath.mClusterId)
{
{{#all_user_clusters_with_incoming_commands}}
{{#unless (isInConfigList (asUpperCamelCase clusterName) "CommandHandlerInterfaceOnlyClusters")}}
{{#if (isServer clusterSide)}}
case Clusters::{{asUpperCamelCase clusterName}}::Id:
Clusters::{{asUpperCamelCase clusterName}}::DispatchServerCommand(apCommandObj, aCommandPath, aReader);
break;
{{/if}}
{{/unless}}
{{/all_user_clusters_with_incoming_commands}}
default:
ChipLogError(Zcl, "Unknown cluster " ChipLogFormatMEI, ChipLogValueMEI(aCommandPath.mClusterId));
Expand Down
Loading

0 comments on commit 8814244

Please sign in to comment.