Skip to content

Commit

Permalink
Move emAfLoadAttributeDefaults to private.
Browse files Browse the repository at this point in the history
Reduce the API surface for ember attribute storage:
- remove unused ability to "load defaults without loading persistence"
- make the full loadDefautls + cluster private for now as it is not used

Looking to reduce the API surface of ember attribute storage to consider
making it pluggable/modular (to allow for better unit testing support).
  • Loading branch information
andy31415 committed Jan 15, 2024
1 parent dbbb79b commit bf60501
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
22 changes: 9 additions & 13 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ EmberAfDefinedEndpoint emAfEndpoints[MAX_ENDPOINT_COUNT];

uint8_t attributeData[ACTUAL_ATTRIBUTE_SIZE];

// ----- internal-only methods, not part of the external API -----

// Loads the attributes from built-in default and storage.
void emAfLoadAttributeDefaults(chip::EndpointId endpoint, chip::Optional<chip::ClusterId> = chip::NullOptional);

namespace {

#if (!defined(ATTRIBUTE_SINGLETONS_SIZE)) || (ATTRIBUTE_SINGLETONS_SIZE == 0)
Expand Down Expand Up @@ -1187,23 +1192,18 @@ uint8_t emberAfGetClustersFromEndpoint(EndpointId endpoint, ClusterId * clusterL

void emberAfInitializeAttributes(EndpointId endpoint)
{
emAfLoadAttributeDefaults(endpoint, false);
}

void emberAfResetAttributes(EndpointId endpoint)
{
emAfLoadAttributeDefaults(endpoint, true);
emAfLoadAttributeDefaults(endpoint);
}

void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional<ClusterId> clusterId)
void emAfLoadAttributeDefaults(EndpointId endpoint, Optional<ClusterId> clusterId)
{
uint16_t ep;
uint8_t clusterI;
uint16_t attr;
uint8_t * ptr;
uint16_t epCount = emberAfEndpointCount();
uint8_t attrData[ATTRIBUTE_LARGEST];
auto * attrStorage = ignoreStorage ? nullptr : app::GetAttributePersistenceProvider();
auto * attrStorage = app::GetAttributePersistenceProvider();
// Don't check whether we actually have an attrStorage here, because it's OK
// to have one if none of our attributes have NVM storage.

Expand Down Expand Up @@ -1245,7 +1245,7 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional
ptr = nullptr; // Will get set to the value to write, as needed.

// First check for a persisted value.
if (!ignoreStorage && am->IsAutomaticallyPersisted())
if (am->IsAutomaticallyPersisted())
{
VerifyOrDie(attrStorage && "Attribute persistence needs a persistence provider");
MutableByteSpan bytes(attrData);
Expand Down Expand Up @@ -1328,10 +1328,6 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional
ptr,
0, // buffer size - unused
true); // write?
if (ignoreStorage)
{
emAfSaveAttributeToStorageIfNeeded(ptr, de->endpoint, record.clusterId, am);
}
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,8 @@ const EmberAfCluster * emberAfFindClusterIncludingDisabledEndpoints(chip::Endpoi
// cast it.
EmberAfGenericClusterFunction emberAfFindClusterFunction(const EmberAfCluster * cluster, EmberAfClusterMask functionMask);

// Public APIs for loading attributes
// Loads attribute defaults and any non-volatile attributes stored
void emberAfInitializeAttributes(chip::EndpointId endpoint);
void emberAfResetAttributes(chip::EndpointId endpoint);

// Loads the attributes from built-in default and / or storage. If
// ignoreStorage is true, only defaults will be read, and the storage for
// non-volatile attributes will be overwritten with those defaults.
void emAfLoadAttributeDefaults(chip::EndpointId endpoint, bool ignoreStorage, chip::Optional<chip::ClusterId> = chip::NullOptional);

// After the RAM value has changed, code should call this function. If this
// attribute has been tagged as non-volatile, its value will be stored.
Expand Down

0 comments on commit bf60501

Please sign in to comment.