-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial cluster data version support
- Loading branch information
1 parent
6d8589f
commit 20dad18
Showing
26 changed files
with
366 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
#include <app/ConcreteClusterPath.h> | ||
#include <app/util/basic-types.h> | ||
#include <lib/support/CodeUtils.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
/** | ||
* Interface for persisting cluster data version value. | ||
*/ | ||
|
||
class ClusterDataVersionPersistenceProvider | ||
{ | ||
public: | ||
virtual ~ClusterDataVersionPersistenceProvider() = default; | ||
ClusterDataVersionPersistenceProvider() = default; | ||
|
||
/** | ||
* Write a version value from the attribute store to non-volatile memory. | ||
* | ||
* @param [in] aPath the cluster path for the version being written. | ||
* @param [in] aValue the data to write. Integer is | ||
* represented in native endianness. The length is | ||
* stored as little-endian. | ||
*/ | ||
virtual CHIP_ERROR WriteValue(const ConcreteClusterPath & aPath, const chip::DataVersion & aValue) = 0; | ||
|
||
/** | ||
* Read an attribute value from non-volatile memory. | ||
* | ||
* @param [in] aPath the cluster path for the version being persisted. | ||
* @param [inout] aValue where to place the data. | ||
* | ||
* The data is expected to be in native endianness for integer. | ||
*/ | ||
virtual CHIP_ERROR ReadValue(const ConcreteClusterPath & aPath, chip::DataVersion & aValue) = 0; | ||
}; | ||
|
||
/** | ||
* Instance getter for the global ClusterDataVersionPersistenceProvider. | ||
* | ||
* Callers have to externally synchronize usage of this function. | ||
* | ||
* @return The global ClusterDataVersionPersistenceProvider. This must never be null. | ||
*/ | ||
ClusterDataVersionPersistenceProvider * GetClusterDataVersionPersistenceProvider(); | ||
|
||
/** | ||
* Instance setter for the global ClusterDataVersionPersistenceProvider. | ||
* | ||
* Callers have to externally synchronize usage of this function. | ||
* | ||
* If the `provider` is nullptr, the value is not changed. | ||
* | ||
* @param[in] provider the ClusterDataVersionPersistenceProvider implementation to use. | ||
*/ | ||
void SetClusterDataVersionPersistenceProvider(ClusterDataVersionPersistenceProvider * aProvider); | ||
|
||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/util/basic-types.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
struct ConcreteClusterPath | ||
{ | ||
ConcreteClusterPath(EndpointId aEndpointId, ClusterId aClusterId) : mEndpointId(aEndpointId), mClusterId(aClusterId) {} | ||
|
||
ConcreteClusterPath() {} | ||
|
||
EndpointId mEndpointId = 0; | ||
ClusterId mClusterId = 0; | ||
}; | ||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <app/DefaultClusterDataVersionPersistenceProvider.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/DefaultStorageKeyAllocator.h> | ||
#include <lib/support/SafeInt.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
CHIP_ERROR DefaultClusterDataVersionPersistenceProvider::WriteValue(const ConcreteClusterPath & aPath, | ||
const chip::DataVersion & aValue) | ||
{ | ||
// TODO: we may want to have a small cache for values that change a lot, so | ||
// we only write them once a bunch of changes happen or on timer or | ||
// shutdown. | ||
DefaultStorageKeyAllocator key; | ||
return mStorage.SyncSetKeyValue(key.ClusterValue(aPath), &aValue, sizeof(aValue)); | ||
} | ||
|
||
CHIP_ERROR DefaultClusterDataVersionPersistenceProvider::ReadValue(const ConcreteClusterPath & aPath, chip::DataVersion & aValue) | ||
{ | ||
DefaultStorageKeyAllocator key; | ||
uint16_t size = sizeof(aValue); | ||
ReturnErrorOnFailure(mStorage.SyncGetKeyValue(key.ClusterValue(aPath), &aValue, size)); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
namespace { | ||
|
||
ClusterDataVersionPersistenceProvider * gDataVersionSaver = nullptr; | ||
|
||
} // anonymous namespace | ||
|
||
ClusterDataVersionPersistenceProvider * GetClusterDataVersionPersistenceProvider() | ||
{ | ||
return gDataVersionSaver; | ||
} | ||
|
||
void SetClusterDataVersionPersistenceProvider(ClusterDataVersionPersistenceProvider * aProvider) | ||
{ | ||
if (aProvider != nullptr) | ||
{ | ||
gDataVersionSaver = aProvider; | ||
} | ||
} | ||
|
||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <app/ClusterDataVersionPersistenceProvider.h> | ||
#include <lib/core/CHIPPersistentStorageDelegate.h> | ||
#include <lib/support/DefaultStorageKeyAllocator.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
/** | ||
* Default implementation of ClusterDataVersionPersistenceProvider. This uses | ||
* PersistentStorageDelegate to store the version. | ||
* | ||
* NOTE: SetAttributePersistenceProvider must still be called with an instance | ||
* of this class, since it can't be constructed automatically without knowing | ||
* what PersistentStorageDelegate is to be used. | ||
*/ | ||
class DefaultClusterDataVersionPersistenceProvider : public ClusterDataVersionPersistenceProvider | ||
{ | ||
public: | ||
// aStorage must outlive this object. | ||
DefaultClusterDataVersionPersistenceProvider(PersistentStorageDelegate & aStorage) : mStorage(aStorage) {} | ||
|
||
// AttributePersistenceProvider implementation. | ||
CHIP_ERROR WriteValue(const ConcreteClusterPath & aPath, const chip::DataVersion & aValue) override; | ||
CHIP_ERROR ReadValue(const ConcreteClusterPath & aPath, chip::DataVersion & aValue) override; | ||
|
||
private: | ||
PersistentStorageDelegate & mStorage; | ||
}; | ||
|
||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.