Skip to content

Commit 362022f

Browse files
zaid-googlerestyled-commitsandy31415bzbarsky-apple
authored
Codegen mandatory attributes arrays in Metadata (#40356)
* jinja and code changes * Codegen * Fix typo * Fix another typo * Address gemini comment * Address review comments * Codegen * Restyled by whitespace * Restyled by clang-format * Remove unused variable * Update array name * Codegen * Replace default Span constructor in software disagnostics * Restyled by clang-format * make size value for span * Restyled by clang-format * Update arrays to use std::array * Codegen * Restyled by clang-format * Restyled by autopep8 * Update scripts/py_matter_idl/matter/idl/generators/cpp/sdk/Metadata.h.jinja * Update scripts/py_matter_idl/matter/idl/generators/cpp/sdk/Metadata.h.jinja Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * fix typo --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andy314@gmail.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 502b51f commit 362022f

File tree

146 files changed

+1025
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1025
-34
lines changed

scripts/py_matter_idl/matter/idl/generators/cpp/sdk/Metadata.h.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <app/data-model-provider/MetadataTypes.h>
8+
#include <array>
89
#include <lib/core/DataModelTypes.h>
910

1011
#include <cstdint>
@@ -39,6 +40,13 @@ inline constexpr DataModel::AttributeEntry kMetadataEntry(
3940
} // namespace {{attribute.definition.name | upfirst}}
4041
{% endfor %}
4142

43+
{%- set mandatoryAttributeList = cluster.attributes | reject("global_attribute") | reject("is_optional") | list -%}
44+
constexpr std::array<DataModel::AttributeEntry, {{ mandatoryAttributeList | length }}> kMandatoryMetadata = {
45+
{% for attribute in mandatoryAttributeList -%}
46+
{{attribute.definition.name | upfirst}}::kMetadataEntry,
47+
{% endfor %}
48+
};
49+
4250
} // namespace Attributes
4351

4452
namespace Commands {

scripts/py_matter_idl/matter/idl/generators/cpp/sdk/sdk_generator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def response_struct(s: Struct) -> bool:
8585
return s.code is not None
8686

8787

88+
def is_optional(attribute: Attribute) -> bool:
89+
return attribute.definition.is_optional
90+
91+
8892
class SdkGenerator(CodeGenerator):
8993
"""
9094
Generation of cpp code for application implementation for matter.
@@ -102,6 +106,7 @@ def __init__(self, storage: GeneratorStorage, idl: Idl, **kargs):
102106
self.jinja_env.filters['name_for_id_usage'] = name_for_id_usage
103107
self.jinja_env.tests['global_attribute'] = global_attribute
104108
self.jinja_env.tests['response_struct'] = response_struct
109+
self.jinja_env.tests['is_optional'] = is_optional
105110

106111
def internal_render_all(self):
107112
"""

src/app/clusters/administrator-commissioning-server/AdministratorCommissioningCluster.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ constexpr DataModel::AcceptedCommandEntry kAcceptedCommandsWithBasicCommissionin
4141
AdministratorCommissioning::Commands::OpenBasicCommissioningWindow::kMetadataEntry,
4242
};
4343

44-
constexpr DataModel::AttributeEntry kMandatoryAttributes[] = {
45-
AdministratorCommissioning::Attributes::WindowStatus::kMetadataEntry,
46-
AdministratorCommissioning::Attributes::AdminFabricIndex::kMetadataEntry,
47-
AdministratorCommissioning::Attributes::AdminVendorId::kMetadataEntry,
48-
};
49-
5044
}; // namespace
5145

