aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Brown <themagnificentmrb@gmail.com>2018-01-09 15:06:06 -0800
committerGarrett Brown <themagnificentmrb@gmail.com>2018-01-09 19:34:57 -0800
commit4bf2362a2c3a45dccc6c740859d0702a6ca11855 (patch)
treee1b8ee7e8b1277163036c118b29b69c24aafa775
parent007dba87c3f42106f7ccbaea809e9efca4430363 (diff)
Peripherals: Replace use of global game controller manager
-rw-r--r--xbmc/ServiceManager.cpp3
-rw-r--r--xbmc/peripherals/Peripherals.cpp4
-rw-r--r--xbmc/peripherals/Peripherals.h14
-rw-r--r--xbmc/peripherals/addons/PeripheralAddon.cpp66
-rw-r--r--xbmc/peripherals/addons/PeripheralAddon.h13
-rw-r--r--xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp2
6 files changed, 75 insertions, 27 deletions
diff --git a/xbmc/ServiceManager.cpp b/xbmc/ServiceManager.cpp
index bb8988737e..7ab9254234 100644
--- a/xbmc/ServiceManager.cpp
+++ b/xbmc/ServiceManager.cpp
@@ -140,7 +140,8 @@ bool CServiceManager::InitStageTwo(const CAppParamParser &params)
m_inputManager->InitializeInputs();
m_peripherals.reset(new PERIPHERALS::CPeripherals(*m_announcementManager,
- *m_inputManager));
+ *m_inputManager,
+ *m_gameControllerManager));
m_gameRenderManager.reset(new RETRO::CGUIGameRenderManager);
diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp
index 696e60f12a..b6069a16a4 100644
--- a/xbmc/peripherals/Peripherals.cpp
+++ b/xbmc/peripherals/Peripherals.cpp
@@ -78,9 +78,11 @@ using namespace XFILE;
using namespace KODI::MESSAGING;
CPeripherals::CPeripherals(ANNOUNCEMENT::CAnnouncementManager &announcements,
- CInputManager &inputManager) :
+ CInputManager &inputManager,
+ GAME::CControllerManager &controllerProfiles) :
m_announcements(announcements),
m_inputManager(inputManager),
+ m_controllerProfiles(controllerProfiles),
m_eventScanner(this)
{
// Register settings
diff --git a/xbmc/peripherals/Peripherals.h b/xbmc/peripherals/Peripherals.h
index 2dc1c93b73..b298e90ea2 100644
--- a/xbmc/peripherals/Peripherals.h
+++ b/xbmc/peripherals/Peripherals.h
@@ -42,6 +42,11 @@ class CKey;
namespace KODI
{
+namespace GAME
+{
+ class CControllerManager;
+}
+
namespace JOYSTICK
{
class IButtonMapper;
@@ -63,7 +68,8 @@ namespace PERIPHERALS
{
public:
explicit CPeripherals(ANNOUNCEMENT::CAnnouncementManager &announcements,
- CInputManager &inputManager);
+ CInputManager &inputManager,
+ KODI::GAME::CControllerManager &controllerProfiles);
~CPeripherals() override;
@@ -320,6 +326,11 @@ namespace PERIPHERALS
*/
CInputManager &GetInputManager() { return m_inputManager; }
+ /*!
+ * \brief Access controller profiles through the construction parameter
+ */
+ KODI::GAME::CControllerManager &GetControllerProfiles() { return m_controllerProfiles; }
+
private:
bool LoadMappings();
bool GetMappingForDevice(const CPeripheralBus &bus, PeripheralScanResult& result) const;
@@ -330,6 +341,7 @@ namespace PERIPHERALS
// Construction parameters
ANNOUNCEMENT::CAnnouncementManager &m_announcements;
CInputManager &m_inputManager;
+ KODI::GAME::CControllerManager &m_controllerProfiles;
#if !defined(HAVE_LIBCEC)
bool m_bMissingLibCecWarningDisplayed = false;
diff --git a/xbmc/peripherals/addons/PeripheralAddon.cpp b/xbmc/peripherals/addons/PeripheralAddon.cpp
index 2c86968f51..f89308aa14 100644
--- a/xbmc/peripherals/addons/PeripheralAddon.cpp
+++ b/xbmc/peripherals/addons/PeripheralAddon.cpp
@@ -20,7 +20,6 @@
#include "PeripheralAddon.h"
#include "PeripheralAddonTranslator.h"
-#include "ServiceBroker.h"
#include "AddonButtonMap.h"
#include "PeripheralAddonTranslator.h"
#include "addons/AddonManager.h"
@@ -58,8 +57,9 @@ using namespace XFILE;
#define SAFE_DELETE(p) do { delete (p); (p) = NULL; } while (0)
#endif
-CPeripheralAddon::CPeripheralAddon(const ADDON::BinaryAddonBasePtr& addonInfo)
+CPeripheralAddon::CPeripheralAddon(const ADDON::BinaryAddonBasePtr& addonInfo, CPeripherals &manager)
: IAddonInstanceHandler(ADDON_INSTANCE_PERIPHERAL, addonInfo),
+ m_manager(manager),
m_bSupportsJoystickRumble(false),
m_bSupportsJoystickPowerOff(false)
{
@@ -774,6 +774,39 @@ void CPeripheralAddon::RefreshButtonMaps(const std::string& strDeviceName /* = "
}
}
+void CPeripheralAddon::TriggerDeviceScan()
+{
+ m_manager.TriggerDeviceScan(PERIPHERAL_BUS_ADDON);
+}
+
+unsigned int CPeripheralAddon::FeatureCount(const std::string &controllerId, JOYSTICK_FEATURE_TYPE type) const
+{
+ using namespace GAME;
+
+ unsigned int count = 0;
+
+ CControllerManager& controllerProfiles = m_manager.GetControllerProfiles();
+ ControllerPtr controller = controllerProfiles.GetController(controllerId);
+ if (controller)
+ count = controller->FeatureCount(CPeripheralAddonTranslator::TranslateFeatureType(type));
+
+ return count;
+}
+
+JOYSTICK_FEATURE_TYPE CPeripheralAddon::FeatureType(const std::string &controllerId, const std::string &featureName) const
+{
+ using namespace GAME;
+
+ JOYSTICK_FEATURE_TYPE type = JOYSTICK_FEATURE_TYPE_UNKNOWN;
+
+ CControllerManager& controllerProfiles = m_manager.GetControllerProfiles();
+ ControllerPtr controller = controllerProfiles.GetController(controllerId);
+ if (controller)
+ type = CPeripheralAddonTranslator::TranslateFeatureType(controller->FeatureType(featureName));
+
+ return type;
+}
+
void CPeripheralAddon::GetPeripheralInfo(const CPeripheral* device, kodi::addon::Peripheral& peripheralInfo)
{
peripheralInfo.SetType(CPeripheralAddonTranslator::TranslateType(device->Type()));
@@ -855,7 +888,10 @@ std::string CPeripheralAddon::GetProvider(PeripheralType type)
void CPeripheralAddon::cb_trigger_scan(void* kodiInstance)
{
- CServiceBroker::GetPeripherals().TriggerDeviceScan(PERIPHERAL_BUS_ADDON);
+ if (kodiInstance == nullptr)
+ return;
+
+ static_cast<CPeripheralAddon*>(kodiInstance)->TriggerDeviceScan();
}
void CPeripheralAddon::cb_refresh_button_maps(void* kodiInstance, const char* deviceName, const char* controllerId)
@@ -868,28 +904,16 @@ void CPeripheralAddon::cb_refresh_button_maps(void* kodiInstance, const char* de
unsigned int CPeripheralAddon::cb_feature_count(void* kodiInstance, const char* controllerId, JOYSTICK_FEATURE_TYPE type)
{
- using namespace GAME;
+ if (kodiInstance == nullptr || controllerId == nullptr)
+ return 0;
- unsigned int count = 0;
-
- CControllerManager& controllerManager = CServiceBroker::GetGameControllerManager();
- ControllerPtr controller = controllerManager.GetController(controllerId);
- if (controller)
- count = controller->FeatureCount(CPeripheralAddonTranslator::TranslateFeatureType(type));
-
- return count;
+ return static_cast<CPeripheralAddon*>(kodiInstance)->FeatureCount(controllerId, type);
}
JOYSTICK_FEATURE_TYPE CPeripheralAddon::cb_feature_type(void* kodiInstance, const char* controllerId, const char* featureName)
{
- using namespace GAME;
-
- JOYSTICK_FEATURE_TYPE type = JOYSTICK_FEATURE_TYPE::JOYSTICK_FEATURE_TYPE_UNKNOWN;
+ if (kodiInstance == nullptr || controllerId == nullptr || featureName == nullptr)
+ return JOYSTICK_FEATURE_TYPE_UNKNOWN;
- CControllerManager& controllerManager = CServiceBroker::GetGameControllerManager();
- ControllerPtr controller = controllerManager.GetController(controllerId);
- if (controller)
- type = CPeripheralAddonTranslator::TranslateFeatureType(controller->FeatureType(featureName));
-
- return type;
+ return static_cast<CPeripheralAddon*>(kodiInstance)->FeatureType(controllerId, featureName);
}
diff --git a/xbmc/peripherals/addons/PeripheralAddon.h b/xbmc/peripherals/addons/PeripheralAddon.h
index 8b825d8a2c..476d07b65e 100644
--- a/xbmc/peripherals/addons/PeripheralAddon.h
+++ b/xbmc/peripherals/addons/PeripheralAddon.h
@@ -45,6 +45,7 @@ namespace PERIPHERALS
{
class CPeripheral;
class CPeripheralJoystick;
+ class CPeripherals;
typedef std::vector<kodi::addon::DriverPrimitive> PrimitiveVector;
typedef std::map<KODI::JOYSTICK::FeatureName, kodi::addon::JoystickFeature> FeatureMap;
@@ -52,7 +53,7 @@ namespace PERIPHERALS
class CPeripheralAddon : public ADDON::IAddonInstanceHandler
{
public:
- explicit CPeripheralAddon(const ADDON::BinaryAddonBasePtr& addonInfo);
+ explicit CPeripheralAddon(const ADDON::BinaryAddonBasePtr& addonInfo, CPeripherals &manager);
~CPeripheralAddon(void) override;
/*!
@@ -100,7 +101,6 @@ namespace PERIPHERALS
void RegisterButtonMap(CPeripheral* device, KODI::JOYSTICK::IButtonMap* buttonMap);
void UnregisterButtonMap(KODI::JOYSTICK::IButtonMap* buttonMap);
- void RefreshButtonMaps(const std::string& strDeviceName = "");
static inline bool ProvidesJoysticks(const ADDON::BinaryAddonBasePtr& addonInfo)
{
@@ -115,6 +115,12 @@ namespace PERIPHERALS
private:
void UnregisterButtonMap(CPeripheral* device);
+ // Binary add-on callbacks
+ void TriggerDeviceScan();
+ void RefreshButtonMaps(const std::string& strDeviceName = "");
+ unsigned int FeatureCount(const std::string &controllerId, JOYSTICK_FEATURE_TYPE type) const;
+ JOYSTICK_FEATURE_TYPE FeatureType(const std::string &controllerId, const std::string &featureName) const;
+
/*!
* @brief Helper functions
*/
@@ -138,6 +144,9 @@ namespace PERIPHERALS
static std::string GetDeviceName(PeripheralType type);
static std::string GetProvider(PeripheralType type);
+ // Construction parameters
+ CPeripherals &m_manager;
+
/* @brief Cache for const char* members in PERIPHERAL_PROPERTIES */
std::string m_strUserPath; /*!< @brief translated path to the user profile */
std::string m_strClientPath; /*!< @brief translated path to this add-on */
diff --git a/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp b/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp
index f980fe290b..d81062d641 100644
--- a/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp
+++ b/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp
@@ -417,7 +417,7 @@ void CPeripheralBusAddon::UpdateAddons(void)
BinaryAddonBaseList::iterator it = std::find_if(newAddons.begin(), newAddons.end(), GetAddon);
if (it != newAddons.end())
{
- PeripheralAddonPtr newAddon = std::make_shared<CPeripheralAddon>(*it);
+ PeripheralAddonPtr newAddon = std::make_shared<CPeripheralAddon>(*it, m_manager);
if (newAddon)
{
bool bCreated;