+ if (uci_handle != NULL) {
+ delete(uci_handle);
+ uci_handle = NULL;
+ }
+}
+
+void DeviceConfig::set_base_dir_name(string store_param) {
+ int pos;
+ int b_count;
+
+ pos = store_param.find_last_of("/");
+ b_count = store_param.length();
+ if (pos == (b_count - 1)) {
+ store_base_dir = store_param;
+ }
+ else {
+ store_base_dir = store_param + "/";
+ }
+}
+
+string DeviceConfig::get_base_dir_name() {
+ return store_base_dir;
+}
+
+string DeviceConfig::get_dir_name(string device_id_param) {
+ string ret_val;
+ string d_name;
+
+ d_name = DeviceConfig::get_base_dir_name();
+ ret_val = W1Util::concat_paths(d_name, device_id_param);
+ return ret_val;
+}
+
+string DeviceConfig::get_file_name(string device_id_param) {
+ string ret_val;
+ string fname;
+
+ fname = DEVICE_CONFIG__FILE_NAME;
+ ret_val = get_dir_name(device_id);
+ ret_val = W1Util::concat_paths(ret_val, fname);
+ return ret_val;
+}
+
+string DeviceConfig::get_cfg_value(string key) {
+ struct uci_section *section;
+ struct uci_option *option;
+ string ret_val;
+
+ if (uci_handle != NULL) {
+ section = uci_lookup_section(uci_handle->ctx, uci_handle->pkg, DEVICE_CONFIG__SECTION_NAME);
+ if (section != NULL) {
+ option = uci_lookup_option(uci_handle->ctx, section, key.c_str());
+ switch (option->type) {
+ case UCI_TYPE_STRING:
+ log_info("config file: key: %s option name: %s, value: %s\n", key.c_str(), option->e.name, option->v.string);
+ ret_val = option->v.string;
+ break;
+ default:
+ log_error("config file: key: %s can not parse parameter value\n", key.c_str());
+ break;
+ }
+ }
+ }
+ return ret_val;