Skip to content

Commit

Permalink
Make use of ZAP's new support for specifying the parent of an endpoin…
Browse files Browse the repository at this point in the history
…t. (project-chip#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.
  • Loading branch information
bzbarsky-apple authored and huangxuyong committed Mar 19, 2024
1 parent ab986ed commit 39fe642
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3069,8 +3069,8 @@ static_assert(ATTRIBUTE_LARGEST <= CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE,
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 \
}
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,8 @@ static_assert(ATTRIBUTE_LARGEST <= CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE,
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 \
}
26 changes: 21 additions & 5 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ constexpr const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS;
#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;
Expand Down Expand Up @@ -183,10 +185,15 @@ void emberAfEndpointConfigure()
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
Expand All @@ -201,7 +208,6 @@ void emberAfEndpointConfigure()
}
#endif // ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT > 0

emberEndpointCount = FIXED_ENDPOINT_COUNT;
DataVersion * currentDataVersions = fixedEndpointDataVersions;
for (ep = 0; ep < FIXED_ENDPOINT_COUNT; ep++)
{
Expand All @@ -210,6 +216,14 @@ void emberAfEndpointConfigure()
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);
Expand All @@ -219,6 +233,8 @@ void emberAfEndpointConfigure()
currentDataVersions += emberAfClusterCountByIndex(ep, /* server = */ true);
}

#endif // FIXED_ENDPOINT_COUNT > 0

#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT
if (MAX_ENDPOINT_COUNT > FIXED_ENDPOINT_COUNT)
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/zap-templates/templates/app/endpoint_config.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static_assert(ATTRIBUTE_LARGEST <= CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE,
// 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}}
13 changes: 0 additions & 13 deletions src/darwin/Framework/CHIP/zap-generated/endpoint_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39fe642

Please sign in to comment.