3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2016-2017 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 * API function declarations for reading from and writing to persistent storage.
24 * Platforms will be responsible for implementing the read/write details.
32 #include <type_traits>
34 #include <core/CHIPConfig.h>
35 #include <core/CHIPError.h>
39 namespace PersistedStorage {
41 // Persistent storage key type is const char * in core config, however
42 // it is uint8_t/uint16_t on other platforms (EFR32 and nRF5 respectively)
43 typedef CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE Key;
49 static constexpr T value = 0; // handles numeric values
53 struct EmptyKey<const char *>
55 static constexpr const char * value = nullptr;
58 } // namespace internal
60 constexpr Key kEmptyKey = internal::EmptyKey<Key>::value;
64 * Read integer value of a key from persistent storage.
65 * Platform is responsible for validating aKey.
67 * @param[in] aKey A key to a persistently-stored value.
68 * @param[in,out] aValue A reference to an integer value.
70 * @return CHIP_ERROR_INVALID_ARGUMENT if aKey is NULL
71 * CHIP_ERROR_INVALID_STRING_LENGTH if aKey exceeds
72 * CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH
73 * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if aKey does not exist
74 * CHIP_NO_ERROR otherwise
76 CHIP_ERROR Read(Key aKey, uint32_t & aValue);
80 * Write the integer value of a key to persistent storage.
81 * Platform is responsible for validating aKey.
82 * If aKey does not exist, it will be created and assigned aValue.
83 * Otherwise any existing value of aKey will be replaced with aValue.
85 * @param[in] aKey A key to a persistently-stored value.
86 * @param[in] aValue The value.
88 * @return CHIP_ERROR_INVALID_ARGUMENT if aKey is NULL
89 * CHIP_ERROR_INVALID_STRING_LENGTH if aKey exceeds
90 * CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH
91 * CHIP_NO_ERROR otherwise
93 CHIP_ERROR Write(Key aKey, uint32_t aValue);
95 } // namespace PersistedStorage
96 } // namespace Platform