Skip to content

Commit

Permalink
Remove unused public api (#32728)
Browse files Browse the repository at this point in the history
* Move single-usage APIs from a global header to cpp.

Some of the af.h functions seem to only be ever used in
attribute-storage.cpp. Place them as static entries there to shrink
the size of the public API we maintain.

* Restyle

* Move the compare values in anonymous namespace as well

* Define EM_BIG_ENDIAN

* Restyle

* move the location of the single-use things to the right place

* Restyle
  • Loading branch information
andy31415 authored and pull[bot] committed Apr 19, 2024
1 parent 0a90ff1 commit 1586696
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 150 deletions.
33 changes: 0 additions & 33 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ chip::EndpointId emberAfParentEndpointFromIndex(uint16_t index);
*/
uint16_t emberAfIndexFromEndpoint(chip::EndpointId endpoint);

/**
* Returns the index of a given endpoint; Does not ignore disabled endpoints.
* Will return 0xFFFF if this is not a valid endpoint id.
*/
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(chip::EndpointId endpoint);

/**
* @brief Returns the index of the given endpoint in the list of all endpoints that might support the given cluster server.
*
Expand Down Expand Up @@ -189,35 +183,8 @@ uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::C
*/
uint16_t emberAfFixedEndpointCount(void);

/**
*@brief Returns true if type is signed, false otherwise.
*/
bool emberAfIsTypeSigned(EmberAfAttributeType dataType);

/** @} END Attribute Storage */

/** @name Miscellaneous */
// @{

/** @brief Returns true if a given ZCL data type is a list type. */
bool emberAfIsThisDataTypeAListType(EmberAfAttributeType dataType);

/**
* @brief Simple integer comparison function.
* Compares two values of a known length as integers.
* Signed integer comparison are supported for numbers with length of
* 4 (bytes) or less.
* The integers are in native endianness.
*
* @return -1, if val1 is smaller
* 0, if they are the same or if two negative numbers with length
* greater than 4 is being compared
* 1, if val2 is smaller.
*/
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber);

/** @} END Miscellaneous */

/** @} END addtogroup */

/**
Expand Down
60 changes: 30 additions & 30 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,36 @@ void UnregisterMatchingAttributeAccessInterfaces(F shouldUnregister)
}
}

bool emberAfIsThisDataTypeAListType(EmberAfAttributeType dataType)
{
return dataType == ZCL_ARRAY_ATTRIBUTE_TYPE;
}

uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEndpoints)
{
if (endpoint == kInvalidEndpointId)
{
return kEmberInvalidEndpointIndex;
}

uint16_t epi;
for (epi = 0; epi < emberAfEndpointCount(); epi++)
{
if (emAfEndpoints[epi].endpoint == endpoint &&
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask.Has(EmberAfEndpointOptions::isEnabled)))
{
return epi;
}
}
return kEmberInvalidEndpointIndex;
}

// Returns the index of a given endpoint. Considers disabled endpoints.
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(EndpointId endpoint)
{
return findIndexFromEndpoint(endpoint, false /* ignoreDisabledEndpoints */);
}

} // anonymous namespace

// Initial configuration
Expand Down Expand Up @@ -354,11 +384,6 @@ bool emberAfEndpointIndexIsEnabled(uint16_t index)
return (emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isEnabled));
}

bool emberAfIsThisDataTypeAListType(EmberAfAttributeType dataType)
{
return dataType == ZCL_ARRAY_ATTRIBUTE_TYPE;
}

// This function is used to call the per-cluster attribute changed callback
void emAfClusterAttributeChangedCallback(const app::ConcreteAttributePath & attributePath)
{
Expand Down Expand Up @@ -845,25 +870,6 @@ const EmberAfCluster * emberAfFindClusterIncludingDisabledEndpoints(EndpointId e
return nullptr;
}

static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEndpoints)
{
if (endpoint == kInvalidEndpointId)
{
return kEmberInvalidEndpointIndex;
}

uint16_t epi;
for (epi = 0; epi < emberAfEndpointCount(); epi++)
{
if (emAfEndpoints[epi].endpoint == endpoint &&
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask.Has(EmberAfEndpointOptions::isEnabled)))
{
return epi;
}
}
return kEmberInvalidEndpointIndex;
}

uint16_t emberAfGetClusterServerEndpointIndex(EndpointId endpoint, ClusterId cluster, uint16_t fixedClusterServerEndpointCount)
{
VerifyOrDie(fixedClusterServerEndpointCount <= FIXED_ENDPOINT_COUNT);
Expand Down Expand Up @@ -980,12 +986,6 @@ uint16_t emberAfIndexFromEndpoint(EndpointId endpoint)
return findIndexFromEndpoint(endpoint, true /* ignoreDisabledEndpoints */);
}

// Returns the index of a given endpoint. Considers disabled endpoints.
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(EndpointId endpoint)
{
return findIndexFromEndpoint(endpoint, false /* ignoreDisabledEndpoints */);
}

