#include <plp/log.h>
#include <plp/retval.h>
+#include <plp/Data.hh>
#include <plp/DeviceData.hh>
#include "DeviceManagerClient.hh"
clean_device_list(_device_list);
}
-const std::list<plp::Device *> *DeviceManagerClient::get_device_list(BusClient *client_param) {
- send_request__get_device_list(client_param);
- return _device_list;
-}
+const std::list<plp::Device *> *DeviceManagerClient::get_device_list(BusClient *client_param,
+ int *err_flg) {
+ //send_request__get_device_list(client_param);
-void DeviceManagerClient::send_request__get_device_list(BusClient *client_param) {
BusMessage *msg_req;
BusMessage *msg_rsp;
msg_req = new BusMessage(MSG_TYPE_ID__GET_DEVICE_LIST);
client_param->send_message_and_wait_response(msg_req, &msg_rsp);
clean_device_list(_device_list);
- _device_list = parse_device_list_msg(msg_rsp);
+ _device_list = parse_device_list_msg(msg_rsp, err_flg);
delete(msg_req);
delete(msg_rsp);
+
+ return _device_list;
}
BusMessage *DeviceManagerClient::get_latest_data(BusClient *client_param, string device_id_param) {
return msg_rsp;
}
-list<Device *> *DeviceManagerClient::parse_device_list_msg(BusMessage *msg_param) {
+list<Device *> *DeviceManagerClient::parse_device_list_msg(BusMessage *msg_param, int *err_flg) {
int ii;
long count;
- int err_flg;
ostringstream key;
string id;
string name;
string type;
+ string datastr;
EnumDeviceLifeCycleStatus state;
int state_i;
Device *dev;
+ Data *data;
list<Device *> *ret_val;
- log_debug("parse_device_list_msg() started\n");
- count = msg_param->get_long_parameter(RSP__DEVICE_LIST__DEVICE_COUNT, &err_flg);
- log_debug("count: %ld\n", count);
+ count = msg_param->get_long_parameter(RSP__DEVICE_LIST__DEVICE_COUNT, err_flg);
+ log_debug("device count: %ld\n", count);
ret_val = new list<Device *>;
- if (err_flg == PLP_OK) {
+ if (*err_flg == PLP_OK) {
for (ii = 0; ii < count; ii++) {
key.str("");
key << RSP__DEVICE_LIST__ID << ii;
- id = msg_param->get_string_parameter(key.str(), &err_flg);
+ id = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK)
+ break;
key.str("");
key << RSP__DEVICE_LIST__NAME << ii;
- name = msg_param->get_string_parameter(key.str(), &err_flg);
+ name = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK)
+ break;
key.str("");
key << RSP__DEVICE_LIST__TYPE << ii;
- type = msg_param->get_string_parameter(key.str(), &err_flg);
+ type = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK)
+ break;
key.str("");
key << RSP__DEVICE_LIST__LF_STATE << ii;
- state_i = msg_param->get_int_parameter(key.str(), &err_flg);
+ state_i = msg_param->get_int_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK)
+ break;
state = (EnumDeviceLifeCycleStatus)state_i;
- dev = new DeviceData(id, type, name, state);
+ key.str("");
+ key << RSP__DEVICE_LIST__DATA << ii;
+ datastr = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK)
+ break;
+
+ data = Data::parse_string(datastr);
+ if (data == NULL) {
+ *err_flg = PLP_ERR;
+ break;
+ }
+
+ dev = new DeviceData(id, type, name, state, data);
ret_val->push_back(dev);
}
}
public:
DeviceManagerClient();
virtual ~DeviceManagerClient();
- const std::list<plp::Device *> *get_device_list(plpbus::BusClient *client_param);
- plpbus::BusMessage *get_latest_data(plpbus::BusClient *client_param, std::string device_id_param);
+ const std::list<plp::Device *> *get_device_list(plpbus::BusClient *client_param,
+ int *err_flg);
+ plpbus::BusMessage *get_latest_data(plpbus::BusClient *client_param,
+ std::string device_id_param);
private:
std::list<plp::Device *> *_device_list;
- void send_request__get_device_list(plpbus::BusClient *client_param);
- list<plp::Device *> *parse_device_list_msg(plpbus::BusMessage *dev_list_msg_param);
+ //void send_request__get_device_list(plpbus::BusClient *client_param);
+ list<plp::Device *> *parse_device_list_msg(plpbus::BusMessage *dev_list_msg_param,
+ int *err_flg);
};
}
}
}
-const std::list<plp::Device *> *DeviceManagerController::get_device_list() {
+const std::list<plp::Device *> *DeviceManagerController::get_device_list(int *err_flg) {
const list<Device *> *ret_val;
+ ret_val = NULL;
try {
if (_dev_man != NULL) {
- ret_val = _dev_man->get_device_list(_bus_client);
+ ret_val = _dev_man->get_device_list(_bus_client, err_flg);
}
else {
ret_val = new list<Device *>;
}
catch(...) {
log_error("Could not get a device list\n");
- ret_val = new list<Device *>;
+ *err_flg = PLP_ERR;
}
return ret_val;
}
-BusMessage *DeviceManagerController::get_latest_data(string device_id_param) {
+BusMessage *DeviceManagerController::get_latest_data(string device_id_param,
+ int *err_flg) {
BusMessage *ret_val;
ret_val = NULL;
public:
DeviceManagerController();
virtual ~DeviceManagerController();
- const std::list<plp::Device *> *get_device_list();
- BusMessage *get_latest_data(std::string device_id_param);
+ const std::list<plp::Device *> *get_device_list(int *err_flg);
+ BusMessage *get_latest_data(std::string device_id_param, int *err_flg);
private:
DeviceManagerClient *_dev_man;
BusClient *_bus_client;
SensorDevice *sensor;
int indx;
ostringstream key;
+ string data_str;
indx = 0;
((BusMessage *)ret_val)->add_int_parameter(RSP__DEVICE_LIST__DEVICE_COUNT, _dev_lst.size());
key << RSP__DEVICE_LIST__DATA << indx;
data = sensor->get_data();
if (data != NULL) {
- log_debug("returning data: %s\n", data->to_string().c_str());
- ((BusMessage *)ret_val)->add_string_parameter(key.str(), data->to_string());
+ data_str = data->to_string();
+ log_debug("returning data: %s\n", data_str.c_str());
+ ((BusMessage *)ret_val)->add_string_parameter(key.str(), data_str);
delete(data);
}
}
if (data != NULL) {
cnt = data->get_value_count();
((BusMessage *)ret_val)->add_int_parameter(RSP__GET_LATEST_DATA__VALUE_COUNT, cnt);
- ((BusMessage *)ret_val)->add_string_parameter(RSP__GET_LATEST_DATA__DATE, data->get_date().to_string());
- add_data_values_to_bus_message(ret_val, data, RSP__GET_LATEST_DATA__VALUE);
+ ((BusMessage *)ret_val)->add_string_parameter(RSP__GET_LATEST_DATA__DATE,
+ data->get_date().to_string());
+ add_data_values_to_bus_message(ret_val,
+ data, RSP__GET_LATEST_DATA__VALUE);
((BusMessage *)ret_val)->printout();
dr = ((DataReader *)reader)->get_daily_summary(MIN);
if (dr != NULL) {
if (dr->get_count() > 0) {
data = dr->get_first()->clone();;
- add_data_values_to_bus_message(ret_val, data, RSP__GET_LATEST_DATA__MIN_VALUE);
+ add_data_values_to_bus_message(ret_val,
+ data,
+ RSP__GET_LATEST_DATA__MIN_VALUE);
}
delete(dr);
}
if (dr != NULL) {
if (dr->get_count() > 0) {
data = dr->get_first()->clone();
- add_data_values_to_bus_message(ret_val, data, RSP__GET_LATEST_DATA__MAX_VALUE);
+ add_data_values_to_bus_message(ret_val,
+ data,
+ RSP__GET_LATEST_DATA__MAX_VALUE);
}
delete(dr);
}