Diffstat (limited to 'libopie2/opiecore/oinputsystem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/oinputsystem.cpp | 113 |
1 files changed, 112 insertions, 1 deletions
diff --git a/libopie2/opiecore/oinputsystem.cpp b/libopie2/opiecore/oinputsystem.cpp index c33d5c8..bfdc31f 100644 --- a/libopie2/opiecore/oinputsystem.cpp +++ b/libopie2/opiecore/oinputsystem.cpp | |||
@@ -6,26 +6,137 @@ | |||
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "oinputsystem.h" | 29 | #include "oinputsystem.h" |
30 | |||
31 | using namespace Opie::Core; | 30 | using namespace Opie::Core; |
31 | |||
32 | /* QT */ | ||
33 | #include <qfile.h> | ||
34 | |||
35 | /* STD */ | ||
36 | #include <errno.h> | ||
37 | #include <string.h> | ||
38 | #include <linux/input.h> | ||
39 | #include <sys/fcntl.h> | ||
40 | #include <sys/ioctl.h> | ||
41 | |||
42 | #define BUFSIZE 256 | ||
43 | |||
44 | /*====================================================================================== | ||
45 | * OInputSystem | ||
46 | *======================================================================================*/ | ||
47 | |||
48 | OInputSystem* OInputSystem::_instance = 0; | ||
49 | |||
50 | OInputSystem::OInputSystem() : QObject() | ||
51 | { | ||
52 | qDebug( "OInputSystem::OInputSystem()" ); | ||
53 | synchronize(); | ||
54 | } | ||
55 | |||
56 | |||
57 | void OInputSystem::synchronize() | ||
58 | { | ||
59 | qDebug( "OInputSystem::synchronize()" ); | ||
60 | if ( QFile::exists( "/dev/input/event0" ) ) _devices.insert( "0", new OInputDevice( this, "/dev/input/event0" ) ); | ||
61 | if ( QFile::exists( "/dev/input/event1" ) ) _devices.insert( "1", new OInputDevice( this, "/dev/input/event1" ) ); | ||
62 | if ( QFile::exists( "/dev/input/event2" ) ) _devices.insert( "2", new OInputDevice( this, "/dev/input/event2" ) ); | ||
63 | if ( QFile::exists( "/dev/input/event3" ) ) _devices.insert( "3", new OInputDevice( this, "/dev/input/event3" ) ); | ||
64 | qDebug( "OInputSystem::synchronize() done" ); | ||
65 | } | ||
66 | |||
67 | |||
68 | OInputSystem::~OInputSystem() | ||
69 | { | ||
70 | qDebug( "OInputSystem::~OInputSystem()" ); | ||
71 | } | ||
72 | |||
73 | |||
74 | int OInputSystem::count() const | ||
75 | { | ||
76 | return _devices.count(); | ||
77 | } | ||
78 | |||
79 | |||
80 | OInputDevice* OInputSystem::device( const QString& device ) const | ||
81 | { | ||
82 | return _devices[device]; | ||
83 | } | ||
84 | |||
85 | |||
86 | OInputSystem* OInputSystem::instance() | ||
87 | { | ||
88 | if ( !_instance ) _instance = new OInputSystem(); | ||
89 | return _instance; | ||
90 | } | ||
91 | |||
92 | |||
93 | OInputSystem::DeviceIterator OInputSystem::iterator() const | ||
94 | { | ||
95 | return OInputSystem::DeviceIterator( _devices ); | ||
96 | } | ||
97 | |||
98 | /*====================================================================================== | ||
99 | * OInputDevice | ||
100 | *======================================================================================*/ | ||
101 | |||
102 | OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name ) | ||
103 | { | ||
104 | qDebug( "OInputDevice::OInputDevice( '%s' )", name ); | ||
105 | |||
106 | _fd = ::open( name, O_RDONLY ); | ||
107 | if ( _fd == -1 ) | ||
108 | { | ||
109 | qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) ); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | |||
114 | OInputDevice::~OInputDevice() | ||
115 | { | ||
116 | qDebug( "OInputDevice::~OInputDevice()" ); | ||
117 | } | ||
118 | |||
119 | |||
120 | QString OInputDevice::identity() const | ||
121 | { | ||
122 | char buf[BUFSIZE] = "<unknown>"; | ||
123 | ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf ); | ||
124 | return buf; | ||
125 | } | ||
126 | |||
127 | |||
128 | QString OInputDevice::path() const | ||
129 | { | ||
130 | char buf[BUFSIZE] = "<unknown>"; | ||
131 | ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf ); | ||
132 | return buf; | ||
133 | } | ||
134 | |||
135 | |||
136 | QString OInputDevice::uniq() const | ||
137 | { | ||
138 | char buf[BUFSIZE] = "<unknown>"; | ||
139 | ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf ); | ||
140 | return buf; | ||
141 | } | ||
142 | |||