3 * Copyright (c) 2020 Project CHIP Authors
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.
21 #include <core/CHIPCore.h>
22 #include <support/DLLUtil.h>
25 namespace Controller {
27 class DLL_EXPORT PersistentStorageResultDelegate
30 enum class Operation : uint8_t
37 virtual ~PersistentStorageResultDelegate() {}
41 * Called when a value is returned from the storage.
42 * This is useful for GetKeyValue() API call.
44 * @param[in] key Key for which the value is being returned
45 * @param[in] value Value or nullptr if not found.
47 virtual void OnValue(const char * key, const char * value) = 0;
51 * Called on completion of an operation in PersistentStorageDelegate API
53 * @param[in] key Key for which the status is being returned
54 * @param[in] op Operation that was being performed on the key
55 * @param[in] result CHIP_NO_ERROR or corresponding error code
57 virtual void OnStatus(const char * key, Operation op, CHIP_ERROR result) = 0;
60 class DLL_EXPORT PersistentStorageDelegate
63 virtual ~PersistentStorageDelegate() {}
67 * Set the callback object with methods that are called on completion
70 * @param[in] delegate The callback object
72 virtual void SetDelegate(PersistentStorageResultDelegate * delegate) = 0;
76 * Lookup the key and call delegate object with it's stringified value
78 * @param[in] key Key to lookup
80 virtual void GetKeyValue(const char * key) = 0;
84 * This is a synchronous Get API, where the value is returned via the output
85 * buffer. This API should be used sparingly, since it may block for
88 * @param[in] key Key to lookup
89 * @param[out] value Value for the key
90 * @param[in, out] size Input value buffer size, output length of value.
91 * The output length could be larger than input value. In
92 * such cases, the user should allocate the buffer large
93 * enough (>= output length), and call the API again.
95 virtual CHIP_ERROR GetKeyValue(const char * key, char * value, uint16_t & size) { return CHIP_ERROR_NOT_IMPLEMENTED; }
99 * Set the value for the key
101 * @param[in] key Key to be set
102 * @param[in] value Value to be set
104 virtual void SetKeyValue(const char * key, const char * value) = 0;
108 * Deletes the value for the key
110 * @param[in] key Key to be deleted
112 virtual void DeleteKeyValue(const char * key) = 0;
115 } // namespace Controller