From be7bcf8ab6ed7cbeef43e9ea2f7c75b407e6a9bc Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 08:45:44 -0700 Subject: [PATCH] PABotBase2: hold message handlers and the rumble callback in MoveOnlyFunction DeviceHandle owns each message handler and the OEM controller owns its rumble callback; neither is copied. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp | 2 +- .../Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h | 5 +++-- .../PABotBase2/NintendoSwitch_PABotBase2_Joycon.h | 2 +- .../PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp | 2 +- .../PABotBase2/NintendoSwitch_PABotBase2_OemController.h | 5 +++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp index 27142afdf0..af7338714c 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp +++ b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp @@ -79,7 +79,7 @@ DeviceHandle::~DeviceHandle(){ void DeviceHandle::add_message_handler( uint8_t opcode, - std::function handler + MoveOnlyFunction handler ){ auto ret = m_message_handlers.emplace(opcode, std::move(handler)); if (!ret.second){ diff --git a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h index ffbee53f0a..7da7a0bc20 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h +++ b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h @@ -11,6 +11,7 @@ #include #include #include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/Concurrency/Mutex.h" @@ -38,7 +39,7 @@ class DeviceHandle final : public CancellableScope, private StreamListener{ virtual ~DeviceHandle(); void add_message_handler( uint8_t opcode, - std::function handler + MoveOnlyFunction handler ); virtual bool cancel(std::exception_ptr exception) noexcept override; @@ -196,7 +197,7 @@ class DeviceHandle final : public CancellableScope, private StreamListener{ std::deque m_buffer; MessageLogger m_message_loggers; - std::map> m_message_handlers; + std::map> m_message_handlers; }; diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h index f722b93909..90caef4a51 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h @@ -30,7 +30,7 @@ class PABotBase2_JoyCon : PABotBase2::Connection& connection, ControllerClass controller_class, ControllerType controller_type, - std::function on_rumble + MoveOnlyFunction on_rumble ) : JoyconType(logger, controller_class) , PABotBase2_OemController( diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp index 082d60c759..51f575e858 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp @@ -122,7 +122,7 @@ PABotBase2_OemController::PABotBase2_OemController( RecursiveThrottler& logging_throttler, PABotBase2::Connection& connection, ControllerType controller_type, - std::function on_rumble + MoveOnlyFunction on_rumble ) : PABotBase2_Controller(logger, logging_throttler, connection) , m_controller_type(controller_type) diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h index f586f83cc4..28bdd3be0d 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h @@ -8,6 +8,7 @@ #define PokemonAutomation_NintendoSwitch_PABotBase2_OemController_H #include "Common/ControllerStates/NintendoSwitch_OemController_State.h" +#include "Common/Cpp/MoveOnlyFunction.h" #include "Controllers/ControllerStatusThread.h" #include "Controllers/JoystickTools.h" //#include "NintendoSwitch/NintendoSwitch_Settings.h" @@ -36,7 +37,7 @@ class PABotBase2_OemController : RecursiveThrottler& logging_throttler, PABotBase2::Connection& connection, ControllerType controller_type, - std::function on_rumble + MoveOnlyFunction on_rumble ); ~PABotBase2_OemController(); void stop(); @@ -166,7 +167,7 @@ class PABotBase2_OemController : Milliseconds m_cooldown; Milliseconds m_timing_variation; - std::function m_on_rumble; + MoveOnlyFunction m_on_rumble; std::unique_ptr m_status_thread;