clean_device_list(_device_list);
}
+list<Device *> *DeviceManagerClient::parse_device_list_msg(BusMessage *msg_param,
+ int *err_flg) {
+ int ii;
+ long count;
+ ostringstream key;
+ string id;
+ string name;
+ string type;
+ string datastr;
+ EnumDeviceLifeCycleStatus state;
+ int state_i;
+ Device *dev;
+ Data *data;
+ list<Device *> *ret_val;
+
+ ret_val = new list<Device *>;
+ count = msg_param->get_long_parameter(RSP__DEVICE_LIST__DEVICE_COUNT, err_flg);
+ log_debug("device count: %ld\n", count);
+ if (*err_flg == PLP_OK) {
+ for (ii = 0; ii < count; ii++) {
+ data = NULL;
+
+ key.str("");
+ key << RSP__DEVICE_LIST__ID << ii;
+ id = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK) {
+ log_error("Failed to parse device id.\n");
+ break;
+ }
+
+ key.str("");
+ key << RSP__DEVICE_LIST__NAME << ii;
+ name = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK) {
+ log_error("Failed to parse name for the device: %s\n", id.c_str());
+ break;
+ }
+
+ key.str("");
+ key << RSP__DEVICE_LIST__TYPE << ii;
+ type = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK) {
+ log_error("Failed to parse type for the device: %s\n", id.c_str());
+ break;
+ }
+
+ key.str("");
+ key << RSP__DEVICE_LIST__LF_STATE << ii;
+ state_i = msg_param->get_int_parameter(key.str(), err_flg);
+ if (*err_flg != PLP_OK) {
+ log_error("Failed to parse life cycle state for the device: %s\n", id.c_str());
+ break;
+ }
+ state = (EnumDeviceLifeCycleStatus)state_i;
+
+ key.str("");
+ key << RSP__DEVICE_LIST__DATA << ii;
+ datastr = msg_param->get_string_parameter(key.str(), err_flg);
+ if (*err_flg == PLP_OK) {
+ data = Data::parse_string(datastr);
+ if (data == NULL) {
+ log_error("No data available for the device: %s\n", id.c_str());
+ }
+ }
+ else {
+ log_error("No data available for the device: %s\n", id.c_str());
+ }
+ dev = new DeviceData(id, type, name, state, data);
+ ret_val->push_back(dev);
+ }
+ }
+ return ret_val;
+}
+
const std::list<plp::Device *> *DeviceManagerClient::get_device_list(BusClient *client_param,
int *err_flg) {
BusMessage *msg_req;
void DeviceManagerClient::parse_device_data_msg(BusMessage *msg_param,
DataRange *result,
- string key,
+ string key_str,
int *err_flg,
string description) {
string data_str;
data = NULL;
if ((msg_param != NULL) &&
(result != NULL)) {
- data_str = msg_param->get_string_parameter(RSP__GET_LATEST_DATA__VALUE, err_flg);
+ data_str = msg_param->get_string_parameter(key_str, err_flg);
if (data_str.empty() == false) {
data = Data::parse_string(data_str);
}
ret_val = NULL;
if (msg_param != NULL) {
ret_val = new DataRange();
- parse_device_data_msg(msg_param, ret_val, RSP__GET_LATEST_DATA__VALUE, err_flg, "latest data");
- parse_device_data_msg(msg_param, ret_val, RSP__GET_LATEST_DATA__MIN_VALUE, err_flg, "min data value");
- parse_device_data_msg(msg_param, ret_val, RSP__GET_LATEST_DATA__MAX_VALUE, err_flg, "max data value");
+ parse_device_data_msg(msg_param, ret_val, RSP__LATEST_DATA_VALUE, err_flg, "latest data");
+ parse_device_data_msg(msg_param, ret_val, RSP__MIN_DATA_VALUE, err_flg, "latest min data value");
+ parse_device_data_msg(msg_param, ret_val, RSP__MAX_DATA_VALUE, err_flg, "latest max data value");
*err_flg = PLP_OK;
}
msg_rsp = NULL;
ret_val = NULL;
msg_req = new BusMessage(MSG_TYPE_ID__GET_LATEST_DATA);
- msg_req->add_string_parameter(REQ__GET_LATEST_DATA__ID, device_id_param.c_str());
+ msg_req->add_string_parameter(REQ__DEVICE_ID, device_id_param.c_str());
client_param->send_message_and_wait_response(msg_req, &msg_rsp);
dr = parse_device_data_msg(msg_rsp, err_flg);
ret_val = dr->get_first();
return ret_val;
}
-list<Device *> *DeviceManagerClient::parse_device_list_msg(BusMessage *msg_param,
- int *err_flg) {
- int ii;
- long count;
- ostringstream key;
- string id;
- string name;
- string type;
- string datastr;
- EnumDeviceLifeCycleStatus state;
- int state_i;
- Device *dev;
- Data *data;
- list<Device *> *ret_val;
-
- ret_val = new list<Device *>;
- count = msg_param->get_long_parameter(RSP__DEVICE_LIST__DEVICE_COUNT, err_flg);
- log_debug("device count: %ld\n", count);
- if (*err_flg == PLP_OK) {
- for (ii = 0; ii < count; ii++) {
- data = NULL;
-
- key.str("");
- key << RSP__DEVICE_LIST__ID << ii;
- id = msg_param->get_string_parameter(key.str(), err_flg);
- if (*err_flg != PLP_OK) {
- log_error("Failed to parse device id.\n");
- break;
- }
+DataRange *DeviceManagerClient::parse_data_range_msg(BusMessage *msg_param,
+ int *err_flg) {
+ DataRange *ret_val;
- key.str("");
- key << RSP__DEVICE_LIST__NAME << ii;
- name = msg_param->get_string_parameter(key.str(), err_flg);
- if (*err_flg != PLP_OK) {
- log_error("Failed to parse name for the device: %s\n", id.c_str());
- break;
- }
+ *err_flg = PLP_ERR;
+ ret_val = NULL;
+ if (msg_param != NULL) {
+ ret_val = new DataRange();
+ parse_device_data_msg(msg_param, ret_val, RSP__FIRST_DATA_VALUE, err_flg, "first data");
+ parse_device_data_msg(msg_param, ret_val, RSP__LATEST_DATA_VALUE, err_flg, "latest data");
+ *err_flg = PLP_OK;
+ }
+ return ret_val;
+}
- key.str("");
- key << RSP__DEVICE_LIST__TYPE << ii;
- type = msg_param->get_string_parameter(key.str(), err_flg);
- if (*err_flg != PLP_OK) {
- log_error("Failed to parse type for the device: %s\n", id.c_str());
- break;
- }
+DataRange *DeviceManagerClient::get_data_range(BusClient *client_param,
+ string device_id_param,
+ int *err_flg) {
+ BusMessage *msg_req;
+ BusMessage *msg_rsp;
+ DataRange *ret_val;
- key.str("");
- key << RSP__DEVICE_LIST__LF_STATE << ii;
- state_i = msg_param->get_int_parameter(key.str(), err_flg);
- if (*err_flg != PLP_OK) {
- log_error("Failed to parse life cycle state for the device: %s\n", id.c_str());
- break;
- }
- state = (EnumDeviceLifeCycleStatus)state_i;
+ msg_rsp = NULL;
+ ret_val = NULL;
+ msg_req = new BusMessage(MSG_TYPE_ID__GET_DATA_RANGE);
+ msg_req->add_string_parameter(REQ__DEVICE_ID, device_id_param.c_str());
+ client_param->send_message_and_wait_response(msg_req, &msg_rsp);
+ ret_val = parse_data_range_msg(msg_rsp, err_flg);
+ delete(msg_req);
+ delete(msg_rsp);
- key.str("");
- key << RSP__DEVICE_LIST__DATA << ii;
- datastr = msg_param->get_string_parameter(key.str(), err_flg);
- if (*err_flg == PLP_OK) {
- data = Data::parse_string(datastr);
- if (data == NULL) {
- log_error("No data available for the device: %s\n", id.c_str());
- }
- }
- else {
- log_error("No data available for the device: %s\n", id.c_str());
- }
- dev = new DeviceData(id, type, name, state, data);
- ret_val->push_back(dev);
- }
- }
return ret_val;
}
((BusMessage *)msg_rsp_param)->add_string_parameter(key_name_base_param, val_str);
}
-void decode_data_to_busmessage(const BusMessage *ret_val,
+void decode_latest_data_to_busmessage(const BusMessage *ret_val,
const DataReader *reader) {
DataRange *dr;
Data *data;
if (data != NULL) {
add_data_values_to_bus_message(ret_val,
data,
- RSP__GET_LATEST_DATA__VALUE);
+ RSP__LATEST_DATA_VALUE);
//((BusMessage *)ret_val)->printout();
delete(data);
}
data = dr->get_first();;
add_data_values_to_bus_message(ret_val,
data,
- RSP__GET_LATEST_DATA__MIN_VALUE);
+ RSP__MIN_DATA_VALUE);
delete(data);
}
delete(dr);
data = dr->get_first();
add_data_values_to_bus_message(ret_val,
data,
- RSP__GET_LATEST_DATA__MAX_VALUE);
+ RSP__MAX_DATA_VALUE);
delete(data);
}
delete(dr);
}
}
+void decode_data_range_to_busmessage(const BusMessage *ret_val,
+ DataRange *dr) {
+ Data *data;
+
+ data = dr->get_first();
+ if (data != NULL) {
+ add_data_values_to_bus_message(ret_val,
+ data,
+ RSP__FIRST_DATA_VALUE);
+ //((BusMessage *)ret_val)->printout();
+ delete(data);
+ }
+ data = dr->get_last();
+ if (data != NULL) {
+ add_data_values_to_bus_message(ret_val,
+ data,
+ RSP__LATEST_DATA_VALUE);
+ //((BusMessage *)ret_val)->printout();
+ delete(data);
+ }
+}
+
void DeviceManagerServer::get_latest_data(BusMessage *msg_req_param,
const BusMessage *ret_val) {
string id;
ostringstream key;
const DataReader *reader;
- id = msg_req_param->get_string_parameter(REQ__GET_LATEST_DATA__ID, &err_flg);
+ id = msg_req_param->get_string_parameter(REQ__DEVICE_ID, &err_flg);
+ if (err_flg == PLP_OK) {
+ dev = (Device *)get_device_by_id(id);
+ if (dev != NULL) {
+ sensor = dynamic_cast<SensorDevice *>(dev);
+ if (sensor != NULL) {
+ reader = sensor->get_datareader();
+ decode_latest_data_to_busmessage(ret_val, reader);
+ }
+ }
+ }
+}
+
+void DeviceManagerServer::get_data_range(BusMessage *msg_req_param,
+ const BusMessage *ret_val) {
+ string id;
+ int err_flg;
+ Device *dev;
+ SensorDevice *sensor;
+ ostringstream key;
+ const DataReader *reader;
+ DataRange *dr;
+
+ id = msg_req_param->get_string_parameter(REQ__DEVICE_ID, &err_flg);
if (err_flg == PLP_OK) {
dev = (Device *)get_device_by_id(id);
if (dev != NULL) {
sensor = dynamic_cast<SensorDevice *>(dev);
if (sensor != NULL) {
reader = sensor->get_datareader();
- decode_data_to_busmessage(ret_val, reader);
+ if (reader != NULL) {
+ dr = ((DataReader *)reader)->get_data_range();
+ if (dr != NULL) {
+ decode_data_range_to_busmessage(ret_val, dr);
+ delete(dr);
+ }
+ }
}
}
}