-rw-r--r-- | libopie2/opiecore/oinputsystem.cpp | 113 | ||||
-rw-r--r-- | libopie2/opiecore/oinputsystem.h | 104 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.h | 4 |
3 files changed, 216 insertions, 5 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 | |||
diff --git a/libopie2/opiecore/oinputsystem.h b/libopie2/opiecore/oinputsystem.h index 2bcdc3a..350656b 100644 --- a/libopie2/opiecore/oinputsystem.h +++ b/libopie2/opiecore/oinputsystem.h | |||
@@ -29,20 +29,120 @@ | |||
29 | #ifndef OINPUTSYSTEM_H | 29 | #ifndef OINPUTSYSTEM_H |
30 | #define OINPUTSYSTEM_H | 30 | #define OINPUTSYSTEM_H |
31 | 31 | ||
32 | /* QT */ | ||
32 | #include <qobject.h> | 33 | #include <qobject.h> |
34 | #include <qdict.h> | ||
35 | |||
36 | /* STD */ | ||
37 | #include <linux/input.h> | ||
33 | 38 | ||
34 | namespace Opie { | 39 | namespace Opie { |
35 | namespace Core { | 40 | namespace Core { |
36 | 41 | ||
42 | class OInputDevice; | ||
43 | |||
37 | /** | 44 | /** |
38 | * ... | 45 | * @brief A container class for all input devices |
46 | * | ||
47 | * This class provides access to all available input system devices of your computer. | ||
39 | * | 48 | * |
49 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
40 | */ | 50 | */ |
41 | |||
42 | class OInputSystem : public QObject | 51 | class OInputSystem : public QObject |
43 | { | 52 | { |
53 | public: | ||
54 | typedef QDict<OInputDevice> DeviceMap; | ||
55 | typedef QDictIterator<OInputDevice> DeviceIterator; | ||
56 | |||
57 | /** | ||
58 | * @returns the number of available input devices | ||
59 | */ | ||
60 | int count() const; | ||
61 | /** | ||
62 | * @returns a pointer to the (one and only) @ref OInputSystem instance. | ||
63 | */ | ||
64 | static OInputSystem* instance(); | ||
65 | /** | ||
66 | * @returns an iterator usable for iterating through all network interfaces. | ||
67 | */ | ||
68 | DeviceIterator iterator() const; | ||
69 | /** | ||
70 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | ||
71 | * @see OAudioInterface | ||
72 | */ | ||
73 | OInputDevice* device( const QString& interface ) const; | ||
74 | /** | ||
75 | * @internal Rebuild the internal interface database | ||
76 | * @note Sometimes it might be useful to call this from client code, | ||
77 | */ | ||
78 | void synchronize(); | ||
79 | /** | ||
80 | * @internal desctructor | ||
81 | */ | ||
82 | ~OInputSystem(); | ||
83 | |||
84 | protected: | ||
85 | OInputSystem(); | ||
86 | |||
87 | static OInputSystem* _instance; | ||
88 | DeviceMap _devices; | ||
44 | }; | 89 | }; |
90 | |||
91 | |||
92 | class OInputDevice : public QObject | ||
93 | { | ||
94 | public: | ||
95 | |||
96 | enum EventType | ||
97 | { | ||
98 | Synchronous = EV_SYN, | ||
99 | Keyboard = EV_KEY, | ||
100 | Relative = EV_REL, | ||
101 | Absolute = EV_ABS, | ||
102 | Miscellaneous = EV_MSC, | ||
103 | Led = EV_LED, | ||
104 | Sound = EV_SND, | ||
105 | AutoRepeat = EV_REP, | ||
106 | ForceFeedback = EV_FF, | ||
107 | PowerManagement = EV_PWR, | ||
108 | ForceFeedbackStatus = EV_FF_STATUS, | ||
109 | }; | ||
110 | |||
111 | enum Bus | ||
112 | { | ||
113 | PCI = BUS_PCI, | ||
114 | ISAPNP = BUS_ISAPNP, | ||
115 | HIL = BUS_HIL, | ||
116 | BLUETOOTH = BUS_BLUETOOTH, | ||
117 | ISA = BUS_ISA, | ||
118 | I8042 = BUS_I8042, | ||
119 | XTKBD = BUS_XTKBD, | ||
120 | RS232 = BUS_RS232, | ||
121 | GAMEPORT = BUS_GAMEPORT, | ||
122 | PARPORT = BUS_PARPORT, | ||
123 | AMIGA = BUS_AMIGA, | ||
124 | ADB = BUS_ADB, | ||
125 | I2C = BUS_I2C, | ||
126 | HOST = BUS_HOST, | ||
127 | }; | ||
128 | |||
129 | public: | ||
130 | OInputDevice( QObject* parent, const char* name = 0 ); | ||
131 | ~OInputDevice(); | ||
132 | |||
133 | public: | ||
134 | QString identity() const; | ||
135 | QString path() const; | ||
136 | QString uniq() const; | ||
137 | |||
138 | private: | ||
139 | int _fd; | ||
140 | input_id _id; | ||
141 | |||
142 | }; | ||
143 | |||
45 | } | 144 | } |
46 | } | 145 | } |
47 | 146 | ||
48 | #endif // OINPUTSYSTEM_H | 147 | #endif // OINPUTSYSTEM_H |
148 | |||
diff --git a/libopie2/opiemm/osoundsystem.h b/libopie2/opiemm/osoundsystem.h index cce90c0..5f6fb7a 100644 --- a/libopie2/opiemm/osoundsystem.h +++ b/libopie2/opiemm/osoundsystem.h | |||
@@ -67,11 +67,11 @@ class OSoundSystem : public QObject | |||
67 | */ | 67 | */ |
68 | int count() const; | 68 | int count() const; |
69 | /** | 69 | /** |
70 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 70 | * @returns a pointer to the (one and only) @ref OSystem instance. |
71 | */ | 71 | */ |
72 | static OSoundSystem* instance(); | 72 | static OSoundSystem* instance(); |
73 | /** | 73 | /** |
74 | * @returns an iterator usable for iterating through all network interfaces. | 74 | * @returns an iterator usable for iterating through all sound cards. |
75 | */ | 75 | */ |
76 | CardIterator iterator() const; | 76 | CardIterator iterator() const; |
77 | /** | 77 | /** |