diff --git a/xbmc/AppParamParser.cpp b/xbmc/AppParamParser.cpp index 064671e9f4c52..08f4dad468b12 100644 --- a/xbmc/AppParamParser.cpp +++ b/xbmc/AppParamParser.cpp @@ -26,12 +26,10 @@ #include "settings/AdvancedSettings.h" #include "utils/log.h" #include "utils/StringUtils.h" +#include "input/InputManager.h" #ifdef TARGET_WINDOWS #include "WIN32Util.h" #endif -#ifdef HAS_LIRC -#include "input/linux/LIRC.h" -#endif #ifndef TARGET_WINDOWS #include "linux/XTimeUtils.h" #endif @@ -49,23 +47,22 @@ void CAppParamParser::Parse(const char* argv[], int nArgs) for (int i = 1; i < nArgs; i++) { ParseArg(argv[i]); -#ifdef HAS_LIRC if (strnicmp(argv[i], "-l", 2) == 0 || strnicmp(argv[i], "--lircdev", 9) == 0) { // check the next arg with the proper value. - int next=i+1; + int next = i + 1; if (next < nArgs) { - if ((argv[next][0] != '-' ) && (argv[next][0] == '/' )) + if ((argv[next][0] != '-') && (argv[next][0] == '/')) { - g_RemoteControl.setDeviceName(argv[next]); + CInputManager::Get().SetRemoteControlName(argv[next]); i++; } } } else if (strnicmp(argv[i], "-n", 2) == 0 || strnicmp(argv[i], "--nolirc", 8) == 0) - g_RemoteControl.setUsed(false); -#endif + CInputManager::Get().DisableRemoteControl(); + if (stricmp(argv[i], "-d") == 0) { if (i + 1 < nArgs) diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 7c32f3c164f79..396a324343506 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -237,13 +237,6 @@ #include "XHandle.h" #endif -#ifdef HAS_LIRC -#include "input/linux/LIRC.h" -#endif -#ifdef HAS_IRSERVERSUITE - #include "input/windows/IRServerSuite.h" -#endif - #if defined(TARGET_ANDROID) #include "android/activity/XBMCApp.h" #include "android/activity/AndroidFeatures.h" @@ -727,16 +720,11 @@ bool CApplication::Create() CLog::Log(LOGFATAL, "CApplication::Create: Unable to start CAddonMgr"); return false; } -#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) - g_RemoteControl.Initialize(); -#endif g_peripherals.Initialise(); // Create the Mouse, Keyboard, Remote, and Joystick devices // Initialize after loading settings to get joystick deadzone setting - - CInputManager::Get().InitializeInputs(); #if defined(TARGET_DARWIN_OSX) @@ -2474,16 +2462,8 @@ void CApplication::FrameMove(bool processEvents, bool processGUI) } CWinEvents::MessagePump(); -#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) - // Read the input from a remote - g_RemoteControl.Update(); -#endif + CInputManager::Get().Process(g_windowManager.GetActiveWindowID(), frameTime); - // process input actions - CInputManager::Get().ProcessRemote(g_windowManager.GetActiveWindowID()); - CInputManager::Get().ProcessGamepad(g_windowManager.GetActiveWindowID()); - CInputManager::Get().ProcessEventServer(g_windowManager.GetActiveWindowID(), frameTime); - CInputManager::Get().ProcessPeripherals(frameTime); if (processGUI && m_renderGUI) { m_pInertialScrollingHandler->ProcessInertialScroll(frameTime); @@ -2508,10 +2488,8 @@ bool CApplication::Cleanup() CAddonMgr::Get().DeInit(); -#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) CLog::Log(LOGNOTICE, "closing down remote control service"); - g_RemoteControl.Disconnect(); -#endif + CInputManager::Get().DisableRemoteControl(); CLog::Log(LOGNOTICE, "unload sections"); @@ -4323,10 +4301,7 @@ void CApplication::ProcessSlow() g_mediaManager.ProcessEvents(); -#ifdef HAS_LIRC - if (g_RemoteControl.IsInUse() && !g_RemoteControl.IsInitialized()) - g_RemoteControl.Initialize(); -#endif + CInputManager::Get().EnableRemoteControl(); if (!m_pPlayer->IsPlayingVideo() && CSettings::Get().GetInt("general.addonupdates") != AUTO_UPDATES_NEVER) diff --git a/xbmc/cores/ExternalPlayer/ExternalPlayer.cpp b/xbmc/cores/ExternalPlayer/ExternalPlayer.cpp index afc1206f0f78f..52e15be6d8d7e 100644 --- a/xbmc/cores/ExternalPlayer/ExternalPlayer.cpp +++ b/xbmc/cores/ExternalPlayer/ExternalPlayer.cpp @@ -39,15 +39,10 @@ #include "utils/TimeUtils.h" #include "utils/log.h" #include "cores/AudioEngine/AEFactory.h" +#include "input/InputManager.h" #if defined(TARGET_WINDOWS) #include "utils/CharsetConverter.h" #include "Windows.h" - #ifdef HAS_IRSERVERSUITE - #include "input/windows/IRServerSuite.h" - #endif -#endif -#if defined(HAS_LIRC) - #include "input/linux/LIRC.h" #endif #if defined(TARGET_ANDROID) #include "android/activity/XBMCApp.h" @@ -466,18 +461,14 @@ BOOL CExternalPlayer::ExecuteAppW32(const char* strPath, const char* strSwitches BOOL CExternalPlayer::ExecuteAppLinux(const char* strSwitches) { CLog::Log(LOGNOTICE, "%s: %s", __FUNCTION__, strSwitches); -#ifdef HAS_LIRC - bool remoteused = g_RemoteControl.IsInUse(); - g_RemoteControl.Disconnect(); - g_RemoteControl.setUsed(false); -#endif + + bool remoteUsed = CInputManager::Get().IsRemoteControlEnabled(); + CInputManager::Get().DisableRemoteControl(); int ret = system(strSwitches); -#ifdef HAS_LIRC - g_RemoteControl.setUsed(remoteused); - g_RemoteControl.Initialize(); -#endif + if (remoteUsed) + CInputManager::Get().EnableRemoteControl(); if (ret != 0) { diff --git a/xbmc/input/InputManager.cpp b/xbmc/input/InputManager.cpp index 5e2ebc915cab0..0efb501168670 100644 --- a/xbmc/input/InputManager.cpp +++ b/xbmc/input/InputManager.cpp @@ -83,6 +83,10 @@ CInputManager& CInputManager::Get() void CInputManager::InitializeInputs() { +#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) + m_RemoteControl.Initialize(); +#endif + #ifdef HAS_SDL_JOYSTICK // Pass the mapping of axis to triggers to m_Joystick m_Joystick.Initialize(); @@ -206,10 +210,10 @@ bool CInputManager::ProcessGamepad(int windowId) bool CInputManager::ProcessRemote(int windowId) { #if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) - if (g_RemoteControl.GetButton()) + if (m_RemoteControl.GetButton()) { - CKey key(g_RemoteControl.GetButton(), g_RemoteControl.GetHoldTime()); - g_RemoteControl.Reset(); + CKey key(m_RemoteControl.GetButton(), m_RemoteControl.GetHoldTime()); + m_RemoteControl.Reset(); return OnKey(key); } #endif @@ -393,6 +397,22 @@ bool CInputManager::ProcessEventServer(int windowId, float frameTime) return false; } +bool CInputManager::Process(int windowId, float frameTime) +{ +#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) + // Read the input from a remote + m_RemoteControl.Update(); +#endif + + // process input actions + ProcessRemote(windowId); + ProcessGamepad(windowId); + ProcessEventServer(windowId, frameTime); + ProcessPeripherals(frameTime); + + return true; +} + bool CInputManager::ProcessJoystickEvent(int windowId, const std::string& joystickName, int wKeyID, short inputType, float fAmount, unsigned int holdTime /*=0*/) { #if defined(HAS_EVENT_SERVER) @@ -666,6 +686,36 @@ bool CInputManager::ExecuteInputAction(const CAction &action) return bResult; } +int CInputManager::ExecuteBuiltin(const std::string& execute, const std::vector& params) +{ +#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) + if (execute == "lirc.stop") + { + m_RemoteControl.Disconnect(); + m_RemoteControl.setUsed(false); + } + else if (execute == "lirc.start") + { + m_RemoteControl.setUsed(true); + m_RemoteControl.Initialize(); + } + else if (execute == "lirc.send") + { + std::string command; + for (int i = 0; i < (int)params.size(); i++) + { + command += params[i]; + if (i < (int)params.size() - 1) + command += ' '; + } + m_RemoteControl.AddSendCommand(command); + } + else + return -1; +#endif + return 0; +} + void CInputManager::SetMouseActive(bool active /* = true */) { m_Mouse.SetActive(active); @@ -700,3 +750,36 @@ void CInputManager::SetMouseState(MOUSE_STATE mouseState) { m_Mouse.SetState(mouseState); } + +bool CInputManager::IsRemoteControlEnabled() +{ +#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) + return m_RemoteControl.IsInUse(); +#else + return false; +#endif +} + +void CInputManager::EnableRemoteControl() +{ +#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) + m_RemoteControl.setUsed(true); + if (!m_RemoteControl.IsInitialized()) + m_RemoteControl.Initialize(); +#endif +} + +void CInputManager::DisableRemoteControl() +{ +#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) + m_RemoteControl.Disconnect(); + m_RemoteControl.setUsed(false); +#endif +} + +void CInputManager::SetRemoteControlName(const std::string& name) +{ +#if defined(HAS_LIRC) + m_RemoteControl.setDeviceName(name); +#endif +} diff --git a/xbmc/input/InputManager.h b/xbmc/input/InputManager.h index d86fbf9ababfd..a2e75128f8289 100644 --- a/xbmc/input/InputManager.h +++ b/xbmc/input/InputManager.h @@ -21,12 +21,20 @@ #include #include +#include #if defined(TARGET_WINDOWS) #include "input/windows/WINJoystick.h" #elif defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER) #include "input/SDLJoystick.h" #endif +#if defined(HAS_LIRC) +#include "input/linux/LIRC.h" +#endif +#if defined(HAS_IRSERVERSUITE) +#include "input/windows/IRServerSuite.h" +#endif + #include "windowing/XBMC_events.h" #include "guilib/Key.h" #include "input/KeyboardStat.h" @@ -83,6 +91,14 @@ class CInputManager */ bool ProcessPeripherals(float frameTime); + /*! \brief Process all inputs + * + * \param windowId Currently active window + * \param frameTime Time in seconds since last call + * \return true on success, false otherwise + */ + bool Process(int windowId, float frameTime); + /*! * \brief Call once during application startup to initialize peripherals that need it */ @@ -164,6 +180,38 @@ class CInputManager */ void SetMouseResolution(int maxX, int maxY, float speedX, float speedY); + /*! \brief Enable the remote control + * + */ + void EnableRemoteControl(); + + /*! \brief Disable the remote control + * + */ + void DisableRemoteControl(); + + /*! \brief Check if the remote control is enabled + * + * \return true if remote control is enabled, false otherwise + */ + bool IsRemoteControlEnabled(); + + /*! \brief Set the device name to use with LIRC, does nothing + * if IRServerSuite is used + * + * \param[in] name Name of the device to use with LIRC + */ + void SetRemoteControlName(const std::string& name); + + /*! \brief Parse a builtin command and execute any input action + * currently only LIRC commands implemented + * + * \param[in] execute Command to execute + * \param[in] params parameters that was passed to the command + * \return 0 on success, -1 on failure + */ + int ExecuteBuiltin(const std::string& execute, const std::vector& params); + private: /*! \brief Process keyboard event and translate into an action @@ -195,6 +243,10 @@ class CInputManager CKeyboardStat m_Keyboard; CMouseStat m_Mouse; +#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) + CRemoteControl m_RemoteControl; +#endif + #ifdef HAS_EVENT_SERVER std::map > m_lastAxisMap; #endif diff --git a/xbmc/input/linux/LIRC.cpp b/xbmc/input/linux/LIRC.cpp index e167d06171bbb..526dfc645f1a3 100644 --- a/xbmc/input/linux/LIRC.cpp +++ b/xbmc/input/linux/LIRC.cpp @@ -37,8 +37,6 @@ #include "settings/AdvancedSettings.h" #include "utils/TimeUtils.h" -CRemoteControl g_RemoteControl; - CRemoteControl::CRemoteControl(): m_deviceName(LIRC_DEVICE) { diff --git a/xbmc/input/linux/LIRC.h b/xbmc/input/linux/LIRC.h index 386a353b8f11d..7d47edd49d676 100644 --- a/xbmc/input/linux/LIRC.h +++ b/xbmc/input/linux/LIRC.h @@ -65,6 +65,4 @@ class CRemoteControl int m_nrSending; }; -extern CRemoteControl g_RemoteControl; - #endif diff --git a/xbmc/input/windows/IRServerSuite.cpp b/xbmc/input/windows/IRServerSuite.cpp index efa0351a6ef29..33fb8a2c11ddb 100644 --- a/xbmc/input/windows/IRServerSuite.cpp +++ b/xbmc/input/windows/IRServerSuite.cpp @@ -29,8 +29,6 @@ #define IRSS_PORT 24000 -CRemoteControl g_RemoteControl; - CRemoteControl::CRemoteControl() : CThread("RemoteControl") { m_socket = INVALID_SOCKET; @@ -75,7 +73,8 @@ void CRemoteControl::Reset() void CRemoteControl::Initialize() { - if (m_isConnecting || m_bInitialized) return; + if (m_isConnecting || m_bInitialized || IsRunning()) + return; //trying to connect when there is nothing to connect to is kinda slow so kick it off in a thread. Create(); } diff --git a/xbmc/input/windows/IRServerSuite.h b/xbmc/input/windows/IRServerSuite.h index a310665c3a25e..d227a3876e4d7 100644 --- a/xbmc/input/windows/IRServerSuite.h +++ b/xbmc/input/windows/IRServerSuite.h @@ -62,5 +62,3 @@ class CRemoteControl : CThread bool HandleRemoteEvent(CIrssMessage& message); }; - -extern CRemoteControl g_RemoteControl; diff --git a/xbmc/interfaces/Builtins.cpp b/xbmc/interfaces/Builtins.cpp index 07108e4273056..8d0a0c633eaac 100644 --- a/xbmc/interfaces/Builtins.cpp +++ b/xbmc/interfaces/Builtins.cpp @@ -27,6 +27,7 @@ #include "Autorun.h" #include "Builtins.h" #include "input/ButtonTranslator.h" +#include "input/InputManager.h" #include "FileItem.h" #include "addons/GUIDialogAddonSettings.h" #include "dialogs/GUIDialogFileBrowser.h" @@ -1772,29 +1773,6 @@ int CBuiltins::Execute(const std::string& execString) { CApplicationMessenger::Get().CECStandby(); } -#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) - else if (execute == "lirc.stop") - { - g_RemoteControl.Disconnect(); - g_RemoteControl.setUsed(false); - } - else if (execute == "lirc.start") - { - g_RemoteControl.setUsed(true); - g_RemoteControl.Initialize(); - } - else if (execute == "lirc.send") - { - std::string command; - for (int i = 0; i < (int)params.size(); i++) - { - command += params[i]; - if (i < (int)params.size() - 1) - command += ' '; - } - g_RemoteControl.AddSendCommand(command); - } -#endif else if (execute == "weather.locationset" && !params.empty()) { int loc = atoi(params[0].c_str()); @@ -1851,6 +1829,6 @@ int CBuiltins::Execute(const std::string& execString) } } else - return -1; + return CInputManager::Get().ExecuteBuiltin(execute, params); return 0; }