From 398ff747598fab342ce1c0abf020631a17dc22bb Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 8 Mar 2017 09:24:57 -0800 Subject: [PATCH] [Peripherals] Move g_peripherals to ServiceManager --- xbmc/Application.cpp | 14 +++------ xbmc/ServiceBroker.cpp | 5 ++++ xbmc/ServiceBroker.h | 6 ++++ xbmc/ServiceManager.cpp | 12 +++++++- xbmc/ServiceManager.h | 7 +++++ .../Peripheral/AddonCallbacksPeripheral.cpp | 2 +- xbmc/dialogs/GUIDialogKaiToast.cpp | 3 +- xbmc/games/GameSettings.cpp | 3 +- xbmc/games/addons/GameClient.cpp | 2 +- .../dialogs/GUIDialogButtonCapture.cpp | 19 +++++------- .../windows/GUIConfigurationWizard.cpp | 19 +++++------- .../controllers/windows/GUIControllerList.cpp | 2 +- .../windows/GUIControllerWindow.cpp | 5 ++-- xbmc/games/ports/PortMapper.cpp | 9 ++++-- xbmc/games/ports/PortMapper.h | 11 ++++++- xbmc/input/InputManager.cpp | 4 +-- xbmc/input/KeyboardStat.cpp | 7 +++-- xbmc/peripherals/Peripherals.cpp | 29 ++++++++----------- xbmc/peripherals/Peripherals.h | 6 ++-- .../peripherals/addons/AddonButtonMapping.cpp | 4 +-- xbmc/peripherals/addons/AddonButtonMapping.h | 3 +- .../peripherals/addons/AddonInputHandling.cpp | 4 +-- xbmc/peripherals/addons/AddonInputHandling.h | 6 +++- xbmc/peripherals/addons/PeripheralAddon.cpp | 2 +- xbmc/peripherals/bus/PeripheralBus.cpp | 6 ++-- xbmc/peripherals/devices/Peripheral.cpp | 11 +++---- xbmc/peripherals/devices/Peripheral.h | 4 ++- .../devices/PeripheralBluetooth.cpp | 4 +-- .../peripherals/devices/PeripheralBluetooth.h | 2 +- .../devices/PeripheralCecAdapter.cpp | 4 +-- .../devices/PeripheralCecAdapter.h | 2 +- xbmc/peripherals/devices/PeripheralDisk.cpp | 4 +-- xbmc/peripherals/devices/PeripheralDisk.h | 2 +- xbmc/peripherals/devices/PeripheralHID.cpp | 4 +-- xbmc/peripherals/devices/PeripheralHID.h | 2 +- xbmc/peripherals/devices/PeripheralImon.cpp | 4 +-- xbmc/peripherals/devices/PeripheralImon.h | 2 +- .../devices/PeripheralJoystick.cpp | 6 ++-- xbmc/peripherals/devices/PeripheralJoystick.h | 4 ++- .../devices/PeripheralJoystickEmulation.cpp | 4 +-- .../devices/PeripheralJoystickEmulation.h | 2 +- xbmc/peripherals/devices/PeripheralNIC.cpp | 4 +-- xbmc/peripherals/devices/PeripheralNIC.h | 2 +- .../devices/PeripheralNyxboard.cpp | 4 +-- xbmc/peripherals/devices/PeripheralNyxboard.h | 2 +- xbmc/peripherals/devices/PeripheralTuner.cpp | 4 +-- xbmc/peripherals/devices/PeripheralTuner.h | 2 +- .../dialogs/GUIDialogPeripheralSettings.cpp | 7 +++-- xbmc/settings/SettingConditions.cpp | 16 ++++------ xbmc/settings/Settings.cpp | 5 ++-- xbmc/windowing/WinEvents.cpp | 3 +- xbmc/windowing/windows/WinEventsWin32.cpp | 5 ++-- 52 files changed, 166 insertions(+), 139 deletions(-) diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 0c594a3f2c1e3..9ffc3451804ed 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -1093,10 +1093,6 @@ bool CApplication::Initialize() StringUtils::Format(g_localizeStrings.Get(178).c_str(), g_sysinfo.GetAppName().c_str()), "special://xbmc/media/icon256x256.png", EventLevel::Basic))); -#if !defined(TARGET_DARWIN_IOS) - g_peripherals.Initialise(); -#endif - getNetwork().WaitForNet(); // Load curl so curl_global_init gets called before any service threads @@ -1340,8 +1336,6 @@ void CApplication::StopServices() CLog::Log(LOGNOTICE, "stop dvd detect media"); m_DetectDVDType.StopThread(); #endif - - g_peripherals.Clear(); } void CApplication::OnSettingChanged(const CSetting *setting) @@ -2315,7 +2309,7 @@ bool CApplication::OnAction(const CAction &action) } } - if (g_peripherals.OnAction(action)) + if (CServiceBroker::GetPeripherals().OnAction(action)) return true; if (action.GetID() == ACTION_MUTE) @@ -4720,7 +4714,7 @@ void CApplication::ShowVolumeBar(const CAction *action) bool CApplication::IsMuted() const { - if (g_peripherals.IsMuted()) + if (CServiceBroker::GetPeripherals().IsMuted()) return true; return CAEFactory::IsMuted(); } @@ -4744,7 +4738,7 @@ void CApplication::SetMute(bool mute) void CApplication::Mute() { - if (g_peripherals.Mute()) + if (CServiceBroker::GetPeripherals().Mute()) return; CAEFactory::SetMute(true); @@ -4754,7 +4748,7 @@ void CApplication::Mute() void CApplication::UnMute() { - if (g_peripherals.UnMute()) + if (CServiceBroker::GetPeripherals().UnMute()) return; CAEFactory::SetMute(false); diff --git a/xbmc/ServiceBroker.cpp b/xbmc/ServiceBroker.cpp index cea7ad9709d7c..700a304bab030 100644 --- a/xbmc/ServiceBroker.cpp +++ b/xbmc/ServiceBroker.cpp @@ -78,6 +78,11 @@ GAME::CGameServices& CServiceBroker::GetGameServices() return g_application.m_ServiceManager->GetGameServices(); } +PERIPHERALS::CPeripherals& CServiceBroker::GetPeripherals() +{ + return g_application.m_ServiceManager->GetPeripherals(); +} + bool CServiceBroker::IsBinaryAddonCacheUp() { return g_application.m_ServiceManager->init_level > 1; diff --git a/xbmc/ServiceBroker.h b/xbmc/ServiceBroker.h index 53a566e3e4562..e78186ecbdc58 100644 --- a/xbmc/ServiceBroker.h +++ b/xbmc/ServiceBroker.h @@ -54,6 +54,11 @@ namespace GAME class CGameServices; } +namespace PERIPHERALS +{ + class CPeripherals; +} + class CServiceBroker { public: @@ -68,5 +73,6 @@ class CServiceBroker static PLAYLIST::CPlayListPlayer& GetPlaylistPlayer(); static CSettings& GetSettings(); static GAME::CGameServices& GetGameServices(); + static PERIPHERALS::CPeripherals& GetPeripherals(); static bool IsBinaryAddonCacheUp(); }; diff --git a/xbmc/ServiceManager.cpp b/xbmc/ServiceManager.cpp index 091c9a3715d6b..3cc05edf684c8 100644 --- a/xbmc/ServiceManager.cpp +++ b/xbmc/ServiceManager.cpp @@ -24,6 +24,7 @@ #include "cores/AudioEngine/Engines/ActiveAE/AudioDSPAddons/ActiveAEDSP.h" #include "cores/DataCacheCore.h" #include "games/GameServices.h" +#include "peripherals/Peripherals.h" #include "PlayListPlayer.h" #include "utils/log.h" #include "interfaces/AnnouncementManager.h" @@ -33,7 +34,8 @@ #include "settings/Settings.h" CServiceManager::CServiceManager() : - m_gameServices(new GAME::CGameServices) + m_gameServices(new GAME::CGameServices), + m_peripherals(new PERIPHERALS::CPeripherals) { } @@ -81,6 +83,8 @@ bool CServiceManager::Init2() m_contextMenuManager.reset(new CContextMenuManager(*m_addonMgr.get())); + m_peripherals->Initialise(); + init_level = 2; return true; } @@ -101,6 +105,7 @@ void CServiceManager::Deinit() m_gameServices->Deinit(); m_contextMenuManager.reset(); m_binaryAddonCache.reset(); + m_peripherals.reset(); if (m_PVRManager) m_PVRManager->Shutdown(); m_PVRManager.reset(); @@ -176,6 +181,11 @@ GAME::CGameServices& CServiceManager::GetGameServices() return *m_gameServices; } +PERIPHERALS::CPeripherals& CServiceManager::GetPeripherals() +{ + return *m_peripherals; +} + // deleters for unique_ptr void CServiceManager::delete_dataCacheCore::operator()(CDataCacheCore *p) const { diff --git a/xbmc/ServiceManager.h b/xbmc/ServiceManager.h index db7f7b64243c2..577dcbe464457 100644 --- a/xbmc/ServiceManager.h +++ b/xbmc/ServiceManager.h @@ -59,6 +59,11 @@ namespace GAME class CGameServices; } +namespace PERIPHERALS +{ + class CPeripherals; +} + class CServiceManager { public: @@ -83,6 +88,7 @@ class CServiceManager */ CPlatform& GetPlatform(); GAME::CGameServices& GetGameServices(); + PERIPHERALS::CPeripherals& GetPeripherals(); PLAYLIST::CPlayListPlayer& GetPlaylistPlayer(); int init_level = 0; @@ -114,4 +120,5 @@ class CServiceManager std::unique_ptr m_playlistPlayer; std::unique_ptr m_settings; std::unique_ptr m_gameServices; + std::unique_ptr m_peripherals; }; diff --git a/xbmc/addons/interfaces/Peripheral/AddonCallbacksPeripheral.cpp b/xbmc/addons/interfaces/Peripheral/AddonCallbacksPeripheral.cpp index 64130d48a0a83..d36bd9b178f1f 100644 --- a/xbmc/addons/interfaces/Peripheral/AddonCallbacksPeripheral.cpp +++ b/xbmc/addons/interfaces/Peripheral/AddonCallbacksPeripheral.cpp @@ -66,7 +66,7 @@ CPeripheralAddon* CAddonCallbacksPeripheral::GetPeripheralAddon(void* addonData, void CAddonCallbacksPeripheral::TriggerScan(void* addonData) { - g_peripherals.TriggerDeviceScan(PERIPHERAL_BUS_ADDON); + CServiceBroker::GetPeripherals().TriggerDeviceScan(PERIPHERAL_BUS_ADDON); } void CAddonCallbacksPeripheral::RefreshButtonMaps(void* addonData, const char* deviceName, const char* controllerId) diff --git a/xbmc/dialogs/GUIDialogKaiToast.cpp b/xbmc/dialogs/GUIDialogKaiToast.cpp index 60beaede9e4f1..7041cc33df405 100644 --- a/xbmc/dialogs/GUIDialogKaiToast.cpp +++ b/xbmc/dialogs/GUIDialogKaiToast.cpp @@ -22,6 +22,7 @@ #include "peripherals/Peripherals.h" #include "threads/SingleLock.h" #include "utils/TimeUtils.h" +#include "ServiceBroker.h" #define POPUP_ICON 400 #define POPUP_CAPTION_TEXT 401 @@ -136,7 +137,7 @@ bool CGUIDialogKaiToast::DoWork() SetSound(toast.withSound); // Activate haptics for this notification - PERIPHERALS::g_peripherals.OnUserNotification(); + CServiceBroker::GetPeripherals().OnUserNotification(); ResetTimer(); return true; diff --git a/xbmc/games/GameSettings.cpp b/xbmc/games/GameSettings.cpp index a72878249f5be..6f51d159c19c3 100644 --- a/xbmc/games/GameSettings.cpp +++ b/xbmc/games/GameSettings.cpp @@ -25,6 +25,7 @@ #include "settings/lib/Setting.h" #include "settings/Settings.h" #include "utils/StringUtils.h" +#include "ServiceBroker.h" #include @@ -46,7 +47,7 @@ void CGameSettings::OnSettingChanged(const CSetting *setting) const std::string& settingId = setting->GetId(); if (settingId == CSettings::SETTING_GAMES_KEYBOARD_PLAYERS) { - PERIPHERALS::g_peripherals.TriggerDeviceScan(PERIPHERALS::PERIPHERAL_BUS_APPLICATION); + CServiceBroker::GetPeripherals().TriggerDeviceScan(PERIPHERALS::PERIPHERAL_BUS_APPLICATION); } else if (settingId == CSettings::SETTING_GAMES_ENABLEREWIND || settingId == CSettings::SETTING_GAMES_REWINDTIME) diff --git a/xbmc/games/addons/GameClient.cpp b/xbmc/games/addons/GameClient.cpp index 7530294e1a3e8..ee9ba1abe343c 100644 --- a/xbmc/games/addons/GameClient.cpp +++ b/xbmc/games/addons/GameClient.cpp @@ -321,7 +321,7 @@ bool CGameClient::InitializeGameplay(const std::string& gamePath, IGameAudioCall m_serializeSize = GetSerializeSize(); m_audio = audio; m_video = video; - m_inputRateHandle = PERIPHERALS::g_peripherals.SetEventScanRate(INPUT_SCAN_RATE); + m_inputRateHandle = CServiceBroker::GetPeripherals().SetEventScanRate(INPUT_SCAN_RATE); if (m_bSupportsKeyboard) OpenKeyboard(); diff --git a/xbmc/games/controllers/dialogs/GUIDialogButtonCapture.cpp b/xbmc/games/controllers/dialogs/GUIDialogButtonCapture.cpp index 490f97a2b4336..38d6f8cbd6761 100644 --- a/xbmc/games/controllers/dialogs/GUIDialogButtonCapture.cpp +++ b/xbmc/games/controllers/dialogs/GUIDialogButtonCapture.cpp @@ -30,6 +30,7 @@ #include "input/ActionIDs.h" #include "peripherals/Peripherals.h" #include "utils/Variant.h" +#include "ServiceBroker.h" #include #include @@ -115,30 +116,24 @@ bool CGUIDialogButtonCapture::MapPrimitive(JOYSTICK::IButtonMap* buttonMap, void CGUIDialogButtonCapture::InstallHooks(void) { - using namespace PERIPHERALS; - - g_peripherals.RegisterJoystickButtonMapper(this); - g_peripherals.RegisterObserver(this); + CServiceBroker::GetPeripherals().RegisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().RegisterObserver(this); } void CGUIDialogButtonCapture::RemoveHooks(void) { - using namespace PERIPHERALS; - - g_peripherals.UnregisterObserver(this); - g_peripherals.UnregisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().UnregisterObserver(this); + CServiceBroker::GetPeripherals().UnregisterJoystickButtonMapper(this); } void CGUIDialogButtonCapture::Notify(const Observable& obs, const ObservableMessage msg) { - using namespace PERIPHERALS; - switch (msg) { case ObservableMessagePeripheralsChanged: { - g_peripherals.UnregisterJoystickButtonMapper(this); - g_peripherals.RegisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().UnregisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().RegisterJoystickButtonMapper(this); break; } default: diff --git a/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp b/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp index 6642bc1d306e8..b9b8adea25487 100644 --- a/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp +++ b/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp @@ -30,6 +30,7 @@ #include "peripherals/Peripherals.h" #include "threads/SingleLock.h" #include "utils/log.h" +#include "ServiceBroker.h" using namespace KODI; using namespace GAME; @@ -335,10 +336,8 @@ bool CGUIConfigurationWizard::OnButtonPress(const std::string& button) void CGUIConfigurationWizard::InstallHooks(void) { - using namespace PERIPHERALS; - - g_peripherals.RegisterJoystickButtonMapper(this); - g_peripherals.RegisterObserver(this); + CServiceBroker::GetPeripherals().RegisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().RegisterObserver(this); // If we're not using emulation, allow keyboard input to abort prompt if (!m_bEmulation) @@ -349,27 +348,23 @@ void CGUIConfigurationWizard::InstallHooks(void) void CGUIConfigurationWizard::RemoveHooks(void) { - using namespace PERIPHERALS; - CInputManager::GetInstance().UnregisterMouseHandler(this); if (!m_bEmulation) CInputManager::GetInstance().UnregisterKeyboardHandler(this); - g_peripherals.UnregisterObserver(this); - g_peripherals.UnregisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().UnregisterObserver(this); + CServiceBroker::GetPeripherals().UnregisterJoystickButtonMapper(this); } void CGUIConfigurationWizard::Notify(const Observable& obs, const ObservableMessage msg) { - using namespace PERIPHERALS; - switch (msg) { case ObservableMessagePeripheralsChanged: { - g_peripherals.UnregisterJoystickButtonMapper(this); - g_peripherals.RegisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().UnregisterJoystickButtonMapper(this); + CServiceBroker::GetPeripherals().RegisterJoystickButtonMapper(this); break; } default: diff --git a/xbmc/games/controllers/windows/GUIControllerList.cpp b/xbmc/games/controllers/windows/GUIControllerList.cpp index 23379b75c6535..71c5fe1aa820e 100644 --- a/xbmc/games/controllers/windows/GUIControllerList.cpp +++ b/xbmc/games/controllers/windows/GUIControllerList.cpp @@ -143,7 +143,7 @@ void CGUIControllerList::ResetController(void) if (!CGUIDialogYesNo::ShowAndGetInput(35060, 35061)) return; - PERIPHERALS::g_peripherals.ResetButtonMaps(strControllerId); + CServiceBroker::GetPeripherals().ResetButtonMaps(strControllerId); } } diff --git a/xbmc/games/controllers/windows/GUIControllerWindow.cpp b/xbmc/games/controllers/windows/GUIControllerWindow.cpp index 7316f8758d3a3..0a57ddae3b814 100644 --- a/xbmc/games/controllers/windows/GUIControllerWindow.cpp +++ b/xbmc/games/controllers/windows/GUIControllerWindow.cpp @@ -31,6 +31,7 @@ #include "guilib/GUIControl.h" #include "guilib/GUIMessage.h" #include "guilib/WindowIDs.h" +#include "ServiceBroker.h" // To check for button mapping support #include "dialogs/GUIDialogOK.h" @@ -204,8 +205,6 @@ void CGUIControllerWindow::OnEvent(const ADDON::CRepositoryUpdater::RepositoryUp void CGUIControllerWindow::OnInitWindow(void) { - using namespace PERIPHERALS; - CGUIDialog::OnInitWindow(); if (!m_featureList) @@ -233,7 +232,7 @@ void CGUIControllerWindow::OnInitWindow(void) OnMessage(msgFocus); // Enable button mapping support - if (!g_peripherals.GetInstance().EnableButtonMapping()) + if (!CServiceBroker::GetPeripherals().EnableButtonMapping()) CLog::Log(LOGDEBUG, "Joystick support not found"); // FIXME: not thread safe diff --git a/xbmc/games/ports/PortMapper.cpp b/xbmc/games/ports/PortMapper.cpp index 282eb513ef74b..38cd65494502c 100644 --- a/xbmc/games/ports/PortMapper.cpp +++ b/xbmc/games/ports/PortMapper.cpp @@ -23,13 +23,18 @@ #include "peripherals/devices/Peripheral.h" #include "peripherals/Peripherals.h" +#include + using namespace KODI; using namespace GAME; using namespace JOYSTICK; using namespace PERIPHERALS; -CPortMapper::CPortMapper() +CPortMapper::CPortMapper(PERIPHERALS::CPeripherals* peripheralManager) : + m_peripheralManager(peripheralManager) { + assert(m_peripheralManager != nullptr); + CPortManager::GetInstance().RegisterObserver(this); } @@ -56,7 +61,7 @@ void CPortMapper::ProcessPeripherals() auto& oldPortMap = m_portMap; PeripheralVector devices; - g_peripherals.GetPeripheralsWithFeature(devices, FEATURE_JOYSTICK); + m_peripheralManager->GetPeripheralsWithFeature(devices, FEATURE_JOYSTICK); std::map newPortMap; CPortManager::GetInstance().MapDevices(devices, newPortMap); diff --git a/xbmc/games/ports/PortMapper.h b/xbmc/games/ports/PortMapper.h index 4d14445812cbb..41ada0d012b06 100644 --- a/xbmc/games/ports/PortMapper.h +++ b/xbmc/games/ports/PortMapper.h @@ -32,12 +32,17 @@ namespace JOYSTICK } } +namespace PERIPHERALS +{ + class CPeripherals; +} + namespace GAME { class CPortMapper : public Observer { public: - CPortMapper(); + CPortMapper(PERIPHERALS::CPeripherals* peripheralManager); virtual ~CPortMapper(); @@ -46,6 +51,10 @@ namespace GAME private: void ProcessPeripherals(); + // Construction parameters + PERIPHERALS::CPeripherals* m_peripheralManager; + + // Port paremters std::map m_portMap; }; } diff --git a/xbmc/input/InputManager.cpp b/xbmc/input/InputManager.cpp index b24387ec829f7..98f45f73fce91 100644 --- a/xbmc/input/InputManager.cpp +++ b/xbmc/input/InputManager.cpp @@ -57,6 +57,7 @@ #include "utils/StringUtils.h" #include "Util.h" #include "settings/Settings.h" +#include "ServiceBroker.h" #ifdef HAS_PERFORMANCE_SAMPLE #include "utils/PerformanceSample.h" @@ -72,7 +73,6 @@ using EVENTSERVER::CEventServer; using namespace KODI; using namespace MESSAGING; -using PERIPHERALS::CPeripherals; CInputManager::CInputManager() : m_mouseButtonMap(new MOUSE::CMouseWindowingButtonMap), @@ -125,7 +125,7 @@ bool CInputManager::ProcessRemote(int windowId) bool CInputManager::ProcessPeripherals(float frameTime) { CKey key; - if (g_peripherals.GetNextKeypress(frameTime, key)) + if (CServiceBroker::GetPeripherals().GetNextKeypress(frameTime, key)) return OnKey(key); return false; } diff --git a/xbmc/input/KeyboardStat.cpp b/xbmc/input/KeyboardStat.cpp index a7c708a2809a0..cad22089da71a 100644 --- a/xbmc/input/KeyboardStat.cpp +++ b/xbmc/input/KeyboardStat.cpp @@ -31,11 +31,10 @@ #include "peripherals/devices/PeripheralHID.h" #include "threads/SystemClock.h" #include "utils/log.h" +#include "ServiceBroker.h" #define HOLD_THRESHOLD 250 -using namespace PERIPHERALS; - bool operator==(const XBMC_keysym& lhs, const XBMC_keysym& rhs) { return lhs.mod == rhs.mod && @@ -60,8 +59,10 @@ void CKeyboardStat::Initialize() bool CKeyboardStat::LookupSymAndUnicodePeripherals(XBMC_keysym &keysym, uint8_t *key, char *unicode) { + using namespace PERIPHERALS; + PeripheralVector hidDevices; - if (g_peripherals.GetPeripheralsWithFeature(hidDevices, FEATURE_HID)) + if (CServiceBroker::GetPeripherals().GetPeripheralsWithFeature(hidDevices, FEATURE_HID)) { for (auto& peripheral : hidDevices) { diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp index 0e5870c86bdf2..cebba33d9eb93 100644 --- a/xbmc/peripherals/Peripherals.cpp +++ b/xbmc/peripherals/Peripherals.cpp @@ -79,7 +79,8 @@ using namespace XFILE; CPeripherals::CPeripherals() : m_bInitialised(false), m_bIsStarted(false), - m_eventScanner(this) + m_eventScanner(this), + m_portMapper(this) { RegisterObserver(&m_portMapper); } @@ -90,12 +91,6 @@ CPeripherals::~CPeripherals() UnregisterObserver(&m_portMapper); } -CPeripherals &CPeripherals::GetInstance() -{ - static CPeripherals peripheralsInstance; - return peripheralsInstance; -} - void CPeripherals::Initialise() { CSingleLock lock(m_critSection); @@ -322,33 +317,33 @@ void CPeripherals::CreatePeripheral(CPeripheralBus &bus, const PeripheralScanRes switch(mappedResult.m_mappedType) { case PERIPHERAL_HID: - peripheral = PeripheralPtr(new CPeripheralHID(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralHID(this, mappedResult, &bus)); break; case PERIPHERAL_NIC: - peripheral = PeripheralPtr(new CPeripheralNIC(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralNIC(this, mappedResult, &bus)); break; case PERIPHERAL_DISK: - peripheral = PeripheralPtr(new CPeripheralDisk(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralDisk(this, mappedResult, &bus)); break; case PERIPHERAL_NYXBOARD: - peripheral = PeripheralPtr(new CPeripheralNyxboard(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralNyxboard(this, mappedResult, &bus)); break; case PERIPHERAL_TUNER: - peripheral = PeripheralPtr(new CPeripheralTuner(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralTuner(this, mappedResult, &bus)); break; case PERIPHERAL_BLUETOOTH: - peripheral = PeripheralPtr(new CPeripheralBluetooth(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralBluetooth(this, mappedResult, &bus)); break; case PERIPHERAL_CEC: #if defined(HAVE_LIBCEC) if (bus.Type() == PERIPHERAL_BUS_CEC) - peripheral = PeripheralPtr(new CPeripheralCecAdapter(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralCecAdapter(this, mappedResult, &bus)); #else if (!m_bMissingLibCecWarningDisplayed) { @@ -360,15 +355,15 @@ void CPeripherals::CreatePeripheral(CPeripheralBus &bus, const PeripheralScanRes break; case PERIPHERAL_IMON: - peripheral = PeripheralPtr(new CPeripheralImon(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralImon(this, mappedResult, &bus)); break; case PERIPHERAL_JOYSTICK: - peripheral = PeripheralPtr(new CPeripheralJoystick(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralJoystick(this, mappedResult, &bus)); break; case PERIPHERAL_JOYSTICK_EMULATION: - peripheral = PeripheralPtr(new CPeripheralJoystickEmulation(mappedResult, &bus)); + peripheral = PeripheralPtr(new CPeripheralJoystickEmulation(this, mappedResult, &bus)); break; default: diff --git a/xbmc/peripherals/Peripherals.h b/xbmc/peripherals/Peripherals.h index 84b3024797eb2..132b5697876ab 100644 --- a/xbmc/peripherals/Peripherals.h +++ b/xbmc/peripherals/Peripherals.h @@ -50,8 +50,6 @@ namespace JOYSTICK namespace PERIPHERALS { - #define g_peripherals CPeripherals::GetInstance() - class CPeripherals : public ISettingCallback, public Observable, public KODI::MESSAGING::IMessageTarget, @@ -59,7 +57,8 @@ namespace PERIPHERALS public ANNOUNCEMENT::IAnnouncer { public: - static CPeripherals &GetInstance(); + CPeripherals(); + virtual ~CPeripherals(); /*! @@ -314,7 +313,6 @@ namespace PERIPHERALS virtual void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data) override; private: - CPeripherals(); bool LoadMappings(); bool GetMappingForDevice(const CPeripheralBus &bus, PeripheralScanResult& result) const; static void GetSettingsFromMappingsFile(TiXmlElement *xmlNode, std::map &m_settings); diff --git a/xbmc/peripherals/addons/AddonButtonMapping.cpp b/xbmc/peripherals/addons/AddonButtonMapping.cpp index 8717033c876eb..cced61ed18487 100644 --- a/xbmc/peripherals/addons/AddonButtonMapping.cpp +++ b/xbmc/peripherals/addons/AddonButtonMapping.cpp @@ -29,9 +29,9 @@ using namespace KODI; using namespace JOYSTICK; using namespace PERIPHERALS; -CAddonButtonMapping::CAddonButtonMapping(CPeripheral* peripheral, IButtonMapper* mapper) +CAddonButtonMapping::CAddonButtonMapping(CPeripherals* manager, CPeripheral* peripheral, IButtonMapper* mapper) { - PeripheralAddonPtr addon = g_peripherals.GetAddonWithButtonMap(peripheral); + PeripheralAddonPtr addon = manager->GetAddonWithButtonMap(peripheral); if (!addon) { diff --git a/xbmc/peripherals/addons/AddonButtonMapping.h b/xbmc/peripherals/addons/AddonButtonMapping.h index 1474ef2a1a02d..a4ce86265b10e 100644 --- a/xbmc/peripherals/addons/AddonButtonMapping.h +++ b/xbmc/peripherals/addons/AddonButtonMapping.h @@ -37,12 +37,13 @@ namespace JOYSTICK namespace PERIPHERALS { class CPeripheral; + class CPeripherals; class CAddonButtonMapping : public KODI::JOYSTICK::IDriverHandler, public KODI::JOYSTICK::IButtonMapCallback { public: - CAddonButtonMapping(CPeripheral* peripheral, KODI::JOYSTICK::IButtonMapper* mapper); + CAddonButtonMapping(CPeripherals* manager, CPeripheral* peripheral, KODI::JOYSTICK::IButtonMapper* mapper); virtual ~CAddonButtonMapping(void); diff --git a/xbmc/peripherals/addons/AddonInputHandling.cpp b/xbmc/peripherals/addons/AddonInputHandling.cpp index cc995ee0b53a8..3c2e79afc1de0 100644 --- a/xbmc/peripherals/addons/AddonInputHandling.cpp +++ b/xbmc/peripherals/addons/AddonInputHandling.cpp @@ -32,9 +32,9 @@ using namespace KODI; using namespace JOYSTICK; using namespace PERIPHERALS; -CAddonInputHandling::CAddonInputHandling(CPeripheral* peripheral, IInputHandler* handler, IDriverReceiver* receiver) +CAddonInputHandling::CAddonInputHandling(CPeripherals* manager, CPeripheral* peripheral, IInputHandler* handler, IDriverReceiver* receiver) { - PeripheralAddonPtr addon = g_peripherals.GetAddonWithButtonMap(peripheral); + PeripheralAddonPtr addon = manager->GetAddonWithButtonMap(peripheral); if (!addon) { diff --git a/xbmc/peripherals/addons/AddonInputHandling.h b/xbmc/peripherals/addons/AddonInputHandling.h index b249792b99aab..3f0cf9953cce8 100644 --- a/xbmc/peripherals/addons/AddonInputHandling.h +++ b/xbmc/peripherals/addons/AddonInputHandling.h @@ -37,12 +37,16 @@ namespace JOYSTICK namespace PERIPHERALS { class CPeripheral; + class CPeripherals; class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler, public KODI::JOYSTICK::IInputReceiver { public: - CAddonInputHandling(CPeripheral* peripheral, KODI::JOYSTICK::IInputHandler* handler, KODI::JOYSTICK::IDriverReceiver* receiver); + CAddonInputHandling(CPeripherals* manager, + CPeripheral* peripheral, + KODI::JOYSTICK::IInputHandler* handler, + KODI::JOYSTICK::IDriverReceiver* receiver); virtual ~CAddonInputHandling(void); diff --git a/xbmc/peripherals/addons/PeripheralAddon.cpp b/xbmc/peripherals/addons/PeripheralAddon.cpp index 0f662b2b5b88e..32b5378795f68 100644 --- a/xbmc/peripherals/addons/PeripheralAddon.cpp +++ b/xbmc/peripherals/addons/PeripheralAddon.cpp @@ -96,7 +96,7 @@ void CPeripheralAddon::ResetProperties(void) ADDON::AddonPtr CPeripheralAddon::GetRunningInstance(void) const { - PeripheralBusAddonPtr addonBus = std::static_pointer_cast(g_peripherals.GetBusByType(PERIPHERAL_BUS_ADDON)); + PeripheralBusAddonPtr addonBus = std::static_pointer_cast(CServiceBroker::GetPeripherals().GetBusByType(PERIPHERAL_BUS_ADDON)); if (addonBus) { ADDON::AddonPtr peripheralAddon; diff --git a/xbmc/peripherals/bus/PeripheralBus.cpp b/xbmc/peripherals/bus/PeripheralBus.cpp index 60e1a5ae5174f..9633577908e75 100644 --- a/xbmc/peripherals/bus/PeripheralBus.cpp +++ b/xbmc/peripherals/bus/PeripheralBus.cpp @@ -48,7 +48,7 @@ bool CPeripheralBus::InitializeProperties(CPeripheral& peripheral) if (peripheral.Type() == PERIPHERAL_JOYSTICK) { // Ensure an add-on is present to translate input - if (!g_peripherals.GetInstance().GetAddonWithButtonMap(&peripheral)) + if (!m_manager->GetAddonWithButtonMap(&peripheral)) { CLog::Log(LOGWARNING, "Button mapping add-on not present for %s (%s), skipping", peripheral.Location().c_str(), peripheral.DeviceName().c_str()); return false; @@ -128,7 +128,7 @@ void CPeripheralBus::RegisterNewDevices(const PeripheralScanResults &results) { const PeripheralScanResult& result = results.m_results.at(iResultPtr); if (!HasPeripheral(result.m_strLocation)) - g_peripherals.CreatePeripheral(*this, result); + m_manager->CreatePeripheral(*this, result); } } @@ -142,7 +142,7 @@ bool CPeripheralBus::ScanForDevices(void) UnregisterRemovedDevices(results); RegisterNewDevices(results); - CPeripherals::GetInstance().NotifyObservers(ObservableMessagePeripheralsChanged); + m_manager->NotifyObservers(ObservableMessagePeripheralsChanged); bReturn = true; } diff --git a/xbmc/peripherals/devices/Peripheral.cpp b/xbmc/peripherals/devices/Peripheral.cpp index 12968e3ec0331..59f508ddfc36b 100644 --- a/xbmc/peripherals/devices/Peripheral.cpp +++ b/xbmc/peripherals/devices/Peripheral.cpp @@ -50,7 +50,8 @@ struct SortBySettingsOrder } }; -CPeripheral::CPeripheral(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : +CPeripheral::CPeripheral(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + m_manager(manager), m_type(scanResult.m_mappedType), m_busType(scanResult.m_busType), m_mappedBusType(scanResult.m_mappedBusType), @@ -151,7 +152,7 @@ bool CPeripheral::Initialise(void) if (m_bInitialised) return bReturn; - g_peripherals.GetSettingsFromMapping(*this); + m_manager->GetSettingsFromMapping(*this); std::string safeDeviceName = m_strDeviceName; StringUtils::Replace(safeDeviceName, ' ', '_'); @@ -543,7 +544,7 @@ void CPeripheral::LoadPersistedSettings(void) void CPeripheral::ResetDefaultSettings(void) { ClearSettings(); - g_peripherals.GetSettingsFromMapping(*this); + m_manager->GetSettingsFromMapping(*this); std::map::iterator it = m_settings.begin(); while (it != m_settings.end()) @@ -571,7 +572,7 @@ void CPeripheral::RegisterJoystickInputHandler(IInputHandler* handler) auto it = m_inputHandlers.find(handler); if (it == m_inputHandlers.end()) { - CAddonInputHandling* addonInput = new CAddonInputHandling(this, handler, GetDriverReceiver()); + CAddonInputHandling* addonInput = new CAddonInputHandling(m_manager, this, handler, GetDriverReceiver()); RegisterJoystickDriverHandler(addonInput, false); m_inputHandlers[handler].reset(addonInput); } @@ -594,7 +595,7 @@ void CPeripheral::RegisterJoystickButtonMapper(IButtonMapper* mapper) std::map::iterator it = m_buttonMappers.find(mapper); if (it == m_buttonMappers.end()) { - IDriverHandler* addonMapping = new CAddonButtonMapping(this, mapper); + IDriverHandler* addonMapping = new CAddonButtonMapping(m_manager, this, mapper); RegisterJoystickDriverHandler(addonMapping, false); m_buttonMappers[mapper] = addonMapping; } diff --git a/xbmc/peripherals/devices/Peripheral.h b/xbmc/peripherals/devices/Peripheral.h index cc2192c40854d..255b55986a9cd 100644 --- a/xbmc/peripherals/devices/Peripheral.h +++ b/xbmc/peripherals/devices/Peripheral.h @@ -44,6 +44,7 @@ namespace PERIPHERALS { class CGUIDialogPeripheralSettings; class CPeripheralBus; + class CPeripherals; typedef enum { @@ -57,7 +58,7 @@ namespace PERIPHERALS friend class CGUIDialogPeripheralSettings; public: - CPeripheral(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheral(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheral(void); bool operator ==(const CPeripheral &right) const; @@ -211,6 +212,7 @@ namespace PERIPHERALS protected: virtual void ClearSettings(void); + CPeripherals* const m_manager; PeripheralType m_type; PeripheralBusType m_busType; PeripheralBusType m_mappedBusType; diff --git a/xbmc/peripherals/devices/PeripheralBluetooth.cpp b/xbmc/peripherals/devices/PeripheralBluetooth.cpp index fab767dc2e7a4..5788996154bf8 100644 --- a/xbmc/peripherals/devices/PeripheralBluetooth.cpp +++ b/xbmc/peripherals/devices/PeripheralBluetooth.cpp @@ -22,8 +22,8 @@ using namespace PERIPHERALS; -CPeripheralBluetooth::CPeripheralBluetooth(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheral(scanResult, bus) +CPeripheralBluetooth::CPeripheralBluetooth(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheral(manager, scanResult, bus) { m_features.push_back(FEATURE_BLUETOOTH); } diff --git a/xbmc/peripherals/devices/PeripheralBluetooth.h b/xbmc/peripherals/devices/PeripheralBluetooth.h index afcaa59bdb235..89369b3f001b0 100644 --- a/xbmc/peripherals/devices/PeripheralBluetooth.h +++ b/xbmc/peripherals/devices/PeripheralBluetooth.h @@ -26,7 +26,7 @@ namespace PERIPHERALS class CPeripheralBluetooth : public CPeripheral { public: - CPeripheralBluetooth(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralBluetooth(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralBluetooth(void) {}; }; } diff --git a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp index 5b5b38df65343..1397c2ca1e6b1 100644 --- a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp +++ b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp @@ -87,8 +87,8 @@ class DllLibCEC : public DllDynamic, DllLibCECInterface END_METHOD_RESOLVE() }; -CPeripheralCecAdapter::CPeripheralCecAdapter(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheralHID(scanResult, bus), +CPeripheralCecAdapter::CPeripheralCecAdapter(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheralHID(manager, scanResult, bus), CThread("CECAdapter"), m_dll(NULL), m_cecAdapter(NULL) diff --git a/xbmc/peripherals/devices/PeripheralCecAdapter.h b/xbmc/peripherals/devices/PeripheralCecAdapter.h index 9274eabd2b766..09fae108b3f46 100644 --- a/xbmc/peripherals/devices/PeripheralCecAdapter.h +++ b/xbmc/peripherals/devices/PeripheralCecAdapter.h @@ -91,7 +91,7 @@ namespace PERIPHERALS friend class CPeripheralCecAdapterReopenJob; public: - CPeripheralCecAdapter(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralCecAdapter(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralCecAdapter(void); void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data); diff --git a/xbmc/peripherals/devices/PeripheralDisk.cpp b/xbmc/peripherals/devices/PeripheralDisk.cpp index 9a8242b81e3a5..186e228643ae9 100644 --- a/xbmc/peripherals/devices/PeripheralDisk.cpp +++ b/xbmc/peripherals/devices/PeripheralDisk.cpp @@ -23,8 +23,8 @@ using namespace PERIPHERALS; -CPeripheralDisk::CPeripheralDisk(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheral(scanResult, bus) +CPeripheralDisk::CPeripheralDisk(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheral(manager, scanResult, bus) { m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35003) : scanResult.m_strDeviceName; m_features.push_back(FEATURE_DISK); diff --git a/xbmc/peripherals/devices/PeripheralDisk.h b/xbmc/peripherals/devices/PeripheralDisk.h index aabf411b34ab1..c6c1f7d42b925 100644 --- a/xbmc/peripherals/devices/PeripheralDisk.h +++ b/xbmc/peripherals/devices/PeripheralDisk.h @@ -26,7 +26,7 @@ namespace PERIPHERALS class CPeripheralDisk : public CPeripheral { public: - CPeripheralDisk(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralDisk(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralDisk(void) {}; }; } diff --git a/xbmc/peripherals/devices/PeripheralHID.cpp b/xbmc/peripherals/devices/PeripheralHID.cpp index 17db77c64469f..63d5b6c8918ff 100644 --- a/xbmc/peripherals/devices/PeripheralHID.cpp +++ b/xbmc/peripherals/devices/PeripheralHID.cpp @@ -25,8 +25,8 @@ using namespace PERIPHERALS; -CPeripheralHID::CPeripheralHID(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheral(scanResult, bus) +CPeripheralHID::CPeripheralHID(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheral(manager, scanResult, bus) { m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35001) : scanResult.m_strDeviceName; m_features.push_back(FEATURE_HID); diff --git a/xbmc/peripherals/devices/PeripheralHID.h b/xbmc/peripherals/devices/PeripheralHID.h index 0fab29b125dd0..12dddce6b918b 100644 --- a/xbmc/peripherals/devices/PeripheralHID.h +++ b/xbmc/peripherals/devices/PeripheralHID.h @@ -27,7 +27,7 @@ namespace PERIPHERALS class CPeripheralHID : public CPeripheral { public: - CPeripheralHID(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralHID(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralHID(void); virtual bool InitialiseFeature(const PeripheralFeature feature); virtual bool LookupSymAndUnicode(XBMC_keysym &keysym, uint8_t *key, char *unicode) { return false; } diff --git a/xbmc/peripherals/devices/PeripheralImon.cpp b/xbmc/peripherals/devices/PeripheralImon.cpp index f5d4330b211f4..bd7f18e99ea5e 100644 --- a/xbmc/peripherals/devices/PeripheralImon.cpp +++ b/xbmc/peripherals/devices/PeripheralImon.cpp @@ -28,8 +28,8 @@ using namespace PERIPHERALS; std::atomic CPeripheralImon::m_lCountOfImonsConflictWithDInput(0L); -CPeripheralImon::CPeripheralImon(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheralHID(scanResult, bus) +CPeripheralImon::CPeripheralImon(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheralHID(manager, scanResult, bus) { m_features.push_back(FEATURE_IMON); m_bImonConflictsWithDInput = false; diff --git a/xbmc/peripherals/devices/PeripheralImon.h b/xbmc/peripherals/devices/PeripheralImon.h index 267cc45866f48..61d4f2127e6d0 100644 --- a/xbmc/peripherals/devices/PeripheralImon.h +++ b/xbmc/peripherals/devices/PeripheralImon.h @@ -30,7 +30,7 @@ namespace PERIPHERALS class CPeripheralImon : public CPeripheralHID { public: - CPeripheralImon(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralImon(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralImon(void) {} virtual bool InitialiseFeature(const PeripheralFeature feature); virtual void OnSettingChanged(const std::string &strChangedSetting); diff --git a/xbmc/peripherals/devices/PeripheralJoystick.cpp b/xbmc/peripherals/devices/PeripheralJoystick.cpp index 5a44a9b530a36..4ba0dcd37771e 100644 --- a/xbmc/peripherals/devices/PeripheralJoystick.cpp +++ b/xbmc/peripherals/devices/PeripheralJoystick.cpp @@ -33,8 +33,8 @@ using namespace KODI; using namespace JOYSTICK; using namespace PERIPHERALS; -CPeripheralJoystick::CPeripheralJoystick(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheral(scanResult, bus), +CPeripheralJoystick::CPeripheralJoystick(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheral(manager, scanResult, bus), m_requestedPort(JOYSTICK_PORT_UNKNOWN), m_buttonCount(0), m_hatCount(0), @@ -93,7 +93,7 @@ bool CPeripheralJoystick::InitialiseFeature(const PeripheralFeature feature) void CPeripheralJoystick::InitializeDeadzoneFiltering() { // Get a button map for deadzone filtering - PeripheralAddonPtr addon = g_peripherals.GetAddonWithButtonMap(this); + PeripheralAddonPtr addon = m_manager->GetAddonWithButtonMap(this); if (addon) { m_buttonMap.reset(new CAddonButtonMap(this, addon, DEFAULT_CONTROLLER_ID)); diff --git a/xbmc/peripherals/devices/PeripheralJoystick.h b/xbmc/peripherals/devices/PeripheralJoystick.h index 3cf3c32016ef2..2403762c08dd7 100644 --- a/xbmc/peripherals/devices/PeripheralJoystick.h +++ b/xbmc/peripherals/devices/PeripheralJoystick.h @@ -44,11 +44,13 @@ namespace JOYSTICK namespace PERIPHERALS { + class CPeripherals; + class CPeripheralJoystick : public CPeripheral, //! @todo extend CPeripheralHID public KODI::JOYSTICK::IDriverReceiver { public: - CPeripheralJoystick(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralJoystick(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralJoystick(void); diff --git a/xbmc/peripherals/devices/PeripheralJoystickEmulation.cpp b/xbmc/peripherals/devices/PeripheralJoystickEmulation.cpp index 266949b32be5b..dd8f5ac285d68 100644 --- a/xbmc/peripherals/devices/PeripheralJoystickEmulation.cpp +++ b/xbmc/peripherals/devices/PeripheralJoystickEmulation.cpp @@ -28,8 +28,8 @@ using namespace KODI; using namespace PERIPHERALS; -CPeripheralJoystickEmulation::CPeripheralJoystickEmulation(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheral(scanResult, bus) +CPeripheralJoystickEmulation::CPeripheralJoystickEmulation(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheral(manager, scanResult, bus) { m_features.push_back(FEATURE_JOYSTICK); } diff --git a/xbmc/peripherals/devices/PeripheralJoystickEmulation.h b/xbmc/peripherals/devices/PeripheralJoystickEmulation.h index 901aedde90c37..80ca8b1c4c166 100644 --- a/xbmc/peripherals/devices/PeripheralJoystickEmulation.h +++ b/xbmc/peripherals/devices/PeripheralJoystickEmulation.h @@ -29,7 +29,7 @@ namespace PERIPHERALS public KODI::KEYBOARD::IKeyboardHandler { public: - CPeripheralJoystickEmulation(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralJoystickEmulation(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralJoystickEmulation(void); diff --git a/xbmc/peripherals/devices/PeripheralNIC.cpp b/xbmc/peripherals/devices/PeripheralNIC.cpp index ed656dfe56cbf..2ddf1f6943bb9 100644 --- a/xbmc/peripherals/devices/PeripheralNIC.cpp +++ b/xbmc/peripherals/devices/PeripheralNIC.cpp @@ -23,8 +23,8 @@ using namespace PERIPHERALS; -CPeripheralNIC::CPeripheralNIC(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheral(scanResult, bus) +CPeripheralNIC::CPeripheralNIC(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheral(manager, scanResult, bus) { m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35002) : scanResult.m_strDeviceName; m_features.push_back(FEATURE_NIC); diff --git a/xbmc/peripherals/devices/PeripheralNIC.h b/xbmc/peripherals/devices/PeripheralNIC.h index 3427b662b7b81..e335d467538e2 100644 --- a/xbmc/peripherals/devices/PeripheralNIC.h +++ b/xbmc/peripherals/devices/PeripheralNIC.h @@ -26,7 +26,7 @@ namespace PERIPHERALS class CPeripheralNIC : public CPeripheral { public: - CPeripheralNIC(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralNIC(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralNIC(void) {}; }; } diff --git a/xbmc/peripherals/devices/PeripheralNyxboard.cpp b/xbmc/peripherals/devices/PeripheralNyxboard.cpp index ebae9870debcd..b4f85d94b6b5f 100644 --- a/xbmc/peripherals/devices/PeripheralNyxboard.cpp +++ b/xbmc/peripherals/devices/PeripheralNyxboard.cpp @@ -25,8 +25,8 @@ using namespace PERIPHERALS; -CPeripheralNyxboard::CPeripheralNyxboard(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheralHID(scanResult, bus) +CPeripheralNyxboard::CPeripheralNyxboard(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheralHID(manager, scanResult, bus) { m_features.push_back(FEATURE_NYXBOARD); } diff --git a/xbmc/peripherals/devices/PeripheralNyxboard.h b/xbmc/peripherals/devices/PeripheralNyxboard.h index c54d457eae3e2..3c9b2d9d6a848 100644 --- a/xbmc/peripherals/devices/PeripheralNyxboard.h +++ b/xbmc/peripherals/devices/PeripheralNyxboard.h @@ -26,7 +26,7 @@ namespace PERIPHERALS class CPeripheralNyxboard : public CPeripheralHID { public: - CPeripheralNyxboard(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralNyxboard(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralNyxboard(void) {}; virtual bool LookupSymAndUnicode(XBMC_keysym &keysym, uint8_t *key, char *unicode); }; diff --git a/xbmc/peripherals/devices/PeripheralTuner.cpp b/xbmc/peripherals/devices/PeripheralTuner.cpp index 510765ad753e7..5f6e88021361f 100644 --- a/xbmc/peripherals/devices/PeripheralTuner.cpp +++ b/xbmc/peripherals/devices/PeripheralTuner.cpp @@ -22,8 +22,8 @@ using namespace PERIPHERALS; -CPeripheralTuner::CPeripheralTuner(const PeripheralScanResult& scanResult, CPeripheralBus* bus) : - CPeripheral(scanResult, bus) +CPeripheralTuner::CPeripheralTuner(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus) : + CPeripheral(manager, scanResult, bus) { m_features.push_back(FEATURE_TUNER); } diff --git a/xbmc/peripherals/devices/PeripheralTuner.h b/xbmc/peripherals/devices/PeripheralTuner.h index a7efefac95c73..7814587a01b6d 100644 --- a/xbmc/peripherals/devices/PeripheralTuner.h +++ b/xbmc/peripherals/devices/PeripheralTuner.h @@ -26,7 +26,7 @@ namespace PERIPHERALS class CPeripheralTuner : public CPeripheral { public: - CPeripheralTuner(const PeripheralScanResult& scanResult, CPeripheralBus* bus); + CPeripheralTuner(CPeripherals* manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus); virtual ~CPeripheralTuner(void) {}; }; } diff --git a/xbmc/peripherals/dialogs/GUIDialogPeripheralSettings.cpp b/xbmc/peripherals/dialogs/GUIDialogPeripheralSettings.cpp index 0cb723ce00fbf..d6806c950571b 100644 --- a/xbmc/peripherals/dialogs/GUIDialogPeripheralSettings.cpp +++ b/xbmc/peripherals/dialogs/GUIDialogPeripheralSettings.cpp @@ -30,6 +30,7 @@ #include "settings/lib/SettingSection.h" #include "utils/log.h" #include "utils/Variant.h" +#include "ServiceBroker.h" using namespace PERIPHERALS; @@ -91,7 +92,7 @@ void CGUIDialogPeripheralSettings::Save() if (m_item == NULL || m_initialising) return; - PeripheralPtr peripheral = g_peripherals.GetByPath(m_item->GetPath()); + PeripheralPtr peripheral = CServiceBroker::GetPeripherals().GetByPath(m_item->GetPath()); if (!peripheral) return; @@ -103,7 +104,7 @@ void CGUIDialogPeripheralSettings::OnResetSettings() if (m_item == NULL) return; - PeripheralPtr peripheral = g_peripherals.GetByPath(m_item->GetPath()); + PeripheralPtr peripheral = CServiceBroker::GetPeripherals().GetByPath(m_item->GetPath()); if (!peripheral) return; @@ -138,7 +139,7 @@ void CGUIDialogPeripheralSettings::InitializeSettings() m_initialising = true; bool usePopup = g_SkinInfo->HasSkinFile("DialogSlider.xml"); - PeripheralPtr peripheral = g_peripherals.GetByPath(m_item->GetPath()); + PeripheralPtr peripheral = CServiceBroker::GetPeripherals().GetByPath(m_item->GetPath()); if (!peripheral) { CLog::Log(LOGDEBUG, "%s - no peripheral", __FUNCTION__); diff --git a/xbmc/settings/SettingConditions.cpp b/xbmc/settings/SettingConditions.cpp index 0d40886612b0c..c099cf8750331 100644 --- a/xbmc/settings/SettingConditions.cpp +++ b/xbmc/settings/SettingConditions.cpp @@ -32,7 +32,6 @@ #include "cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.h" #include "guilib/LocalizeStrings.h" #include "peripherals/Peripherals.h" -#include "peripherals/bus/virtual/PeripheralBusAddon.h" #include "profiles/ProfilesManager.h" #include "pvr/PVRGUIActions.h" #include "settings/SettingAddon.h" @@ -45,6 +44,7 @@ #if defined(TARGET_DARWIN_OSX) #include "platform/darwin/DarwinUtils.h" #endif// defined(TARGET_DARWIN_OSX) +#include "ServiceBroker.h" bool AddonHasSettings(const std::string &condition, const std::string &value, const CSetting *setting, void *data) { @@ -77,28 +77,22 @@ bool CheckPVRParentalPin(const std::string &condition, const std::string &value, bool HasPeripherals(const std::string &condition, const std::string &value, const CSetting *setting, void *data) { - return PERIPHERALS::g_peripherals.GetNumberOfPeripherals() > 0; + return CServiceBroker::GetPeripherals().GetNumberOfPeripherals() > 0; } bool HasRumbleFeature(const std::string &condition, const std::string &value, const CSetting *setting, void *data) { - using namespace PERIPHERALS; - - return g_peripherals.SupportsFeature(FEATURE_RUMBLE); + return CServiceBroker::GetPeripherals().SupportsFeature(PERIPHERALS::FEATURE_RUMBLE); } bool HasRumbleController(const std::string &condition, const std::string &value, const CSetting *setting, void *data) { - using namespace PERIPHERALS; - - return g_peripherals.HasPeripheralWithFeature(FEATURE_RUMBLE); + return CServiceBroker::GetPeripherals().HasPeripheralWithFeature(PERIPHERALS::FEATURE_RUMBLE); } bool HasPowerOffFeature(const std::string &condition, const std::string &value, const CSetting *setting, void *data) { - using namespace PERIPHERALS; - - return g_peripherals.SupportsFeature(FEATURE_POWER_OFF); + return CServiceBroker::GetPeripherals().SupportsFeature(PERIPHERALS::FEATURE_POWER_OFF); } bool IsFullscreen(const std::string &condition, const std::string &value, const CSetting *setting, void *data) diff --git a/xbmc/settings/Settings.cpp b/xbmc/settings/Settings.cpp index a058dcc2d3c06..85cfc64297fde 100644 --- a/xbmc/settings/Settings.cpp +++ b/xbmc/settings/Settings.cpp @@ -85,6 +85,7 @@ #include "utils/Variant.h" #include "view/ViewStateSettings.h" #include "input/InputManager.h" +#include "ServiceBroker.h" #define SETTINGS_XML_FOLDER "special://xbmc/system/settings/" #define SETTINGS_XML_ROOT "settings" @@ -1183,7 +1184,7 @@ void CSettings::InitializeISettingCallbacks() settingSet.insert(CSettings::SETTING_INPUT_CONTROLLERCONFIG); settingSet.insert(CSettings::SETTING_INPUT_TESTRUMBLE); settingSet.insert(CSettings::SETTING_LOCALE_LANGUAGE); - m_settingsManager->RegisterCallback(&PERIPHERALS::CPeripherals::GetInstance(), settingSet); + m_settingsManager->RegisterCallback(&CServiceBroker::GetPeripherals(), settingSet); #if defined(TARGET_DARWIN_OSX) settingSet.clear(); @@ -1244,7 +1245,7 @@ void CSettings::UninitializeISettingCallbacks() m_settingsManager->UnregisterCallback(&g_timezone); #endif // defined(TARGET_LINUX) m_settingsManager->UnregisterCallback(&g_weatherManager); - m_settingsManager->UnregisterCallback(&PERIPHERALS::CPeripherals::GetInstance()); + m_settingsManager->UnregisterCallback(&CServiceBroker::GetPeripherals()); #if defined(TARGET_DARWIN_OSX) m_settingsManager->UnregisterCallback(&XBMCHelper::GetInstance()); #endif diff --git a/xbmc/windowing/WinEvents.cpp b/xbmc/windowing/WinEvents.cpp index 7688fcaf47d5d..d7fa9a261fd72 100644 --- a/xbmc/windowing/WinEvents.cpp +++ b/xbmc/windowing/WinEvents.cpp @@ -21,6 +21,7 @@ #include "WinEvents.h" #include "peripherals/Peripherals.h" #include "threads/SingleLock.h" +#include "ServiceBroker.h" #if defined(TARGET_WINDOWS) #include "windows/WinEventsWin32.h" @@ -64,7 +65,7 @@ void Init() CSingleLock lock(g_lock); if (!g_init) { - PERIPHERALS::CPeripherals::GetInstance().RegisterObserver(&g_imp); + CServiceBroker::GetPeripherals().RegisterObserver(&g_imp); g_init = true; } } diff --git a/xbmc/windowing/windows/WinEventsWin32.cpp b/xbmc/windowing/windows/WinEventsWin32.cpp index fe5f031180ecf..77bed1c27ce26 100644 --- a/xbmc/windowing/windows/WinEventsWin32.cpp +++ b/xbmc/windowing/windows/WinEventsWin32.cpp @@ -53,7 +53,6 @@ #ifdef TARGET_WINDOWS -using namespace PERIPHERALS; using namespace KODI::MESSAGING; HWND g_hWnd = NULL; @@ -794,13 +793,13 @@ LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, L switch(wParam) { case DBT_DEVNODES_CHANGED: - g_peripherals.TriggerDeviceScan(PERIPHERAL_BUS_USB); + CServiceBroker::GetPeripherals().TriggerDeviceScan(PERIPHERAL_BUS_USB); break; case DBT_DEVICEARRIVAL: case DBT_DEVICEREMOVECOMPLETE: if (((_DEV_BROADCAST_HEADER*) lParam)->dbcd_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { - g_peripherals.TriggerDeviceScan(PERIPHERAL_BUS_USB); + CServiceBroker::GetPeripherals().TriggerDeviceScan(PERIPHERAL_BUS_USB); } // check if an usb or optical media was inserted or removed if (((_DEV_BROADCAST_HEADER*) lParam)->dbcd_devicetype == DBT_DEVTYP_VOLUME)