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 | |||
@@ -27,5 +27,116 @@ | |||
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 | |||