|
8 | 8 | #define PokemonAutomation_AbstractBotBase_H |
9 | 9 |
|
10 | 10 | #include "Common/Cpp/CancellableScope.h" |
11 | | -#include "Common/Cpp/LifetimeSanitizer.h" |
12 | 11 |
|
13 | 12 | namespace PokemonAutomation{ |
14 | 13 |
|
@@ -73,66 +72,6 @@ class BotBaseController{ |
73 | 72 |
|
74 | 73 |
|
75 | 74 |
|
76 | | -class ControllerContext0 : public CancellableScope{ |
77 | | -public: |
78 | | - virtual void wait_for_all_requests() const = 0; |
79 | | - virtual void cancel_now() = 0; |
80 | | - virtual void cancel_lazy() = 0; |
81 | | -}; |
82 | | - |
83 | | - |
84 | | -// A wrapper for BotBase that allows for asynchronous cancelling. |
85 | | -class BotBaseControllerContext final : public ControllerContext0{ |
86 | | -public: |
87 | | - using ControllerType = BotBaseController; |
88 | | - |
89 | | -public: |
90 | | - BotBaseControllerContext(BotBaseController& botbase) |
91 | | - : m_controller(botbase) |
92 | | - {} |
93 | | - BotBaseControllerContext(CancellableScope& parent, BotBaseController& botbase) |
94 | | - : m_controller(botbase) |
95 | | - { |
96 | | - attach(parent); |
97 | | - } |
98 | | - virtual ~BotBaseControllerContext(){ |
99 | | - detach(); |
100 | | - } |
101 | | - |
102 | | - |
103 | | - virtual void wait_for_all_requests() const override; |
104 | | - |
105 | | - operator BotBaseController&() const{ return m_controller; } |
106 | | - BotBaseController& controller() const{ return m_controller; } |
107 | | - |
108 | | - // Stop all commands in this context now. |
109 | | - virtual void cancel_now() override; |
110 | | - |
111 | | - // Stop the commands in this context, but do it lazily. |
112 | | - // Still will stop new commands from being issued to the device, |
113 | | - // and will tell the device that the next command that is issued |
114 | | - // should replace the command queue. |
115 | | - // This cancel is used when you need continuity from an ongoing |
116 | | - // sequence. |
117 | | - virtual void cancel_lazy() override; |
118 | | - |
119 | | - |
120 | | - virtual bool cancel(std::exception_ptr exception) noexcept override; |
121 | | - |
122 | | - |
123 | | -public: |
124 | | - bool try_issue_request(const BotBaseRequest& request) const; |
125 | | - void issue_request(const BotBaseRequest& request) const; |
126 | | - BotBaseMessage issue_request_and_wait(const BotBaseRequest& request) const; |
127 | | - |
128 | | - |
129 | | -private: |
130 | | - BotBaseController& m_controller; |
131 | | - LifetimeSanitizer m_lifetime_sanitizer; |
132 | | -}; |
133 | | - |
134 | | - |
135 | | - |
136 | 75 |
|
137 | 76 |
|
138 | 77 | } |
|
0 commit comments