Added mutex lock for UInput

This commit is contained in:
Ingo Ruhnke 2011-01-25 01:52:33 +01:00
parent ab4c8b3017
commit 54a83fb352
5 changed files with 26 additions and 17 deletions

View file

@ -40,6 +40,8 @@ DefaultMessageProcessor::send(const XboxGenericMsg& msg_in, int msec_delta)
{
if (!m_config->empty())
{
boost::mutex::scoped_lock lock(m_uinput.get_mutex());
XboxGenericMsg msg = msg_in;
// handling switching of configurations

View file

@ -20,6 +20,18 @@
#include "uinput.hpp"
bool
UIEvent::is_mouse_button(int ev_code)
{
return (ev_code >= BTN_MOUSE && ev_code <= BTN_TASK);
}
bool
UIEvent::is_keyboard_button(int ev_code)
{
return (ev_code < 256);
}
UIEvent
UIEvent::create(int device_id, int type, int code)
{
@ -96,11 +108,11 @@ UIEvent::resolve_device_id(int slot, bool extra_devices)
switch(type)
{
case EV_KEY:
if (uInput::is_mouse_button(code))
if (is_mouse_button(code))
{
m_device_id = DEVICEID_MOUSE;
}
else if (uInput::is_keyboard_button(code))
else if (is_keyboard_button(code))
{
m_device_id = DEVICEID_KEYBOARD;
}

View file

@ -40,6 +40,10 @@ public:
static UIEvent create(int device_id, int type, int code);
static UIEvent invalid();
public:
static bool is_mouse_button(int ev_code);
static bool is_keyboard_button(int ev_code);
public:
void resolve_device_id(int slot, bool extra_devices);
bool is_valid() const;

View file

@ -20,20 +20,10 @@
#include "log.hpp"
bool
uInput::is_mouse_button(int ev_code)
{
return (ev_code >= BTN_MOUSE && ev_code <= BTN_TASK);
}
bool
uInput::is_keyboard_button(int ev_code)
{
return (ev_code < 256);
}
uInput::uInput() :
uinput_devs(),
rel_repeat_lst()
rel_repeat_lst(),
m_mutex()
{
#ifdef FIXME
if (cfg.force_feedback)

View file

@ -24,6 +24,7 @@
#include <memory>
#include <stdexcept>
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include "axis_event.hpp"
#include "button_event.hpp"
@ -53,9 +54,7 @@ private:
std::map<UIEvent, RelRepeat> rel_repeat_lst;
public:
static bool is_mouse_button(int ev_code);
static bool is_keyboard_button(int ev_code);
boost::mutex m_mutex;
public:
uInput();
@ -90,6 +89,8 @@ public:
LinuxUinput* get_force_feedback_uinput() const;
boost::mutex& get_mutex() { return m_mutex; }
private:
/** create a LinuxUinput with the given device_id, if some already
exist return a pointer to it */