]> pilppa.org Git - libplp.git/blob - src/DeviceConfig.hh
add read_interval DeviceConfig methods
[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 <stdbool.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        "device_cfg"
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,
39                                 uci_package *pkg_param,
40                                 const char *short_fname_param,
41                                 const char *full_fname_param);
42                         ~ConfigHandle();
43                         struct uci_context      *_ctx;
44                         struct uci_package      *_pkg;
45                         char                    *short_fname;
46                         char                    *full_fname;
47         };
48
49         class DeviceConfig {
50                 public:
51                         DeviceConfig(std::string device_id_param);
52                         virtual ~DeviceConfig();
53                         static std::string get_base_dir_name();
54                         static void set_base_dir_name(std::string store_param);
55                         static long get_read_interval_seconds();
56                         static void set_read_interval_seconds(long seconds_param);
57                         static DeviceConfig *get_device_config(std::string device_id);
58                         std::string get_config_value(std::string key);
59                         void set_config_value(std::string key,
60                                         std::string value);
61                         EnumSummaryCalculationType get_summary_calculation_type();
62                 private:
63                         static std::string      store_base_dir;
64                         static long             read_interval_seconds;
65                         std::string             device_id;
66                         std::string             device_type;
67                         ConfigHandle            *uci_handle;
68                         ConfigHandle *load_device_config(std::string device_id_param);
69                         std::string get_dir_name(std::string device_id);
70                         std::string get_file_name(std::string device_id_param);
71         };
72 }
73
74 #endif /* DEVICECONFIG_HH_ */