1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/*
* Copyright (C) 2014-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "AddonInputHandling.h"
#include "input/joysticks/generic/DriverReceiving.h"
#include "input/joysticks/generic/InputHandling.h"
#include "input/joysticks/interfaces/IDriverReceiver.h"
#include "input/joysticks/interfaces/IInputHandler.h"
#include "input/keyboard/generic/KeyboardInputHandling.h"
#include "input/keyboard/interfaces/IKeyboardInputHandler.h"
#include "input/mouse/generic/MouseInputHandling.h"
#include "input/mouse/interfaces/IMouseInputHandler.h"
#include "peripherals/addons/AddonButtonMap.h"
#include "peripherals/devices/Peripheral.h"
#include "utils/log.h"
using namespace KODI;
using namespace JOYSTICK;
using namespace PERIPHERALS;
CAddonInputHandling::CAddonInputHandling(CPeripherals& manager,
CPeripheral* peripheral,
std::shared_ptr<CPeripheralAddon> addon,
IInputHandler* handler,
IDriverReceiver* receiver)
: m_manager(manager),
m_peripheral(peripheral),
m_addon(std::move(addon)),
m_joystickInputHandler(handler),
m_joystickDriverReceiver(receiver)
{
}
CAddonInputHandling::CAddonInputHandling(CPeripherals& manager,
CPeripheral* peripheral,
std::shared_ptr<CPeripheralAddon> addon,
KEYBOARD::IKeyboardInputHandler* handler)
: m_manager(manager),
m_peripheral(peripheral),
m_addon(std::move(addon)),
m_keyboardInputHandler(handler)
{
}
CAddonInputHandling::CAddonInputHandling(CPeripherals& manager,
CPeripheral* peripheral,
std::shared_ptr<CPeripheralAddon> addon,
MOUSE::IMouseInputHandler* handler)
: m_manager(manager),
m_peripheral(peripheral),
m_addon(std::move(addon)),
m_mouseInputHandler(handler)
{
}
CAddonInputHandling::~CAddonInputHandling(void)
{
m_joystickDriverHandler.reset();
m_joystickInputReceiver.reset();
m_keyboardDriverHandler.reset();
m_mouseDriverHandler.reset();
m_buttonMap.reset();
}
bool CAddonInputHandling::Load()
{
std::string controllerId;
if (m_joystickInputHandler != nullptr)
controllerId = m_joystickInputHandler->ControllerID();
else if (m_keyboardInputHandler != nullptr)
controllerId = m_keyboardInputHandler->ControllerID();
else if (m_mouseInputHandler != nullptr)
controllerId = m_mouseInputHandler->ControllerID();
if (!controllerId.empty())
m_buttonMap = std::make_unique<CAddonButtonMap>(m_peripheral, m_addon, controllerId, m_manager);
if (m_buttonMap && m_buttonMap->Load())
{
if (m_joystickInputHandler != nullptr)
{
m_joystickDriverHandler =
std::make_unique<CInputHandling>(m_joystickInputHandler, m_buttonMap.get());
if (m_joystickDriverReceiver != nullptr)
{
m_joystickInputReceiver =
std::make_unique<CDriverReceiving>(m_joystickDriverReceiver, m_buttonMap.get());
// Interfaces are connected here because they share button map as a common resource
m_joystickInputHandler->SetInputReceiver(m_joystickInputReceiver.get());
}
return true;
}
else if (m_keyboardInputHandler != nullptr)
{
m_keyboardDriverHandler = std::make_unique<KEYBOARD::CKeyboardInputHandling>(
m_keyboardInputHandler, m_buttonMap.get());
return true;
}
else if (m_mouseInputHandler != nullptr)
{
m_mouseDriverHandler =
std::make_unique<MOUSE::CMouseInputHandling>(m_mouseInputHandler, m_buttonMap.get());
return true;
}
}
return false;
}
bool CAddonInputHandling::OnButtonMotion(unsigned int buttonIndex, bool bPressed)
{
if (m_joystickDriverHandler)
return m_joystickDriverHandler->OnButtonMotion(buttonIndex, bPressed);
return false;
}
bool CAddonInputHandling::OnHatMotion(unsigned int hatIndex, HAT_STATE state)
{
if (m_joystickDriverHandler)
return m_joystickDriverHandler->OnHatMotion(hatIndex, state);
return false;
}
bool CAddonInputHandling::OnAxisMotion(unsigned int axisIndex,
float position,
int center,
unsigned int range)
{
if (m_joystickDriverHandler)
return m_joystickDriverHandler->OnAxisMotion(axisIndex, position, center, range);
return false;
}
void CAddonInputHandling::OnInputFrame(void)
{
if (m_joystickDriverHandler)
m_joystickDriverHandler->OnInputFrame();
}
bool CAddonInputHandling::OnKeyPress(const CKey& key)
{
if (m_keyboardDriverHandler)
return m_keyboardDriverHandler->OnKeyPress(key);
return false;
}
void CAddonInputHandling::OnKeyRelease(const CKey& key)
{
if (m_keyboardDriverHandler)
m_keyboardDriverHandler->OnKeyRelease(key);
}
bool CAddonInputHandling::OnPosition(int x, int y)
{
if (m_mouseDriverHandler)
return m_mouseDriverHandler->OnPosition(x, y);
return false;
}
bool CAddonInputHandling::OnButtonPress(MOUSE::BUTTON_ID button)
{
if (m_mouseDriverHandler)
return m_mouseDriverHandler->OnButtonPress(button);
return false;
}
void CAddonInputHandling::OnButtonRelease(MOUSE::BUTTON_ID button)
{
if (m_mouseDriverHandler)
m_mouseDriverHandler->OnButtonRelease(button);
}
bool CAddonInputHandling::SetRumbleState(const JOYSTICK::FeatureName& feature, float magnitude)
{
if (m_joystickInputReceiver)
return m_joystickInputReceiver->SetRumbleState(feature, magnitude);
return false;
}
|