director.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "director.h"
  2. Dispatch::Dispatch(Director &dir) : d{dir} {};
  3. // virtuals
  4. void Dispatch::server_line(const std::string &line){};
  5. void Dispatch::server_prompt(const std::string &prompt){};
  6. void Dispatch::client_input(const std::string &input){};
  7. void Dispatch::to_server(const std::string &send) { d.to_server(send); }
  8. void Dispatch::to_client(const std::string &send) { d.to_client(send); }
  9. Director::Director(Session &s) : session{s} {}
  10. void Director::server_line(const std::string &line) {
  11. if (server_line_)
  12. server_line_(line);
  13. }
  14. void Director::server_prompt(const std::string &prompt) {
  15. if (server_prompt_)
  16. server_prompt_(prompt);
  17. }
  18. void Director::client_input(const std::string &input) {
  19. if (client_input_)
  20. client_input_(input);
  21. }
  22. // These would be called by the Dispatch --
  23. // since it has direct access to us.
  24. void Director::to_server(const std::string &send) { session.to_server(send); }
  25. void Director::to_client(const std::string &send) { session.to_client(send); }
  26. void Director::set_server_line(stringFunc new_sl) { server_line_ = new_sl; }
  27. void Director::set_server_prompt(stringFunc new_sp) { server_prompt_ = new_sp; }
  28. void Director::set_client_input(stringFunc new_ci) { client_input_ = new_ci; }
  29. OldValues Director::get_state(void) {
  30. OldValues values;
  31. values.server_line = server_line_;
  32. values.server_prompt = server_prompt_;
  33. values.client_input = client_input_;
  34. values.to_client = to_client_;
  35. server_line_(nullptr);
  36. server_prompt_(nullptr);
  37. client_input_(nullptr);
  38. to_client_ = false;
  39. return values;
  40. }
  41. void Director::restore_state(OldValues v) {
  42. server_line_ = v.server_line;
  43. server_prompt_ = v.server_prompt;
  44. client_input_ = v.client_input;
  45. to_client_ = v.to_client;
  46. }