5246
DataModel::ActionReturnStatus AdministratorCommissioningCluster::ReadAttribute(const DataModel::ReadAttributeRequest & request,
@@ -105,7 +99,7 @@ CHIP_ERROR AdministratorCommissioningCluster::Attributes(const ConcreteClusterPa
10599
{
106100

107101
AttributeListBuilder listBuilder(builder);
108-
return listBuilder.Append(Span(kMandatoryAttributes), {});
102+
return listBuilder.Append(Span(AdministratorCommissioning::Attributes::kMandatoryMetadata), {});
109103
}
110104

111105
std::optional<DataModel::ActionReturnStatus> AdministratorCommissioningWithBasicCommissioningWindowCluster::InvokeCommand(

src/app/clusters/general-diagnostics-server/general-diagnostics-cluster.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,6 @@ HandlePayloadTestRequest(CommandHandler & handler, const ConcreteCommandPath & c
214214
namespace chip {
215215
namespace app {
216216
namespace Clusters {
217-
namespace {
218-
constexpr DataModel::AttributeEntry kMandatoryAttributes[] = {
219-
GeneralDiagnostics::Attributes::NetworkInterfaces::kMetadataEntry,
220-
GeneralDiagnostics::Attributes::RebootCount::kMetadataEntry,
221-
GeneralDiagnostics::Attributes::UpTime::kMetadataEntry,
222-
GeneralDiagnostics::Attributes::TestEventTriggersEnabled::kMetadataEntry,
223-
};
224-
}
225217

226218
CHIP_ERROR GeneralDiagnosticsCluster::Startup(ServerClusterContext & context)
227219
{
@@ -333,9 +325,16 @@ CHIP_ERROR GeneralDiagnosticsCluster::Attributes(const ConcreteClusterPath & pat
333325
{ mEnabledAttributes.enableActiveHardwareFaults, GeneralDiagnostics::Attributes::ActiveHardwareFaults::kMetadataEntry },
334326
{ mEnabledAttributes.enableActiveRadioFaults, GeneralDiagnostics::Attributes::ActiveRadioFaults::kMetadataEntry },
335327
{ mEnabledAttributes.enableActiveNetworkFaults, GeneralDiagnostics::Attributes::ActiveNetworkFaults::kMetadataEntry },
328+
/*
329+
* Enforcing UpTime to always be added here because it is a mandatory attribute for
330+
* revision 2 and beyond, but is left as optional in the XML for now for backwards
331+
* compatibility. This allows us to still use the code generated mandatory attributes
332+
* and have support for UpTime.
333+
*/
334+
{ true, GeneralDiagnostics::Attributes::UpTime::kMetadataEntry },
336335
};
337336

338-
return listBuilder.Append(Span(kMandatoryAttributes), Span(optionalAttributeEntries));
337+
return listBuilder.Append(Span(GeneralDiagnostics::Attributes::kMandatoryMetadata), Span(optionalAttributeEntries));
339338
}
340339

341340
CHIP_ERROR GeneralDiagnosticsCluster::AcceptedCommands(const ConcreteClusterPath & path,

src/app/clusters/push-av-stream-transport-server/push-av-stream-transport-cluster.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ constexpr CommandId kGeneratedCommands[] = {
5151
FindTransportResponse::Id,
5252
};
5353

54-
constexpr DataModel::AttributeEntry kMandatoryAttributes[] = {
55-
PushAvStreamTransport::Attributes::SupportedFormats::kMetadataEntry,
56-
PushAvStreamTransport::Attributes::CurrentConnections::kMetadataEntry,
57-
};
58-
5954
} // namespace
6055

6156
using Protocols::InteractionModel::Status;
@@ -65,7 +60,7 @@ CHIP_ERROR PushAvStreamTransportServer::Attributes(const ConcreteClusterPath & p
6560
ReadOnlyBufferBuilder<DataModel::AttributeEntry> & builder)
6661
{
6762
AttributeListBuilder listBuilder(builder);
68-
return listBuilder.Append(Span(kMandatoryAttributes), {});
63+
return listBuilder.Append(Span(PushAvStreamTransport::Attributes::kMandatoryMetadata), {});
6964
}
7065

7166
CHIP_ERROR PushAvStreamTransportServer::ReadAndEncodeSupportedFormats(const AttributeValueEncoder::ListEncodeHelper & encoder)

src/app/clusters/software-diagnostics-server/software-diagnostics-logic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ CHIP_ERROR SoftwareDiagnosticsLogic::Attributes(ReadOnlyBufferBuilder<DataModel:
107107
{ mEnabledAttributes.enableCurrentWatermarks, Attributes::CurrentHeapHighWatermark::kMetadataEntry },
108108
};
109109

110-
return listBuilder.Append(Span<const DataModel::AttributeEntry>() /* mandatory */, Span(optionalEntries));
110+
return listBuilder.Append(Span(SoftwareDiagnostics::Attributes::kMandatoryMetadata), Span(optionalEntries));
111111
}
112112

113113
} // namespace Clusters

zzz_generated/app-common/clusters/AccessControl/Metadata.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <app/data-model-provider/MetadataTypes.h>
8+
#include <array>
89
#include <lib/core/DataModelTypes.h>
910

1011
#include <cstdint>
@@ -55,6 +56,13 @@ inline constexpr DataModel::AttributeEntry
5556
kMetadataEntry(Arl::Id, BitFlags<DataModel::AttributeQualityFlags>(DataModel::AttributeQualityFlags::kListAttribute),
5657
Access::Privilege::kView, std::nullopt);
5758
} // namespace Arl
59+
constexpr std::array<DataModel::AttributeEntry, 4> kMandatoryMetadata = {
60+
Acl::kMetadataEntry,
61+
SubjectsPerAccessControlEntry::kMetadataEntry,
62+
TargetsPerAccessControlEntry::kMetadataEntry,
63+
AccessControlEntriesPerFabric::kMetadataEntry,
64+
65+
};
5866

5967
} // namespace Attributes
6068

zzz_generated/app-common/clusters/AccountLogin/Metadata.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <app/data-model-provider/MetadataTypes.h>
8+
#include <array>
89
#include <lib/core/DataModelTypes.h>
910

1011
#include <cstdint>
@@ -18,7 +19,12 @@ namespace AccountLogin {
1819

1920
inline constexpr uint32_t kRevision = 2;
2021

21-
namespace Attributes {} // namespace Attributes
22+
namespace Attributes {
23+
constexpr std::array<DataModel::AttributeEntry, 0> kMandatoryMetadata = {
24+
25+
};
26+
27+
} // namespace Attributes
2228

2329
namespace Commands {
2430
namespace GetSetupPIN {

zzz_generated/app-common/clusters/Actions/Metadata.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <app/data-model-provider/MetadataTypes.h>
8+
#include <array>
89
#include <lib/core/DataModelTypes.h>
910

1011
#include <cstdint>
@@ -33,6 +34,11 @@ namespace SetupURL {
3334
inline constexpr DataModel::AttributeEntry kMetadataEntry(SetupURL::Id, BitFlags<DataModel::AttributeQualityFlags>(),
3435
Access::Privilege::kView, std::nullopt);
3536
} // namespace SetupURL
37+
constexpr std::array<DataModel::AttributeEntry, 2> kMandatoryMetadata = {
38+
ActionList::kMetadataEntry,
39+
EndpointLists::kMetadataEntry,
40+
41+
};
3642

3743
} // namespace Attributes
3844

zzz_generated/app-common/clusters/ActivatedCarbonFilterMonitoring/Metadata.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <app/data-model-provider/MetadataTypes.h>
8+
#include <array>
89
#include <lib/core/DataModelTypes.h>
910

1011
#include <cstdint>
@@ -45,6 +46,10 @@ inline constexpr DataModel::AttributeEntry
4546
BitFlags<DataModel::AttributeQualityFlags>(DataModel::AttributeQualityFlags::kListAttribute),
4647
Access::Privilege::kView, std::nullopt);
4748
} // namespace ReplacementProductList
49+
constexpr std::array<DataModel::AttributeEntry, 1> kMandatoryMetadata = {
50+
ChangeIndication::kMetadataEntry,
51+
52+
};
4853

4954
} // namespace Attributes
5055

0 commit comments

Comments
 (0)