2019-10-31 18:00:42 +00:00
|
|
|
#pragma once
|
|
|
|
#include "switch.h"
|
|
|
|
#include "IController.h"
|
|
|
|
#include "SwitchControllerHandler.h"
|
|
|
|
|
|
|
|
//This class is a base class for SwitchHDLHandler and SwitchAbstractedPaadHandler.
|
|
|
|
class SwitchVirtualGamepadHandler
|
|
|
|
{
|
|
|
|
protected:
|
2019-11-02 17:42:24 +00:00
|
|
|
u32 m_vibrationDeviceHandle;
|
2019-10-31 18:00:42 +00:00
|
|
|
SwitchControllerHandler m_controllerHandler;
|
|
|
|
|
|
|
|
bool m_keepInputThreadRunning;
|
2019-11-06 12:28:56 +00:00
|
|
|
Thread m_inputThread;
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
bool m_keepOutputThreadRunning;
|
2019-11-06 12:28:56 +00:00
|
|
|
Thread m_outputThread;
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
SwitchVirtualGamepadHandler(std::unique_ptr<IController> &&controller);
|
|
|
|
virtual ~SwitchVirtualGamepadHandler();
|
|
|
|
|
|
|
|
//Don't allow to move this class in any way because it holds a thread member that reads from the instance's address
|
|
|
|
SwitchVirtualGamepadHandler(SwitchVirtualGamepadHandler &&other) = delete;
|
|
|
|
SwitchVirtualGamepadHandler(SwitchVirtualGamepadHandler &other) = delete;
|
|
|
|
SwitchVirtualGamepadHandler &operator=(SwitchVirtualGamepadHandler &&other) = delete;
|
|
|
|
SwitchVirtualGamepadHandler &operator=(SwitchVirtualGamepadHandler &other) = delete;
|
|
|
|
|
|
|
|
//Override this if you want a custom init procedure
|
|
|
|
virtual Result Initialize();
|
|
|
|
//Override this if you want a custom exit procedure
|
|
|
|
virtual void Exit();
|
|
|
|
|
|
|
|
//Separately init the input-reading thread
|
2019-11-06 12:28:56 +00:00
|
|
|
Result InitInputThread();
|
2019-10-31 18:00:42 +00:00
|
|
|
//Separately close the input-reading thread
|
|
|
|
void ExitInputThread();
|
|
|
|
|
|
|
|
//Separately init the rumble sending thread
|
2019-11-06 12:28:56 +00:00
|
|
|
Result InitOutputThread();
|
2019-10-31 18:00:42 +00:00
|
|
|
//Separately close the rumble sending thread
|
|
|
|
void ExitOutputThread();
|
|
|
|
|
|
|
|
//The function to call indefinitely by the input thread
|
|
|
|
virtual void UpdateInput() = 0;
|
|
|
|
//The function to call indefinitely by the output thread
|
|
|
|
virtual void UpdateOutput() = 0;
|
|
|
|
|
|
|
|
//Get the raw controller handler pointer
|
2019-11-06 12:28:56 +00:00
|
|
|
inline bool *GetInputThreadBool() { return &m_keepInputThreadRunning; }
|
|
|
|
inline bool *GetOutputThreadBool() { return &m_keepOutputThreadRunning; }
|
2019-10-31 18:00:42 +00:00
|
|
|
inline SwitchControllerHandler *GetControllerHandler() { return &m_controllerHandler; }
|
|
|
|
inline IController *GetController() { return m_controllerHandler.GetController(); }
|
2019-11-02 17:42:24 +00:00
|
|
|
inline u32 *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
|
2019-10-31 18:00:42 +00:00
|
|
|
};
|