Debian Codegraph @

src/api/xinput/XInputDLL.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2014-2021 Garrett Brown
3 * Copyright (C) 2014-2021 Team Kodi
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSE.md for more information.
7 */
8
9 #pragma once
10
11 #include <mutex>
12 #include <string>
13 #include <windows.h>
14 #include <Xinput.h>
15
16 // Missing from XInput API
17 #define XINPUT_GAMEPAD_GUIDE 0x0400
18
19 namespace JOYSTICK
20 {
21 struct XINPUT_GAMEPAD_EX
22 {
23 WORD wButtons;
24 BYTE bLeftTrigger;
25 BYTE bRightTrigger;
26 SHORT sThumbLX;
27 SHORT sThumbLY;
28 SHORT sThumbRX;
29 SHORT sThumbRY;
30 DWORD dwPaddingReserved;
31 };
32
33 struct XINPUT_STATE_EX
34 {
35 DWORD dwPacketNumber;
36 XINPUT_GAMEPAD_EX Gamepad;
37 };
38
39 class CXInputDLL
40 {
41 private:
42 CXInputDLL(void);
43
44 public:
45 static CXInputDLL& Get(void);
46 virtual ~CXInputDLL(void) { Unload(); }
47
48 bool Load(void);
49 void Unload(void);
50
51 // Available after library is loaded successfully
52 const std::string& Version(void) const { return m_strVersion; }
53
54 bool HasGuideButton(void) const;
55 bool SupportsPowerOff() const;
56
57 bool GetState(unsigned int controllerId, XINPUT_STATE& state);
58 bool GetStateWithGuide(unsigned int controllerId, XINPUT_STATE_EX& state);
59 bool SetState(unsigned int controllerId, XINPUT_VIBRATION& vibration);
60 bool GetCapabilities(unsigned int controllerId, XINPUT_CAPABILITIES& caps);
61
62 enum class BatteryDeviceType
63 {
64 Controller,
65 Headset
66 };
67 bool GetBatteryInformation(unsigned int controllerId, BatteryDeviceType deviceType, XINPUT_BATTERY_INFORMATION& battery);
68
69 bool PowerOff(unsigned int controllerId);
70
71 private:
72 // Forward decl's for XInput API's we load dynamically and use if available
73 // [in] Index of the gamer associated with the device
74 // [out] Receives the current state
75 typedef DWORD (WINAPI* FnXInputGetState)(DWORD dwUserIndex, XINPUT_STATE* pState);
76 typedef DWORD (WINAPI* FnXInputGetStateEx)(DWORD dwUserIndex, XINPUT_STATE_EX* pState);
77
78 // [in] Index of the gamer associated with the device
79 // [in, out] The vibration information to send to the controller
80 typedef DWORD (WINAPI* FnXInputSetState)(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
81
82 // [in] Index of the gamer associated with the device
83 // [in] Input flags that identify the device type
84 // [out] Receives the capabilities
85 typedef DWORD (WINAPI* FnXInputGetCapabilities)(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
86
87 // [in] Index of the gamer associated with the device
88 // [in] Device associated with this user index to be queried. Must be BATTERY_DEVTYPE_GAMEPAD or BATTERY_DEVTYPE_HEADSET.
89 typedef DWORD (WINAPI* FnXInputGetBatteryInformation)(DWORD dwUserIndex, BYTE devType, XINPUT_BATTERY_INFORMATION *pBatteryInformation);
90
91 // [in] Index of the gamer associated with the device
92 typedef DWORD (WINAPI* FnXInputPowerOffController)(DWORD dwUserIndex);
93
94 HMODULE m_dll;
95 std::string m_strVersion;
96 FnXInputGetState m_getState;
97 FnXInputGetStateEx m_getStateEx;
98 FnXInputSetState m_setState;
99 FnXInputGetCapabilities m_getCaps;
100 FnXInputGetBatteryInformation m_getBatteryInfo;
101 FnXInputPowerOffController m_powerOff;
102 std::recursive_mutex m_mutex;
103 };
104 }