Skip to content

Commit

Permalink
Update ZAP to force lists to be external-storage. (project-chip#13846)
Browse files Browse the repository at this point in the history
The Power Source cluster addition is because that was one of two lists
that we did not already have AttributeAccessInterface handling for
(and the other one was in a cluster that already had an
AttributeAccessInterface).

Now that we have AttributeAccessInterface for all lists, we no longer
need the fake "return an empty list" thing in
ember-compatibility-functions.cpp.
  • Loading branch information
bzbarsky-apple authored and selissia committed Jan 28, 2022
1 parent 0f2088f commit 4ef6b6b
Show file tree
Hide file tree
Showing 38 changed files with 3,469 additions and 5,524 deletions.
1 change: 1 addition & 0 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wake-on-lan-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/pump-configuration-and-control-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/src"
#${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ias-zone-client
)
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ target_sources(${APP_TARGET} PRIVATE
${APP_CLUSTERS}/general-diagnostics-server/general-diagnostics-server.cpp
${APP_CLUSTERS}/group-key-mgmt-server/group-key-mgmt-server.cpp
${APP_CLUSTERS}/power-source-configuration-server/power-source-configuration-server.cpp
${APP_CLUSTERS}/power-source-server/power-source-server.cpp
${APP_CLUSTERS}/ota-requestor/ota-requestor-server.cpp
${APP_CLUSTERS}/ota-requestor/BDXDownloader.cpp
${APP_CLUSTERS}/ota-requestor/OTARequestor.cpp
Expand Down
2 changes: 2 additions & 0 deletions examples/lock-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ idf_component_register(INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/group-key-mgmt-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-server"
PRIV_REQUIRES bt chip QRCode)

get_filename_component(CHIP_ROOT ../third_party/connectedhomeip REALPATH)
Expand Down Expand Up @@ -153,6 +154,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-commissioning-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/user-label-server"
PRIV_REQUIRES chip QRCode bt)

Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ target_sources(${APP_TARGET} PRIVATE
${CHIP_ROOT}/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp
${CHIP_ROOT}/src/app/clusters/on-off-server/on-off-server.cpp
${CHIP_ROOT}/src/app/clusters/power-source-configuration-server/power-source-configuration-server.cpp
${CHIP_ROOT}/src/app/clusters/power-source-server/power-source-server.cpp
${CHIP_ROOT}/src/app/clusters/user-label-server/user-label-server.cpp
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ CHIP_ERROR ApplicationBasicAttrAccess::Read(const app::ConcreteReadAttributePath

if (isDelegateNull(delegate, endpoint))
{
if (aPath.mAttributeId == Attributes::AllowedVendorList::Id)
{
return aEncoder.EncodeEmptyList();
}
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,22 @@ CHIP_ERROR ApplicationLauncherAttrAccess::Read(const app::ConcreteReadAttributeP
EndpointId endpoint = aPath.mEndpointId;
Delegate * delegate = GetDelegate(endpoint);

if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

switch (aPath.mAttributeId)
{
case app::Clusters::ApplicationLauncher::Attributes::ApplicationLauncherList::Id: {
if (isDelegateNull(delegate, endpoint))
{
return aEncoder.EncodeEmptyList();
}

return ReadCatalogListAttribute(aEncoder, delegate);
}
case app::Clusters::ApplicationLauncher::Attributes::ApplicationLauncherApp::Id: {
if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

return ReadCurrentAppAttribute(aEncoder, delegate);
}
default: {
Expand Down
15 changes: 10 additions & 5 deletions src/app/clusters/audio-output-server/audio-output-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,22 @@ CHIP_ERROR AudioOutputAttrAccess::Read(const app::ConcreteReadAttributePath & aP
EndpointId endpoint = aPath.mEndpointId;
Delegate * delegate = GetDelegate(endpoint);

if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

switch (aPath.mAttributeId)
{
case app::Clusters::AudioOutput::Attributes::AudioOutputList::Id: {
if (isDelegateNull(delegate, endpoint))
{
return aEncoder.EncodeEmptyList();
}

return ReadOutputListAttribute(aEncoder, delegate);
}
case app::Clusters::AudioOutput::Attributes::CurrentAudioOutput::Id: {
if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

return ReadCurrentOutputAttribute(aEncoder, delegate);
}
default: {
Expand Down
20 changes: 15 additions & 5 deletions src/app/clusters/channel-server/channel-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,30 @@ CHIP_ERROR ChannelAttrAccess::Read(const app::ConcreteReadAttributePath & aPath,
EndpointId endpoint = aPath.mEndpointId;
Delegate * delegate = GetDelegate(endpoint);

if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

switch (aPath.mAttributeId)
{
case app::Clusters::Channel::Attributes::ChannelList::Id: {
if (isDelegateNull(delegate, endpoint))
{
return aEncoder.EncodeEmptyList();
}

return ReadChannelListAttribute(aEncoder, delegate);
}
case app::Clusters::Channel::Attributes::ChannelLineup::Id: {
if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

return ReadLineupAttribute(aEncoder, delegate);
}
case app::Clusters::Channel::Attributes::CurrentChannel::Id: {
if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

return ReadCurrentChannelAttribute(aEncoder, delegate);
}
default: {
Expand Down
15 changes: 10 additions & 5 deletions src/app/clusters/content-launch-server/content-launch-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,22 @@ CHIP_ERROR ContentLauncherAttrAccess::Read(const app::ConcreteReadAttributePath
EndpointId endpoint = aPath.mEndpointId;
Delegate * delegate = GetDelegate(endpoint);

if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

switch (aPath.mAttributeId)
{
case app::Clusters::ContentLauncher::Attributes::AcceptHeaderList::Id: {
if (isDelegateNull(delegate, endpoint))
{
return aEncoder.EncodeEmptyList();
}

return ReadAcceptHeaderAttribute(aEncoder, delegate);
}
case app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::Id: {
if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

return ReadSupportedStreamingProtocolsAttribute(aEncoder, delegate);
}
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath
case LocationCapability::Id: {
return ReadIfSupported(&ConfigurationManager::GetLocationCapability, aEncoder);
}
case BasicCommissioningInfoList::Id: {
// TODO: This should not be a list at all!
return aEncoder.EncodeEmptyList();
}
default: {
break;
}
Expand Down
15 changes: 10 additions & 5 deletions src/app/clusters/media-input-server/media-input-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,22 @@ CHIP_ERROR MediaInputAttrAccess::Read(const app::ConcreteReadAttributePath & aPa
EndpointId endpoint = aPath.mEndpointId;
Delegate * delegate = GetDelegate(endpoint);

if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

switch (aPath.mAttributeId)
{
case app::Clusters::MediaInput::Attributes::MediaInputList::Id: {
if (isDelegateNull(delegate, endpoint))
{
return aEncoder.EncodeEmptyList();
}

return ReadInputListAttribute(aEncoder, delegate);
}
case app::Clusters::MediaInput::Attributes::CurrentMediaInput::Id: {
if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

return ReadCurrentInputAttribute(aEncoder, delegate);
}
default: {
Expand Down
70 changes: 70 additions & 0 deletions src/app/clusters/power-source-server/power-source-server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/****************************************************************************
* @file
* @brief Implementation for the Power Source Server Cluster
***************************************************************************/

#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterface.h>
#include <app/util/attribute-storage.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::PowerSource::Attributes;

namespace {

class PowerSourceAttrAccess : public AttributeAccessInterface
{
public:
// Register on all endpoints.
PowerSourceAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), PowerSource::Id) {}

CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
};

PowerSourceAttrAccess gAttrAccess;

CHIP_ERROR PowerSourceAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
CHIP_ERROR err = CHIP_NO_ERROR;

switch (aPath.mAttributeId)
{
case ActiveBatteryFaults::Id:
// TODO: Needs implementation.
err = aEncoder.EncodeEmptyList();
break;
default:
break;
}

return err;
}

} // anonymous namespace

void MatterPowerSourcePluginServerInitCallback(void)
{
registerAttributeAccessOverride(&gAttrAccess);
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,22 @@ CHIP_ERROR TargetNavigatorAttrAccess::Read(const app::ConcreteReadAttributePath
EndpointId endpoint = aPath.mEndpointId;
Delegate * delegate = GetDelegate(endpoint);

if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

switch (aPath.mAttributeId)
{
case app::Clusters::TargetNavigator::Attributes::TargetNavigatorList::Id: {
if (isDelegateNull(delegate, endpoint))
{
return aEncoder.EncodeEmptyList();
}

return ReadTargetListAttribute(aEncoder, delegate);
}
case app::Clusters::TargetNavigator::Attributes::CurrentNavigatorTarget::Id: {
if (isDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

return ReadCurrentTargetAttribute(aEncoder, delegate);
}
default: {
Expand Down
15 changes: 0 additions & 15 deletions src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,21 +658,6 @@ CHIP_ERROR ReadSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, b
}
break;
}
case ZCL_ARRAY_ATTRIBUTE_TYPE: {
// We only get here for attributes of list type that have no override
// registered. There should not be any nonempty lists like that.
uint16_t length = emberAfGetInt16u(attributeData, 0, 2);
if (length != 0)
{
return CHIP_ERROR_INCORRECT_STATE;
}

// Just encode an empty array.
TLV::TLVType containerType;
ReturnErrorOnFailure(writer->StartContainer(tag, TLV::kTLVType_Array, containerType));
ReturnErrorOnFailure(writer->EndContainer(containerType));
break;
}
default:
ChipLogError(DataManagement, "Attribute type 0x%x not handled", static_cast<int>(attributeType));
emberStatus = EMBER_ZCL_STATUS_WRITE_ONLY;
Expand Down
1 change: 0 additions & 1 deletion src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ void MatterPressureMeasurementPluginServerInitCallback() {}
void MatterTemperatureMeasurementPluginServerInitCallback() {}
void MatterFlowMeasurementPluginServerInitCallback() {}
void MatterOnOffSwitchConfigurationPluginServerInitCallback() {}
void MatterPowerSourcePluginServerInitCallback() {}
void MatterThermostatUserInterfaceConfigurationPluginServerInitCallback() {}
void MatterBridgedDeviceBasicInformationPluginServerInitCallback() {}
void MatterPowerConfigurationPluginServerInitCallback() {}
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/zcl/zcl.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@
"commandDiscovery": true
}
},
"listsUseAttributeAccessInterface": true,
"attributeAccessInterfaceAttributes": {},
"defaultReportingPolicy": "mandatory"
}
2 changes: 1 addition & 1 deletion src/app/zap_cluster_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
'OTA_BOOTLOAD_CLUSTER': [],
'OTA_PROVIDER_CLUSTER': ['ota-provider'],
'OTA_REQUESTOR_CLUSTER': ['ota-requestor'],
'POWER_SOURCE_CLUSTER': [],
'POWER_SOURCE_CLUSTER': ['power-source-server'],
'POWER_SOURCE_CONFIGURATION_CLUSTER': ['power-source-configuration-server'],
'POLL_CONTROL_CLUSTER': [],
'POWER_CONFIG_CLUSTER': [],
Expand Down
2 changes: 2 additions & 0 deletions src/darwin/Framework/CHIP/templates/clusters-tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ CHIPDevice * GetConnectedDevice(void)
{{#unless (isStrEqual "Basic" name)}}
{{#unless (isStrEqual "Thermostat" name)}}
{{#unless (isStrEqual "OTA Software Update Provider" name)}}
{{#unless (isStrEqual "Network Commissioning" name)}} {{! "Networks" is broken }}
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
- (void)testSendCluster{{asUpperCamelCase parent.name}}ReadAttribute{{asUpperCamelCase name}}WithCompletionHandler
Expand Down Expand Up @@ -275,6 +276,7 @@ CHIPDevice * GetConnectedDevice(void)
{{/unless}}
{{/unless}}
{{/unless}}
{{/unless}}
{{/chip_client_clusters}}

@end
Loading

0 comments on commit 4ef6b6b

Please sign in to comment.