]> pilppa.org Git - lib1wire.git/blob - src/DeviceConfig.hh
Initial support for reading and writing device specific config data.
[lib1wire.git] / src / DeviceConfig.hh
1 /*
2  * DeviceConfig.hh
3  *
4  *  Created on: Dec 9, 2010
5  *      Author: lamikr
6  */
7
8 #ifndef DEVICECONFIG_HH_
9 #define DEVICECONFIG_HH_
10
11 #include <string>
12
13 extern "C" {
14 #include <uci.h>
15 #include <plp/config.h>
16 }
17
18 #define DEVICE_CONFIG__FILE_NAME                "dev_cfg.txt"
19 #define DEVICE_CONFIG__SECTION_TYPE             "device"
20 #define DEVICE_CONFIG__SECTION_NAME             "base_data"
21 #define DEVICE_CONFIG_VALUE_KEY__TYPE           "type"
22 #define DEVICE_CONFIG_VALUE_KEY__NAME           "name"
23
24 namespace w1 {
25         enum enum_summary_calculation {SUM, DELTA, MEAN, MAX, MIN};
26
27         struct ConfigHandle {
28                 public:
29                         ConfigHandle(uci_context *ctx_param, uci_package *pkg_param);
30                         ~ConfigHandle();
31                         struct uci_context      *ctx;
32                         struct uci_package      *pkg;
33         };
34
35         class DeviceConfig {
36                 public:
37                         DeviceConfig(std::string device_id_param);
38                         virtual ~DeviceConfig();
39                         static std::string get_base_dir_name();
40                         static void set_base_dir_name(std::string store_param);
41                         std::string get_cfg_value(std::string key);
42                         void set_cfg_value(std::string key, std::string value);
43                         enum_summary_calculation get_summary_calculation_type();
44                 private:
45                         static std::string      store_base_dir;
46                         std::string             device_id;
47                         std::string             device_type;
48                         ConfigHandle            *uci_handle;
49                         ConfigHandle *load_device_config(std::string device_id_param);
50                         std::string get_dir_name(std::string device_id);
51                         std::string get_file_name(std::string device_id_param);
52         };
53 }
54
55 #endif /* DEVICECONFIG_HH_ */