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