Skip to content

Commit

Permalink
Encapsulated g_RemoteControl in CInputManager.
Browse files Browse the repository at this point in the history
Removed several ifdefs from callers and hid it inside inputmanager
  • Loading branch information
Paxxi committed Mar 2, 2015
1 parent 80d6110 commit 0c15ffe
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 88 deletions.
15 changes: 6 additions & 9 deletions xbmc/AppParamParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
31 changes: 3 additions & 28 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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");

Expand Down Expand Up @@ -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)
Expand Down
21 changes: 6 additions & 15 deletions xbmc/cores/ExternalPlayer/ExternalPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down
89 changes: 86 additions & 3 deletions xbmc/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -666,6 +686,36 @@ bool CInputManager::ExecuteInputAction(const CAction &action)
return bResult;
}

int CInputManager::ExecuteBuiltin(const std::string& execute, const std::vector<std::string>& 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);
Expand Down Expand Up @@ -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
}
52 changes: 52 additions & 0 deletions xbmc/input/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@

#include <map>
#include <string>
#include <vector>

#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"
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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<std::string>& params);

private:

/*! \brief Process keyboard event and translate into an action
Expand Down Expand Up @@ -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<std::string, std::map<int, float> > m_lastAxisMap;
#endif
Expand Down
2 changes: 0 additions & 2 deletions xbmc/input/linux/LIRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#include "settings/AdvancedSettings.h"
#include "utils/TimeUtils.h"

CRemoteControl g_RemoteControl;

CRemoteControl::CRemoteControl():
m_deviceName(LIRC_DEVICE)
{
Expand Down
2 changes: 0 additions & 2 deletions xbmc/input/linux/LIRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,4 @@ class CRemoteControl
int m_nrSending;
};

extern CRemoteControl g_RemoteControl;

#endif
5 changes: 2 additions & 3 deletions xbmc/input/windows/IRServerSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

#define IRSS_PORT 24000

CRemoteControl g_RemoteControl;

CRemoteControl::CRemoteControl() : CThread("RemoteControl")
{
m_socket = INVALID_SOCKET;
Expand Down Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit 0c15ffe

Please sign in to comment.