]> pilppa.org Git - libplp.git/blob - src/DeviceConfig.hh
w1 independent file cleanups.
[libplp.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 "config.h"
16 }
17
18 enum EnumSummaryPeriod{PERIOD_YEARLY, PERIOD_MONTHLY, PERIOD_DAILY, PERIOD_HOURLY, PERIOD_MINUTELY, PERIOD_SECONDLY};
19 enum EnumSummaryCalculationType {SUM, DELTA, MIN, MAX, MEAN};
20
21 const std::string SUMMARY_PERIOD_NAMES_ARRAY[]          = {"yearly", "monthly", "daily", "minutely", "secondly"};
22 const std::string CALCULATION_TYPE_NAMES_ARRAY[]        = {"sum", "delta", "min", "max", "mean"};
23
24 #define DEVICE_CONFIG__FILE_NAME                "dev_cfg.txt"
25 #define DEVICE_CONFIG__SECTION_TYPE             "device"
26 #define DEVICE_CONFIG__SECTION_NAME             "base_data"
27 #define DEVICE_CONFIG_VALUE_KEY__TYPE           "type"
28 #define DEVICE_CONFIG_VALUE_KEY__ID             "id"
29 #define DEVICE_CONFIG_VALUE_KEY__NAME           "name"
30
31 #define DEFAULT_STORAGE_BASE_DIR                "/tmp/w1data"
32 #define DATAFILE_SUFFIX                         ".txt"
33 #define CACHE_DIR_NAME                          "cache"
34
35 namespace plp {
36         struct ConfigHandle {
37                 public:
38                         ConfigHandle(uci_context *ctx_param, uci_package *pkg_param);
39                         ~ConfigHandle();
40                         struct uci_context      *_ctx;
41                         struct uci_package      *_pkg;
42         };
43
44         class DeviceConfig {
45                 public:
46                         DeviceConfig(std::string device_id_param);
47                         virtual ~DeviceConfig();
48                         static std::string get_base_dir_name();
49                         static void set_base_dir_name(std::string store_param);
50                         static DeviceConfig *get_device_config(std::string device_id);
51                         std::string get_cfg_value(std::string key);
52                         void set_cfg_value(std::string key, std::string value);
53                         EnumSummaryCalculationType get_summary_calculation_type();
54                 private:
55                         static std::string      store_base_dir;
56                         std::string             device_id;
57                         std::string             device_type;
58                         ConfigHandle            *uci_handle;
59                         ConfigHandle *load_device_config(std::string device_id_param);
60                         std::string get_dir_name(std::string device_id);
61                         std::string get_file_name(std::string device_id_param);
62         };
63 }
64
65 #endif /* DEVICECONFIG_HH_ */