1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 Google, Inc.
4  *  Copyright (C) 2018 The Linux Foundation
5  *
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:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  ******************************************************************************/
19 
20 #pragma once
21 
22 #include <stdbool.h>
23 #include <stddef.h>
24 
25 #include <string>
26 
27 #include "device_iot_conf_defs.h"
28 #include "internal_include/bt_target.h"
29 
30 static const char DEVICE_IOT_CONFIG_MODULE[] = "device_iot_config_module";
31 
32 bool device_iot_config_get_int(const std::string& section,
33                                const std::string& key, int& value);
34 bool device_iot_config_set_int(const std::string& section,
35                                const std::string& key, int value);
36 bool device_iot_config_int_add_one(const std::string& section,
37                                    const std::string& key);
38 bool device_iot_config_get_hex(const std::string& section,
39                                const std::string& key, int& value);
40 bool device_iot_config_set_hex(const std::string& section,
41                                const std::string& key, int value, int byte_num);
42 bool device_iot_config_set_hex_if_greater(const std::string& section,
43                                           const std::string& key, int value,
44                                           int byte_num);
45 bool device_iot_config_get_str(const std::string& section,
46                                const std::string& key, char* value,
47                                int* size_bytes);
48 bool device_iot_config_set_str(const std::string& section,
49                                const std::string& key,
50                                const std::string& value);
51 bool device_iot_config_get_bin(const std::string& section,
52                                const std::string& key, uint8_t* value,
53                                size_t* length);
54 bool device_iot_config_set_bin(const std::string& section,
55                                const std::string& key, const uint8_t* value,
56                                size_t length);
57 size_t device_iot_config_get_bin_length(const std::string& section,
58                                         const std::string& key);
59 
60 #define DEVICE_IOT_CONFIG_ADDR(method, addr, ...) \
61   device_iot_config_##method((addr).ToString(), ##__VA_ARGS__)
62 
63 #define DEVICE_IOT_CONFIG_ADDR_GET_INT(addr, ...) \
64   DEVICE_IOT_CONFIG_ADDR(get_int, addr, ##__VA_ARGS__)
65 
66 #define DEVICE_IOT_CONFIG_ADDR_SET_INT(addr, ...) \
67   DEVICE_IOT_CONFIG_ADDR(set_int, addr, ##__VA_ARGS__)
68 
69 #define DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(addr, ...) \
70   DEVICE_IOT_CONFIG_ADDR(int_add_one, addr, ##__VA_ARGS__)
71 
72 #define DEVICE_IOT_CONFIG_ADDR_GET_HEX(addr, ...) \
73   DEVICE_IOT_CONFIG_ADDR(get_hex, addr, ##__VA_ARGS__)
74 
75 #define DEVICE_IOT_CONFIG_ADDR_SET_HEX(addr, ...) \
76   DEVICE_IOT_CONFIG_ADDR(set_hex, addr, ##__VA_ARGS__)
77 
78 #define DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(addr, ...) \
79   DEVICE_IOT_CONFIG_ADDR(set_hex_if_greater, addr, ##__VA_ARGS__)
80 
81 #define DEVICE_IOT_CONFIG_ADDR_GET_STR(addr, ...) \
82   DEVICE_IOT_CONFIG_ADDR(set_gtr, addr, ##__VA_ARGS__)
83 
84 #define DEVICE_IOT_CONFIG_ADDR_SET_STR(addr, ...) \
85   DEVICE_IOT_CONFIG_ADDR(set_str, addr, ##__VA_ARGS__)
86 
87 #define DEVICE_IOT_CONFIG_ADDR_GET_BIN(addr, ...) \
88   DEVICE_IOT_CONFIG_ADDR(get_bin, addr, ##__VA_ARGS__)
89 
90 #define DEVICE_IOT_CONFIG_ADDR_SET_BIN(addr, ...) \
91   DEVICE_IOT_CONFIG_ADDR(set_bin, addr, ##__VA_ARGS__)
92 
93 #define DEVICE_IOT_CONFIG_ADDR_GET_BIN_LENGTH(addr, ...) \
94   DEVICE_IOT_CONFIG_ADDR(get_bin, addr, ##__VA_ARGS__)
95 
96 bool device_iot_config_has_section(const std::string& section);
97 bool device_iot_config_exist(const std::string& section,
98                              const std::string& key);
99 bool device_iot_config_remove(const std::string& section,
100                               const std::string& key);
101 
102 void device_iot_config_flush(void);
103 bool device_iot_config_clear(void);
104 
105 void device_debug_iot_config_dump(int fd);
106