id = id_param;
type = type_param;
lifecycle_status = LIFECYCLE_STATUS__UNAVAILABLE;
+ _cfg = NULL;
}
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() {
#define DEVICEINFO_HH_
#include <string>
+#include "DeviceConfig.hh"
using namespace std;
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();
std::string id;
std::string name;
std::string type;
+ plp::DeviceConfig *_cfg;
plp::EnumDeviceLifeCycleStatus lifecycle_status;
};
}
#include "log.h"
#include "config.h"
#include "private/uci_config.h"
+#include "retval.h"
using namespace std;
using namespace plp;
bool DeviceConfig::get_config_value(string key, string& value) {
char *ret;
bool ret_val;
+ int err_flg;
ret_val = false;
value.clear();
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;
}
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) {
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() {
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();
}
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,
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);
#include "uci_config.h"
#include "../log.h"
+#include "../retval.h"
int uci_create_named_section(struct uci_context *ctx,
const char *conf_fname_base,
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,
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;
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"