summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/oinputsystem.cpp
authormickeyl <mickeyl>2005-02-02 15:23:01 (UTC)
committer mickeyl <mickeyl>2005-02-02 15:23:01 (UTC)
commit227d06128b74ef78b8268e18dabe454469b65cc8 (patch) (unidiff)
tree64632ebff3bb6df1ba81ce1e70638cbce15de33c /libopie2/opiecore/oinputsystem.cpp
parent1a5dc271114432e0e598af499c076bfbf69ff972 (diff)
downloadopie-227d06128b74ef78b8268e18dabe454469b65cc8.zip
opie-227d06128b74ef78b8268e18dabe454469b65cc8.tar.gz
opie-227d06128b74ef78b8268e18dabe454469b65cc8.tar.bz2
first work on input system abstractions
Diffstat (limited to 'libopie2/opiecore/oinputsystem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oinputsystem.cpp113
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
31using namespace Opie::Core; 30using 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
48OInputSystem* OInputSystem::_instance = 0;
49
50OInputSystem::OInputSystem() : QObject()
51{
52 qDebug( "OInputSystem::OInputSystem()" );
53 synchronize();
54}
55
56
57void 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
68OInputSystem::~OInputSystem()
69{
70 qDebug( "OInputSystem::~OInputSystem()" );
71}
72
73
74int OInputSystem::count() const
75{
76 return _devices.count();
77}
78
79
80OInputDevice* OInputSystem::device( const QString& device ) const
81{
82 return _devices[device];
83}
84
85
86OInputSystem* OInputSystem::instance()
87{
88 if ( !_instance ) _instance = new OInputSystem();
89 return _instance;
90}
91
92
93OInputSystem::DeviceIterator OInputSystem::iterator() const
94{
95 return OInputSystem::DeviceIterator( _devices );
96}
97
98/*======================================================================================
99 * OInputDevice
100 *======================================================================================*/
101
102OInputDevice::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
114OInputDevice::~OInputDevice()
115{
116 qDebug( "OInputDevice::~OInputDevice()" );
117}
118
119
120QString OInputDevice::identity() const
121{
122 char buf[BUFSIZE] = "<unknown>";
123 ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf );
124 return buf;
125}
126
127
128QString OInputDevice::path() const
129{
130 char buf[BUFSIZE] = "<unknown>";
131 ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf );
132 return buf;
133}
134
135
136QString OInputDevice::uniq() const
137{
138 char buf[BUFSIZE] = "<unknown>";
139 ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf );
140 return buf;
141}
142