Skip to content

Commit

Permalink
Add default initializers to cluster-objects structs. (#13678)
Browse files Browse the repository at this point in the history
* Add default initializers to cluster-objects structs.

These were missed when adding initializers to other things, because
the structs' members are defined in a separate file now.

* Address review comments
  • Loading branch information
bzbarsky-apple authored Jan 19, 2022
1 parent d5e7431 commit 7f766c6
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 157 deletions.
4 changes: 1 addition & 3 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ uint8_t gListUint8Data[kAttributeListLength];
OctetStringData gListOctetStringData[kAttributeListLength];
OctetStringData gListOperationalCert[kAttributeListLength];
Structs::TestListStructOctet::Type listStructOctetStringData[kAttributeListLength];
Structs::SimpleStruct::Type gStructAttributeValue = { 0, false, SimpleEnum::kValueA,
ByteSpan(), CharSpan(), BitFlags<SimpleBitmap>(),
0, 0 };
Structs::SimpleStruct::Type gStructAttributeValue;
NullableStruct::TypeInfo::Type gNullableStructAttributeValue;

// We don't actually support any interesting bits in the struct for now, except
Expand Down
4 changes: 2 additions & 2 deletions src/app/zap-templates/partials/cluster-objects-struct.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace {{asUpperCamelCase name}} {
struct Type {
public:
{{#zcl_struct_items}}
{{zapTypeToEncodableClusterObjectType type}} {{asLowerCamelCase label}};
{{zapTypeToEncodableClusterObjectType type}} {{asLowerCamelCase label}}{{> cluster_objects_field_init}};
{{/zcl_struct_items}}

CHIP_ERROR Encode(TLV::TLVWriter &writer, TLV::Tag tag) const;
Expand All @@ -27,7 +27,7 @@ namespace {{asUpperCamelCase name}} {
struct DecodableType {
public:
{{#zcl_struct_items}}
{{zapTypeToDecodableClusterObjectType type}} {{asLowerCamelCase label}};
{{zapTypeToDecodableClusterObjectType type}} {{asLowerCamelCase label}}{{> cluster_objects_field_init}};
{{/zcl_struct_items}}
CHIP_ERROR Decode(TLV::TLVReader &reader);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,12 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_WriteThreadNetw
ThreadNetworkDiagnostics::Structs::SecurityPolicy::Type securityPolicy;
static_assert(sizeof(securityPolicy) == sizeof(activeDataset.mSecurityPolicy),
"securityPolicy Struct do not match otSecurityPolicy");
memcpy(&securityPolicy, &activeDataset.mSecurityPolicy, sizeof(securityPolicy));
uint16_t policyAsInts[2];
static_assert(sizeof(policyAsInts) == sizeof(activeDataset.mSecurityPolicy),
"We're missing some members of otSecurityPolicy?");
memcpy(&policyAsInts, &activeDataset.mSecurityPolicy, sizeof(policyAsInts));
securityPolicy.rotationTime = policyAsInts[0];
securityPolicy.flags = policyAsInts[1];

err = encoder.EncodeList([securityPolicy](const auto & aEncoder) -> CHIP_ERROR {
ReturnErrorOnFailure(aEncoder.Encode(securityPolicy));
Expand Down
Loading

0 comments on commit 7f766c6

Please sign in to comment.