Skip to content

Commit eed2a1a

Browse files
authored
Remove unused public api (project-chip#32728)
* 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
1 parent 4f9e9ea commit eed2a1a

File tree

4 files changed

+134
-150
lines changed

4 files changed

+134
-150
lines changed

src/app/util/af.h

-33
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ chip::EndpointId emberAfParentEndpointFromIndex(uint16_t index);
136136
*/
137137
uint16_t emberAfIndexFromEndpoint(chip::EndpointId endpoint);
138138

139-
/**
140-
* Returns the index of a given endpoint; Does not ignore disabled endpoints.
141-
* Will return 0xFFFF if this is not a valid endpoint id.
142-
*/
143-
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(chip::EndpointId endpoint);
144-
145139
/**
146140
* @brief Returns the index of the given endpoint in the list of all endpoints that might support the given cluster server.
147141
*
@@ -189,35 +183,8 @@ uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::C
189183
*/
190184
uint16_t emberAfFixedEndpointCount(void);
191185

192-
/**
193-
*@brief Returns true if type is signed, false otherwise.
194-
*/
195-
bool emberAfIsTypeSigned(EmberAfAttributeType dataType);
196-
197186
/** @} END Attribute Storage */
198187

199-
/** @name Miscellaneous */
200-
// @{
201-
202-
/** @brief Returns true if a given ZCL data type is a list type. */
203-
bool emberAfIsThisDataTypeAListType(EmberAfAttributeType dataType);
204-
205-
/**
206-
* @brief Simple integer comparison function.
207-
* Compares two values of a known length as integers.
208-
* Signed integer comparison are supported for numbers with length of
209-
* 4 (bytes) or less.
210-
* The integers are in native endianness.
211-
*
212-
* @return -1, if val1 is smaller
213-
* 0, if they are the same or if two negative numbers with length
214-
* greater than 4 is being compared
215-
* 1, if val2 is smaller.
216-
*/
217-
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber);
218-
219-
/** @} END Miscellaneous */
220-
221188
/** @} END addtogroup */
222189

223190
/**

src/app/util/attribute-storage.cpp

+30-30
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,36 @@ void UnregisterMatchingAttributeAccessInterfaces(F shouldUnregister)
175175
}
176176
}
177177

178+
bool emberAfIsThisDataTypeAListType(EmberAfAttributeType dataType)
179+
{
180+
return dataType == ZCL_ARRAY_ATTRIBUTE_TYPE;
181+
}
182+
183+
uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEndpoints)
184+
{
185+
if (endpoint == kInvalidEndpointId)
186+
{
187+
return kEmberInvalidEndpointIndex;
188+
}
189+
190+
uint16_t epi;
191+
for (epi = 0; epi < emberAfEndpointCount(); epi++)
192+
{
193+
if (emAfEndpoints[epi].endpoint == endpoint &&
194+
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask.Has(EmberAfEndpointOptions::isEnabled)))
195+
{
196+
return epi;
197+
}
198+
}
199+
return kEmberInvalidEndpointIndex;
200+
}
201+
202+
// Returns the index of a given endpoint. Considers disabled endpoints.
203+
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(EndpointId endpoint)
204+
{
205+
return findIndexFromEndpoint(endpoint, false /* ignoreDisabledEndpoints */);
206+
}
207+
178208
} // anonymous namespace
179209

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

