Skip to content

Commit

Permalink
[Peripherals] Move g_peripherals to ServiceManager
Browse files Browse the repository at this point in the history
  • Loading branch information
garbear committed Mar 8, 2017
1 parent f89abd3 commit 398ff74
Show file tree
Hide file tree
Showing 52 changed files with 166 additions and 139 deletions.
14 changes: 4 additions & 10 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand All @@ -4744,7 +4738,7 @@ void CApplication::SetMute(bool mute)

void CApplication::Mute()
{
if (g_peripherals.Mute())
if (CServiceBroker::GetPeripherals().Mute())
return;

CAEFactory::SetMute(true);
Expand All @@ -4754,7 +4748,7 @@ void CApplication::Mute()

void CApplication::UnMute()
{
if (g_peripherals.UnMute())
if (CServiceBroker::GetPeripherals().UnMute())
return;

CAEFactory::SetMute(false);
Expand Down
5 changes: 5 additions & 0 deletions xbmc/ServiceBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions xbmc/ServiceBroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ namespace GAME
class CGameServices;
}

namespace PERIPHERALS
{
class CPeripherals;
}

class CServiceBroker
{
public:
Expand All @@ -68,5 +73,6 @@ class CServiceBroker
static PLAYLIST::CPlayListPlayer& GetPlaylistPlayer();
static CSettings& GetSettings();
static GAME::CGameServices& GetGameServices();
static PERIPHERALS::CPeripherals& GetPeripherals();
static bool IsBinaryAddonCacheUp();
};
12 changes: 11 additions & 1 deletion xbmc/ServiceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
{
}

Expand Down Expand Up @@ -81,6 +83,8 @@ bool CServiceManager::Init2()

m_contextMenuManager.reset(new CContextMenuManager(*m_addonMgr.get()));

m_peripherals->Initialise();

init_level = 2;
return true;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down
7 changes: 7 additions & 0 deletions xbmc/ServiceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ namespace GAME
class CGameServices;
}

namespace PERIPHERALS
{
class CPeripherals;
}

class CServiceManager
{
public:
Expand All @@ -83,6 +88,7 @@ class CServiceManager
*/
CPlatform& GetPlatform();
GAME::CGameServices& GetGameServices();
PERIPHERALS::CPeripherals& GetPeripherals();

PLAYLIST::CPlayListPlayer& GetPlaylistPlayer();
int init_level = 0;
Expand Down Expand Up @@ -114,4 +120,5 @@ class CServiceManager
std::unique_ptr<PLAYLIST::CPlayListPlayer> m_playlistPlayer;
std::unique_ptr<CSettings> m_settings;
std::unique_ptr<GAME::CGameServices> m_gameServices;
std::unique_ptr<PERIPHERALS::CPeripherals> m_peripherals;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion xbmc/dialogs/GUIDialogKaiToast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion xbmc/games/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "settings/lib/Setting.h"
#include "settings/Settings.h"
#include "utils/StringUtils.h"
#include "ServiceBroker.h"

#include <cstring>

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/addons/GameClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 7 additions & 12 deletions xbmc/games/controllers/dialogs/GUIDialogButtonCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "input/ActionIDs.h"
#include "peripherals/Peripherals.h"
#include "utils/Variant.h"
#include "ServiceBroker.h"

#include <algorithm>
#include <iterator>
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 7 additions & 12 deletions xbmc/games/controllers/windows/GUIConfigurationWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/controllers/windows/GUIControllerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void CGUIControllerList::ResetController(void)
if (!CGUIDialogYesNo::ShowAndGetInput(35060, 35061))
return;

PERIPHERALS::g_peripherals.ResetButtonMaps(strControllerId);
CServiceBroker::GetPeripherals().ResetButtonMaps(strControllerId);
}
}

Expand Down
5 changes: 2 additions & 3 deletions xbmc/games/controllers/windows/GUIControllerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -204,8 +205,6 @@ void CGUIControllerWindow::OnEvent(const ADDON::CRepositoryUpdater::RepositoryUp

void CGUIControllerWindow::OnInitWindow(void)
{
using namespace PERIPHERALS;

CGUIDialog::OnInitWindow();

if (!m_featureList)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions xbmc/games/ports/PortMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
#include "peripherals/devices/Peripheral.h"
#include "peripherals/Peripherals.h"

#include <assert.h>

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);
}

Expand All @@ -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<PeripheralPtr, IInputHandler*> newPortMap;
CPortManager::GetInstance().MapDevices(devices, newPortMap);
Expand Down
Loading

0 comments on commit 398ff74

Please sign in to comment.