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 <cstdint>
26 #include <string>
27 
28 #include "device_iot_conf_defs.h"
29 #include "internal_include/bt_target.h"
30 
31 static const char DEVICE_IOT_CONFIG_MODULE[] = "device_iot_config_module";
32 
33 bool device_iot_config_get_int(const std::string& section, const std::string& key, int& value);
34 bool device_iot_config_set_int(const std::string& section, const std::string& key, int value);
35 bool device_iot_config_int_add_one(const std::string& section, const std::string& key);
36 bool device_iot_config_get_hex(const std::string& section, const std::string& key, int& value);
37 bool device_iot_config_set_hex(const std::string& section, const std::string& key, int value,
38                                int byte_num);
39 bool device_iot_config_set_hex_if_greater(const std::string& section, const std::string& key,
40                                           int value, int byte_num);
41 bool device_iot_config_get_str(const std::string& section, const std::string& key, char* value,
42                                int* size_bytes);
43 bool device_iot_config_set_str(const std::string& section, const std::string& key,
44                                const std::string& value);
45 bool device_iot_config_get_bin(const std::string& section, const std::string& key, uint8_t* value,
46                                size_t* length);
47 bool device_iot_config_set_bin(const std::string& section, const std::string& key,
48                                const uint8_t* value, size_t length);
49 size_t device_iot_config_get_bin_length(const std::string& section, const std::string& key);
50 
51 #define DEVICE_IOT_CONFIG_ADDR(method, addr, ...) \
52   device_iot_config_##method((addr).ToString(), ##__VA_ARGS__)
53 
54 #define DEVICE_IOT_CONFIG_ADDR_GET_INT(addr, ...) \
55   DEVICE_IOT_CONFIG_ADDR(get_int, addr, ##__VA_ARGS__)
56 
57 #define DEVICE_IOT_CONFIG_ADDR_SET_INT(addr, ...) \
58   DEVICE_IOT_CONFIG_ADDR(set_int, addr, ##__VA_ARGS__)
59 
60 #define DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(addr, ...) \
61   DEVICE_IOT_CONFIG_ADDR(int_add_one, addr, ##__VA_ARGS__)
62 
63 #define DEVICE_IOT_CONFIG_ADDR_GET_HEX(addr, ...) \
64   DEVICE_IOT_CONFIG_ADDR(get_hex, addr, ##__VA_ARGS__)
65 
66 #define DEVICE_IOT_CONFIG_ADDR_SET_HEX(addr, ...) \
67   DEVICE_IOT_CONFIG_ADDR(set_hex, addr, ##__VA_ARGS__)
68 
69 #define DEVICE_IOT_CONFIG_ADDR_SET_HEX_IF_GREATER(addr, ...) \
70   DEVICE_IOT_CONFIG_ADDR(set_hex_if_greater, addr, ##__VA_ARGS__)
71 
72 #define DEVICE_IOT_CONFIG_ADDR_GET_STR(addr, ...) \
73   DEVICE_IOT_CONFIG_ADDR(set_gtr, addr, ##__VA_ARGS__)
74 
75 #define DEVICE_IOT_CONFIG_ADDR_SET_STR(addr, ...) \
76   DEVICE_IOT_CONFIG_ADDR(set_str, addr, ##__VA_ARGS__)
77 
78 #define DEVICE_IOT_CONFIG_ADDR_GET_BIN(addr, ...) \
79   DEVICE_IOT_CONFIG_ADDR(get_bin, addr, ##__VA_ARGS__)
80 
81 #define DEVICE_IOT_CONFIG_ADDR_SET_BIN(addr, ...) \
82   DEVICE_IOT_CONFIG_ADDR(set_bin, addr, ##__VA_ARGS__)
83 
84 #define DEVICE_IOT_CONFIG_ADDR_GET_BIN_LENGTH(addr, ...) \
85   DEVICE_IOT_CONFIG_ADDR(get_bin, addr, ##__VA_ARGS__)
86 
87 bool device_iot_config_has_section(const std::string& section);
88 bool device_iot_config_exist(const std::string& section, const std::string& key);
89 bool device_iot_config_remove(const std::string& section, const std::string& key);
90 
91 void device_iot_config_flush(void);
92 bool device_iot_config_clear(void);
93 
94 void device_debug_iot_config_dump(int fd);
95