357-
bool emberAfIsThisDataTypeAListType(EmberAfAttributeType dataType)
358-
{
359-
return dataType == ZCL_ARRAY_ATTRIBUTE_TYPE;
360-
}
361-
362387
// This function is used to call the per-cluster attribute changed callback
363388
void emAfClusterAttributeChangedCallback(const app::ConcreteAttributePath & attributePath)
364389
{
@@ -845,25 +870,6 @@ const EmberAfCluster * emberAfFindClusterIncludingDisabledEndpoints(EndpointId e
845870
return nullptr;
846871
}
847872

848-
static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEndpoints)
849-
{
850-
if (endpoint == kInvalidEndpointId)
851-
{
852-
return kEmberInvalidEndpointIndex;
853-
}
854-
855-
uint16_t epi;
856-
for (epi = 0; epi < emberAfEndpointCount(); epi++)
857-
{
858-
if (emAfEndpoints[epi].endpoint == endpoint &&
859-
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask.Has(EmberAfEndpointOptions::isEnabled)))
860-
{
861-
return epi;
862-
}
863-
}
864-
return kEmberInvalidEndpointIndex;
865-
}
866-
867873
uint16_t emberAfGetClusterServerEndpointIndex(EndpointId endpoint, ClusterId cluster, uint16_t fixedClusterServerEndpointCount)
868874
{
869875
VerifyOrDie(fixedClusterServerEndpointCount <= FIXED_ENDPOINT_COUNT);
@@ -980,12 +986,6 @@ uint16_t emberAfIndexFromEndpoint(EndpointId endpoint)
980986
return findIndexFromEndpoint(endpoint, true /* ignoreDisabledEndpoints */);
981987
}
982988

