]> pilppa.org Git - libplp.git/commitdiff
cleanups for devices with no data
authorMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 09:27:06 +0000 (12:27 +0300)
committerMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 09:27:06 +0000 (12:27 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/Device.cc
src/Device.hh
src/DeviceConfig.cc
src/DeviceData.cc
src/DeviceData.hh
src/config.c
src/private/uci_config.c
src/private/uci_config.h

index 714e830e13bcbafdda786fa10522e6339f544220..d09d53b66432c9ce28a5d4e0171424d92f0e2bb8 100644 (file)
@@ -16,6 +16,7 @@ Device::Device(string id_param,
        id                      = id_param;
        type                    = type_param;
        lifecycle_status        = LIFECYCLE_STATUS__UNAVAILABLE;
+       _cfg                    = NULL;
 }
 
 Device::Device(std::string id_param,
@@ -26,10 +27,11 @@ Device::Device(std::string id_param,
        type                    = type_param;
        name                    = name_param;
        lifecycle_status        = status_param;
+       _cfg                    = NULL;
 }
 
 //Device::~Device() {
-//     log_debug("Device: constructor\n");
+//     delete(_cfg);
 //}
 
 string Device::get_id() {
index daef2f89d7002c3a2d3b00628c5819a162ac5baa..d73395a7d87d08eb931a5f825eaaf32d4e392540 100644 (file)
@@ -9,6 +9,7 @@
 #define DEVICEINFO_HH_
 
 #include <string>
+#include "DeviceConfig.hh"
 
 using namespace std;
 
@@ -18,8 +19,11 @@ namespace plp {
        class Device {
                public:
                        Device(string id_param, string type_param);
-                       Device(string id_param, string type_param, string name_param, EnumDeviceLifeCycleStatus status_param);
-                       virtual ~Device() { }
+                       Device(string id_param,
+                               string type_param,
+                               string name_param,
+                               EnumDeviceLifeCycleStatus status_param);
+                       virtual ~Device() { delete(_cfg); }
                        std::string get_id();
                        std::string get_name();
                        std::string get_type();
@@ -30,6 +34,7 @@ namespace plp {
                        std::string id;
                        std::string name;
                        std::string type;
+                       plp::DeviceConfig *_cfg;
                        plp::EnumDeviceLifeCycleStatus lifecycle_status;
        };
 }
index 75af9f396579b0adad82b6ce9144120a6c88d473..a25727565de371aceef170389c994c3d5fac2ced 100644 (file)
@@ -16,6 +16,7 @@
 #include "log.h"
 #include "config.h"
 #include "private/uci_config.h"
+#include "retval.h"
 
 using namespace std;
 using namespace plp;
@@ -122,6 +123,7 @@ string DeviceConfig::get_pathless_config_file_name() {
 bool DeviceConfig::get_config_value(string key, string& value) {
        char    *ret;
        bool    ret_val;
+       int     err_flg;
 
        ret_val = false;
        value.clear();
@@ -132,8 +134,10 @@ bool DeviceConfig::get_config_value(string key, string& value) {
                        ret     = uci_get_config_value(uci_handle->_ctx,
                                                uci_handle->_pkg,
                                                DEVICE_CONFIG__SECTION_NAME,
-                                               key.c_str());
-                       if (ret != NULL) {
+                                               key.c_str(),
+                                               &err_flg);
+                       if ((err_flg == PLP_OK) &&
+                           (ret != NULL)) {
                                ret_val = true;
                                value   = ret;
                        }
@@ -216,7 +220,7 @@ ConfigHandle *DeviceConfig::load_device_config(string device_id_param) {
                if (access(fname_full.c_str(), R_OK) == 0) {
                        ctx     = uci_alloc_context();
                        if (ctx != NULL) {
-                               log_debug("configuration file: %s\n", fname_full.c_str());
+                               //log_debug("configuration file: %s\n", fname_full.c_str());
                                uci_set_confdir(ctx, cfg_dir.c_str());
                                err_flg = uci_load(ctx, fname_full.c_str(), &pkg);
                                if (err_flg == UCI_OK) {
index 9deed93682a228abee52a6c5831bc72e7eca8d92..fa57a5213706fc3cfd113d42f51bf976dd4e77e7 100644 (file)
@@ -20,12 +20,16 @@ DeviceData::DeviceData(string id_param,
                string type_param,
                string name_param,
                EnumDeviceLifeCycleStatus status_param,
-               Data *latest_data) : Device(id_param, type_param, name_param, status_param) {
-       _latest_data    = latest_data;
+               Data *data_param) : Device(id_param, type_param, name_param, status_param) {
+       //if (latest_data != NULL)
+       //      _latest_data    = latest_data->clone();
+       _latest_data    = data_param;
 }
 
 DeviceData::~DeviceData() {
-       delete(_latest_data);
+       if (_latest_data != NULL)
+               delete(_latest_data);
+       _latest_data    = NULL;
 }
 
 void DeviceData::printout() {
@@ -37,9 +41,10 @@ void DeviceData::printout() {
        log_debug("\tname: %s\n", get_name().c_str());
        log_debug("\ttype: %s\n", get_type().c_str());
        log_debug("\tlifecycle state: %d\n", get_lifecycle_state());
-       if (_latest_data != NULL)
+       if (_latest_data != NULL) {
                log_debug("data not null\n");
+               _latest_data->printout();
+       }
        else
                log_debug("data null\n");
-       _latest_data->printout();
 }
index 8e9335ed28dc95e17c8ae292014252480e5304f6..fdc3c7982a2b1f232385d3b332ab7c5e086ec44a 100644 (file)
@@ -14,7 +14,8 @@
 namespace plp {
        class DeviceData : public Device {
                public:
-                       DeviceData(std::string id_param, std::string type_param);
+                       DeviceData(std::string id_param,
+                               std::string type_param);
                        DeviceData(std::string id_param,
                                std::string type_param,
                                std::string name_param,
index 9c479a0e255e70c8dac7c6217849cc6c4d49ca79..2c746f25da47a0821cf5ffa9952ae46947a6de53 100644 (file)
@@ -125,7 +125,8 @@ char* get_config_value_and_close(const char *conf_dir_name,
                                                ret_val = uci_get_config_value(ctx,
                                                                        pkg,
                                                                        section_name,
-                                                                       key);
+                                                                       key,
+                                                                       &err_flg);
                                                // need to duplicate response val, as uci_free_context() would free the value otherwise
                                                if (ret_val != NULL)
                                                        ret_val = strdup(ret_val);
index 756f2b7bf5ba150db1449976386928e5cf6b751c..765a1be0f111474d4db7a362a4f3221f7343d5a2 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "uci_config.h"
 #include "../log.h"
+#include "../retval.h"
 
 int uci_create_named_section(struct uci_context *ctx,
                                const char *conf_fname_base,
@@ -161,12 +162,14 @@ bool uci_set_config_value(struct uci_context *ctx,
 char *uci_get_config_value(struct uci_context *ctx,
                        struct uci_package *pkg,
                        const char *section_name,
-                       const char *key_name) {
+                       const char *key_name,
+                       int *err_flg) {
        struct uci_section      *section;
        struct uci_option       *option;
        char                    *ret_val;
 
        ret_val = NULL;
+       *err_flg        = PLP_OK;
        if ((ctx != NULL) &&
            (pkg != NULL)) {
                section = uci_lookup_section(ctx,
@@ -184,15 +187,18 @@ char *uci_get_config_value(struct uci_context *ctx,
                                                break;
                                        default:
                                                log_error("Failed to read configuration value for key: %s\n", key_name);
+                                               *err_flg        = PLP_ERR_IO;
                                                break;
                                }
                        }
                        else {
-                               log_error("Failed to find configuration key: %s\n", key_name);
+                               *err_flg        = PLP_ERR_DATA_NOT_FOUND;
+                               //log_error("Failed to find configuration key: %s\n", key_name);
                        }
                }
                else {
-                       log_error("Failed to find configuration section name: %s\n", section_name);
+                       *err_flg        = PLP_ERR_DATA_NOT_FOUND;
+                       //log_error("Failed to find configuration section name: %s\n", section_name);
                }
        }
        return ret_val;
index c06e7250719460fc5d27497abb7d2c2d4830e398..c3bb23172e5aea4ea594686ea8fa071e7f26199d 100644 (file)
@@ -43,7 +43,8 @@ extern "C"
 char *uci_get_config_value(struct uci_context *ctx,
                        struct uci_package *pkg,
                        const char *section_name,
-                       const char *key_name);
+                       const char *key_name,
+                       int *err_flg);
 
 #ifdef __cplusplus
 extern "C"