summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/linux
Unidiff
Diffstat (limited to 'libopie2/opiecore/linux') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/linux/.cvsignore6
-rw-r--r--libopie2/opiecore/linux/linux.pro10
-rw-r--r--libopie2/opiecore/linux/ofilenotify.cpp406
-rw-r--r--libopie2/opiecore/linux/ofilenotify.h326
-rw-r--r--libopie2/opiecore/linux/oinputsystem.cpp222
-rw-r--r--libopie2/opiecore/linux/oinputsystem.h142
-rw-r--r--libopie2/opiecore/linux/oinputsystemenums.h405
-rw-r--r--libopie2/opiecore/linux/opcmciasystem.cpp142
-rw-r--r--libopie2/opiecore/linux/opcmciasystem.h129
9 files changed, 1788 insertions, 0 deletions
diff --git a/libopie2/opiecore/linux/.cvsignore b/libopie2/opiecore/linux/.cvsignore
new file mode 100644
index 0000000..972e959
--- a/dev/null
+++ b/libopie2/opiecore/linux/.cvsignore
@@ -0,0 +1,6 @@
1Makefile*
2moc*
3*moc
4*.o
5~*
6obj
diff --git a/libopie2/opiecore/linux/linux.pro b/libopie2/opiecore/linux/linux.pro
new file mode 100644
index 0000000..c396e59
--- a/dev/null
+++ b/libopie2/opiecore/linux/linux.pro
@@ -0,0 +1,10 @@
1HEADERS += \
2 linux/ofilenotify.h \
3 linux/oinputsystem.h \
4 linux/opcmciasystem.h
5
6SOURCES += \
7 linux/ofilenotify.cpp \
8 linux/oinputsystem.cpp \
9 linux/opcmciasystem.cpp
10
diff --git a/libopie2/opiecore/linux/ofilenotify.cpp b/libopie2/opiecore/linux/ofilenotify.cpp
new file mode 100644
index 0000000..36ec6bf
--- a/dev/null
+++ b/libopie2/opiecore/linux/ofilenotify.cpp
@@ -0,0 +1,406 @@
1/*
2                This file is part of the Opie Project
3 =. Copyright (C) 2004-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5          .>+-=
6_;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10- .   .-<_>     .<> Foundation; version 2 of the License.
11    ._= =}       :
12   .%`+i>       _;_.
13   .i_,=:_.      -<s. This program is distributed in the hope that
14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15   : ..    .:,     . . . without even the implied warranty of
16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20:     =  ...= . :.=-
21-.   .:....=;==+<; You should have received a copy of the GNU
22 -_. . .   )=.  = Library General Public License along with
23   --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27*/
28
29#include "ofilenotify.h"
30using namespace Opie::Core;
31
32/* OPIE */
33
34/* QT */
35#include <qobject.h>
36#include <qsocketnotifier.h>
37#include <qsignal.h>
38#include <qintdict.h>
39#include <qdir.h>
40
41/* STD */
42#include <sys/types.h>
43#include <sys/stat.h>
44#include <sys/ioctl.h>
45#include <fcntl.h>
46#include <assert.h>
47#include <string.h>
48#include <errno.h>
49#include <unistd.h>
50
51static QIntDict<OFileNotification> notification_list;
52
53QSocketNotifier* OFileNotification::_sn;
54int OFileNotification::_fd = -1;
55
56#define INOTIFY_DEVICE "/dev/inotify"
57
58namespace Opie {
59namespace Core {
60
61//=================================================================================================
62// OFile
63//=================================================================================================
64
65OFile::OFile() : QObject( 0, 0 ), QFile()
66{
67 qDebug( "OFile()" );
68}
69
70OFile::OFile( const QString& name ) : QObject( 0, 0 ), QFile( name )
71{
72 qDebug( "OFile()" );
73}
74
75OFile::~OFile()
76{
77 qDebug( "~OFile()" );
78}
79
80void OFile::connectNotify( const char *signal )
81{
82 QString s = normalizeSignalSlot( signal+1 );
83 qDebug( "OFile::connectNotify() signal = '%s'", (const char*) s );
84
85 if ( s.startsWith( "accessed" ) )
86
87
88
89
90
91
92
93 QObject::connectNotify( signal );
94
95/*
96 void accessed( const QString& );
97 void modified( const QString& );
98 void attributed( const QString& );
99 void closed( const QString&, bool );
100 void opened( const QString& );
101 void deleted( const QString& );
102 void unmounted( const QString& );
103*/
104
105}
106
107void OFile::disconnectNotify( const char* signal )
108{
109 qDebug( "OFile::disconnectNotify() signal = '%s'", signal );
110 QObject::disconnectNotify( signal );
111}
112
113int OFile::startWatch( int mode )
114{
115}
116
117//=================================================================================================
118// OFileNotificationEvent
119//=================================================================================================
120OFileNotificationEvent::OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name )
121 :_parent( parent ), _wd( wd ), _mask( mask ), _cookie( cookie ), _name( name )
122{
123 qDebug( "OFileNotificationEvent()" );
124}
125
126
127OFileNotificationEvent::~OFileNotificationEvent()
128{
129 qDebug( "~OFileNotificationEvent()" );
130}
131
132//=================================================================================================
133// OFileNotification
134//=================================================================================================
135OFileNotification::OFileNotification( QObject* parent, const char* name )
136 :QObject( parent, name ), _active( false ), _multi( true )
137{
138 qDebug( "OFileNotification::OFileNotification()" );
139}
140
141
142OFileNotification::~OFileNotification()
143{
144 stop();
145 qDebug( "OFileNotification::~OFileNotification()" );
146}
147
148
149bool OFileNotification::isActive() const
150{
151 return _active;
152}
153
154
155int OFileNotification::watch( const QString& path, bool sshot, OFileNotificationType type )
156{
157 // check if path exists and is a regular file
158 struct stat s;
159 if ( ::stat( (const char*) path, &s ) == -1 )
160 {
161 qWarning( "OFileNotification::watch(): Can't watch '%s': %s.", (const char*) path, strerror( errno ) );
162 return -1;
163 }
164 if ( !S_ISREG( s.st_mode ) )
165 {
166 qWarning( "OFileNotification::watch(): Can't watch '%s': %s.", (const char*) path, "not a regular file" );
167 return -1;
168 }
169
170 return startWatching( path, sshot, type );
171}
172
173
174int OFileNotification::startWatching( const QString& path, bool sshot, OFileNotificationType type )
175{
176 if ( notification_list.isEmpty() )
177 {
178 OFileNotification::registerEventHandler();
179 }
180
181 struct inotify_watch_request iwr;
182 ::memset( &iwr, 0, sizeof iwr );
183 iwr.name = const_cast<char*>( (const char*) path );
184 iwr.mask = type;
185
186 _wd = ::ioctl( OFileNotification::_fd, INOTIFY_WATCH, &iwr );
187
188 if ( _wd < 0 )
189 {
190 qWarning( "OFileNotification::watch(): inotify can't watch '%s': %s.", (const char*) path, strerror( errno ) );
191 return -1;
192 }
193
194 notification_list.insert( _wd, this );
195 _path = path;
196 _multi = !sshot;
197 _type = type;
198 _active = true;
199 qDebug( "OFileNotification::watch(): watching '%s' [wd=%d].", (const char*) path, _wd );
200 return _wd;
201}
202
203
204void OFileNotification::stop()
205{
206 notification_list.remove( _wd );
207 _path = QString::null;
208 _wd = 0;
209 _active = false;
210 if ( notification_list.isEmpty() )
211 {
212 OFileNotification::unregisterEventHandler();
213 }
214}
215
216
217OFileNotificationType OFileNotification::type() const
218{
219 return _type;
220}
221
222
223QString OFileNotification::path() const
224{
225 return _path;
226}
227
228
229bool OFileNotification::activate( const OFileNotificationEvent* e )
230{
231 qDebug( "OFileNotification::activate(): e = ( %s, %d, 0x%08x, %d, %s )", (const char*) _path, e->descriptor(), e->mask(), e->cookie(), (const char*) e->name() );
232
233 // dumb signal
234 _signal.activate();
235
236 // generic signal
237 emit triggered( _path, e->mask(), e->name() );
238
239 // specialized signals
240 switch ( e->mask() )
241 {
242 case Access: emit accessed( _path ); break;
243 case Modify: emit modified( _path ); break;
244 case Attrib: emit attributed( _path); break;
245 case CloseWrite: emit closed( _path, true ); break;
246 case CloseNoWrite: emit closed( _path, false ); break;
247 case Open: emit opened( _path ); break;
248 case MovedFrom: emit movedFrom( _path, e->name() ); break;
249 case MovedTo: emit movedTo( _path, e->name() ); break;
250 case DeleteSubdir: emit deletedSubdir( _path, e->name() ); break;
251 case DeleteFile: emit deletedFile( _path, e->name() ); break;
252 case CreateSubdir: emit createdSubdir( _path, e->name() ); break;
253 case CreateFile: emit createdFile( _path, e->name() ); break;
254 case DeleteSelf: emit deleted( _path ); break;
255 case Unmount: emit unmounted( _path ); break;
256 default: assert( 0 );
257 }
258
259 if ( !_multi ) stop();
260
261 return true;
262}
263
264
265bool OFileNotification::singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type )
266{
267 OFileNotification* ofn = new OFileNotification();
268 ofn->_signal.connect( receiver, member );
269 return ofn->watch( path, true, type ) != -1;
270}
271
272
273void OFileNotification::inotifyEventHandler()
274{
275 qDebug( "OFileNotification::inotifyEventHandler(): reached." );
276
277 char buffer[16384];
278 ssize_t buffer_i;
279 struct inotify_event *pevent, *event;
280 ssize_t r;
281 size_t event_size;
282 int count = 0;
283
284 r = ::read(_fd, buffer, 16384);
285
286 if ( r <= 0 )
287 return;
288
289 buffer_i = 0;
290 while ( buffer_i < r )
291 {
292 pevent = (struct inotify_event *)&buffer[buffer_i];
293 event_size = sizeof(struct inotify_event) + pevent->len;
294 OFileNotificationEvent* e = new OFileNotificationEvent( notification_list[ pevent->wd ], pevent->wd, pevent->mask,
295 pevent->cookie, pevent->len ? pevent->name : 0 );
296 e->activate();
297 buffer_i += event_size;
298 count++;
299 }
300
301 qDebug( "OFileNotification::inotifyEventHandler(): processed %d events", count );
302}
303
304
305bool OFileNotification::registerEventHandler()
306{
307 OFileNotification::_fd = ::open( INOTIFY_DEVICE, O_RDONLY );
308 if ( OFileNotification::_fd < 0 )
309 {
310 qWarning( "OFileNotification::registerEventHandler(): couldn't register event handler: %s", strerror( errno ) );
311 return false;
312 }
313
314 OFileNotification::_sn = new QSocketNotifier( _fd, QSocketNotifier::Read, this, "inotify event" );
315 connect( OFileNotification::_sn, SIGNAL( activated(int) ), this, SLOT( inotifyEventHandler() ) );
316
317 qDebug( "OFileNotification::registerEventHandler(): done" );
318 return true;
319}
320
321
322void OFileNotification::unregisterEventHandler()
323{
324 if ( _sn ) delete _sn;
325 if ( OFileNotification::_fd )
326 ::close( OFileNotification::_fd );
327 qDebug( "OFileNotification::unregisterEventHandler(): done" );
328}
329
330//=================================================================================================
331// ODirNotification
332//=================================================================================================
333ODirNotification::ODirNotification( QObject* parent, const char* name )
334 :QObject( parent, name )
335{
336 qDebug( "ODirNotification::ODirNotification()" );
337}
338
339
340ODirNotification::~ODirNotification()
341{
342 qDebug( "ODirNotification::~ODirNotification()" );
343}
344
345
346int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationType type, int recurse )
347{
348 qDebug( "ODirNotification::watch( %s, %d, 0x%08x, %d )", (const char*) path, sshot, type, recurse );
349
350 if ( recurse == 0 )
351 {
352 OFileNotification* fn = new OFileNotification( this, "ODirNotification delegate" );
353 int result = fn->startWatching( path, sshot, type );
354 if ( result != -1 )
355 {
356 connect( fn, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ), this, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ) );
357 connect( fn, SIGNAL( accessed( const QString& ) ), this, SIGNAL( accessed( const QString& ) ) );
358 connect( fn, SIGNAL( modified( const QString& ) ), this, SIGNAL( modified( const QString& ) ) );
359 connect( fn, SIGNAL( attributed( const QString& ) ), this, SIGNAL( attributed( const QString& ) ) );
360 connect( fn, SIGNAL( closed( const QString&, bool ) ), this, SIGNAL( closed( const QString&, bool ) ) );
361 connect( fn, SIGNAL( opened( const QString& ) ), this, SIGNAL( opened( const QString& ) ) );
362 connect( fn, SIGNAL( movedTo( const QString&, const QString& ) ), this, SIGNAL( movedTo( const QString&, const QString& ) ) );
363 connect( fn, SIGNAL( movedFrom( const QString&, const QString& ) ), this, SIGNAL( movedFrom( const QString&, const QString& ) ) );
364 connect( fn, SIGNAL( deletedSubdir( const QString&, const QString& ) ), this, SIGNAL( deletedSubdir( const QString&, const QString& ) ) );
365 connect( fn, SIGNAL( deletedFile( const QString&, const QString& ) ), this, SIGNAL( deletedFile( const QString&, const QString& ) ) );;
366 connect( fn, SIGNAL( createdSubdir( const QString&, const QString& ) ), this, SIGNAL( createdSubdir( const QString&, const QString& ) ) );
367 connect( fn, SIGNAL( createdFile( const QString&, const QString& ) ), this, SIGNAL( createdFile( const QString&, const QString& ) ) );
368 connect( fn, SIGNAL( deleted( const QString& ) ), this, SIGNAL( deleted( const QString& ) ) );
369 connect( fn, SIGNAL( unmounted( const QString& ) ), this, SIGNAL( unmounted( const QString& ) ) );
370 }
371 return result;
372 }
373 else
374 {
375
376 return 1;
377 }
378}
379
380
381// void ODirNotification::subdirCreated( const QString& name )
382
383
384/*
385 Love-Trowbridge recursive directory scanning algorithm:
386
387 Step 1. Start at initial directory foo. Add watch.
388
389 Step 2. Setup handlers for watch created in Step 1.
390 Specifically, ensure that a directory created
391 in foo will result in a handled CREATE_SUBDIR
392 event.
393
394 Step 3. Read the contents of foo.
395
396 Step 4. For each subdirectory of foo read in step 3, repeat
397 step 1.
398
399 Step 5. For any CREATE_SUBDIR event on bar, if a watch is
400 not yet created on bar, repeat step 1 on bar.
401*/
402
403
404} // namespace Ui
405
406} // namespace Opie
diff --git a/libopie2/opiecore/linux/ofilenotify.h b/libopie2/opiecore/linux/ofilenotify.h
new file mode 100644
index 0000000..05343b9
--- a/dev/null
+++ b/libopie2/opiecore/linux/ofilenotify.h
@@ -0,0 +1,326 @@
1/*
2                This file is part of the Opie Project
3 =. Copyright (C) 2004-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5          .>+-=
6_;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10- .   .-<_>     .<> Foundation; version 2 of the License.
11    ._= =}       :
12   .%`+i>       _;_.
13   .i_,=:_.      -<s. This program is distributed in the hope that
14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15   : ..    .:,     . . . without even the implied warranty of
16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20:     =  ...= . :.=-
21-.   .:....=;==+<; You should have received a copy of the GNU
22 -_. . .   )=.  = Library General Public License along with
23   --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27*/
28
29#ifndef OFILENOTIFY_H
30#define OFILENOTIFY_H
31#if defined (__GNUC__) && (__GNUC__ < 3)
32#define _GNU_SOURCE
33#endif
34
35#include "linux_inotify.h"
36
37/* QT */
38#include <qsocketnotifier.h>
39#include <qsignal.h>
40#include <qstring.h>
41#include <qobject.h>
42#include <qfile.h>
43
44namespace Opie {
45namespace Core {
46
47class OFile : public QObject, public QFile
48{
49 Q_OBJECT
50
51 public:
52 OFile();
53 OFile( const QString & name );
54 virtual ~OFile();
55
56 protected:
57 virtual void connectNotify( const char* signal );
58 virtual void disconnectNotify( const char* signal );
59
60 private:
61 int startWatch( int mode );
62
63 signals:
64 void accessed( const QString& );
65 void modified( const QString& );
66 void attributed( const QString& );
67 void closed( const QString&, bool );
68 void opened( const QString& );
69 void deleted( const QString& );
70 void unmounted( const QString& );
71};
72
73/*
74 void movedTo( const QString&, const QString& );
75 void movedFrom( const QString&, const QString& );
76 void deletedSubdir( const QString&, const QString& );
77 void deletedFile( const QString&, const QString& );
78 void createdSubdir( const QString&, const QString& );
79 void createdFile( const QString&, const QString& );
80*/
81
82class OFileNotificationEvent;
83
84/*======================================================================================
85 * OFileNotificationType
86 *======================================================================================*/
87
88/**
89 * @brief An enumerate for the different types of file notifications
90 *
91 * This enumerate provides a means to specify the type of events that you are interest in.
92 * Valid values are:
93 * <ul>
94 * <li>Access: The file was accessed (read)
95 * <li>Modify The file was modified (write,truncate)
96 * <li>Attrib = The file had its attributes changed (chmod,chown,chgrp)
97 * <li>CloseWrite = Writable file was closed
98 * <li>CloseNoWrite = Unwritable file was closed
99 * <li>Open = File was opened
100 * <li>MovedFrom = File was moved from X
101 * <li>MovedTo = File was moved to Y
102 * <li>DeleteSubdir = Subdir was deleted
103 * <li>DeleteFile = Subfile was deleted
104 * <li>CreateSubdir = Subdir was created
105 * <li>CreateFile = Subfile was created
106 * <li>DeleteSelf = Self was deleted
107 * <li>Unmount = The backing filesystem was unmounted
108 * </ul>
109 *
110 **/
111
112enum OFileNotificationType
113{
114 Access = IN_ACCESS,
115 Modify = IN_MODIFY,
116 Attrib = IN_ATTRIB,
117 CloseWrite = IN_CLOSE_WRITE,
118 CloseNoWrite = IN_CLOSE_NOWRITE,
119 Open = IN_OPEN,
120 MovedFrom = IN_MOVED_FROM,
121 MovedTo = IN_MOVED_TO,
122 DeleteSubdir = IN_DELETE_SUBDIR,
123 DeleteFile = IN_DELETE_FILE,
124 CreateSubdir = IN_CREATE_SUBDIR,
125 CreateFile = IN_CREATE_FILE,
126 DeleteSelf = IN_DELETE_SELF,
127 Unmount = IN_UNMOUNT,
128 _QueueOverflow = IN_Q_OVERFLOW, /* Internal, don't use this in client code */
129 _Ignored = IN_IGNORED, /* Internal, don't use this in client code */
130};
131
132/*======================================================================================
133 * OFileNotification
134 *======================================================================================*/
135
136/**
137 * @brief Represents a file notification
138 *
139 * This class allows to watch for events happening to files.
140 * It uses the inotify linux (2.6.x) kernel interface.
141 *
142 * @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/
143 *
144 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
145 *
146 **/
147
148class OFileNotification : public QObject
149{
150 Q_OBJECT
151
152 public:
153 OFileNotification( QObject* parent = 0, const char* name = 0 );
154 ~OFileNotification();
155 /**
156 * This static function calls a slot when an event with @a type happens to file @a path.
157 *
158 * It is very convenient to use this function because you do not need to
159 * bother with a timerEvent or to create a local QTimer object.
160 *
161 * Example:
162 * <pre>
163 *
164 * #include <opie2/oapplication.h>
165 * #include <opie2/ofilenotify.h>
166 * using namespace Opie::Core;
167 *
168 * int main( int argc, char **argv )
169 * {
170 * OApplication a( argc, argv, "File Notification Example" );
171 * OFileNotification::singleShot( "/tmp/quit", &a, SLOT(quit()), Access );
172 * ... // create and show your widgets
173 * return a.exec();
174 * }
175 * </pre>
176 *
177 * This sample program automatically terminates when the file "/tmp/quit" has been accessed.
178 *
179 *
180 * The @a receiver is the receiving object and the @a member is the slot.
181 **/
182 static bool singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify );
183 /**
184 * Starts to watch for @a type changes to @a path. Set @a sshot to True if you want to be notified only once.
185 * Note that in that case it may be more convenient to use @ref OFileNotification::singleShot() then.
186 **/
187 int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
188 /**
189 * Stop watching for file events.
190 **/
191 void stop();
192 /**
193 * @returns the notification type as set by @ref start().
194 **/
195 OFileNotificationType type() const;
196 /**
197 * @returns the path to the file being watched by this instance.
198 **/
199 QString path() const;
200 /**
201 * @returns if a file is currently being watched.
202 **/
203 bool isActive() const;
204 /**
205 * @internal
206 */
207 int startWatching( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
208
209 signals:
210 void triggered( const QString&, unsigned int, const QString& );
211 void accessed( const QString& );
212 void modified( const QString& );
213 void attributed( const QString& );
214 void closed( const QString&, bool );
215 void opened( const QString& );
216 void movedTo( const QString&, const QString& );
217 void movedFrom( const QString&, const QString& );
218 void deletedSubdir( const QString&, const QString& );
219 void deletedFile( const QString&, const QString& );
220 void createdSubdir( const QString&, const QString& );
221 void createdFile( const QString&, const QString& );
222 void deleted( const QString& );
223 void unmounted( const QString& );
224
225 protected:
226 bool activate( const OFileNotificationEvent* e );
227
228 private slots:
229 void inotifyEventHandler();
230
231 private:
232 bool registerEventHandler();
233 void unregisterEventHandler();
234
235 QString _path;
236 OFileNotificationType _type;
237 QSignal _signal;
238 bool _active;
239 bool _multi;
240 static QSocketNotifier* _sn;
241 int _wd; // inotify watch descriptor
242 static int _fd; // inotify device descriptor
243
244 friend class OFileNotificationEvent;
245};
246
247/*======================================================================================
248 * ODirNotification
249 *======================================================================================*/
250
251/**
252 * @brief Represents a directory notification
253 *
254 * This class allows to watch for events happening to directories
255 * It uses the OFileNotification class
256 *
257 * @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/
258 *
259 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
260 *
261 **/
262
263class ODirNotification : public QObject
264{
265 Q_OBJECT
266
267 public:
268 ODirNotification( QObject* parent = 0, const char* name = 0 );
269 ~ODirNotification();
270 /**
271 * Starts to watch for @a type changes to @a path. Recurse @a recurse levels down the filesystem tree,
272 * use 0 for no recursion and -1 for unlimited recursion.
273 * Set @a sshot to True if you want to be notified only once.
274 **/
275 int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify, int recurse = 0 );
276
277 signals:
278 /**
279 * This signal is emitted if an event happens of the specified type happens to the directory being watched.
280 **/
281 void triggered( const QString&, unsigned int, const QString& );
282 void accessed( const QString& );
283 void modified( const QString& );
284 void attributed( const QString& );
285 void closed( const QString&, bool );
286 void opened( const QString& );
287 void movedTo( const QString&, const QString& );
288 void movedFrom( const QString&, const QString& );
289 void deletedSubdir( const QString&, const QString& );
290 void deletedFile( const QString&, const QString& );
291 void createdSubdir( const QString&, const QString& );
292 void createdFile( const QString&, const QString& );
293 void deleted( const QString& );
294 void unmounted( const QString& );
295};
296
297/*======================================================================================
298 * OFileNotificationEvent
299 *======================================================================================*/
300
301class OFileNotificationEvent
302{
303 public:
304 OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name );
305 ~OFileNotificationEvent();
306 OFileNotification* parent() const { return _parent; };
307 int descriptor() const { return _wd; };
308 unsigned int mask() const { return _mask; };
309 unsigned int cookie() const { return _cookie; };
310 QString name() const { return _name; };
311 void activate() { _parent->activate( this ); };
312
313 private:
314 OFileNotification* _parent;
315 int _wd;
316 unsigned int _mask;
317 unsigned int _cookie;
318 QString _name;
319};
320
321
322}
323}
324
325#endif
326
diff --git a/libopie2/opiecore/linux/oinputsystem.cpp b/libopie2/opiecore/linux/oinputsystem.cpp
new file mode 100644
index 0000000..bad27ed
--- a/dev/null
+++ b/libopie2/opiecore/linux/oinputsystem.cpp
@@ -0,0 +1,222 @@
1/*
2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l.
5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       :
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27*/
28
29#include "oinputsystem.h"
30using namespace Opie::Core;
31
32/* QT */
33#include <qdir.h>
34#include <qfile.h>
35
36/* STD */
37#include <errno.h>
38#include <string.h>
39#include <sys/fcntl.h>
40#include <sys/ioctl.h>
41#include <unistd.h>
42
43#define BUFSIZE 256
44#define BIT_MASK( name, numbits ) \
45 unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \
46 memset( name, 0, sizeof( name ) )
47#define BIT_TEST( bitmask, bit ) \
48 ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) )
49
50/*======================================================================================
51 * OInputSystem
52 *======================================================================================*/
53
54OInputSystem* OInputSystem::_instance = 0;
55
56OInputSystem::OInputSystem() : QObject()
57{
58 qDebug( "OInputSystem::OInputSystem()" );
59 synchronize();
60}
61
62
63void OInputSystem::synchronize()
64{
65 qDebug( "OInputSystem::synchronize()" );
66 QDir devInput( "/dev/input/" );
67 if ( devInput.exists() )
68 {
69 QStringList devInputFiles = devInput.entryList( QDir::System, QDir::Name );
70 for ( QStringList::Iterator it = devInputFiles.begin(); it != devInputFiles.end(); ++it )
71 {
72 QString absPath = devInput.absFilePath( *it );
73 bool isValid = OInputDevice::isValid( absPath );
74 qDebug( "OInputSystem::synchronize() - checking if '%s' is a valid input system node... '%s' [%s]",
75 (const char*) absPath, isValid ? "yes" : "no", isValid ? "(ok)" : strerror( errno ) );
76 if ( isValid ) _devices.insert( *it, new OInputDevice( this, absPath ) );
77 }
78 }
79 qDebug( "OInputSystem::synchronize() done" );
80 if ( !_devices.count() )
81 qWarning( "OInputSystem::no devices found" );
82}
83
84
85OInputSystem::~OInputSystem()
86{
87 qDebug( "OInputSystem::~OInputSystem()" );
88}
89
90
91int OInputSystem::count() const
92{
93 return _devices.count();
94}
95
96
97OInputDevice* OInputSystem::device( const QString& device ) const
98{
99 return _devices[device];
100}
101
102
103OInputSystem* OInputSystem::instance()
104{
105 if ( !_instance ) _instance = new OInputSystem();
106 return _instance;
107}
108
109
110OInputSystem::DeviceIterator OInputSystem::iterator() const
111{
112 return OInputSystem::DeviceIterator( _devices );
113}
114
115/*======================================================================================
116 * OInputDevice
117 *======================================================================================*/
118
119OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name )
120{
121 qDebug( "OInputDevice::OInputDevice( '%s' )", name );
122
123 _fd = ::open( name, O_RDONLY );
124 if ( _fd == -1 )
125 {
126 qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) );
127 }
128}
129
130
131OInputDevice::~OInputDevice()
132{
133 qDebug( "OInputDevice::~OInputDevice()" );
134}
135
136
137QString OInputDevice::identity() const
138{
139 char buf[BUFSIZE] = "<unknown>";
140 ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf );
141 return buf;
142}
143
144
145QString OInputDevice::path() const
146{
147 char buf[BUFSIZE] = "<unknown>";
148 ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf );
149 return buf;
150}
151
152
153QString OInputDevice::uniq() const
154{
155 char buf[BUFSIZE] = "<unknown>";
156 ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf );
157 return buf;
158}
159
160
161bool OInputDevice::hasFeature( Feature bit ) const
162{
163 BIT_MASK( features, EV_MAX );
164
165 if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 )
166 {
167 perror( "EVIOCGBIT" );
168 return false;
169 }
170 else
171 return BIT_TEST( features, bit );
172}
173
174
175bool OInputDevice::isHeld( Key bit ) const
176{
177 BIT_MASK( keys, KEY_MAX );
178
179 if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 )
180 {
181 perror( "EVIOCGKEY" );
182 return false;
183 }
184 else
185 {
186 return BIT_TEST( keys, bit );
187 }
188}
189
190
191QString OInputDevice::globalKeyMask() const
192{
193 BIT_MASK( keys, KEY_MAX );
194
195 if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 )
196 {
197 perror( "EVIOCGKEY" );
198 return QString::null;
199 }
200 else
201 {
202 QString keymask;
203 for ( int i = 0; i < KEY_MAX; ++i )
204 {
205 if ( BIT_TEST( keys, i ) ) keymask.append( QString().sprintf( "%0d, ", i ) );
206 }
207 return keymask;
208
209 }
210}
211
212
213bool OInputDevice::isValid( const QString& path )
214{
215 char buf[BUFSIZE] = "<unknown>";
216 int fd = ::open( (const char*) path, O_RDONLY );
217 if ( fd < 0 ) return false;
218 int res = ::ioctl( fd, EVIOCGNAME(sizeof buf), buf );
219 ::close( fd );
220 return res >= 0;
221}
222
diff --git a/libopie2/opiecore/linux/oinputsystem.h b/libopie2/opiecore/linux/oinputsystem.h
new file mode 100644
index 0000000..9676e73
--- a/dev/null
+++ b/libopie2/opiecore/linux/oinputsystem.h
@@ -0,0 +1,142 @@
1/*
2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l.
5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       :
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27*/
28
29#ifndef OINPUTSYSTEM_H
30#define OINPUTSYSTEM_H
31
32#include "linux_input.h"
33
34/* QT */
35#include <qobject.h>
36#include <qdict.h>
37
38namespace Opie {
39namespace Core {
40
41class OInputDevice;
42
43/**
44 * @brief A container class for the Linux input device subsystem
45 *
46 * This class provides access to all available input system devices of your device.
47 *
48 * @author Michael 'Mickey' Lauer <mickey@Vanille.de>
49 */
50class OInputSystem : public QObject
51{
52 public:
53 typedef QDict<OInputDevice> DeviceMap;
54 typedef QDictIterator<OInputDevice> DeviceIterator;
55
56 /**
57 * @returns the number of available input devices
58 */
59 int count() const;
60 /**
61 * @returns a pointer to the (one and only) @ref OInputSystem instance.
62 */
63 static OInputSystem* instance();
64 /**
65 * @returns an iterator usable for iterating through all network interfaces.
66 */
67 DeviceIterator iterator() const;
68 /**
69 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found
70 * @see OAudioInterface
71 */
72 OInputDevice* device( const QString& interface ) const;
73 /**
74 * @internal Rebuild the internal interface database
75 * @note Sometimes it might be useful to call this from client code,
76 */
77 void synchronize();
78 /**
79 * @internal destructor
80 */
81 ~OInputSystem();
82
83 protected:
84 OInputSystem();
85
86 static OInputSystem* _instance;
87 DeviceMap _devices;
88};
89
90
91class OInputDevice : public QObject
92{
93 public:
94 OInputDevice( QObject* parent, const char* name = 0 );
95 ~OInputDevice();
96
97 #include "oinputsystemenums.h"
98
99 public:
100 /**
101 * @returns the identity string of this input device
102 */
103 QString identity() const;
104 /**
105 * @returns the path of this input device
106 */
107 QString path() const;
108 /**
109 * @returns a unique identifier for this input device
110 * @note Only a few devices support this
111 */
112 QString uniq() const;
113 /**
114 * @returns whether a certain @a Feature is being supported by this device
115 */
116 bool hasFeature( Feature ) const;
117 /**
118 * @returns whether a given @a Key or Button is being held at the moment
119 */
120 bool isHeld( Key ) const;
121 /**
122 * @internal
123 * @returns a string containing a printable form of the global keymask
124 */
125 QString globalKeyMask() const;
126 /**
127 * @internal
128 * @returns whether a certain @a path corresponds to an input device
129 */
130 static bool isValid( const QString& path );
131
132 private:
133 int _fd;
134 input_id _id;
135
136};
137
138}
139}
140
141#endif // OINPUTSYSTEM_H
142
diff --git a/libopie2/opiecore/linux/oinputsystemenums.h b/libopie2/opiecore/linux/oinputsystemenums.h
new file mode 100644
index 0000000..3461e5a
--- a/dev/null
+++ b/libopie2/opiecore/linux/oinputsystemenums.h
@@ -0,0 +1,405 @@
1
2 enum Feature
3 {
4 Synchronous = EV_SYN,
5 Keys = EV_KEY,
6 Relative = EV_REL,
7 Absolute = EV_ABS,
8 Miscellaneous = EV_MSC,
9 Leds = EV_LED,
10 Sound = EV_SND,
11 AutoRepeat = EV_REP,
12 ForceFeedback = EV_FF,
13 PowerManagement = EV_PWR,
14 ForceFeedbackStatus = EV_FF_STATUS,
15 };
16
17 enum Bus
18 {
19 PCI = BUS_PCI,
20 ISAPNP = BUS_ISAPNP,
21 HIL = BUS_HIL,
22 BLUETOOTH = BUS_BLUETOOTH,
23 ISA = BUS_ISA,
24 I8042 = BUS_I8042,
25 XTKBD = BUS_XTKBD,
26 RS232 = BUS_RS232,
27 GAMEPORT = BUS_GAMEPORT,
28 PARPORT = BUS_PARPORT,
29 AMIGA = BUS_AMIGA,
30 ADB = BUS_ADB,
31 I2C = BUS_I2C,
32 HOST = BUS_HOST,
33 };
34
35 enum Key
36 {
37 Key_RESERVED = 0,
38 Key_ESC = 1,
39 Key_1 = 2,
40 Key_2 = 3,
41 Key_3 = 4,
42 Key_4 = 5,
43 Key_5 = 6,
44 Key_6 = 7,
45 Key_7 = 8,
46 Key_8 = 9,
47 Key_9 = 10,
48 Key_0 = 11,
49 Key_MINUS = 12,
50 Key_EQUAL = 13,
51 Key_BACKSPACE = 14,
52 Key_TAB = 15,
53 Key_Q = 16,
54 Key_W = 17,
55 Key_E = 18,
56 Key_R = 19,
57 Key_T = 20,
58 Key_Y = 21,
59 Key_U = 22,
60 Key_I = 23,
61 Key_O = 24,
62 Key_P = 25,
63 Key_LEFTBRACE = 26,
64 Key_RIGHTBRACE = 27,
65 Key_ENTER = 28,
66 Key_LEFTCTRL = 29,
67 Key_A = 30,
68 Key_S = 31,
69 Key_D = 32,
70 Key_F = 33,
71 Key_G = 34,
72 Key_H = 35,
73 Key_J = 36,
74 Key_K = 37,
75 Key_L = 38,
76 Key_SEMICOLON = 39,
77 Key_APOSTROPHE = 40,
78 Key_GRAVE = 41,
79 Key_LEFTSHIFT = 42,
80 Key_BACKSLASH = 43,
81 Key_Z = 44,
82 Key_X = 45,
83 Key_C = 46,
84 Key_V = 47,
85 Key_B = 48,
86 Key_N = 49,
87 Key_M = 50,
88 Key_COMMA = 51,
89 Key_DOT = 52,
90 Key_SLASH = 53,
91 Key_RIGHTSHIFT = 54,
92 Key_KPASTERISK = 55,
93 Key_LEFTALT = 56,
94 Key_SPACE = 57,
95 Key_CAPSLOCK = 58,
96 Key_F1 = 59,
97 Key_F2 = 60,
98 Key_F3 = 61,
99 Key_F4 = 62,
100 Key_F5 = 63,
101 Key_F6 = 64,
102 Key_F7 = 65,
103 Key_F8 = 66,
104 Key_F9 = 67,
105 Key_F10 = 68,
106 Key_NUMLOCK = 69,
107 Key_SCROLLLOCK = 70,
108 Key_KP7 = 71,
109 Key_KP8 = 72,
110 Key_KP9 = 73,
111 Key_KPMINUS = 74,
112 Key_KP4 = 75,
113 Key_KP5 = 76,
114 Key_KP6 = 77,
115 Key_KPPLUS = 78,
116 Key_KP1 = 79,
117 Key_KP2 = 80,
118 Key_KP3 = 81,
119 Key_KP0 = 82,
120 Key_KPDOT = 83,
121
122 Key_ZENKAKUHANKAKU= 85,
123 Key_102ND = 86,
124 Key_F11 = 87,
125 Key_F12 = 88,
126 Key_RO = 89,
127 Key_KATAKANA = 90,
128 Key_HIRAGANA = 91,
129 Key_HENKAN = 92,
130 Key_KATAKANAHIRAGANA= 93,
131 Key_MUHENKAN = 94,
132 Key_KPJPCOMMA = 95,
133 Key_KPENTER = 96,
134 Key_RIGHTCTRL = 97,
135 Key_KPSLASH = 98,
136 Key_SYSRQ = 99,
137 Key_RIGHTALT = 100,
138 Key_LINEFEED = 101,
139 Key_HOME = 102,
140 Key_UP = 103,
141 Key_PAGEUP = 104,
142 Key_LEFT = 105,
143 Key_RIGHT = 106,
144 Key_END = 107,
145 Key_DOWN = 108,
146 Key_PAGEDOWN = 109,
147 Key_INSERT = 110,
148 Key_DELETE = 111,
149 Key_MACRO = 112,
150 Key_MUTE = 113,
151 Key_VOLUMEDOWN = 114,
152 Key_VOLUMEUP = 115,
153 Key_POWER = 116,
154 Key_KPEQUAL = 117,
155 Key_KPPLUSMINUS = 118,
156 Key_PAUSE = 119,
157
158 Key_KPCOMMA = 121,
159 Key_HANGUEL = 122,
160 Key_HANJA = 123,
161 Key_YEN = 124,
162 Key_LEFTMETA = 125,
163 Key_RIGHTMETA = 126,
164 Key_COMPOSE = 127,
165
166 Key_STOP = 128,
167 Key_AGAIN = 129,
168 Key_PROPS = 130,
169 Key_UNDO = 131,
170 Key_FRONT = 132,
171 Key_COPY = 133,
172 Key_OPEN = 134,
173 Key_PASTE = 135,
174 Key_FIND = 136,
175 Key_CUT = 137,
176 Key_HELP = 138,
177 Key_MENU = 139,
178 Key_CALC = 140,
179 Key_SETUP = 141,
180 Key_SLEEP = 142,
181 Key_WAKEUP = 143,
182 Key_FILE = 144,
183 Key_SENDFILE = 145,
184 Key_DELETEFILE = 146,
185 Key_XFER = 147,
186 Key_PROG1 = 148,
187 Key_PROG2 = 149,
188 Key_WWW = 150,
189 Key_MSDOS = 151,
190 Key_COFFEE = 152,
191 Key_DIRECTION = 153,
192 Key_CYCLEWINDOWS= 154,
193 Key_MAIL = 155,
194 Key_BOOKMARKS = 156,
195 Key_COMPUTER = 157,
196 Key_BACK = 158,
197 Key_FORWARD = 159,
198 Key_CLOSECD = 160,
199 Key_EJECTCD = 161,
200 Key_EJECTCLOSECD= 162,
201 Key_NEXTSONG = 163,
202 Key_PLAYPAUSE = 164,
203 Key_PREVIOUSSONG= 165,
204 Key_STOPCD = 166,
205 Key_RECORD = 167,
206 Key_REWIND = 168,
207 Key_PHONE = 169,
208 Key_ISO = 170,
209 Key_CONFIG = 171,
210 Key_HOMEPAGE = 172,
211 Key_REFRESH = 173,
212 Key_EXIT = 174,
213 Key_MOVE = 175,
214 Key_EDIT = 176,
215 Key_SCROLLUP = 177,
216 Key_SCROLLDOWN = 178,
217 Key_KPLEFTPAREN = 179,
218 Key_KPRIGHTPAREN= 180,
219
220 Key_F13 = 183,
221 Key_F14 = 184,
222 Key_F15 = 185,
223 Key_F16 = 186,
224 Key_F17 = 187,
225 Key_F18 = 188,
226 Key_F19 = 189,
227 Key_F20 = 190,
228 Key_F21 = 191,
229 Key_F22 = 192,
230 Key_F23 = 193,
231 Key_F24 = 194,
232
233 Key_PLAYCD = 200,
234 Key_PAUSECD = 201,
235 Key_PROG3 = 202,
236 Key_PROG4 = 203,
237 Key_SUSPEND = 205,
238 Key_CLOSE = 206,
239 Key_PLAY = 207,
240 Key_FASTFORWARD = 208,
241 Key_BASSBOOST = 209,
242 Key_PRINT = 210,
243 Key_HP = 211,
244 Key_CAMERA = 212,
245 Key_SOUND = 213,
246 Key_QUESTION = 214,
247 Key_EMAIL = 215,
248 Key_CHAT = 216,
249 Key_SEARCH = 217,
250 Key_CONNECT = 218,
251 Key_FINANCE = 219,
252 Key_SPORT = 220,
253 Key_SHOP = 221,
254 Key_ALTERASE = 222,
255 Key_CANCEL = 223,
256 Key_BRIGHTNESSDOWN= 224,
257 Key_BRIGHTNESSUP= 225,
258 Key_MEDIA = 226,
259
260 Key_UNKNOWN = 240,
261
262 Button_MISC = 0x100,
263 Button_0 = 0x100,
264 Button_1 = 0x101,
265 Button_2 = 0x102,
266 Button_3 = 0x103,
267 Button_4 = 0x104,
268 Button_5 = 0x105,
269 Button_6 = 0x106,
270 Button_7 = 0x107,
271 Button_8 = 0x108,
272 Button_9 = 0x109,
273
274 Button_MOUSE = 0x110,
275 Button_LEFT = 0x110,
276 Button_RIGHT = 0x111,
277 Button_MIDDLE = 0x112,
278 Button_SIDE = 0x113,
279 Button_EXTRA = 0x114,
280 Button_FORWARD = 0x115,
281 Button_BACK = 0x116,
282 Button_TASK = 0x117,
283
284 Button_JOYSTICK = 0x120,
285 Button_TRIGGER = 0x120,
286 Button_THUMB = 0x121,
287 Button_THUMB2 = 0x122,
288 Button_TOP = 0x123,
289 Button_TOP2 = 0x124,
290 Button_PINKIE = 0x125,
291 Button_BASE = 0x126,
292 Button_BASE2 = 0x127,
293 Button_BASE3 = 0x128,
294 Button_BASE4 = 0x129,
295 Button_BASE5 = 0x12a,
296 Button_BASE6 = 0x12b,
297 Button_DEAD = 0x12f,
298
299 Button_GAMEPAD = 0x130,
300 Button_A = 0x130,
301 Button_B = 0x131,
302 Button_C = 0x132,
303 Button_X = 0x133,
304 Button_Y = 0x134,
305 Button_Z = 0x135,
306 Button_TL = 0x136,
307 Button_TR = 0x137,
308 Button_TL2 = 0x138,
309 Button_TR2 = 0x139,
310 Button_SELECT = 0x13a,
311 Button_START = 0x13b,
312 Button_MODE = 0x13c,
313 Button_THUMBL = 0x13d,
314 Button_THUMBR = 0x13e,
315
316 Button_DIGI = 0x140,
317 Button_TOOL_PEN = 0x140,
318 Button_TOOL_RUBBER = 0x141,
319 Button_TOOL_BRUSH = 0x142,
320 Button_TOOL_PENCIL = 0x143,
321 Button_TOOL_AIRBRUSH= 0x144,
322 Button_TOOL_FINGER = 0x145,
323 Button_TOOL_MOUSE = 0x146,
324 Button_TOOL_LENS = 0x147,
325 Button_TOUCH = 0x14a,
326 Button_STYLUS = 0x14b,
327 Button_STYLUS2 = 0x14c,
328 Button_TOOL_DOUBLETAP= 0x14d,
329 Button_TOOL_TRIPLETAP= 0x14e,
330
331 Button_WHEEL = 0x150,
332 Button_GEAR_DOWN = 0x150,
333 Button_GEAR_UP = 0x151,
334
335 Key_OK = 0x160,
336 Key_SELECT = 0x161,
337 Key_GOTO = 0x162,
338 Key_CLEAR = 0x163,
339 Key_POWER2 = 0x164,
340 Key_OPTION = 0x165,
341 Key_INFO = 0x166,
342 Key_TIME = 0x167,
343 Key_VENDOR = 0x168,
344 Key_ARCHIVE = 0x169,
345 Key_PROGRAM = 0x16a,
346 Key_CHANNEL = 0x16b,
347 Key_FAVORITES = 0x16c,
348 Key_EPG = 0x16d,
349 Key_PVR = 0x16e,
350 Key_MHP = 0x16f,
351 Key_LANGUAGE = 0x170,
352 Key_TITLE = 0x171,
353 Key_SUBTITLE = 0x172,
354 Key_ANGLE = 0x173,
355 Key_ZOOM = 0x174,
356 Key_MODE = 0x175,
357 Key_KEYBOARD = 0x176,
358 Key_SCREEN = 0x177,
359 Key_PC = 0x178,
360 Key_TV = 0x179,
361 Key_TV2 = 0x17a,
362 Key_VCR = 0x17b,
363 Key_VCR2 = 0x17c,
364 Key_SAT = 0x17d,
365 Key_SAT2 = 0x17e,
366 Key_CD = 0x17f,
367 Key_TAPE = 0x180,
368 Key_RADIO = 0x181,
369 Key_TUNER = 0x182,
370 Key_PLAYER = 0x183,
371 Key_TEXT = 0x184,
372 Key_DVD = 0x185,
373 Key_AUX = 0x186,
374 Key_MP3 = 0x187,
375 Key_AUDIO = 0x188,
376 Key_VIDEO = 0x189,
377 Key_DIRECTORY = 0x18a,
378 Key_LIST = 0x18b,
379 Key_MEMO = 0x18c,
380 Key_CALENDAR = 0x18d,
381 Key_RED = 0x18e,
382 Key_GREEN = 0x18f,
383 Key_YELLOW = 0x190,
384 Key_BLUE = 0x191,
385 Key_CHANNELUP = 0x192,
386 Key_CHANNELDOWN = 0x193,
387 Key_FIRST = 0x194,
388 Key_LAST = 0x195,
389 Key_AB = 0x196,
390 Key_NEXT = 0x197,
391 Key_RESTART = 0x198,
392 Key_SLOW = 0x199,
393 Key_SHUFFLE = 0x19a,
394 Key_BREAK = 0x19b,
395 Key_PREVIOUS = 0x19c,
396 Key_DIGITS = 0x19d,
397 Key_TEEN = 0x19e,
398 Key_TWEN = 0x19f,
399
400 Key_DEL_EOL = 0x1c0,
401 Key_DEL_EOS = 0x1c1,
402 Key_INS_LINE = 0x1c2,
403 Key_DEL_LINE = 0x1c3,
404 };
405
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp
new file mode 100644
index 0000000..a924696
--- a/dev/null
+++ b/libopie2/opiecore/linux/opcmciasystem.cpp
@@ -0,0 +1,142 @@
1/*
2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l.
5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       :
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27
28*/
29
30#include "opcmciasystem.h"
31using namespace Opie::Core;
32
33/* OPIE */
34#include <opie2/odebug.h>
35
36/* QT */
37#include <qfile.h>
38#include <qtextstream.h>
39
40/* STD */
41#include <errno.h>
42#include <fcntl.h>
43#include <string.h>
44#include <sys/ioctl.h>
45#include <sys/types.h>
46#include <sys/stat.h>
47
48/*======================================================================================
49 * OPcmciaSystem
50 *======================================================================================*/
51
52OPcmciaSystem* OPcmciaSystem::_instance = 0;
53
54OPcmciaSystem::OPcmciaSystem()
55{
56 qDebug( "OPcmciaSystem::OPcmciaSystem()" );
57 synchronize();
58}
59
60void OPcmciaSystem::synchronize()
61{
62 qDebug( "OPcmciaSystem::synchronize()" );
63 _interfaces.clear();
64
65 //FIXME: Use cardmgr subsystem ioctls
66
67 QString fileName;
68 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; }
69 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; }
70 else { fileName = "/var/lib/pcmcia/stab"; }
71 QFile cardinfofile( fileName );
72 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) )
73 {
74 qWarning( "pcmcia info file not found or unaccessible" );
75 return;
76 }
77 QTextStream cardinfo( &cardinfofile );
78 while ( !cardinfo.atEnd() )
79 {
80 QString line = cardinfo.readLine();
81 if ( line.startsWith( "Socket" ) )
82 {
83 int mid = line.find( ':' );
84 QString name = line.right( line.length() - mid - 1 );
85 QString id = line.right( line.length() - mid + 1 );
86 if ( mid ) _interfaces.insert( name, new OPcmciaCard( this, (const char*) id ) );
87 }
88 else
89 {
90 continue;
91 }
92 }
93}
94
95
96int OPcmciaSystem::count() const
97{
98 return _interfaces.count();
99}
100
101
102OPcmciaCard* OPcmciaSystem::card( const QString& iface ) const
103{
104 return _interfaces[iface];
105}
106
107
108OPcmciaSystem* OPcmciaSystem::instance()
109{
110 if ( !_instance ) _instance = new OPcmciaSystem();
111 return _instance;
112}
113
114
115OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const
116{
117 return OPcmciaSystem::CardIterator( _interfaces );
118}
119
120
121/*======================================================================================
122 * OPcmciaCard
123 *======================================================================================*/
124
125OPcmciaCard::OPcmciaCard( QObject* parent, const char* name )
126 :QObject( parent, name )
127{
128 odebug << "OPcmciaCard::OPcmciaCard()" << oendl;
129 init();
130}
131
132
133OPcmciaCard::~OPcmciaCard()
134{
135}
136
137
138void OPcmciaCard::init()
139{
140}
141
142
diff --git a/libopie2/opiecore/linux/opcmciasystem.h b/libopie2/opiecore/linux/opcmciasystem.h
new file mode 100644
index 0000000..694bf16
--- a/dev/null
+++ b/libopie2/opiecore/linux/opcmciasystem.h
@@ -0,0 +1,129 @@
1/*
2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l.
5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       :
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27
28*/
29
30#ifndef OPCMCIASYSTEM_H
31#define OPCMCIASYSTEM_H
32
33#include <qobject.h>
34#include <qdict.h>
35#include <qmap.h>
36
37namespace Opie {
38namespace Core {
39
40class OPcmciaCard;
41
42/*======================================================================================
43 * OPcmciaSystem
44 *======================================================================================*/
45
46/**
47 * @brief A container class for the linux pcmcia subsystem
48 *
49 * This class provides access to all available pcmcia/cf cards on your device.
50 *
51 * @author Michael 'Mickey' Lauer <mickey@Vanille.de>
52 */
53class OPcmciaSystem : public QObject
54{
55 Q_OBJECT
56
57 public:
58 typedef QDict<OPcmciaCard> CardMap;
59 typedef QDictIterator<OPcmciaCard> CardIterator;
60
61 public:
62 /**
63 * @returns the number of available interfaces
64 */
65 int count() const;
66 /**
67 * @returns a pointer to the (one and only) @ref OSystem instance.
68 */
69 static OPcmciaSystem* instance();
70 /**
71 * @returns an iterator usable for iterating through all sound cards.
72 */
73 CardIterator iterator() const;
74 /**
75 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found
76 * @see OAudioInterface
77 */
78 OPcmciaCard* card( const QString& interface ) const;
79 /**
80 * @internal Rebuild the internal interface database
81 * @note Sometimes it might be useful to call this from client code,
82 * e.g. after issuing a cardctl insert
83 */
84 void synchronize();
85
86 protected:
87 OPcmciaSystem();
88
89 private:
90 static OPcmciaSystem* _instance;
91 CardMap _interfaces;
92 class Private;
93 Private *d;
94};
95
96
97/*======================================================================================
98 * OPcmciaCard
99 *======================================================================================*/
100
101class OPcmciaCard : public QObject
102{
103 Q_OBJECT
104
105 public:
106 /**
107 * Constructor. Normally you don't create @ref OPcmciaCard objects yourself,
108 * but access them via @ref OPcmciaSystem::card().
109 */
110 OPcmciaCard( QObject* parent, const char* name );
111 /**
112 * Destructor.
113 */
114 virtual ~OPcmciaCard();
115
116 protected:
117
118 private:
119 void init();
120 private:
121 class Private;
122 Private *d;
123};
124
125
126}
127}
128
129#endif // OPCMCIASYSTEM_H