director.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. const std::string &Dispatch::get_prompt(void) { return d.get_prompt(); }
  10. Director::Director(Session &s) : session{s} {}
  11. void Director::server_line(const std::string &line) {
  12. if (server_line_)
  13. server_line_(line);
  14. }
  15. void Director::server_prompt(const std::string &prompt) {
  16. if (server_prompt_)
  17. server_prompt_(prompt);
  18. }
  19. void Director::client_input(const std::string &input) {
  20. if (client_input_)
  21. client_input_(input);
  22. }
  23. // These would be called by the Dispatch --
  24. // since it has direct access to us.
  25. void Director::to_server(const std::string &send) { session.to_server(send); }
  26. void Director::to_client(const std::string &send) { session.to_client(send); }
  27. const std::string &Director::get_prompt(void) { return session.get_prompt(); }
  28. void Director::set_server_line(stringFunc new_sl) { server_line_ = new_sl; }
  29. void Director::set_server_prompt(stringFunc new_sp) { server_prompt_ = new_sp; }
  30. void Director::set_client_input(stringFunc new_ci) { client_input_ = new_ci; }
  31. OldValues Director::get_state(void) {
  32. OldValues values;
  33. values.server_line = server_line_;
  34. values.server_prompt = server_prompt_;
  35. values.client_input = client_input_;
  36. values.to_client = to_client_;
  37. server_line_(nullptr);
  38. server_prompt_(nullptr);
  39. client_input_(nullptr);
  40. to_client_ = false;
  41. return values;
  42. }
  43. void Director::restore_state(OldValues v) {
  44. server_line_ = v.server_line;
  45. server_prompt_ = v.server_prompt;
  46. client_input_ = v.client_input;
  47. to_client_ = v.to_client;
  48. }