]> pilppa.org Git - libplp.git/blob - src/DeviceConfig.hh
api fixes and 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 #include "DataSummary.hh"
13
14 extern "C" {
15         #include <uci.h>
16         #include <stdbool.h>
17 }
18
19 #define DEVICE_CONFIG__FILE_NAME        "device_cfg"
20 #define DEVICE_CONFIG__SECTION_TYPE     "device"
21 #define DEVICE_CONFIG__SECTION_NAME     "base_data"
22 #define DEVICE_CONFIG_VALUE_KEY__TYPE   "type"
23 #define DEVICE_CONFIG_VALUE_KEY__ID     "id"
24 #define DEVICE_CONFIG_VALUE_KEY__NAME   "name"
25
26 #define DEFAULT_STORAGE_BASE_DIR        "/tmp/w1data"
27 #define DATAFILE_SUFFIX                 ".txt"
28 #define CACHE_DIR_NAME                  "cache"
29
30 namespace plp {
31         struct ConfigHandle {
32                 public:
33                         ConfigHandle(uci_context *ctx_param,
34                                 uci_package *pkg_param,
35                                 const char *short_fname_param,
36                                 const char *full_fname_param);
37                         ~ConfigHandle();
38                         struct uci_context      *_ctx;
39                         struct uci_package      *_pkg;
40                         char                    *short_fname;
41                         char                    *full_fname;
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 long get_read_interval_seconds();
51                         static void set_read_interval_seconds(long seconds_param);
52                         static DeviceConfig *get_device_config(std::string device_id);
53                         bool get_config_value(std::string key, std::string& value);
54                         bool set_config_value(std::string key,
55                                         std::string value,
56                                         bool save_immediately);
57                         std::string get_config_path_name();
58                         std::string get_config_file_name();
59                         std::string get_pathless_config_file_name();
60                         EnumSummaryCalculationType get_summary_calculation_type();
61                 private:
62                         static std::string      store_base_dir;
63                         static long             read_interval_seconds;
64                         std::string             device_id;
65                         std::string             device_type;
66                         ConfigHandle            *uci_handle;
67                         ConfigHandle *load_device_config(std::string device_id_param);
68
69         };
70 }
71
72 #endif /* DEVICECONFIG_HH_ */