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