Mbed OS Reference
Loading...
Searching...
No Matches
kvstore_global_api.h
1/*
2 * Copyright (c) 2018 ARM Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 * Licensed under the Apache License, Version 2.0 (the License); you may
5 * not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _KVSTORE_STATIC_API
17#define _KVSTORE_STATIC_API
18
19#include "stddef.h"
20#include "stdint.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/**
27 * \addtogroup kvstore
28 * @{
29 * \defgroup kvstore_global_api KVStore Global API
30 * @{
31 */
32
33typedef struct _opaque_kv_key_iterator *kv_iterator_t;
34
35#define KV_WRITE_ONCE_FLAG (1 << 0)
36#define KV_REQUIRE_CONFIDENTIALITY_FLAG (1 << 1)
37#define KV_RESERVED_FLAG (1 << 2)
38#define KV_REQUIRE_REPLAY_PROTECTION_FLAG (1 << 3)
39
40#define KV_MAX_KEY_LENGTH 128
41
42/**
43 * The key size
44 */
45typedef struct info {
46 /**
47 * The key size
48 */
49 size_t size;
50 /*
51 * The Key flags, possible flags combination:
52 * WRITE_ONCE_FLAG,
53 * REQUIRE_CONFIDENTIALITY_FLAG,
54 * REQUIRE_REPLAY_PROTECTION_FLAG
55 */
56 uint32_t flags;
58
59/**
60 * @brief Set one KVStore item, given key and value.
61 *
62 * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
63 * @param[in] buffer Value data buffer.
64 * @param[in] size Value data size.
65 * @param[in] create_flags Flag mask.
66 *
67 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
68 */
69int kv_set(const char *full_name_key, const void *buffer, size_t size, uint32_t create_flags);
70
71/**
72 * @brief Get one KVStore item by given key.
73 *
74 * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
75 * @param[in] buffer Value data buffer.
76 * @param[in] buffer_size Value data buffer size.
77 * @param[out] actual_size Actual read size.
78 *
79 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
80 */
81int kv_get(const char *full_name_key, void *buffer, size_t buffer_size, size_t *actual_size);
82
83/**
84 * @brief Get information of a given key.The returned info contains size and flags
85 *
86 * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
87 * @param[out] info Returned information structure.
88 *
89 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
90 */
91int kv_get_info(const char *full_name_key, kv_info_t *info);
92
93/**
94 * @brief Remove a KVStore item by given key.
95 *
96 * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
97 *
98 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
99 */
100int kv_remove(const char *full_name_key);
101
102/**
103 * @brief Start an iteration over KVStore keys to find all the entries
104 * that fit the full_prefix. There are no issues with any other operations while
105 * iterator is open.
106 *
107 * @param[out] it Allocating iterator handle.
108 * Do not forget to call kv_iterator_close
109 * to deallocate the memory.
110 * @param[in] full_prefix full_prefix Partition/Key prefix. If
111 * empty key or NULL pointer, all keys
112 * will match.
113 *
114 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
115 */
116int kv_iterator_open(kv_iterator_t *it, const char *full_prefix);
117
118/**
119 * @brief Get next key in iteration that matches the prefix. There are no issues with any
120 * other operations while iterator is open.
121 *
122 * @param[in] it Iterator handle.
123 * @param[in] key Buffer for returned key.
124 * @param[in] key_size Key buffer size.
125 *
126 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
127 */
128int kv_iterator_next(kv_iterator_t it, char *key, size_t key_size);
129
130/**
131 * @brief Close iteration and deallocate the iterator handle.
132 *
133 * @param[in] it Iterator handle.
134 *
135 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
136 */
137int kv_iterator_close(kv_iterator_t it);
138
139/**
140 * @brief Remove all keys and related data from a specified partition.
141 *
142 * @param[in] kvstore_path /Partition/
143 *
144 * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
145 */
146int kv_reset(const char *kvstore_path);
147
148/// @}
149/// @}
150
151#ifdef __cplusplus
152} // closing brace for extern "C"
153#endif
154#endif
int kv_get(const char *full_name_key, void *buffer, size_t buffer_size, size_t *actual_size)
Get one KVStore item by given key.
int kv_set(const char *full_name_key, const void *buffer, size_t size, uint32_t create_flags)
Set one KVStore item, given key and value.
int kv_iterator_close(kv_iterator_t it)
Close iteration and deallocate the iterator handle.
int kv_iterator_open(kv_iterator_t *it, const char *full_prefix)
Start an iteration over KVStore keys to find all the entries that fit the full_prefix.
struct info kv_info_t
The key size.
int kv_reset(const char *kvstore_path)
Remove all keys and related data from a specified partition.
int kv_get_info(const char *full_name_key, kv_info_t *info)
Get information of a given key.The returned info contains size and flags.
int kv_iterator_next(kv_iterator_t it, char *key, size_t key_size)
Get next key in iteration that matches the prefix.
int kv_remove(const char *full_name_key)
Remove a KVStore item by given key.
The key size.
size_t size
The key size.