dispatchers.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef DISPATCHERS_H
  2. #define DISPATCHERS_H
  3. #include <map>
  4. #include <memory>
  5. #include <string>
  6. #include "director.h"
  7. #include "session_common.h"
  8. /*
  9. Item of the day:
  10. class Result {
  11. // holds unique_ptr or shared_ptr to the "dispatcher"
  12. // when I'm done -- delete the result, cleaning up
  13. // the dispatcher
  14. }
  15. How does this call another?
  16. How does it return a result?
  17. possibly: io_service::post( DONE ); !
  18. */
  19. class Dispatch {
  20. protected:
  21. Director &director;
  22. notifyFunc notify_;
  23. std::shared_ptr<Dispatch> chain;
  24. public:
  25. Dispatch(Director &);
  26. virtual ~Dispatch();
  27. void setNotify(notifyFunc nf);
  28. void notify(void);
  29. virtual void activate(void) = 0;
  30. virtual void deactivate(void) = 0;
  31. const std::string &get_prompt(void);
  32. void to_server(const std::string &send);
  33. void to_client(const std::string &send);
  34. // default to chain calls
  35. void chain_client_input(const std::string &input);
  36. void chain_server_line(const std::string &line, const std::string &raw_line);
  37. void chain_server_prompt(const std::string &prompt);
  38. virtual void client_input(const std::string &input);
  39. virtual void server_line(const std::string &line, const std::string &raw_line);
  40. virtual void server_prompt(const std::string &prompt);
  41. };
  42. /*
  43. * Some options for input:
  44. *
  45. * numeric only
  46. *
  47. */
  48. class InputDispatch : public Dispatch {
  49. private:
  50. public:
  51. InputDispatch(Director &);
  52. ~InputDispatch();
  53. std::string prompt;
  54. size_t max_length;
  55. std::string input;
  56. void activate(void) override;
  57. void deactivate(void) override;
  58. // optional here
  59. void server_line(const std::string &line,
  60. const std::string &raw_line) override;
  61. // void server_prompt(const std::string &prompt);
  62. void client_input(const std::string &cinput) override;
  63. };
  64. class MenuDispatch : public Dispatch {
  65. private:
  66. void help(void);
  67. void menubox(void);
  68. size_t max_width;
  69. size_t max_option_width;
  70. bool instant = false;
  71. void calculate_widths(void);
  72. std::string centered(int length, const std::string &);
  73. public:
  74. MenuDispatch(Director &);
  75. ~MenuDispatch();
  76. std::string menu_box_color;
  77. std::string menu_text_color;
  78. std::string menu_title;
  79. std::string menu_options_color;
  80. std::string menu_prompt;
  81. bool lazy = true;
  82. std::map<std::string, std::string> menu;
  83. bool case_sensitive = false;
  84. std::string input;
  85. int choice;
  86. void activate(void) override;
  87. void deactivate(void) override;
  88. // optional here
  89. void server_line(const std::string &line, const std::string &raw_line) override;
  90. // void server_prompt(const std::string &prompt);
  91. void client_input(const std::string &cinput) override;
  92. };
  93. class CIMDispatch : public Dispatch {
  94. public:
  95. CIMDispatch(Director &);
  96. int count;
  97. void activate(void) override;
  98. void deactivate(void) override;
  99. // optional here
  100. void server_line(const std::string &line, const std::string &raw_line) override;
  101. };
  102. class MoveDispatch : public Dispatch {
  103. public:
  104. MoveDispatch(Director &);
  105. sector_type move_to;
  106. sector_type starting;
  107. int state;
  108. int success;
  109. int warp_pos;
  110. std::string at_destination;
  111. std::vector<int> warp_lane;
  112. void activate(void) override;
  113. void deactivate(void) override;
  114. // optional here
  115. void server_line(const std::string &line, const std::string &raw_line) override;
  116. void server_prompt(const std::string &prompt) override;
  117. void client_input(const std::string &input) override;
  118. private:
  119. bool density_clear(density d); // int sector, int density);
  120. };
  121. class CoreDispatch : public Dispatch {
  122. public:
  123. CoreDispatch(Director &);
  124. void activate(void) override;
  125. void deactivate(void) override;
  126. // optional here
  127. void server_line(const std::string &line, const std::string &raw_line) override;
  128. void server_prompt(const std::string &prompt) override;
  129. void client_input(const std::string &input) override;
  130. };
  131. #endif