EndpointId emberAfEndpointFromIndex(uint16_t index)
{
return emAfEndpoints[index].endpoint;
Expand Down
104 changes: 104 additions & 0 deletions src/app/util/attribute-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,114 @@
#include <app/reporting/reporting.h>
#include <protocols/interaction_model/Constants.h>

#if (CHIP_CONFIG_BIG_ENDIAN_TARGET)
#define EM_BIG_ENDIAN true
#else
#define EM_BIG_ENDIAN false
#endif

using chip::Protocols::InteractionModel::Status;

using namespace chip;

namespace {

// Zigbee spec says types between signed 8 bit and signed 64 bit
bool emberAfIsTypeSigned(EmberAfAttributeType dataType)
{
return (dataType >= ZCL_INT8S_ATTRIBUTE_TYPE && dataType <= ZCL_INT64S_ATTRIBUTE_TYPE);
}

/**
* @brief Simple integer comparison function.
* Compares two values of a known length as integers.
* Signed integer comparison are supported for numbers with length of
* 4 (bytes) or less.
* The integers are in native endianness.
*
* @return -1, if val1 is smaller
* 0, if they are the same or if two negative numbers with length
* greater than 4 is being compared
* 1, if val2 is smaller.
*
* You can pass in val1 as NULL, which will assume that it is
* pointing to an array of all zeroes. This is used so that
* default value of NULL is treated as all zeroes.
*/
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber)
{
if (len == 0)
{
// no length means nothing to compare. Shouldn't even happen, since len is sizeof(some-integer-type).
return 0;
}

if (signedNumber)
{ // signed number comparison
if (len <= 4)
{ // only number with 32-bits or less is supported
int32_t accum1 = 0x0;
int32_t accum2 = 0x0;
int32_t all1s = -1;

for (uint16_t i = 0; i < len; i++)
{
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
accum1 |= j << (8 * (len - 1 - i));

uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
accum2 |= k << (8 * (len - 1 - i));
}

// sign extending, no need for 32-bits numbers
if (len < 4)
{
if ((accum1 & (1 << (8 * len - 1))) != 0)
{ // check sign
accum1 |= all1s - ((1 << (len * 8)) - 1);
}
if ((accum2 & (1 << (8 * len - 1))) != 0)
{ // check sign
accum2 |= all1s - ((1 << (len * 8)) - 1);
}
}

if (accum1 > accum2)
{
return 1;
}
if (accum1 < accum2)
{
return -1;
}

return 0;
}

// not supported
return 0;
}

// regular unsigned number comparison
for (uint16_t i = 0; i < len; i++)
{
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);

if (j > k)
{
return 1;
}
if (k > j)
{
return -1;
}
}
return 0;
}

} // namespace

Status emAfWriteAttributeExternal(EndpointId endpoint, ClusterId cluster, AttributeId attributeID, uint8_t * dataPtr,
EmberAfAttributeType dataType)
{
Expand Down
87 changes: 0 additions & 87 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,93 +140,6 @@ void MatterPowerTopologyPluginServerInitCallback() {}
void MatterElectricalEnergyMeasurementPluginServerInitCallback() {}
void MatterElectricalPowerMeasurementPluginServerInitCallback() {}

#if (CHIP_CONFIG_BIG_ENDIAN_TARGET)
#define EM_BIG_ENDIAN true
#else
#define EM_BIG_ENDIAN false
#endif

// You can pass in val1 as NULL, which will assume that it is
// pointing to an array of all zeroes. This is used so that
// default value of NULL is treated as all zeroes.
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber)
{
if (len == 0)
{
// no length means nothing to compare. Shouldn't even happen, since len is sizeof(some-integer-type).
return 0;
}

if (signedNumber)
{ // signed number comparison
if (len <= 4)
{ // only number with 32-bits or less is supported
int32_t accum1 = 0x0;
int32_t accum2 = 0x0;
int32_t all1s = -1;

for (uint16_t i = 0; i < len; i++)
{
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
accum1 |= j << (8 * (len - 1 - i));

uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
accum2 |= k << (8 * (len - 1 - i));
}

// sign extending, no need for 32-bits numbers
if (len < 4)
{
if ((accum1 & (1 << (8 * len - 1))) != 0)
{ // check sign
accum1 |= all1s - ((1 << (len * 8)) - 1);
}
if ((accum2 & (1 << (8 * len - 1))) != 0)
{ // check sign
accum2 |= all1s - ((1 << (len * 8)) - 1);
}
}

if (accum1 > accum2)
{
return 1;
}
if (accum1 < accum2)
{
return -1;
}

return 0;
}

// not supported
return 0;
}

// regular unsigned number comparison
for (uint16_t i = 0; i < len; i++)
{
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);

if (j > k)
{
return 1;
}
if (k > j)
{
return -1;
}
}
return 0;
}

// Zigbee spec says types between signed 8 bit and signed 64 bit
bool emberAfIsTypeSigned(EmberAfAttributeType dataType)
{
return (dataType >= ZCL_INT8S_ATTRIBUTE_TYPE && dataType <= ZCL_INT64S_ATTRIBUTE_TYPE);
}

bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId)
{
return (emberAfGetServerAttributeIndexByAttributeId(endpoint, clusterId, attributeId) != UINT16_MAX);
Expand Down

0 comments on commit 1586696

Please sign in to comment.