aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Brown <themagnificentmrb@gmail.com>2024-01-11 15:03:44 -0800
committerGarrett Brown <themagnificentmrb@gmail.com>2024-02-02 08:44:55 -0800
commitbd33d448512006d7bc1b8ae2d3a2feab54c798a0 (patch)
tree17d65d5988db06ce48b31a4a83cf4d7dd536d00c
parent829f6500491cf1b5abfa5075eb3a67f71022ba14 (diff)
[Peripherals] Factor add-on lookup out of buttonmap
In the future, when an add-on can't be found, a default translator for keyboards/mice can be used.
-rw-r--r--xbmc/peripherals/addons/AddonInputHandling.cpp130
-rw-r--r--xbmc/peripherals/addons/AddonInputHandling.h25
-rw-r--r--xbmc/peripherals/devices/Peripheral.cpp67
3 files changed, 132 insertions, 90 deletions
diff --git a/xbmc/peripherals/addons/AddonInputHandling.cpp b/xbmc/peripherals/addons/AddonInputHandling.cpp
index 88921baa0b..d6d3911141 100644
--- a/xbmc/peripherals/addons/AddonInputHandling.cpp
+++ b/xbmc/peripherals/addons/AddonInputHandling.cpp
@@ -16,95 +16,37 @@
#include "input/keyboard/interfaces/IKeyboardInputHandler.h"
#include "input/mouse/generic/MouseInputHandling.h"
#include "input/mouse/interfaces/IMouseInputHandler.h"
-#include "peripherals/Peripherals.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,
+CAddonInputHandling::CAddonInputHandling(CPeripheral* peripheral,
+ std::shared_ptr<CPeripheralAddon> addon,
IInputHandler* handler,
IDriverReceiver* receiver)
+ : m_peripheral(peripheral),
+ m_addon(std::move(addon)),
+ m_joystickInputHandler(handler),
+ m_joystickDriverReceiver(receiver)
{
- PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral);
-
- if (!addon)
- {
- CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", peripheral->DeviceName());
- }
- else
- {
- m_buttonMap.reset(new CAddonButtonMap(peripheral, addon, handler->ControllerID()));
- if (m_buttonMap->Load())
- {
- m_joystickDriverHandler = std::make_unique<CInputHandling>(handler, m_buttonMap.get());
-
- if (receiver)
- {
- m_joystickInputReceiver = std::make_unique<CDriverReceiving>(receiver, m_buttonMap.get());
-
- // Interfaces are connected here because they share button map as a common resource
- handler->SetInputReceiver(m_joystickInputReceiver.get());
- }
- }
- else
- {
- m_buttonMap.reset();
- }
- }
}
-CAddonInputHandling::CAddonInputHandling(CPeripherals& manager,
- CPeripheral* peripheral,
+CAddonInputHandling::CAddonInputHandling(CPeripheral* peripheral,
+ std::shared_ptr<CPeripheralAddon> addon,
KEYBOARD::IKeyboardInputHandler* handler)
+ : m_peripheral(peripheral), m_addon(std::move(addon)), m_keyboardInputHandler(handler)
{
- PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral);
-
- if (!addon)
- {
- CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", peripheral->DeviceName());
- }
- else
- {
- m_buttonMap.reset(new CAddonButtonMap(peripheral, addon, handler->ControllerID()));
- if (m_buttonMap->Load())
- {
- m_keyboardDriverHandler =
- std::make_unique<KEYBOARD::CKeyboardInputHandling>(handler, m_buttonMap.get());
- }
- else
- {
- m_buttonMap.reset();
- }
- }
}
-CAddonInputHandling::CAddonInputHandling(CPeripherals& manager,
- CPeripheral* peripheral,
+CAddonInputHandling::CAddonInputHandling(CPeripheral* peripheral,
+ std::shared_ptr<CPeripheralAddon> addon,
MOUSE::IMouseInputHandler* handler)
+ : m_peripheral(peripheral), m_addon(std::move(addon)), m_mouseInputHandler(handler)
{
- PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral);
-
- if (!addon)
- {
- CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", peripheral->DeviceName());
- }
- else
- {
- m_buttonMap.reset(new CAddonButtonMap(peripheral, addon, handler->ControllerID()));
- if (m_buttonMap->Load())
- {
- m_mouseDriverHandler =
- std::make_unique<MOUSE::CMouseInputHandling>(handler, m_buttonMap.get());
- }
- else
- {
- m_buttonMap.reset();
- }
- }
}
CAddonInputHandling::~CAddonInputHandling(void)
@@ -116,6 +58,52 @@ CAddonInputHandling::~CAddonInputHandling(void)
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);
+
+ 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)
diff --git a/xbmc/peripherals/addons/AddonInputHandling.h b/xbmc/peripherals/addons/AddonInputHandling.h
index f4ee8b3fef..c6b8e2c2d6 100644
--- a/xbmc/peripherals/addons/AddonInputHandling.h
+++ b/xbmc/peripherals/addons/AddonInputHandling.h
@@ -38,7 +38,7 @@ class IMouseInputHandler;
namespace PERIPHERALS
{
class CPeripheral;
-class CPeripherals;
+class CPeripheralAddon;
class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler,
public KODI::JOYSTICK::IInputReceiver,
@@ -46,21 +46,23 @@ class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler,
public KODI::MOUSE::IMouseDriverHandler
{
public:
- CAddonInputHandling(CPeripherals& manager,
- CPeripheral* peripheral,
+ CAddonInputHandling(CPeripheral* peripheral,
+ std::shared_ptr<CPeripheralAddon> addon,
KODI::JOYSTICK::IInputHandler* handler,
KODI::JOYSTICK::IDriverReceiver* receiver);
- CAddonInputHandling(CPeripherals& manager,
- CPeripheral* peripheral,
+ CAddonInputHandling(CPeripheral* peripheral,
+ std::shared_ptr<CPeripheralAddon> addon,
KODI::KEYBOARD::IKeyboardInputHandler* handler);
- CAddonInputHandling(CPeripherals& manager,
- CPeripheral* peripheral,
+ CAddonInputHandling(CPeripheral* peripheral,
+ std::shared_ptr<CPeripheralAddon> addon,
KODI::MOUSE::IMouseInputHandler* handler);
~CAddonInputHandling(void) override;
+ bool Load();
+
// implementation of IDriverHandler
bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) override;
bool OnHatMotion(unsigned int hatIndex, KODI::JOYSTICK::HAT_STATE state) override;
@@ -83,6 +85,15 @@ public:
bool SetRumbleState(const KODI::JOYSTICK::FeatureName& feature, float magnitude) override;
private:
+ // Construction parameters
+ CPeripheral* const m_peripheral;
+ const std::shared_ptr<CPeripheralAddon> m_addon;
+ KODI::JOYSTICK::IInputHandler* const m_joystickInputHandler{nullptr};
+ KODI::JOYSTICK::IDriverReceiver* const m_joystickDriverReceiver{nullptr};
+ KODI::KEYBOARD::IKeyboardInputHandler* m_keyboardInputHandler{nullptr};
+ KODI::MOUSE::IMouseInputHandler* const m_mouseInputHandler{nullptr};
+
+ // Input parameters
std::unique_ptr<KODI::JOYSTICK::IDriverHandler> m_joystickDriverHandler;
std::unique_ptr<KODI::JOYSTICK::IInputReceiver> m_joystickInputReceiver;
std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler> m_keyboardDriverHandler;
diff --git a/xbmc/peripherals/devices/Peripheral.cpp b/xbmc/peripherals/devices/Peripheral.cpp
index 2c656a392b..4146b59cb5 100644
--- a/xbmc/peripherals/devices/Peripheral.cpp
+++ b/xbmc/peripherals/devices/Peripheral.cpp
@@ -588,10 +588,21 @@ void CPeripheral::RegisterInputHandler(IInputHandler* handler, bool bPromiscuous
auto it = m_inputHandlers.find(handler);
if (it == m_inputHandlers.end())
{
- CAddonInputHandling* addonInput =
- new CAddonInputHandling(m_manager, this, handler, GetDriverReceiver());
- RegisterJoystickDriverHandler(addonInput, bPromiscuous);
- m_inputHandlers[handler].reset(addonInput);
+ PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this);
+ if (addon)
+ {
+ std::unique_ptr<CAddonInputHandling> addonInput = std::make_unique<CAddonInputHandling>(
+ this, std::move(addon), handler, GetDriverReceiver());
+ if (addonInput->Load())
+ {
+ RegisterJoystickDriverHandler(addonInput.get(), bPromiscuous);
+ m_inputHandlers[handler] = std::move(addonInput);
+ }
+ }
+ else
+ {
+ CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation);
+ }
}
}
@@ -613,10 +624,26 @@ void CPeripheral::RegisterKeyboardHandler(KEYBOARD::IKeyboardInputHandler* handl
auto it = m_keyboardHandlers.find(handler);
if (it == m_keyboardHandlers.end())
{
- std::unique_ptr<CAddonInputHandling> addonInput(
- new CAddonInputHandling(m_manager, this, handler));
- RegisterKeyboardDriverHandler(addonInput.get(), bPromiscuous);
- m_keyboardHandlers[handler] = std::move(addonInput);
+ std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler> keyboardDriverHandler;
+
+ PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this);
+ if (addon)
+ {
+ std::unique_ptr<CAddonInputHandling> addonInput =
+ std::make_unique<CAddonInputHandling>(this, std::move(addon), handler);
+ if (addonInput->Load())
+ keyboardDriverHandler = std::move(addonInput);
+ }
+ else
+ {
+ CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation);
+ }
+
+ if (keyboardDriverHandler)
+ {
+ RegisterKeyboardDriverHandler(keyboardDriverHandler.get(), bPromiscuous);
+ m_keyboardHandlers[handler] = std::move(keyboardDriverHandler);
+ }
}
}
@@ -635,10 +662,26 @@ void CPeripheral::RegisterMouseHandler(MOUSE::IMouseInputHandler* handler, bool
auto it = m_mouseHandlers.find(handler);
if (it == m_mouseHandlers.end())
{
- std::unique_ptr<CAddonInputHandling> addonInput(
- new CAddonInputHandling(m_manager, this, handler));
- RegisterMouseDriverHandler(addonInput.get(), bPromiscuous);
- m_mouseHandlers[handler] = std::move(addonInput);
+ std::unique_ptr<KODI::MOUSE::IMouseDriverHandler> mouseDriverHandler;
+
+ PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this);
+ if (addon)
+ {
+ std::unique_ptr<CAddonInputHandling> addonInput =
+ std::make_unique<CAddonInputHandling>(this, std::move(addon), handler);
+ if (addonInput->Load())
+ mouseDriverHandler = std::move(addonInput);
+ }
+ else
+ {
+ CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", m_strLocation);
+ }
+
+ if (mouseDriverHandler)
+ {
+ RegisterMouseDriverHandler(mouseDriverHandler.get(), bPromiscuous);
+ m_mouseHandlers[handler] = std::move(mouseDriverHandler);
+ }
}
}