Skip to content

Commit

Permalink
Delete last remnant of emberAfFindClusterServerEndpointIndex (#27052)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Feb 5, 2024
1 parent d394b26 commit d84ee0d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 97 deletions.
13 changes: 8 additions & 5 deletions examples/tv-app/android/java/LevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ static constexpr size_t kLevelManagerTableSize = EMBER_AF_LEVEL_CONTROL_CLUSTER_
namespace {

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

}
} // namespace

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

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

LevelManager * GetLevelManager(EndpointId endpoint)
{
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, app::Clusters::LevelControl::Id);
return ((ep == kEmberInvalidEndpointIndex || ep >= kLevelManagerTableSize) ? nullptr : gLevelManagerTable[ep]);
uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::LevelControl::Id,
EMBER_AF_LEVEL_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT);
return ((ep >= kLevelManagerTableSize) ? nullptr : gLevelManagerTable[ep]);
}

void LevelManager::PostLevelChanged(chip::EndpointId endpoint, uint8_t value)
Expand Down
15 changes: 8 additions & 7 deletions examples/tv-app/android/java/OnOffManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ static constexpr size_t kOnffManagerTableSize = EMBER_AF_ON_OFF_CLUSTER_SERVER_E
namespace {

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

}
} // namespace

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

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

OnOffManager * GetOnOffManager(EndpointId endpoint)
{
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, app::Clusters::OnOff::Id);
return ((ep == kEmberInvalidEndpointIndex || ep >= EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT)
? nullptr
: gOnOffManagerTable[ep]);
uint16_t ep =
emberAfGetClusterServerEndpointIndex(endpoint, app::Clusters::OnOff::Id, EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT);
return (ep >= kOnffManagerTableSize ? nullptr : gOnOffManagerTable[ep]);
}

void OnOffManager::PostOnOffChanged(chip::EndpointId endpoint, bool value)
Expand Down
11 changes: 7 additions & 4 deletions src/app/clusters/ota-provider/ota-provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ using Protocols::InteractionModel::Status;

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

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

OTAProviderDelegate * GetDelegate(EndpointId endpoint)
{
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id);
return (ep == 0xFFFF ? nullptr : gDelegateTable[ep]);
uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id,
EMBER_AF_OTA_SOFTWARE_UPDATE_PROVIDER_CLUSTER_SERVER_ENDPOINT_COUNT);
return (ep >= kOtaProviderDelegateTableSize ? nullptr : gDelegateTable[ep]);
}

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

void SetDelegate(EndpointId endpoint, OTAProviderDelegate * delegate)
{
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id);
if (ep != 0xFFFF)
uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, OtaSoftwareUpdateProvider::Id,
EMBER_AF_OTA_SOFTWARE_UPDATE_PROVIDER_CLUSTER_SERVER_ENDPOINT_COUNT);
if (ep < kOtaProviderDelegateTableSize)
{
gDelegateTable[ep] = delegate;
}
Expand Down
42 changes: 5 additions & 37 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,50 +149,18 @@ uint16_t emberAfIndexFromEndpoint(chip::EndpointId endpoint);
*/
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(chip::EndpointId endpoint);

/**
* Returns the index of the given endpoint in the list of all defined endpoints
* (including disabled ones) that support the given cluster.
*
* Returns kEmberInvalidEndpointIndex if the given endpoint does not support the
* given cluster.
*
* For fixed endpoints, the returned value never changes, but for dynamic
* endpoints it can change if a dynamic endpoint is defined at a lower index
* that also supports the given cluster.
*
* For example, if a device has 4 fixed endpoints (ids 0-3) and 2 dynamic
* endpoints, and cluster X is supported on endpoints 1 and 3, then:
*
* 1) emberAfFindClusterServerEndpointIndex(0, X) returns kEmberInvalidEndpointIndex
* 2) emberAfFindClusterServerEndpointIndex(1, X) returns 0
* 3) emberAfFindClusterServerEndpointIndex(2, X) returns kEmberInvalidEndpointIndex
* 4) emberAfFindClusterServerEndpointIndex(3, X) returns 1
*
* If the second dynamic endpoint is defined (via
* emberAfSetDynamicEndpoint(1, 7, ...)) to
* have endpoint id 7, and supports cluster X, but the first dynamic endpoint is
* not defined, then emberAfFindClusterServerEndpointIndex(7, X) returns 2.
*
* If now the first dynamic endpoint is defined (via
* emberAfSetDynamicEndpoint(0, 9, ...))
* to have endpoint id 9, and supports cluster X, then
* emberAfFindClusterServerEndpointIndex(7, X) starts returning 3 and
* emberAfFindClusterServerEndpointIndex(9, X) returns 2.
*/
uint16_t emberAfFindClusterServerEndpointIndex(chip::EndpointId endpoint, chip::ClusterId clusterId);

