dispatchers.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef DISPATCHERS_H
  2. #define DISPATCHERS_H
  3. #include "session_common.h"
  4. /*
  5. Item of the day:
  6. class Result {
  7. // holds unique_ptr or shared_ptr to the "dispatcher"
  8. // when I'm done -- delete the result, cleaning up
  9. // the dispatcher
  10. }
  11. How does this call another?
  12. How does it return a result?
  13. possibly: io_service::post( DONE ); !
  14. */
  15. class Session;
  16. class Dispatch {
  17. protected:
  18. Session *sess;
  19. notifyFunc notify_;
  20. public:
  21. Dispatch(Session *);
  22. virtual ~Dispatch();
  23. void setNotify(notifyFunc nf);
  24. void notify(void);
  25. virtual void activate(void) = 0;
  26. virtual void deactivate(void) = 0;
  27. const std::string &get_prompt(void);
  28. void to_server(const std::string &send);
  29. void to_client(const std::string &send);
  30. };
  31. class InputDispatch : public Dispatch {
  32. private:
  33. DispatchSettings ds;
  34. public:
  35. InputDispatch(Session *);
  36. std::string prompt;
  37. size_t max_length;
  38. std::string input;
  39. void activate(void) override;
  40. void deactivate(void) override;
  41. // optional here
  42. void server_line(const std::string &line);
  43. // void server_prompt(const std::string &prompt);
  44. void client_input(const std::string &cinput);
  45. };
  46. /**
  47. * The main/first proxy Dispatcher.
  48. *
  49. * Don't follow this as an example. On disable,
  50. * it resets everything back to nothing active.
  51. * (Which is likely not what you want.)
  52. *
  53. */
  54. class MainDispatch : public Dispatch {
  55. private:
  56. InputDispatch id;
  57. public:
  58. MainDispatch(Session *);
  59. ~MainDispatch();
  60. void activate(void) override;
  61. void deactivate(void) override;
  62. void have_input(void);
  63. void server_line(const std::string &line);
  64. void server_prompt(const std::string &prompt);
  65. // void client_input(const std::string &input);
  66. private:
  67. int count;
  68. std::string old_prompt;
  69. };
  70. class MenuDispatch : public Dispatch {
  71. public:
  72. MenuDispatch(Session *);
  73. void activate(void) override;
  74. void deactivate(void) override;
  75. // optional here
  76. void server_line(const std::string &line);
  77. void server_prompt(const std::string &prompt);
  78. void client_input(const std::string &input);
  79. };
  80. class CoreDispatch : public Dispatch {
  81. public:
  82. CoreDispatch(Session *);
  83. void activate(void) override;
  84. void deactivate(void) override;
  85. // optional here
  86. void server_line(const std::string &line);
  87. void server_prompt(const std::string &prompt);
  88. void client_input(const std::string &input);
  89. };
  90. #include "session.h"
  91. #endif