Skip to content

Commit 69d3a61

Browse files
committed
Cleanup the controller class tree.
1 parent 3c90ca2 commit 69d3a61

File tree

209 files changed

+578
-819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+578
-819
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,6 @@ file(GLOB MAIN_SOURCES
611611
Source/Controllers/ControllerSelectorWidget.h
612612
Source/Controllers/SerialPABotBase/SerialPABotBase.cpp
613613
Source/Controllers/SerialPABotBase/SerialPABotBase.h
614-
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp
615-
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h
616-
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp
617-
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h
618614
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp
619615
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp
620616
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.h

SerialPrograms/SerialPrograms.pro

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ SOURCES += \
310310
Source/Controllers/ControllerSession.cpp \
311311
Source/Controllers/ControllerDescriptor.cpp \
312312
Source/Controllers/SerialPABotBase/SerialPABotBase.cpp \
313-
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp \
314-
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp \
315313
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp \
316314
Source/Integrations/DiscordIntegrationSettings.cpp \
317315
Source/Integrations/DiscordIntegrationTable.cpp \
@@ -1427,8 +1425,6 @@ HEADERS += \
14271425
Source/Controllers/ControllerSession.h \
14281426
Source/Controllers/ControllerDescriptor.h \
14291427
Source/Controllers/SerialPABotBase/SerialPABotBase.h \
1430-
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h \
1431-
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h \
14321428
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.h \
14331429
Source/Integrations/DiscordIntegrationSettings.h \
14341430
Source/Integrations/DiscordIntegrationTable.h \

SerialPrograms/Source/Controllers/ControllerCapability.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ namespace PokemonAutomation{
4444
//
4545
class ControllerRequirements{
4646
public:
47-
#if 0
48-
template <class... Args>
49-
ControllerRequirements(Args&&... args)
50-
: m_map(std::forward<Args>(args)...)
51-
, m_sanitizer("ControllerRequirements")
52-
{}
53-
#endif
5447
ControllerRequirements(std::initializer_list<std::map<std::string, std::set<std::string>>::value_type> args)
5548
: m_map(std::move(args))
5649
, m_sanitizer("ControllerRequirements")

SerialPrograms/Source/Controllers/ControllerConnection.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace PokemonAutomation{
1515

16-
class BotBaseRequest; // REMOVE
17-
1816

1917
class ControllerConnection{
2018
public:
@@ -34,15 +32,11 @@ class ControllerConnection{
3432
std::string status_text() const;
3533

3634

37-
public:
38-
virtual std::string stop_pending_commands() = 0;
39-
virtual std::string set_next_command_replace() = 0;
40-
virtual std::string send_request(const BotBaseRequest& request) = 0; // REMOVE
41-
4235
protected:
4336
void signal_ready_changed(bool ready);
4437
void signal_status_text_changed(const std::string& text);
4538

39+
4640
protected:
4741
std::atomic<bool> m_ready;
4842

SerialPrograms/Source/Controllers/ControllerDescriptor.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77
#include "Common/Cpp/Json/JsonValue.h"
88
#include "Common/Cpp/Json/JsonObject.h"
99
#include "ControllerDescriptor.h"
10-
1110
#include "Controllers/SerialPABotBase/SerialPABotBase.h"
12-
#include "Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h"
11+
#include "NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.h"
1312
#include "ControllerConnection.h"
1413

1514
namespace PokemonAutomation{
1615

1716

18-
std::unique_ptr<ControllerDescriptor> NullControllerDescriptor::clone() const{
19-
return std::unique_ptr<ControllerDescriptor>(new NullControllerDescriptor());
20-
}
2117
bool NullControllerDescriptor::operator==(const ControllerDescriptor& x) const{
2218
return typeid(*this) == typeid(x);
2319
}
@@ -60,8 +56,8 @@ void ControllerOption::load_json(const JsonValue& json){
6056
m_current = std::move(descriptor);
6157
return;
6258
}
63-
if (type == SerialPABotBase::INTERFACE_NAME){
64-
auto descriptor = std::make_unique<SerialPABotBase::SerialDescriptor>();
59+
if (type == SerialPABotBase::NintendoSwitch_Basic){
60+
auto descriptor = std::make_unique<NintendoSwitch::SwitchController_SerialPABotBase_Descriptor>();
6561
descriptor->load_json(params);
6662
m_current = std::move(descriptor);
6763
return;

SerialPrograms/Source/Controllers/ControllerDescriptor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class ControllerConnection;
2222
class ControllerDescriptor{
2323
public:
2424
virtual ~ControllerDescriptor() = default;
25-
virtual std::unique_ptr<ControllerDescriptor> clone() const = 0;
2625
virtual bool operator==(const ControllerDescriptor& x) const = 0;
2726

2827
virtual const char* type_name() const = 0;
@@ -39,7 +38,6 @@ class ControllerDescriptor{
3938

4039
class NullControllerDescriptor : public ControllerDescriptor{
4140
public:
42-
virtual std::unique_ptr<ControllerDescriptor> clone() const override;
4341
virtual bool operator==(const ControllerDescriptor& x) const override;
4442
virtual const char* type_name() const override;
4543
virtual std::string display_name() const override;

SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Controllers/ControllerCapability.h"
1010
#include "ControllerSelectorWidget.h"
1111
#include "SerialPABotBase/SerialPABotBase.h"
12-
#include "SerialPABotBase/SerialPABotBase_Descriptor.h"
12+
#include "NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.h"
1313

1414
//#include <iostream>
1515
//using std::cout;
@@ -87,8 +87,9 @@ void ControllerSelectorWidget::refresh(){
8787
m_device_list.emplace_back(new NullControllerDescriptor());
8888

8989
// If SerialPABotBase is supported, add them to the list.
90-
if (m_session.requirements().contains_device(SerialPABotBase::INTERFACE_NAME)){
91-
std::vector<std::unique_ptr<const ControllerDescriptor>> serial = SerialPABotBase::get_all_devices();
90+
if (m_session.requirements().contains_device(SerialPABotBase::NintendoSwitch_Basic)){ // REMOVE
91+
std::vector<std::unique_ptr<const ControllerDescriptor>> serial =
92+
NintendoSwitch::SwitchController_SerialPABotBase_Descriptor::get_all_devices();
9293
std::move(serial.begin(), serial.end(), std::back_inserter(m_device_list));
9394
}
9495

SerialPrograms/Source/Controllers/ControllerSession.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,30 +176,6 @@ std::string ControllerSession::reset(){
176176

177177
return "";
178178
}
179-
std::string ControllerSession::stop_pending_commands(){
180-
std::lock_guard<std::mutex> lg(m_state_lock);
181-
// cout << "ControllerSession::stop_pending_commands() = " << m_connection.get() << endl;
182-
if (!m_connection){
183-
return "No controller set.";
184-
}
185-
return m_connection->stop_pending_commands();
186-
}
187-
std::string ControllerSession::set_next_command_replace(){
188-
std::lock_guard<std::mutex> lg(m_state_lock);
189-
// cout << "ControllerSession::stop_pending_commands() = " << m_connection.get() << endl;
190-
if (!m_connection){
191-
return "No controller set.";
192-
}
193-
return m_connection->set_next_command_replace();
194-
}
195-
std::string ControllerSession::send_request(const BotBaseRequest& request){
196-
std::lock_guard<std::mutex> lg(m_state_lock);
197-
// cout << "ControllerSession::stop_pending_commands() = " << m_connection.get() << endl;
198-
if (!m_connection){
199-
return "No controller set.";
200-
}
201-
return m_connection->send_request(request);
202-
}
203179

204180

205181

SerialPrograms/Source/Controllers/ControllerSession.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <mutex>
1111
#include "Common/Cpp/ListenerSet.h"
12+
#include "Common/Cpp/Exceptions.h"
1213
#include "ControllerDescriptor.h"
1314
#include "ControllerConnection.h"
1415

@@ -66,12 +67,31 @@ class ControllerSession{
6667
public:
6768
bool set_device(const std::shared_ptr<const ControllerDescriptor>& device);
6869

70+
6971
public:
7072
// Returns empty string on success. Otherwise returns error message.
7173
std::string reset();
72-
std::string stop_pending_commands();
73-
std::string set_next_command_replace();
74-
std::string send_request(const BotBaseRequest& request); // REMOVE
74+
75+
// Try to run the following lambda on the underlying controller type.
76+
// Returns true if successful.
77+
template <typename ControllerType, typename Lambda>
78+
bool try_run(Lambda&& function){
79+
std::lock_guard<std::mutex> lg(m_state_lock);
80+
if (!m_connection){
81+
return false;
82+
}
83+
84+
// This will be a cross-cast in most cases.
85+
ControllerType* child = dynamic_cast<ControllerType*>(m_connection.get());
86+
if (child == nullptr){
87+
throw InternalProgramError(
88+
&m_logger, PA_CURRENT_FUNCTION,
89+
"Incompatible controller type cast."
90+
);
91+
}
92+
function(*child);
93+
return true;
94+
}
7595

7696

7797
private:

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
*
55
*/
66

7+
#include "Common/PokemonSwSh/PokemonProgramIDs.h"
78
#include "SerialPABotBase.h"
89

910
namespace PokemonAutomation{
1011
namespace SerialPABotBase{
1112

1213

13-
const char INTERFACE_NAME[] = "SerialPABotBase";
1414

15+
const char NintendoSwitch_Basic[] = "NintendoSwitch-SerialPABotBase";
1516

17+
18+
// Feature List
1619
const char* to_string(Features feature){
1720
switch (feature){
1821
case Features::TickPrecise: return "TickPrecise";
@@ -24,10 +27,28 @@ const char* to_string(Features feature){
2427
}
2528

2629

30+
// Defaults
31+
const std::pair<std::string, std::set<std::string>> OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS{
32+
NintendoSwitch_Basic,
33+
{
34+
to_string(SerialPABotBase::Features::TickPrecise),
35+
to_string(SerialPABotBase::Features::NintendoSwitch_Basic),
36+
to_string(SerialPABotBase::Features::NintendoSwitch_Macros),
37+
to_string(SerialPABotBase::Features::NintendoSwitch_DateSkip),
38+
}
39+
};
40+
2741

42+
// Internal Parsing
2843
std::set<std::string> program_id_to_features(uint8_t id){
2944
switch (id){
3045
case PABB_PID_PABOTBASE_12KB:
46+
return {
47+
to_string(Features::TickPrecise),
48+
to_string(Features::NintendoSwitch_Basic),
49+
to_string(Features::NintendoSwitch_Macros),
50+
// to_string(Features::NintendoSwitch_DateSkip),
51+
};
3152
case PABB_PID_PABOTBASE_31KB:
3253
return {
3354
to_string(Features::TickPrecise),
@@ -40,15 +61,6 @@ std::set<std::string> program_id_to_features(uint8_t id){
4061
}
4162

4263

43-
const std::pair<std::string, std::set<std::string>> OLD_SERIAL_DEFAULT{
44-
SerialPABotBase::INTERFACE_NAME,
45-
{
46-
to_string(SerialPABotBase::Features::TickPrecise),
47-
to_string(SerialPABotBase::Features::NintendoSwitch_Basic),
48-
to_string(SerialPABotBase::Features::NintendoSwitch_Macros),
49-
to_string(SerialPABotBase::Features::NintendoSwitch_DateSkip),
50-
}
51-
};
5264

5365

5466

0 commit comments

Comments
 (0)