Make use of ZAP's new support for specifying the parent of an endpoint. (#32487)
Specific changes:
* Remove unused FIXED_NETWORKS bit from endpoint_config.h.
* Add FIXED_PARENT_ENDPOINTS which lists the parents of each fixed endpoint.
* Condition the fixed endpoint initialization code on FIXED_ENDPOINT_COUNT > 0
and remove some Darwin hackery that was needed because it was not thus
conditioned.
* Add initialization of parentEndpointId for fixed endpoints from
FIXED_PARENT_ENDPOINTS.
At the moment FIXED_PARENT_ENDPOINTS uses 0 to mean "no parent specified", but I
am hoping the ZAP folks will fix things so that we can just have
kInvalidEndpointId in there and the code in emberAfEndpointConfigure can become
simpler/smaller.
diff --git a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h
index 8c1c6c7..09b1744 100644
--- a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h
+++ b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h
@@ -3069,8 +3069,8 @@
0, 1, 2, 3 \
}
-// Array of networks supported on each endpoint
-#define FIXED_NETWORKS \
+// Array of parent endpoints for each endpoint
+#define FIXED_PARENT_ENDPOINTS \
{ \
0, 0, 0, 0 \
}
diff --git a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h
index 4e21190..0e6ba62 100644
--- a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h
+++ b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h
@@ -1207,8 +1207,8 @@
0, 1 \
}
-// Array of networks supported on each endpoint
-#define FIXED_NETWORKS \
+// Array of parent endpoints for each endpoint
+#define FIXED_PARENT_ENDPOINTS \
{ \
0, 0 \
}
diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp
index 431f309..3bce63e 100644
--- a/src/app/util/attribute-storage.cpp
+++ b/src/app/util/attribute-storage.cpp
@@ -130,11 +130,13 @@
#define ZAP_CLUSTER_INDEX(index) (&generatedClusters[index])
#endif
+#if FIXED_ENDPOINT_COUNT > 0
constexpr const EmberAfEndpointType generatedEmberAfEndpointTypes[] = GENERATED_ENDPOINT_TYPES;
constexpr const EmberAfDeviceType fixedDeviceTypeList[] = FIXED_DEVICE_TYPES;
// Not const, because these need to mutate.
DataVersion fixedEndpointDataVersions[ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT];
+#endif // FIXED_ENDPOINT_COUNT > 0
AttributeAccessInterface * gAttributeAccessOverrides = nullptr;
AttributeAccessInterfaceCache gAttributeAccessInterfaceCache;
@@ -183,10 +185,15 @@
static_assert(FIXED_ENDPOINT_COUNT <= std::numeric_limits<decltype(ep)>::max(),
"FIXED_ENDPOINT_COUNT must not exceed the size of the endpoint data type");
- uint16_t fixedEndpoints[] = FIXED_ENDPOINT_ARRAY;
- uint16_t fixedDeviceTypeListLengths[] = FIXED_DEVICE_TYPE_LENGTHS;
- uint16_t fixedDeviceTypeListOffsets[] = FIXED_DEVICE_TYPE_OFFSETS;
- uint8_t fixedEmberAfEndpointTypes[] = FIXED_ENDPOINT_TYPES;
+ emberEndpointCount = FIXED_ENDPOINT_COUNT;
+
+#if FIXED_ENDPOINT_COUNT > 0
+
+ constexpr uint16_t fixedEndpoints[] = FIXED_ENDPOINT_ARRAY;
+ constexpr uint16_t fixedDeviceTypeListLengths[] = FIXED_DEVICE_TYPE_LENGTHS;
+ constexpr uint16_t fixedDeviceTypeListOffsets[] = FIXED_DEVICE_TYPE_OFFSETS;
+ constexpr uint8_t fixedEmberAfEndpointTypes[] = FIXED_ENDPOINT_TYPES;
+ constexpr EndpointId fixedParentEndpoints[] = FIXED_PARENT_ENDPOINTS;
#if ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT > 0
// Initialize our data version storage. If
@@ -201,7 +208,6 @@
}
#endif // ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT > 0
- emberEndpointCount = FIXED_ENDPOINT_COUNT;
DataVersion * currentDataVersions = fixedEndpointDataVersions;
for (ep = 0; ep < FIXED_ENDPOINT_COUNT; ep++)
{
@@ -210,6 +216,14 @@
Span<const EmberAfDeviceType>(&fixedDeviceTypeList[fixedDeviceTypeListOffsets[ep]], fixedDeviceTypeListLengths[ep]);
emAfEndpoints[ep].endpointType = &generatedEmberAfEndpointTypes[fixedEmberAfEndpointTypes[ep]];
emAfEndpoints[ep].dataVersions = currentDataVersions;
+ if (fixedParentEndpoints[ep] == 0)
+ {
+ emAfEndpoints[ep].parentEndpointId = kInvalidEndpointId;
+ }
+ else
+ {
+ emAfEndpoints[ep].parentEndpointId = fixedParentEndpoints[ep];
+ }
emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isFlatComposition);
@@ -219,6 +233,8 @@
currentDataVersions += emberAfClusterCountByIndex(ep, /* server = */ true);
}
+#endif // FIXED_ENDPOINT_COUNT > 0
+
#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT
if (MAX_ENDPOINT_COUNT > FIXED_ENDPOINT_COUNT)
{
diff --git a/src/app/zap-templates/templates/app/endpoint_config.zapt b/src/app/zap-templates/templates/app/endpoint_config.zapt
index f67c779..43ef324 100644
--- a/src/app/zap-templates/templates/app/endpoint_config.zapt
+++ b/src/app/zap-templates/templates/app/endpoint_config.zapt
@@ -95,7 +95,7 @@
// Array of endpoint types supported on each endpoint
#define FIXED_ENDPOINT_TYPES {{endpoint_fixed_endpoint_type_array}}
-// Array of networks supported on each endpoint
-#define FIXED_NETWORKS {{endpoint_fixed_network_array}}
+// Array of parent endpoints for each endpoint
+#define FIXED_PARENT_ENDPOINTS {{endpoint_fixed_parent_id_array}}
{{/endpoint_config}}
diff --git a/src/darwin/Framework/CHIP/zap-generated/endpoint_config.h b/src/darwin/Framework/CHIP/zap-generated/endpoint_config.h
index 27cfbdb..5f79658 100644
--- a/src/darwin/Framework/CHIP/zap-generated/endpoint_config.h
+++ b/src/darwin/Framework/CHIP/zap-generated/endpoint_config.h
@@ -36,16 +36,3 @@
#define GENERATED_ATTRIBUTES {}
-#define GENERATED_ENDPOINT_TYPES {}
-
-#define FIXED_DEVICE_TYPES {}
-
-#define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT 0
-
-#define FIXED_ENDPOINT_ARRAY {}
-
-#define FIXED_DEVICE_TYPE_LENGTHS {}
-
-#define FIXED_DEVICE_TYPE_OFFSETS {}
-
-#define FIXED_ENDPOINT_TYPES {}