Merge pull request #4592 from koying/fixlinhotplug
[vuplus_xbmc] / xbmc / input / linux / LinuxInputDevices.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20 #ifndef LINUXINPUTDEVICES_H_
21 #define LINUXINPUTDEVICES_H_
22
23 #include <vector>
24 #include <string>
25 #include "windowing/XBMC_events.h"
26 #include "input/XBMC_keyboard.h"
27 #include "threads/SingleLock.h"
28
29 struct KeymapEntry
30 {
31   int code;
32   unsigned short base;
33   unsigned short shift;
34   unsigned short alt;
35   unsigned short altShift;
36 };
37
38 class CLinuxInputDevice
39 {
40 public:
41   CLinuxInputDevice(const std::string fileName, int index);
42   ~CLinuxInputDevice();
43   XBMC_Event ReadEvent();
44   const std::string& GetFileName();
45   bool IsUnplugged();
46  
47 private:
48   void SetupKeyboardAutoRepeat(int fd);
49   XBMCKey TranslateKey(unsigned short code);
50   bool KeyEvent(const struct input_event& levt, XBMC_Event& devt);
51   bool RelEvent(const struct input_event& levt, XBMC_Event& devt);
52   bool AbsEvent(const struct input_event& levt, XBMC_Event& devt);
53   bool TranslateEvent(const struct input_event& levt, XBMC_Event& devt);
54   void SetLed(int led, int state);
55   void GetInfo(int fd);
56   bool Open();
57   void Close();
58   unsigned short KeyboardReadValue(unsigned char table, unsigned char index);
59   XBMCMod UpdateModifiers(XBMC_Event& devt);
60   bool GetKeymapEntry(KeymapEntry& entry);
61   int KeyboardGetSymbol(unsigned short value);
62
63   int m_fd;
64   int m_vt_fd;
65   bool m_hasLeds;
66   std::string m_fileName;
67   bool m_ledState[3];
68   int m_mouseX;
69   int m_mouseY;
70   int m_deviceIndex;
71   int m_keyMods;
72   int m_lastKeyMods;
73   char m_deviceName[256];
74   int m_deviceType;
75   int m_devicePreferredId;
76   int m_deviceCaps;
77   int m_deviceMinKeyCode;
78   int m_deviceMaxKeyCode;
79   int m_deviceMaxAxis;
80   bool m_bSkipNonKeyEvents;
81   bool m_bUnplugged;
82 };
83
84 class CLinuxInputDevices
85 {
86 public:
87   void InitAvailable();
88   void CheckHotplugged();
89   XBMC_Event ReadEvent();
90   bool IsRemoteLowBattery();
91   bool IsRemoteNotPaired();
92   size_t Size() { return m_devices.size(); }
93 private:
94   CCriticalSection m_devicesListLock;
95   bool CheckDevice(const char *device);
96   std::vector<CLinuxInputDevice*> m_devices;
97   bool m_bReInitialize;
98   time_t m_lastHotplugCheck;
99 };
100
101 #endif /* LINUXINPUTDEVICES_H_ */