diff options
-rw-r--r-- | xbmc/peripherals/addons/AddonInputHandling.cpp | 130 | ||||
-rw-r--r-- | xbmc/peripherals/addons/AddonInputHandling.h | 25 | ||||
-rw-r--r-- | xbmc/peripherals/devices/Peripheral.cpp | 67 |
3 files changed, 90 insertions, 132 deletions
diff --git a/xbmc/peripherals/addons/AddonInputHandling.cpp b/xbmc/peripherals/addons/AddonInputHandling.cpp index d6d3911141..88921baa0b 100644 --- a/xbmc/peripherals/addons/AddonInputHandling.cpp +++ b/xbmc/peripherals/addons/AddonInputHandling.cpp @@ -16,37 +16,95 @@ #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(CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, +CAddonInputHandling::CAddonInputHandling(CPeripherals& manager, + CPeripheral* peripheral, 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(CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, +CAddonInputHandling::CAddonInputHandling(CPeripherals& manager, + CPeripheral* peripheral, 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(CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, +CAddonInputHandling::CAddonInputHandling(CPeripherals& manager, + CPeripheral* peripheral, 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) @@ -58,52 +116,6 @@ 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 c6b8e2c2d6..f4ee8b3fef 100644 --- a/xbmc/peripherals/addons/AddonInputHandling.h +++ b/xbmc/peripherals/addons/AddonInputHandling.h @@ -38,7 +38,7 @@ class IMouseInputHandler; namespace PERIPHERALS { class CPeripheral; -class CPeripheralAddon; +class CPeripherals; class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler, public KODI::JOYSTICK::IInputReceiver, @@ -46,23 +46,21 @@ class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler, public KODI::MOUSE::IMouseDriverHandler { public: - CAddonInputHandling(CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, + CAddonInputHandling(CPeripherals& manager, + CPeripheral* peripheral, KODI::JOYSTICK::IInputHandler* handler, KODI::JOYSTICK::IDriverReceiver* receiver); - CAddonInputHandling(CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, + CAddonInputHandling(CPeripherals& manager, + CPeripheral* peripheral, KODI::KEYBOARD::IKeyboardInputHandler* handler); - CAddonInputHandling(CPeripheral* peripheral, - std::shared_ptr<CPeripheralAddon> addon, + CAddonInputHandling(CPeripherals& manager, + CPeripheral* peripheral, 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; @@ -85,15 +83,6 @@ 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 4146b59cb5..2c656a392b 100644 --- a/xbmc/peripherals/devices/Peripheral.cpp +++ b/xbmc/peripherals/devices/Peripheral.cpp @@ -588,21 +588,10 @@ void CPeripheral::RegisterInputHandler(IInputHandler* handler, bool bPromiscuous auto it = m_inputHandlers.find(handler); if (it == m_inputHandlers.end()) { - 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); - } + CAddonInputHandling* addonInput = + new CAddonInputHandling(m_manager, this, handler, GetDriverReceiver()); + RegisterJoystickDriverHandler(addonInput, bPromiscuous); + m_inputHandlers[handler].reset(addonInput); } } @@ -624,26 +613,10 @@ void CPeripheral::RegisterKeyboardHandler(KEYBOARD::IKeyboardInputHandler* handl auto it = m_keyboardHandlers.find(handler); if (it == m_keyboardHandlers.end()) { - 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); - } + std::unique_ptr<CAddonInputHandling> addonInput( + new CAddonInputHandling(m_manager, this, handler)); + RegisterKeyboardDriverHandler(addonInput.get(), bPromiscuous); + m_keyboardHandlers[handler] = std::move(addonInput); } } @@ -662,26 +635,10 @@ void CPeripheral::RegisterMouseHandler(MOUSE::IMouseInputHandler* handler, bool auto it = m_mouseHandlers.find(handler); if (it == m_mouseHandlers.end()) { - 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); - } + std::unique_ptr<CAddonInputHandling> addonInput( + new CAddonInputHandling(m_manager, this, handler)); + RegisterMouseDriverHandler(addonInput.get(), bPromiscuous); + m_mouseHandlers[handler] = std::move(addonInput); } } |