1 /** 2 * @file kv.h 3 * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited 4 */ 5 6 #ifndef AOS_KV_H 7 #define AOS_KV_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #include <kv_api.h> 14 15 /** @addtogroup aos_kv KV 16 * KV AOS API: Data storing service based on key-value paring. 17 * 18 * @{ 19 */ 20 21 /** 22 * Init the kv module. 23 * 24 * @retrun 0 on success, otherwise will be failed. 25 */ 26 int aos_kv_init(void); 27 28 /** 29 * Deinit the kv module. 30 * 31 * @retrun none 32 */ 33 void aos_kv_deinit(void); 34 35 /** 36 * Add a new KV pair. 37 * 38 * @param[in] key the key of the KV pair. 39 * @param[in] value the value of the KV pair. 40 * @param[in] len the length of the value. 41 * @param[in] sync save the KV pair to flash right now (should always be 1). 42 * 43 * @return 0 on success, negative error on failure. 44 */ 45 int aos_kv_set(const char *key, const void *value, int len, int sync); 46 47 /** 48 * Get the KV pair's value stored in buffer by its key. 49 * 50 * @note: the buffer_len should not be smaller than the real length of the value, 51 * otherwise buffer would be NULL. 52 * 53 * @param[in] key the key of the KV pair to get. 54 * @param[out] buffer the memory to store the value. 55 * @param[in,out] buffer_len in: the length of the input buffer. 56 * out: the real length of the value. 57 * 58 * @return 0 on success, negative error on failure. 59 */ 60 int aos_kv_get(const char *key, void *buffer, int *buffer_len); 61 62 /** 63 * Delete the KV pair by its key. 64 * 65 * @param[in] key the key of the KV pair to delete. 66 * 67 * @return 0 on success, negative error on failure. 68 */ 69 int aos_kv_del(const char *key); 70 71 /** 72 * Delete the KV pair by its prefix. 73 * 74 * @param[in] prefix the prefix of the kv pair which is need to delete. 75 * 76 * @return 0 on success, negative error on failure. 77 */ 78 int aos_kv_del_by_prefix(const char *prefix); 79 80 /** 81 * Add a new KV pair with encryption. 82 * 83 * @param[in] key the key of the KV pair. 84 * @param[in] value the value of the KV pair. 85 * @param[in] len the length of the value. 86 * @param[in] sync save the KV pair to flash right now (should always be 1). 87 * 88 * @return 0 on success, negative error on failure. 89 */ 90 int aos_kv_secure_set(const char *key, const void *value, int len, int sync); 91 92 /** 93 * Get the KV pair's value stored in buffer by its key with decrypt. 94 * 95 * @note: the buffer_len should be larger than the real length of the value, 96 * otherwise buffer would be NULL. 97 * 98 * @param[in] key the key of the KV pair to get. 99 * @param[out] buffer the memory to store the value. 100 * @param[in-out] buffer_len in: the length of the input buffer. 101 * out: the real length of the value. 102 * 103 * @return 0 on success, negative error on failure. 104 */ 105 int aos_kv_secure_get(const char *key, void *buffer, int *buffer_len); 106 107 /** @} */ 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif /* AOS_KV_H */ 114 115