1- /* SerialPABotBase : Status Thread Helper
1+ /* Controllers : Status Thread Helper
22 *
33 * From: https://github.com/PokemonAutomation/
44 *
55 * This is a helper class to reuse the code for the status updater thread.
66 *
77 */
88
9- #ifndef PokemonAutomation_SerialPABotBase_StatusThread_H
10- #define PokemonAutomation_SerialPABotBase_StatusThread_H
9+ #ifndef PokemonAutomation_Controllers_StatusThread_H
10+ #define PokemonAutomation_Controllers_StatusThread_H
1111
12+ #include " Common/Cpp/Exceptions.h"
1213#include " Common/Cpp/PrettyPrint.h"
1314#include " Common/Cpp/Concurrency/Mutex.h"
1415#include " Common/Cpp/Concurrency/ConditionVariable.h"
16+ #include " Common/Cpp/Concurrency/AsyncTask.h"
17+ #include " Common/Cpp/Concurrency/ThreadPool.h"
1518#include " CommonFramework/Tools/GlobalThreadPools.h"
16- #include " SerialPABotBase_Connection .h"
19+ #include " Controllers/ControllerConnection .h"
1720
1821// #include <iostream>
1922// using std::cout;
2023// using std::endl;
2124
2225namespace PokemonAutomation {
23- namespace SerialPABotBase {
2426
2527
2628
@@ -36,7 +38,7 @@ struct ControllerStatusThreadCallback{
3638class ControllerStatusThread {
3739public:
3840 ControllerStatusThread (
39- SerialPABotBase_Connection & connection,
41+ ControllerConnection & connection,
4042 ControllerStatusThreadCallback& callback
4143 )
4244 : m_connection(connection)
@@ -56,12 +58,9 @@ class ControllerStatusThread{
5658 m_scope.cancel (nullptr );
5759 {
5860 std::unique_lock<Mutex> lg (m_sleep_lock);
59- BotBaseController* botbase = m_connection.botbase ();
60- if (botbase){
61- botbase->on_cancellable_cancel ();
62- }
63- m_cv.notify_all ();
61+ m_connection.cancel ();
6462 }
63+ m_cv.notify_all ();
6564 m_status_thread.wait_and_ignore_exceptions ();
6665 }
6766
@@ -121,11 +120,7 @@ class ControllerStatusThread{
121120 last_ack.store (current_time (), std::memory_order_relaxed);
122121 }catch (OperationCancelledException&){
123122 break ;
124- }catch (InvalidConnectionStateException& e){
125- error = e.message ();
126- }catch (SerialProtocolException& e){
127- error = e.message ();
128- }catch (ConnectionException& e){
123+ }catch (Exception& e){
129124 error = e.message ();
130125 }catch (...){
131126 error = " Unknown error." ;
@@ -157,7 +152,7 @@ class ControllerStatusThread{
157152 }
158153
159154private:
160- SerialPABotBase::SerialPABotBase_Connection & m_connection;
155+ ControllerConnection & m_connection;
161156 ControllerStatusThreadCallback& m_callback;
162157 CancellableHolder<CancellableScope> m_scope;
163158 std::atomic<bool > m_stopping;
@@ -172,6 +167,5 @@ class ControllerStatusThread{
172167
173168
174169
175- }
176170}
177171#endif
0 commit comments