summaryrefslogtreecommitdiff
path: root/src/input_common/sdl/sdl_impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/sdl/sdl_impl.h')
-rw-r--r--src/input_common/sdl/sdl_impl.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/sdl/sdl_impl.h
new file mode 100644
index 000000000..2579741d6
--- /dev/null
+++ b/src/input_common/sdl/sdl_impl.h
@@ -0,0 +1,63 @@
1// Copyright 2018 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <atomic>
8#include <memory>
9#include <thread>
10#include "common/threadsafe_queue.h"
11#include "input_common/sdl/sdl.h"
12
13union SDL_Event;
14using SDL_Joystick = struct _SDL_Joystick;
15using SDL_JoystickID = s32;
16
17namespace InputCommon::SDL {
18
19class SDLJoystick;
20class SDLButtonFactory;
21class SDLAnalogFactory;
22
23class SDLState : public State {
24public:
25 /// Initializes and registers SDL device factories
26 SDLState();
27
28 /// Unregisters SDL device factories and shut them down.
29 ~SDLState() override;
30
31 /// Handle SDL_Events for joysticks from SDL_PollEvent
32 void HandleGameControllerEvent(const SDL_Event& event);
33
34 std::shared_ptr<SDLJoystick> GetSDLJoystickBySDLID(SDL_JoystickID sdl_id);
35 std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port);
36
37 /// Get all DevicePoller that use the SDL backend for a specific device type
38 Pollers GetPollers(Polling::DeviceType type) override;
39
40 /// Used by the Pollers during config
41 std::atomic<bool> polling = false;
42 Common::SPSCQueue<SDL_Event> event_queue;
43
44private:
45 void InitJoystick(int joystick_index);
46 void CloseJoystick(SDL_Joystick* sdl_joystick);
47
48 /// Needs to be called before SDL_QuitSubSystem.
49 void CloseJoysticks();
50
51 /// Map of GUID of a list of corresponding virtual Joysticks
52 std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
53 std::mutex joystick_map_mutex;
54
55 std::shared_ptr<SDLButtonFactory> button_factory;
56 std::shared_ptr<SDLAnalogFactory> analog_factory;
57
58 bool start_thread = false;
59 std::atomic<bool> initialized = false;
60
61 std::thread poll_thread;
62};
63} // namespace InputCommon::SDL