983-
// Returns the index of a given endpoint. Considers disabled endpoints.
984-
uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(EndpointId endpoint)
985-
{
986-
return findIndexFromEndpoint(endpoint, false /* ignoreDisabledEndpoints */);
987-
}
988-
989989
EndpointId emberAfEndpointFromIndex(uint16_t index)
990990
{
991991
return emAfEndpoints[index].endpoint;

src/app/util/attribute-table.cpp

+104
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,114 @@
2525
#include <app/reporting/reporting.h>
2626
#include <protocols/interaction_model/Constants.h>
2727

28+
#if (CHIP_CONFIG_BIG_ENDIAN_TARGET)
29+
#define EM_BIG_ENDIAN true
30+
#else
31+
#define EM_BIG_ENDIAN false
32+
#endif
33+
2834
using chip::Protocols::InteractionModel::Status;
2935

3036
using namespace chip;
3137

38+
namespace {
39+
40+
// Zigbee spec says types between signed 8 bit and signed 64 bit
41+
bool emberAfIsTypeSigned(EmberAfAttributeType dataType)
42+
{
43+
return (dataType >= ZCL_INT8S_ATTRIBUTE_TYPE && dataType <= ZCL_INT64S_ATTRIBUTE_TYPE);
44+
}
45+
46+
/**
47+
* @brief Simple integer comparison function.
48+
* Compares two values of a known length as integers.
49+
* Signed integer comparison are supported for numbers with length of
50+
* 4 (bytes) or less.
51+
* The integers are in native endianness.
52+
*
53+
* @return -1, if val1 is smaller
54+
* 0, if they are the same or if two negative numbers with length
55+
* greater than 4 is being compared
56+
* 1, if val2 is smaller.
57+
*
58+
* You can pass in val1 as NULL, which will assume that it is
59+
* pointing to an array of all zeroes. This is used so that
60+
* default value of NULL is treated as all zeroes.
61+
*/
62+
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber)
63+
{
64+
if (len == 0)
65+
{
66+
// no length means nothing to compare. Shouldn't even happen, since len is sizeof(some-integer-type).
67+
return 0;
68+
}
69+
70+
if (signedNumber)
71+
{ // signed number comparison
72+
if (len <= 4)
73+
{ // only number with 32-bits or less is supported
74+
int32_t accum1 = 0x0;
75+
int32_t accum2 = 0x0;
76+
int32_t all1s = -1;
77+
78+
for (uint16_t i = 0; i < len; i++)
79+
{
80+
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
81+
accum1 |= j << (8 * (len - 1 - i));
82+
83+
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
84+
accum2 |= k << (8 * (len - 1 - i));
85+
}
86+
87+
// sign extending, no need for 32-bits numbers
88+
if (len < 4)
89+
{
90+
if ((accum1 & (1 << (8 * len - 1))) != 0)
91+
{ // check sign
92+
accum1 |= all1s - ((1 << (len * 8)) - 1);
93+
}
94+
if ((accum2 & (1 << (8 * len - 1))) != 0)
95+
{ // check sign
96+
accum2 |= all1s - ((1 << (len * 8)) - 1);
97+
}
98+
}
99+
100+
if (accum1 > accum2)
101+
{
102+
return 1;
103+
}
104+
if (accum1 < accum2)
105+
{
106+
return -1;
107+
}
108+
109+
return 0;
110+
}
111+
112+
// not supported
113+
return 0;
114+
}
115+
116+
// regular unsigned number comparison
117+
for (uint16_t i = 0; i < len; i++)
118+
{
119+
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
120+
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
121+
122+
if (j > k)
123+
{
124+
return 1;
125+
}
126+
if (k > j)
127+
{
128+
return -1;
129+
}
130+
}
131+
return 0;
132+
}
133+
134+
} // namespace
135+
32136
Status emAfWriteAttributeExternal(EndpointId endpoint, ClusterId cluster, AttributeId attributeID, uint8_t * dataPtr,
33137
EmberAfAttributeType dataType)
34138
{

src/app/util/util.cpp

-87
Original file line numberDiff line numberDiff line change
@@ -140,93 +140,6 @@ void MatterPowerTopologyPluginServerInitCallback() {}
140140
void MatterElectricalEnergyMeasurementPluginServerInitCallback() {}
141141
void MatterElectricalPowerMeasurementPluginServerInitCallback() {}
142142

143-
#if (CHIP_CONFIG_BIG_ENDIAN_TARGET)
144-
#define EM_BIG_ENDIAN true
145-
#else
146-
#define EM_BIG_ENDIAN false
147-
#endif
148-
149-
// You can pass in val1 as NULL, which will assume that it is
150-
// pointing to an array of all zeroes. This is used so that
151-
// default value of NULL is treated as all zeroes.
152-
int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t len, bool signedNumber)
153-
{
154-
if (len == 0)
155-
{
156-
// no length means nothing to compare. Shouldn't even happen, since len is sizeof(some-integer-type).
157-
return 0;
158-
}
159-
160-
if (signedNumber)
161-
{ // signed number comparison
162-
if (len <= 4)
163-
{ // only number with 32-bits or less is supported
164-
int32_t accum1 = 0x0;
165-
int32_t accum2 = 0x0;
166-
int32_t all1s = -1;
167-
168-
for (uint16_t i = 0; i < len; i++)
169-
{
170-
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
171-
accum1 |= j << (8 * (len - 1 - i));
172-
173-
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
174-
accum2 |= k << (8 * (len - 1 - i));
175-
}
176-
177-
// sign extending, no need for 32-bits numbers
178-
if (len < 4)
179-
{
180-
if ((accum1 & (1 << (8 * len - 1))) != 0)
181-
{ // check sign
182-
accum1 |= all1s - ((1 << (len * 8)) - 1);
183-
}
184-
if ((accum2 & (1 << (8 * len - 1))) != 0)
185-
{ // check sign
186-
accum2 |= all1s - ((1 << (len * 8)) - 1);
187-
}
188-
}
189-
190-
if (accum1 > accum2)
191-
{
192-
return 1;
193-
}
194-
if (accum1 < accum2)
195-
{
196-
return -1;
197-
}
198-
199-
return 0;
200-
}
201-
202-
// not supported
203-
return 0;
204-
}
205-
206-
// regular unsigned number comparison
207-
for (uint16_t i = 0; i < len; i++)
208-
{
209-
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
210-
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
211-
212-
if (j > k)
213-
{
214-
return 1;
215-
}
216-
if (k > j)
217-
{
218-
return -1;
219-
}
220-
}
221-
return 0;
222-
}
223-
224-
// Zigbee spec says types between signed 8 bit and signed 64 bit
225-
bool emberAfIsTypeSigned(EmberAfAttributeType dataType)
226-
{
227-
return (dataType >= ZCL_INT8S_ATTRIBUTE_TYPE && dataType <= ZCL_INT64S_ATTRIBUTE_TYPE);
228-
}
229-
230143
bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId)
231144
{
232145
return (emberAfGetServerAttributeIndexByAttributeId(endpoint, clusterId, attributeId) != UINT16_MAX);

0 commit comments

Comments
 (0)