response.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "response.h"
  2. #include <client.h>
  3. #include <status_codes.h>
  4. #include <stdexcept>
  5. #define WRONG_RESPONSE "Got wrong response from server."
  6. using std::logic_error;
  7. using std::runtime_error;
  8. interpret_response::interpret_response()
  9. {
  10. }
  11. interpret_response::~interpret_response()
  12. {
  13. }
  14. bool interpret_response::get_logged_in()
  15. {
  16. return client_::logged_in;
  17. }
  18. void interpret_response::set_logged_in(bool value)
  19. {
  20. client_::logged_in = value;
  21. }
  22. string interpret_response::get_username()
  23. {
  24. return *client_::username;
  25. }
  26. void interpret_response::set_username(string username)
  27. {
  28. *client_::username = username;
  29. }
  30. unsigned long interpret_response::get_session_key()
  31. {
  32. return client_::session_key;
  33. }
  34. void interpret_response::set_session_key(unsigned long session_key)
  35. {
  36. client_::session_key = session_key;
  37. }
  38. int interpret_response::interpret(response *res)
  39. {
  40. if (res->type == command_type::BAD_CMD)
  41. throw runtime_error(
  42. status_codes::get(res->response_u.bad.response));
  43. if (res->type != get_command())
  44. throw logic_error(WRONG_RESPONSE);
  45. return perform(res);
  46. }