#define MSG_TYPE_ID__GET_DEVICE_LIST 1
#define MSG_TYPE_ID__GET_LATEST_DATA 2
#define MSG_TYPE_ID__GET_DATA_RANGE 3
+#define MSG_TYPE_ID__GET_DATA_BETWEEN_DATES 4
#define RSP__DEVICE_LIST__DEVICE_COUNT "devcount"
#define RSP__DEVICE_LIST__ID "id_"
#define RSP__DEVICE_LIST__DATA "data_"
#define REQ__DEVICE_ID "id"
+#define REQ__DATE1 "date1"
+#define REQ__DATE2 "date2"
#define RSP__FIRST_DATA_VALUE "firstvalue_"
#define RSP__LATEST_DATA_VALUE "lastvalue_"
#define RSP__MIN_DATA_VALUE "minvalue_"
#define RSP__MAX_DATA_VALUE "maxvalue_"
+#define RSP__COUNT "count"
+#define RSP__DATA_VALUE "dvalue"
+#define RSP__DATA_UNIT "dunit"
+
#endif /* DEVICEBUSMESSAGEID_HH_ */
}
if (data != NULL) {
result->add(data);
- log_debug("%s\n", description.c_str());
+ //log_debug("%s\n", description.c_str());
data->printout();
delete(data);
}
return ret_val;
}
-DataRange *DeviceManagerClient::parse_data_range_msg(BusMessage *msg_param,
+DataRange *DeviceManagerClient::parse_first_and_last_data_msg(BusMessage *msg_param,
int *err_flg) {
DataRange *ret_val;
return ret_val;
}
+DataRange *DeviceManagerClient::parse_data_range_msg(BusMessage *msg_param,
+ int *err_flg) {
+ DataRange *ret_val;
+ int ii;
+ int count;
+ string data_str;
+ string key_str;
+ string desc_str;
+ ostringstream key;
+ ostringstream desc;
+
+ *err_flg = PLP_ERR;
+ ret_val = NULL;
+ if (msg_param != NULL) {
+ ret_val = new DataRange();
+ count = msg_param->get_int_parameter(RSP__COUNT, err_flg);
+ //unit = msg_param->get_string_parameter(RSP__DATA_UNIT, err_flg);
+ for (ii = 0; ii < count; ii++) {
+ key.str("");
+ key << RSP__DATA_VALUE << ii;
+ desc.str("");
+ desc << "value_" << ii;
+ parse_device_data_msg(msg_param,
+ ret_val,
+ key.str(),
+ err_flg,
+ desc.str());
+ }
+ *err_flg = PLP_OK;
+ }
+ return ret_val;
+}
+
DataRange *DeviceManagerClient::get_data_range(BusClient *client_param,
string device_id_param,
int *err_flg) {
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());
+ msg_req->add_string_parameter(REQ__DEVICE_ID, device_id_param);
+ client_param->send_message_and_wait_response(msg_req, &msg_rsp);
+ ret_val = parse_first_and_last_data_msg(msg_rsp, err_flg);
+ delete(msg_req);
+ delete(msg_rsp);
+
+ return ret_val;
+}
+
+DataRange *DeviceManagerClient::get_data(BusClient *client_param,
+ string device_id_param,
+ Date *start_date,
+ Date *end_date,
+ int *err_flg) {
+ BusMessage *msg_req;
+ BusMessage *msg_rsp;
+ DataRange *ret_val;
+
+ msg_rsp = NULL;
+ ret_val = NULL;
+ msg_req = new BusMessage(MSG_TYPE_ID__GET_DATA_BETWEEN_DATES);
+ msg_req->add_string_parameter(REQ__DEVICE_ID, device_id_param);
+ msg_req->add_string_parameter(REQ__DATE1, start_date->to_string());
+ msg_req->add_string_parameter(REQ__DATE2, end_date->to_string());
client_param->send_message_and_wait_response(msg_req, &msg_rsp);
ret_val = parse_data_range_msg(msg_rsp, err_flg);
delete(msg_req);
DataRange *get_data_range(BusClient *client_param,
string device_id_param,
int *err_flg);
+ DataRange *get_data(BusClient *client_param,
+ string device_id_param,
+ Date *start_date,
+ Date *end_date,
+ int *err_flg);
private:
list<plp::Device *> *_device_list;
list<plp::Device *> *parse_device_list_msg(plpbus::BusMessage *dev_list_msg_param,
string description);
DataRange *parse_device_data_msg(BusMessage *msg_param,
int *err_flg);
- DataRange *parse_data_range_msg(BusMessage *msg_param,
+ DataRange *parse_first_and_last_data_msg(BusMessage *msg_param,
int *err_flg);
+ DataRange *parse_data_range_msg(BusMessage *msg_param,
+ int *err_flg);
};
}
}
return ret_val;
}
+
+DataRange *DeviceManagerController::get_data(std::string device_id_param,
+ plp::Date *start_date,
+ plp::Date *end_date,
+ int *err_flg) {
+ DataRange *ret_val;
+
+ ret_val = NULL;
+ *err_flg = PLP_ERR;
+ try {
+ if (_dev_man != NULL) {
+ ret_val = _dev_man->get_data(_bus_client,
+ device_id_param,
+ start_date,
+ end_date,
+ err_flg);
+ }
+ }
+ catch(...) {
+ log_error("Could not get data\n");
+ *err_flg = PLP_ERR;
+ }
+ return ret_val;
+}
int *err_flg);
DataRange *get_data_range(std::string device_id_param,
int *err_flg);
+ DataRange *get_data(std::string device_id_param,
+ plp::Date *start_date,
+ plp::Date *end_date,
+ int *err_flg);
private:
DeviceManagerClient *_dev_man;
BusClient *_bus_client;
}
}
-void decode_data_range_to_busmessage(const BusMessage *ret_val,
- DataRange *dr) {
+void decode_first_and_last_data_to_busmessage(const BusMessage *ret_val,
+ DataRange *dr) {
Data *data;
data = dr->get_first();
}
}
+void decode_data_range_to_busmessage(const BusMessage *ret_val,
+ DataRange *dr) {
+ Data *data;
+ int ii;
+ int count;
+ ostringstream key;
+
+ count = dr->get_count();
+ ((BusMessage *)ret_val)->add_int_parameter(RSP__COUNT, count);
+ for (ii = 0; ii < count; ii++) {
+ data = dr->get(ii);
+ if (data != NULL) {
+ key.str("");
+ key << RSP__DATA_VALUE << ii;
+ add_data_values_to_bus_message(ret_val,
+ data,
+ key.str());
+ delete(data);
+ }
+ }
+}
+
void DeviceManagerServer::get_latest_data(BusMessage *msg_req_param,
const BusMessage *ret_val) {
string id;
reader = sensor->get_datareader();
if (reader != NULL) {
dr = ((DataReader *)reader)->get_data_range();
+ if (dr != NULL) {
+ decode_first_and_last_data_to_busmessage(ret_val, dr);
+ delete(dr);
+ }
+ }
+ }
+ }
+ }
+}
+
+void DeviceManagerServer::get_data_between_dates(BusMessage *msg_req_param,
+ const BusMessage *ret_val) {
+ string id;
+ int err_flg;
+ Device *dev;
+ SensorDevice *sensor;
+ ostringstream key;
+ const DataReader *reader;
+ DataRange *dr;
+ string startdate_str;
+ string enddate_str;
+ Date sdate;
+ Date edate;
+
+ log_debug("started\n");
+ id = msg_req_param->get_string_parameter(REQ__DEVICE_ID, &err_flg);
+ if (err_flg == PLP_OK)
+ startdate_str = msg_req_param->get_string_parameter(REQ__DATE1, &err_flg);
+ if (err_flg == PLP_OK)
+ enddate_str = msg_req_param->get_string_parameter(REQ__DATE2, &err_flg);
+ log_debug("id: %s, sdate: %s, edate: %s\n", id.c_str(), startdate_str.c_str(), enddate_str.c_str());
+ if (err_flg == PLP_OK) {
+ sdate = Date::parse_date_str(startdate_str);
+ edate = Date::parse_date_str(enddate_str);
+ log_debug("id: %s, sdate: %s, edate: %s\n", id.c_str(), startdate_str.c_str(), enddate_str.c_str());
+ dev = (Device *)get_device_by_id(id);
+ if (dev != NULL) {
+ sensor = dynamic_cast<SensorDevice *>(dev);
+ if (sensor != NULL) {
+ reader = sensor->get_datareader();
+ if (reader != NULL) {
+ dr = ((DataReader *)reader)->get_data(&sdate, &edate);
+ log_debug("dr.size: %d\n", dr->get_count());
if (dr != NULL) {
decode_data_range_to_busmessage(ret_val, dr);
delete(dr);
}
}
}
+ else {
+ log_error("Invalid request parameters.\n");
+ }
}
const BusMessage *msq_rsp_param);
void get_data_range(BusMessage *msg_req_param,
const BusMessage *msq_rsp_param);
+ void get_data_between_dates(BusMessage *msg_req_param,
+ const BusMessage *msq_rsp_param);
private:
std::list<plp::Device *> _dev_lst;
pthread_t _lstnr_thrd;
case MSG_TYPE_ID__GET_DEVICE_LIST:
log_debug("get device list request handling started\n");
_dev_man->get_device_list(msg_rsp_param);
- ret_val = 0;
+ ret_val = 0;
break;
case MSG_TYPE_ID__GET_LATEST_DATA:
log_debug("get latest data request handling started\n");
_dev_man->get_latest_data((BusMessage *)msg_req_param, msg_rsp_param);
- ret_val = 0;
+ ret_val = 0;
break;
case MSG_TYPE_ID__GET_DATA_RANGE:
log_debug("get data range request handling started\n");
_dev_man->get_data_range((BusMessage *)msg_req_param, msg_rsp_param);
- ret_val = 0;
+ ret_val = 0;
+ break;
+ case MSG_TYPE_ID__GET_DATA_BETWEEN_DATES:
+ log_debug("get data between dates handling started\n");
+ _dev_man->get_data_between_dates((BusMessage *)msg_req_param, msg_rsp_param);
+ ret_val = 0;
break;
default:
log_debug("unknown message type-id received: %ld\n", type_id);