cmd_delete.cpp 878 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "cmd_delete.h"
  2. #include <stdexcept>
  3. using std::exception;
  4. cmd_delete::cmd_delete()
  5. {
  6. }
  7. cmd_delete::~cmd_delete()
  8. {
  9. }
  10. command_type cmd_delete::get_command()
  11. {
  12. return command_type::DELETE_CMD;
  13. }
  14. response cmd_delete::perform(request *req)
  15. {
  16. vector<sensor_data> *data;
  17. int sensor_id;
  18. memset(&res, 0, sizeof res);
  19. res.type = get_command();
  20. try {
  21. data = get_user_db(req->request_u.existing.session_key);
  22. } catch (exception &e) {
  23. res.response_u.active.response = status::INVALID_SESSION_KEY;
  24. return res;
  25. }
  26. sensor_id = req->request_u.existing.sensor_id;
  27. for (auto it = data->begin(); it != data->end(); it++) {
  28. if (it->sensor_id == sensor_id) {
  29. delete[] it->values.values_val;
  30. data->erase(it);
  31. res.response_u.active.response = status::VALID;
  32. return res;
  33. }
  34. }
  35. res.response_u.active.response = status::NO_DATA_FOUND;
  36. return res;
  37. }