/**
* @brief Returns the index of the given endpoint in the list of all endpoints that might support the given cluster server.
*
* Returns kEmberInvalidEndpointIndex if the given endpoint does not support the
* given cluster or if the given endpoint is disabled.
*
* Unlike emberAfFindClusterServerEndpointIndex, this function always returns the same index
* for a given endpointId instance, fixed or dynamic, if it does not return kEmberInvalidEndpointIndex.
* This function always returns the same index for a given endpointId instance, fixed or dynamic.
*
* The return index is identical to emberAfFindClusterServerEndpointIndex for fixed endpoints,
* but for dynamic endpoints the indexing assumes that any dynamic endpoint could start supporting
* the given server cluster.
* The return index for fixed endpoints will range from 0 to (fixedClusterServerEndpointCount - 1),
* For dynamic endpoints the indexing assumes that any dynamic endpoint could start supporting
* the given server cluster and their index will range from fixedClusterServerEndpointCount to
* (fixedClusterServerEndpointCount + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT - 1).
*
* For example, if a device has 4 fixed endpoints (ids 0-3) and 2 dynamic
* endpoints, and cluster X is supported on endpoints 1 and 3, then
Expand Down
42 changes: 0 additions & 42 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ DataVersion fixedEndpointDataVersions[ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT];
app::AttributeAccessInterface * gAttributeAccessOverrides = nullptr;
} // anonymous namespace

//------------------------------------------------------------------------------
// Forward declarations

// Returns endpoint index within a given cluster
static uint16_t findClusterEndpointIndex(EndpointId endpoint, ClusterId clusterId, uint8_t mask);

//------------------------------------------------------------------------------

// Initial configuration
void emberAfEndpointConfigure()
{
Expand Down Expand Up @@ -825,40 +817,6 @@ const EmberAfCluster * emberAfFindClusterIncludingDisabledEndpoints(EndpointId e
return nullptr;
}

// Server wrapper for findClusterEndpointIndex
uint16_t emberAfFindClusterServerEndpointIndex(EndpointId endpoint, ClusterId clusterId)
{
return findClusterEndpointIndex(endpoint, clusterId, CLUSTER_MASK_SERVER);
}

// Returns the endpoint index within a given cluster
static uint16_t findClusterEndpointIndex(EndpointId endpoint, ClusterId clusterId, uint8_t mask)
{
uint16_t i, epi = 0;

if (emberAfFindServerCluster(endpoint, clusterId) == nullptr)
{
return kEmberInvalidEndpointIndex;
}

for (i = 0; i < emberAfEndpointCount(); i++)
{
if (emAfEndpoints[i].endpoint == endpoint)
{
break;
}
if (emAfEndpoints[i].endpoint == kInvalidEndpointId)
{
// Not actually a configured endpoint.
continue;
}
epi = static_cast<uint16_t>(
epi + ((emberAfFindClusterIncludingDisabledEndpoints(emAfEndpoints[i].endpoint, clusterId, mask) != nullptr) ? 1 : 0));
}

return epi;
}

static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEndpoints)
{
if (endpoint == kInvalidEndpointId)
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRIMDispatch.mm
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aPath, TLV::TLVRea
* Called by the OTA provider cluster server to determine an index
* into its array.
*/
uint16_t emberAfFindClusterServerEndpointIndex(EndpointId endpoint, ClusterId clusterId)
uint16_t emberAfGetClusterServerEndpointIndex(EndpointId endpoint, ClusterId cluster, uint16_t fixedClusterServerEndpointCount)
{
if (endpoint == kSupportedEndpoint && clusterId == OtaSoftwareUpdateProvider::Id) {
if (endpoint == kSupportedEndpoint && cluster == OtaSoftwareUpdateProvider::Id) {
return 0;
}

Expand Down

0 comments on commit d84ee0d

Please sign in to comment.