Skip to content

Commit 5165007

Browse files
Delete last remnant of emberAfFindClusterServerEndpointIndex (#27052)
* Delete last remnant of emberAfFindClusterServerEndpointIndex * findClusterEndpointIndex endups not being used anymore either. delete it too * fix build errors caught by ci * fix a build error caught by ci
1 parent 991f367 commit 5165007

File tree

6 files changed

+30
-97
lines changed

6 files changed

+30
-97
lines changed

examples/tv-app/android/java/LevelManager.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ static constexpr size_t kLevelManagerTableSize = EMBER_AF_LEVEL_CONTROL_CLUSTER_
3232
namespace {
3333

3434
LevelManager * gLevelManagerTable[kLevelManagerTableSize] = { nullptr };
35+
static_assert(kLevelManagerTableSize <= kEmberInvalidEndpointIndex, "gLevelManagerTable table size error");
3536

36-
}
37+
} // namespace
3738

3839
void emberAfLevelControlClusterInitCallback(EndpointId endpoint)
3940
{
@@ -44,8 +45,9 @@ void emberAfLevelControlClusterInitCallback(EndpointId endpoint)
4445
void LevelManager::NewManager(jint endpoint, jobject manager)
4546
{
4647
ChipLogProgress(Zcl, "TV Android App: LevelManager::NewManager");
47-
uint16_t ep = emberAfFindClusterServerEndpointIndex(static_cast<chip::EndpointId>(endpoint), app::Clusters::LevelControl::Id);
48-
VerifyOrReturn(ep != kEmberInvalidEndpointIndex && ep < kLevelManagerTableSize,
48+
uint16_t ep = emberAfGetClusterServerEndpointIndex(static_cast<chip::EndpointId>(endpoint), app::Clusters::LevelControl::Id,
49+
EMBER_AF_LEVEL_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT);
50+
VerifyOrReturn(ep < kLevelManagerTableSize,
4951
ChipLogError(Zcl, "TV Android App::Level::NewManager: endpoint %d not found", endpoint));
5052

5153
VerifyOrReturn(gLevelManagerTable[ep] == nullptr,
@@ -65,8 +67,9 @@ void LevelManager::NewManager(jint endpoint, jobject manager)
6567

6668
LevelManager * GetLevelManager(EndpointId endpoint)
6769
{
68-
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, app::Clusters::LevelControl::Id);
69-
return ((ep == kEmberInvalidEndpointIndex || ep >= kLevelManagerTableSize) ? nullptr : gLevelManagerTable[ep]);
70+
uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::LevelControl::Id,
71+
EMBER_AF_LEVEL_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT);
72+
return ((ep >= kLevelManagerTableSize) ? nullptr : gLevelManagerTable[ep]);
7073
}
7174

7275
void LevelManager::PostLevelChanged(chip::EndpointId endpoint, uint8_t value)

examples/tv-app/android/java/OnOffManager.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ static constexpr size_t kOnffManagerTableSize = EMBER_AF_ON_OFF_CLUSTER_SERVER_E
3232
namespace {
3333

3434
OnOffManager * gOnOffManagerTable[kOnffManagerTableSize] = { nullptr };
35+
static_assert(kOnffManagerTableSize <= kEmberInvalidEndpointIndex, "gOnOffManagerTable table size error");
3536

36-
}
37+
} // namespace
3738

3839
void emberAfOnOffClusterInitCallback(EndpointId endpoint)
3940
{
@@ -44,8 +45,9 @@ void emberAfOnOffClusterInitCallback(EndpointId endpoint)
4445
void OnOffManager::NewManager(jint endpoint, jobject manager)
4546
{
4647
ChipLogProgress(Zcl, "TV Android App: OnOffManager::NewManager");
47-
uint16_t ep = emberAfFindClusterServerEndpointIndex(static_cast<chip::EndpointId>(endpoint), app::Clusters::OnOff::Id);
48-
VerifyOrReturn(ep != kEmberInvalidEndpointIndex && ep < EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT,
48+
uint16_t ep = emberAfGetClusterServerEndpointIndex(static_cast<chip::EndpointId>(endpoint), app::Clusters::OnOff::Id,
49+
EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT);
50+
VerifyOrReturn(ep < kOnffManagerTableSize,
4951
ChipLogError(Zcl, "TV Android App::OnOff::NewManager: endpoint %d not found", endpoint));
5052

5153
VerifyOrReturn(gOnOffManagerTable[ep] == nullptr,
@@ -65,10 +67,9 @@ void OnOffManager::NewManager(jint endpoint, jobject manager)
6567

6668
OnOffManager * GetOnOffManager(EndpointId endpoint)
6769
{
68-
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, app::Clusters::OnOff::Id);
69-
return ((ep == kEmberInvalidEndpointIndex || ep >= EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT)
70-
? nullptr
71-
: gOnOffManagerTable[ep]);
70+
uint16_t ep =
71+
emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OnOff::Id, EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT);
72+
return (ep >= kOnffManagerTableSize ? nullptr : gOnOffManagerTable[ep]);
7273
}
7374

7475
void OnOffManager::PostOnOffChanged(chip::EndpointId endpoint, bool value)

src/app/clusters/ota-provider/ota-provider.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ using Protocols::InteractionModel::Status;
4747

4848
static constexpr size_t kOtaProviderDelegateTableSize =
4949
EMBER_AF_OTA_SOFTWARE_UPDATE_PROVIDER_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
50+
static_assert(kOtaProviderDelegateTableSize <= kEmberInvalidEndpointIndex, "OtaProvider Delegate table size error");
5051

5152
namespace {
5253
constexpr size_t kLocationLen = 2; // The expected length of the location parameter in QueryImage
@@ -58,8 +59,9 @@ OTAProviderDelegate * gDelegateTable[kOtaProviderDelegateTableSize] = { nullptr
5859

5960
OTAProviderDelegate * GetDelegate(EndpointId endpoint)
6061
{
61-
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id);
62-
return (ep == 0xFFFF ? nullptr : gDelegateTable[ep]);
62+
uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id,
63+
EMBER_AF_OTA_SOFTWARE_UPDATE_PROVIDER_CLUSTER_SERVER_ENDPOINT_COUNT);
64+
return (ep >= kOtaProviderDelegateTableSize ? nullptr : gDelegateTable[ep]);
6365
}
6466

6567
bool SendStatusIfDelegateNull(app::CommandHandler * commandObj, const app::ConcreteCommandPath & path)
@@ -226,8 +228,9 @@ namespace OTAProvider {
226228

227229
void SetDelegate(EndpointId endpoint, OTAProviderDelegate * delegate)
228230
{
229-
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id);
230-
if (ep != 0xFFFF)
231+
uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id,
232+
EMBER_AF_OTA_SOFTWARE_UPDATE_PROVIDER_CLUSTER_SERVER_ENDPOINT_COUNT);
233+
if (ep < kOtaProviderDelegateTableSize)
231234
{
232235
gDelegateTable[ep] = delegate;
233236
}

src/app/util/af.h

+5-37
Original file line numberDiff line numberDiff line change
@@ -149,50 +149,18 @@ uint16_t emberAfIndexFromEndpoint(chip::EndpointId endpoint);
149149
*/
150150
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(chip::EndpointId endpoint);
151151

152-
/**
153-
* Returns the index of the given endpoint in the list of all defined endpoints
154-
* (including disabled ones) that support the given cluster.
155-
*
156-
* Returns kEmberInvalidEndpointIndex if the given endpoint does not support the
157-
* given cluster.
158-
*
159-
* For fixed endpoints, the returned value never changes, but for dynamic
160-
* endpoints it can change if a dynamic endpoint is defined at a lower index
161-
* that also supports the given cluster.
162-
*
163-
* For example, if a device has 4 fixed endpoints (ids 0-3) and 2 dynamic
164-
* endpoints, and cluster X is supported on endpoints 1 and 3, then:
165-
*
166-
* 1) emberAfFindClusterServerEndpointIndex(0, X) returns kEmberInvalidEndpointIndex
167-
* 2) emberAfFindClusterServerEndpointIndex(1, X) returns 0
168-
* 3) emberAfFindClusterServerEndpointIndex(2, X) returns kEmberInvalidEndpointIndex
169-
* 4) emberAfFindClusterServerEndpointIndex(3, X) returns 1
170-
*
171-
* If the second dynamic endpoint is defined (via
172-
* emberAfSetDynamicEndpoint(1, 7, ...)) to
173-
* have endpoint id 7, and supports cluster X, but the first dynamic endpoint is
174-
* not defined, then emberAfFindClusterServerEndpointIndex(7, X) returns 2.
175-
*
176-
* If now the first dynamic endpoint is defined (via
177-
* emberAfSetDynamicEndpoint(0, 9, ...))
178-
* to have endpoint id 9, and supports cluster X, then
179-
* emberAfFindClusterServerEndpointIndex(7, X) starts returning 3 and
180-
* emberAfFindClusterServerEndpointIndex(9, X) returns 2.
181-
*/
182-
uint16_t emberAfFindClusterServerEndpointIndex(chip::EndpointId endpoint, chip::ClusterId clusterId);
183-
184152
/**
185153
* @brief Returns the index of the given endpoint in the list of all endpoints that might support the given cluster server.
186154
*
187155
* Returns kEmberInvalidEndpointIndex if the given endpoint does not support the
188156
* given cluster or if the given endpoint is disabled.
189157
*
190-
* Unlike emberAfFindClusterServerEndpointIndex, this function always returns the same index
191-
* for a given endpointId instance, fixed or dynamic, if it does not return kEmberInvalidEndpointIndex.
158+
* This function always returns the same index for a given endpointId instance, fixed or dynamic.
192159
*
193-
* The return index is identical to emberAfFindClusterServerEndpointIndex for fixed endpoints,
194-
* but for dynamic endpoints the indexing assumes that any dynamic endpoint could start supporting
195-
* the given server cluster.
160+
* The return index for fixed endpoints will range from 0 to (fixedClusterServerEndpointCount - 1),
161+
* For dynamic endpoints the indexing assumes that any dynamic endpoint could start supporting
162+
* the given server cluster and their index will range from fixedClusterServerEndpointCount to
163+
* (fixedClusterServerEndpointCount + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT - 1).
196164
*
197165
* For example, if a device has 4 fixed endpoints (ids 0-3) and 2 dynamic
198166
* endpoints, and cluster X is supported on endpoints 1 and 3, then

src/app/util/attribute-storage.cpp

-42
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,6 @@ DataVersion fixedEndpointDataVersions[ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT];
121121
app::AttributeAccessInterface * gAttributeAccessOverrides = nullptr;
122122
} // anonymous namespace
123123

124-
//------------------------------------------------------------------------------
125-
// Forward declarations
126-
127-
// Returns endpoint index within a given cluster
128-
static uint16_t findClusterEndpointIndex(EndpointId endpoint, ClusterId clusterId, uint8_t mask);
129-
130-
//------------------------------------------------------------------------------
131-
132124
// Initial configuration
133125
void emberAfEndpointConfigure()
134126
{
@@ -825,40 +817,6 @@ const EmberAfCluster * emberAfFindClusterIncludingDisabledEndpoints(EndpointId e
825817
return nullptr;
826818
}
827819

828-
// Server wrapper for findClusterEndpointIndex
829-
uint16_t emberAfFindClusterServerEndpointIndex(EndpointId endpoint, ClusterId clusterId)
830-
{
831-
return findClusterEndpointIndex(endpoint, clusterId, CLUSTER_MASK_SERVER);
832-
}
833-
834-
// Returns the endpoint index within a given cluster
835-
static uint16_t findClusterEndpointIndex(EndpointId endpoint, ClusterId clusterId, uint8_t mask)
836-
{
837-
uint16_t i, epi = 0;
838-
839-
if (emberAfFindServerCluster(endpoint, clusterId) == nullptr)
840-
{
841-
return kEmberInvalidEndpointIndex;
842-
}
843-
844-
for (i = 0; i < emberAfEndpointCount(); i++)
845-
{
846-
if (emAfEndpoints[i].endpoint == endpoint)
847-
{
848-
break;
849-
}
850-
if (emAfEndpoints[i].endpoint == kInvalidEndpointId)
851-
{
852-
// Not actually a configured endpoint.
853-
continue;
854-
}
855-
epi = static_cast<uint16_t>(
856-
epi + ((emberAfFindClusterIncludingDisabledEndpoints(emAfEndpoints[i].endpoint, clusterId, mask) != nullptr) ? 1 : 0));
857-
}
858-
859-
return epi;
860-
}
861-
862820
static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEndpoints)
863821
{
864822
if (endpoint == kInvalidEndpointId)

src/darwin/Framework/CHIP/MTRIMDispatch.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aPath, TLV::TLVRea
230230
* Called by the OTA provider cluster server to determine an index
231231
* into its array.
232232
*/
233-
uint16_t emberAfFindClusterServerEndpointIndex(EndpointId endpoint, ClusterId clusterId)
233+
uint16_t emberAfGetClusterServerEndpointIndex(EndpointId endpoint, ClusterId cluster, uint16_t fixedClusterServerEndpointCount)
234234
{
235-
if (endpoint == kSupportedEndpoint && clusterId == OtaSoftwareUpdateProvider::Id) {
235+
if (endpoint == kSupportedEndpoint && cluster == OtaSoftwareUpdateProvider::Id) {
236236
return 0;
237237
}
238238

0 commit comments

Comments
 (0)