From 25519223b2b20ab7fb6bf6fa0b9c8547b7c83ae3 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 22 Nov 2021 23:09:53 -0500 Subject: [PATCH] Fix type of endpoint id list in EndpointListStruct. (#12065) At this point all our codegen at least does not blow up on this. Fixes https://github.com/project-chip/connectedhomeip/issues/11123 --- .../chip/bridged-actions-cluster.xml | 2 +- .../java/zap-generated/CHIPReadCallbacks.cpp | 16 ++----------- .../chip/devicecontroller/ChipClusters.java | 9 +------- .../python/chip/clusters/CHIPClusters.cpp | 2 +- .../python/chip/clusters/Objects.py | 4 ++-- .../CHIP/zap-generated/CHIPCallbackBridge.mm | 2 +- .../CHIP/zap-generated/CHIPStructsObjc.h | 2 +- .../CHIP/zap-generated/CHIPStructsObjc.mm | 2 +- .../zap-generated/CHIPTestClustersObjc.mm | 23 ++++++++++++++++++- .../zap-generated/attribute-size.cpp | 17 ++++---------- .../app-common/zap-generated/af-structs.h | 2 +- .../zap-generated/cluster-objects.h | 13 ++++++++--- 12 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/app/zap-templates/zcl/data-model/chip/bridged-actions-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/bridged-actions-cluster.xml index 5158b7777b98f6..21e805243e1a3b 100644 --- a/src/app/zap-templates/zcl/data-model/chip/bridged-actions-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/bridged-actions-cluster.xml @@ -81,7 +81,7 @@ limitations under the License. - + diff --git a/src/controller/java/zap-generated/CHIPReadCallbacks.cpp b/src/controller/java/zap-generated/CHIPReadCallbacks.cpp index b833ed1f04be37..26d3578e867e71 100644 --- a/src/controller/java/zap-generated/CHIPReadCallbacks.cpp +++ b/src/controller/java/zap-generated/CHIPReadCallbacks.cpp @@ -1046,7 +1046,7 @@ void CHIPBridgedActionsEndpointListAttributeCallback::CallbackFn( ChipLogError(Zcl, "Could not find class chip/devicecontroller/ChipClusters$BridgedActionsCluster$EndpointListAttribute")); chip::JniClass attributeJniClass(attributeClass); jmethodID attributeCtor = - env->GetMethodID(attributeClass, "", "(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;[B)V"); + env->GetMethodID(attributeClass, "", "(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;)V"); VerifyOrReturn(attributeCtor != nullptr, ChipLogError(Zcl, "Could not find EndpointListAttribute constructor")); auto iter = list.begin(); @@ -1096,19 +1096,7 @@ void CHIPBridgedActionsEndpointListAttributeCallback::CallbackFn( type = env->NewObject(typeEntryCls, typeEntryTypeCtor, typeValue); } - bool endpointsNull = false; - bool endpointsHasValue = true; - - chip::ByteSpan endpointsValue = entry.endpoints; - - jbyteArray endpoints = nullptr; - if (!endpointsNull && endpointsHasValue) - { - endpoints = env->NewByteArray(endpointsValue.size()); - env->SetByteArrayRegion(endpoints, 0, endpointsValue.size(), reinterpret_cast(endpointsValue.data())); - } - - jobject attributeObj = env->NewObject(attributeClass, attributeCtor, endpointListID, name, type, endpoints); + jobject attributeObj = env->NewObject(attributeClass, attributeCtor, endpointListID, name, type); VerifyOrReturn(attributeObj != nullptr, ChipLogError(Zcl, "Could not create EndpointListAttribute object")); env->CallBooleanMethod(arrayListObj, arrayListAddMethod, attributeObj); diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java index 8fd75046c437e2..ae0afec5e267f5 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java @@ -1698,14 +1698,11 @@ public static class EndpointListAttribute { public Integer endpointListID; public String name; public Integer type; - public byte[] endpoints; - public EndpointListAttribute( - Integer endpointListID, String name, Integer type, byte[] endpoints) { + public EndpointListAttribute(Integer endpointListID, String name, Integer type) { this.endpointListID = endpointListID; this.name = name; this.type = type; - this.endpoints = endpoints; } @Override @@ -1723,10 +1720,6 @@ public String toString() { output.append(this.type); output.append("\n"); - output.append("byte[] "); - output.append(Arrays.toString(endpoints)); - output.append("\n"); - return output.toString(); } } diff --git a/src/controller/python/chip/clusters/CHIPClusters.cpp b/src/controller/python/chip/clusters/CHIPClusters.cpp index b957a3d41a24db..29476bfebedc6c 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.cpp +++ b/src/controller/python/chip/clusters/CHIPClusters.cpp @@ -281,7 +281,7 @@ static void OnBridgedActionsEndpointListListAttributeResponse( ChipLogProgress(Zcl, " EndpointListID: %" PRIu16 ",", entry.endpointListID); ChipLogProgress(Zcl, " Name: %.*s,", static_cast(entry.name.size()), entry.name.data()); ChipLogProgress(Zcl, " Type: %" PRIu8 ",", entry.type); - ChipLogProgress(Zcl, " Endpoints: %s,", ByteSpanToString(entry.endpoints).c_str()); + ChipLogProgress(chipTool, " Endpoints: list member of struct element of list attribute printing not supported yet"); ChipLogProgress(Zcl, " },"); #endif // CHIP_PROGRESS_LOGGING } diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index 951f9c92fad9a9..7d7d22705b9969 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -4840,13 +4840,13 @@ def descriptor(cls) -> ClusterObjectDescriptor: ClusterObjectFieldDescriptor( Label="type", Tag=2, Type=BridgedActions.Enums.EndpointListTypeEnum), ClusterObjectFieldDescriptor( - Label="endpoints", Tag=3, Type=bytes), + Label="endpoints", Tag=3, Type=typing.List[uint]), ]) endpointListID: 'uint' = None name: 'str' = None type: 'BridgedActions.Enums.EndpointListTypeEnum' = None - endpoints: 'bytes' = None + endpoints: 'typing.List[uint]' = None class Commands: @dataclass diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm index 1e499d598d69c8..cdf70ebe7297ba 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm @@ -162,7 +162,7 @@ @"endpointListID" : [NSNumber numberWithUnsignedShort:entry.endpointListID], @"name" : [[NSString alloc] initWithBytes:entry.name.data() length:entry.name.size() encoding:NSUTF8StringEncoding], @"type" : [NSNumber numberWithUnsignedChar:entry.type], - @"endpoints" : [NSData dataWithBytes:entry.endpoints.data() length:entry.endpoints.size()], + @"endpoints" : [[NSMutableArray alloc] init], }]; } if (iter.GetStatus() != CHIP_NO_ERROR) { diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.h b/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.h index 1503aff64055c1..52d4ef27dd49d8 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.h +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.h @@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN @property (strong, nonatomic) NSNumber * _Nonnull endpointListID; @property (strong, nonatomic) NSString * _Nonnull name; @property (strong, nonatomic) NSNumber * _Nonnull type; -@property (strong, nonatomic) NSData * _Nonnull endpoints; +@property (strong, nonatomic) NSArray * _Nonnull endpoints; - (instancetype)init; @end diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.mm index 683e4410555f60..652f6f1302549e 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPStructsObjc.mm @@ -132,7 +132,7 @@ - (instancetype)init _type = @(0); - _endpoints = [NSData data]; + _endpoints = [NSArray array]; } return self; } diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm index ae2519c698f234..173f0c53c8845c 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm @@ -845,7 +845,28 @@ new CHIPDefaultSuccessCallbackBridge(self.callbackQueue, responseHandler, ^(Canc listHolder_0->mList[i].name = [self asCharSpan:element_0.name]; listHolder_0->mList[i].type = static_castmList[i].type)>>( element_0.type.unsignedCharValue); - listHolder_0->mList[i].endpoints = [self asByteSpan:element_0.endpoints]; + { + using ListType = std::remove_reference_tmList[i].endpoints)>; + using ListMemberType = ListMemberTypeGetter::Type; + if (element_0.endpoints.count != 0) { + auto * listHolder_2 = new ListHolder(element_0.endpoints.count); + if (listHolder_2 == nullptr || listHolder_2->mList == nullptr) { + return CHIP_ERROR_INVALID_ARGUMENT; + } + listFreer.add(listHolder_2); + for (size_t i = 0; i < element_0.endpoints.count; ++i) { + if (![element_0.endpoints[i] isKindOfClass:[NSNumber class]]) { + // Wrong kind of value. + return CHIP_ERROR_INVALID_ARGUMENT; + } + auto element_2 = (NSNumber *) element_0.endpoints[i]; + listHolder_2->mList[i] = element_2.unsignedShortValue; + } + listHolder_0->mList[i].endpoints = ListType(listHolder_2->mList, element_0.endpoints.count); + } else { + listHolder_0->mList[i].endpoints = ListType(); + } + } } cppValue = ListType(listHolder_0->mList, value.count); } else { diff --git a/zzz_generated/all-clusters-app/zap-generated/attribute-size.cpp b/zzz_generated/all-clusters-app/zap-generated/attribute-size.cpp index 143de1eb0f0303..2cc27f9fa86272 100644 --- a/zzz_generated/all-clusters-app/zap-generated/attribute-size.cpp +++ b/zzz_generated/all-clusters-app/zap-generated/attribute-size.cpp @@ -173,7 +173,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo } case 0x0001: // endpoint list { - entryLength = 295; + entryLength = 39; if (((index - 1) * entryLength) > (am->size - entryLength)) { ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index); @@ -194,16 +194,9 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo } entryOffset = static_cast(entryOffset + 34); copyListMember(write ? dest : (uint8_t *) &entry->Type, write ? (uint8_t *) &entry->Type : src, write, &entryOffset, - sizeof(entry->Type)); // EndpointListTypeEnum - ByteSpan * EndpointsSpan = &entry->Endpoints; // OCTET_STRING - if (CHIP_NO_ERROR != - (write ? WriteByteSpan(dest + entryOffset, 258, EndpointsSpan) - : ReadByteSpan(src + entryOffset, 258, EndpointsSpan))) - { - ChipLogError(Zcl, "Index %" PRId32 " is invalid. Not enough remaining space", index); - return 0; - } - entryOffset = static_cast(entryOffset + 258); + sizeof(entry->Type)); // EndpointListTypeEnum + copyListMember(write ? dest : (uint8_t *) &entry->Endpoints, write ? (uint8_t *) &entry->Endpoints : src, write, + &entryOffset, sizeof(entry->Endpoints)); // ENDPOINT_NO break; } } @@ -1160,7 +1153,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut break; case 0x0001: // endpoint list // Struct _EndpointListStruct - entryLength = 295; + entryLength = 39; break; } break; diff --git a/zzz_generated/app-common/app-common/zap-generated/af-structs.h b/zzz_generated/app-common/app-common/zap-generated/af-structs.h index ae0318953357b9..6cac4edc1fc76c 100644 --- a/zzz_generated/app-common/app-common/zap-generated/af-structs.h +++ b/zzz_generated/app-common/app-common/zap-generated/af-structs.h @@ -183,7 +183,7 @@ typedef struct _EndpointListStruct uint16_t EndpointListID; chip::CharSpan Name; uint8_t Type; - chip::ByteSpan Endpoints; + /* TYPE WARNING: array array defaults to */ uint8_t * Endpoints; } EndpointListStruct; // Struct for FabricDescriptor diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index ef1425c5bc5a1e..38b501a359680b 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -5960,13 +5960,20 @@ struct Type uint16_t endpointListID; chip::CharSpan name; EndpointListTypeEnum type; - chip::ByteSpan endpoints; + DataModel::List endpoints; CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; - CHIP_ERROR Decode(TLV::TLVReader & reader); }; -using DecodableType = Type; +struct DecodableType +{ +public: + uint16_t endpointListID; + chip::CharSpan name; + EndpointListTypeEnum type; + DataModel::DecodableList endpoints; + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; } // namespace EndpointListStruct } // namespace Structs