10e98b08fSopenharmony_ci/* 20e98b08fSopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd. 30e98b08fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40e98b08fSopenharmony_ci * you may not use this file except in compliance with the License. 50e98b08fSopenharmony_ci * You may obtain a copy of the License at 60e98b08fSopenharmony_ci * 70e98b08fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80e98b08fSopenharmony_ci * 90e98b08fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100e98b08fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110e98b08fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120e98b08fSopenharmony_ci * See the License for the specific language governing permissions and 130e98b08fSopenharmony_ci * limitations under the License. 140e98b08fSopenharmony_ci */ 150e98b08fSopenharmony_ci 160e98b08fSopenharmony_ci/** 170e98b08fSopenharmony_ci * @addtogroup kv_store 180e98b08fSopenharmony_ci * @{ 190e98b08fSopenharmony_ci * 200e98b08fSopenharmony_ci * @brief Provides functions for obtaining, setting, and deleting a key-value pair. 210e98b08fSopenharmony_ci * 220e98b08fSopenharmony_ci * 230e98b08fSopenharmony_ci * Key-value pairs can be permanently stored in the file system. \n 240e98b08fSopenharmony_ci * If {@link FEATURE_KV_CACHE} is enabled, key-value pairs can be stored in the cache. \n 250e98b08fSopenharmony_ci * For details about cache specifications, see {@link MAX_CACHE_SIZE}. \n 260e98b08fSopenharmony_ci * For details about the number of key-value pairs that can be stored in an application, see {@link MAX_KV_SUM}. \n 270e98b08fSopenharmony_ci * 280e98b08fSopenharmony_ci * @since 1.0 290e98b08fSopenharmony_ci * @version 1.0 300e98b08fSopenharmony_ci */ 310e98b08fSopenharmony_ci 320e98b08fSopenharmony_ci/** 330e98b08fSopenharmony_ci * @file kv_store.h 340e98b08fSopenharmony_ci * 350e98b08fSopenharmony_ci * @brief Provides functions for obtaining, setting, and deleting a key-value pair. 360e98b08fSopenharmony_ci * 370e98b08fSopenharmony_ci * @since 1.0 380e98b08fSopenharmony_ci * @version 1.0 390e98b08fSopenharmony_ci */ 400e98b08fSopenharmony_ci 410e98b08fSopenharmony_ci#ifndef KV_STORE_API_H 420e98b08fSopenharmony_ci#define KV_STORE_API_H 430e98b08fSopenharmony_ci 440e98b08fSopenharmony_ci#include "utils_config.h" 450e98b08fSopenharmony_ci 460e98b08fSopenharmony_ci#ifdef __cplusplus 470e98b08fSopenharmony_ci#if __cplusplus 480e98b08fSopenharmony_ciextern "C" { 490e98b08fSopenharmony_ci#endif 500e98b08fSopenharmony_ci#endif /* __cplusplus */ 510e98b08fSopenharmony_ci 520e98b08fSopenharmony_ci/** 530e98b08fSopenharmony_ci * @brief Obtains the value matching a specified key from the file system or cache. 540e98b08fSopenharmony_ci * 550e98b08fSopenharmony_ci * @param key Indicates the key to be indexed. It allows only lowercase letters, digits, underscores (_), and dots (.). 560e98b08fSopenharmony_ci * Its length cannot exceed 32 bytes (including the end-of-text character in the string). 570e98b08fSopenharmony_ci * @param value Indicates the buffer for storing the value that matches the key. This is an output parameter. 580e98b08fSopenharmony_ci * @param len Indicates the size of the value space in the buffer. 590e98b08fSopenharmony_ci * @return Returns the length of the value if the operation is successful; 600e98b08fSopenharmony_ci * returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios; 610e98b08fSopenharmony_ci * returns <b>0</b> if the value is obtained from the cache. 620e98b08fSopenharmony_ci * @since 1.0. 630e98b08fSopenharmony_ci * @version 1.0. 640e98b08fSopenharmony_ci */ 650e98b08fSopenharmony_ciint UtilsGetValue(const char* key, char* value, unsigned int len); 660e98b08fSopenharmony_ci 670e98b08fSopenharmony_ci/** 680e98b08fSopenharmony_ci * @brief Adds or updates the value matching a specified key in the file system or cache. 690e98b08fSopenharmony_ci * 700e98b08fSopenharmony_ci * @param key Indicates the key whose value is to be added or updated. 710e98b08fSopenharmony_ci * It allows only lowercase letters, digits, underscores (_), and dots (.). 720e98b08fSopenharmony_ci * Its length cannot exceed 32 bytes (including the end-of-text character in the string). 730e98b08fSopenharmony_ci * @param value Indicates the value to be added or updated. 740e98b08fSopenharmony_ci * Its length cannot exceed 128 bytes (including the end-of-text character in the string). 750e98b08fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns <b>-9</b> if a parameter is incorrect; 760e98b08fSopenharmony_ci * returns <b>-1</b> in other scenarios. 770e98b08fSopenharmony_ci * @since 1.0. 780e98b08fSopenharmony_ci * @version 1.0. 790e98b08fSopenharmony_ci */ 800e98b08fSopenharmony_ciint UtilsSetValue(const char* key, const char* value); 810e98b08fSopenharmony_ci 820e98b08fSopenharmony_ci/** 830e98b08fSopenharmony_ci * @brief Deletes the value matching a specified key from the file system or cache. 840e98b08fSopenharmony_ci * 850e98b08fSopenharmony_ci * @param key Indicates the key whose value is to be deleted. 860e98b08fSopenharmony_ci * It allows only lowercase letters, digits, underscores (_), and dots (.). 870e98b08fSopenharmony_ci * Its length cannot exceed 32 bytes (including the end-of-text character in the string). 880e98b08fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns <b>-9</b> if a parameter is incorrect; 890e98b08fSopenharmony_ci * returns <b>-1</b> in other scenarios. 900e98b08fSopenharmony_ci * @since 1.0. 910e98b08fSopenharmony_ci * @version 1.0. 920e98b08fSopenharmony_ci */ 930e98b08fSopenharmony_ciint UtilsDeleteValue(const char* key); 940e98b08fSopenharmony_ci 950e98b08fSopenharmony_ci#ifdef FEATURE_KV_CACHE 960e98b08fSopenharmony_ci 970e98b08fSopenharmony_ci/** 980e98b08fSopenharmony_ci * @brief Clears all key-value pairs from the cache. 990e98b08fSopenharmony_ci * 1000e98b08fSopenharmony_ci * @attention This function is available only if {@link FEATURE_KV_CACHE} is enabled. 1010e98b08fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 1020e98b08fSopenharmony_ci * @since 1.0. 1030e98b08fSopenharmony_ci * @version 1.0. 1040e98b08fSopenharmony_ci */ 1050e98b08fSopenharmony_ciint ClearKVCache(void); 1060e98b08fSopenharmony_ci#endif 1070e98b08fSopenharmony_ci 1080e98b08fSopenharmony_ci#ifdef __cplusplus 1090e98b08fSopenharmony_ci#if __cplusplus 1100e98b08fSopenharmony_ci} 1110e98b08fSopenharmony_ci#endif 1120e98b08fSopenharmony_ci#endif /* __cplusplus */ 1130e98b08fSopenharmony_ci 1140e98b08fSopenharmony_ci#endif // KV_STORE_API_H 1150e98b08fSopenharmony_ci/** @} */