diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 09:25:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 09:25:13 +0000 |
commit | e353c8eff2bef4b84c539d4c03dc7c0a5adf9f9b (patch) | |
tree | 7ac20f83cf66e65d9e27e7be128f2142324466d7 /xbmc/peripherals/addons/AddonInputHandling.cpp | |
parent | Adding upstream version 2:20.4+dfsg. (diff) | |
download | kodi-e353c8eff2bef4b84c539d4c03dc7c0a5adf9f9b.tar.xz kodi-e353c8eff2bef4b84c539d4c03dc7c0a5adf9f9b.zip |
Adding upstream version 2:20.5+dfsg.upstream/2%20.5+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/peripherals/addons/AddonInputHandling.cpp')
-rw-r--r-- | xbmc/peripherals/addons/AddonInputHandling.cpp | 167 |
1 files changed, 83 insertions, 84 deletions
diff --git a/xbmc/peripherals/addons/AddonInputHandling.cpp b/xbmc/peripherals/addons/AddonInputHandling.cpp index 7490b96..644c33e 100644 --- a/xbmc/peripherals/addons/AddonInputHandling.cpp +++ b/xbmc/peripherals/addons/AddonInputHandling.cpp @@ -16,8 +16,8 @@ #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; @@ -26,106 +26,105 @@ 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) { + 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_driverHandler.reset(new CInputHandling(handler, m_buttonMap.get())); + + if (receiver) + { + m_inputReceiver.reset(new CDriverReceiving(receiver, m_buttonMap.get())); + + // Interfaces are connected here because they share button map as a common resource + handler->SetInputReceiver(m_inputReceiver.get()); + } + } + else + { + m_buttonMap.reset(); + } + } } 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) { + 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_keyboardHandler.reset(new KEYBOARD::CKeyboardInputHandling(handler, m_buttonMap.get())); + } + else + { + m_buttonMap.reset(); + } + } } 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) { -} + PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral); -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 (!addon) { - 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) + 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>( - m_keyboardInputHandler, m_buttonMap.get()); - return true; + m_mouseHandler.reset(new MOUSE::CMouseInputHandling(handler, m_buttonMap.get())); } - else if (m_mouseInputHandler != nullptr) + else { - m_mouseDriverHandler = - std::make_unique<MOUSE::CMouseInputHandling>(m_mouseInputHandler, m_buttonMap.get()); - return true; + m_buttonMap.reset(); } } +} - return false; +CAddonInputHandling::~CAddonInputHandling(void) +{ + m_driverHandler.reset(); + m_inputReceiver.reset(); + m_keyboardHandler.reset(); + m_buttonMap.reset(); } bool CAddonInputHandling::OnButtonMotion(unsigned int buttonIndex, bool bPressed) { - if (m_joystickDriverHandler) - return m_joystickDriverHandler->OnButtonMotion(buttonIndex, bPressed); + if (m_driverHandler) + return m_driverHandler->OnButtonMotion(buttonIndex, bPressed); return false; } bool CAddonInputHandling::OnHatMotion(unsigned int hatIndex, HAT_STATE state) { - if (m_joystickDriverHandler) - return m_joystickDriverHandler->OnHatMotion(hatIndex, state); + if (m_driverHandler) + return m_driverHandler->OnHatMotion(hatIndex, state); return false; } @@ -135,58 +134,58 @@ bool CAddonInputHandling::OnAxisMotion(unsigned int axisIndex, int center, unsigned int range) { - if (m_joystickDriverHandler) - return m_joystickDriverHandler->OnAxisMotion(axisIndex, position, center, range); + if (m_driverHandler) + return m_driverHandler->OnAxisMotion(axisIndex, position, center, range); return false; } void CAddonInputHandling::OnInputFrame(void) { - if (m_joystickDriverHandler) - m_joystickDriverHandler->OnInputFrame(); + if (m_driverHandler) + m_driverHandler->OnInputFrame(); } bool CAddonInputHandling::OnKeyPress(const CKey& key) { - if (m_keyboardDriverHandler) - return m_keyboardDriverHandler->OnKeyPress(key); + if (m_keyboardHandler) + return m_keyboardHandler->OnKeyPress(key); return false; } void CAddonInputHandling::OnKeyRelease(const CKey& key) { - if (m_keyboardDriverHandler) - m_keyboardDriverHandler->OnKeyRelease(key); + if (m_keyboardHandler) + m_keyboardHandler->OnKeyRelease(key); } bool CAddonInputHandling::OnPosition(int x, int y) { - if (m_mouseDriverHandler) - return m_mouseDriverHandler->OnPosition(x, y); + if (m_mouseHandler) + return m_mouseHandler->OnPosition(x, y); return false; } bool CAddonInputHandling::OnButtonPress(MOUSE::BUTTON_ID button) { - if (m_mouseDriverHandler) - return m_mouseDriverHandler->OnButtonPress(button); + if (m_mouseHandler) + return m_mouseHandler->OnButtonPress(button); return false; } void CAddonInputHandling::OnButtonRelease(MOUSE::BUTTON_ID button) { - if (m_mouseDriverHandler) - m_mouseDriverHandler->OnButtonRelease(button); + if (m_mouseHandler) + m_mouseHandler->OnButtonRelease(button); } bool CAddonInputHandling::SetRumbleState(const JOYSTICK::FeatureName& feature, float magnitude) { - if (m_joystickInputReceiver) - return m_joystickInputReceiver->SetRumbleState(feature, magnitude); + if (m_inputReceiver) + return m_inputReceiver->SetRumbleState(feature, magnitude); return false; } |