Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ofilenotify.h

Go to the documentation of this file.
00001 /*
00002                             This file is part of the Opie Project
00003              =.             Copyright (C) 2004-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
00004            .=l.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005           .>+-=
00006 _;:,     .>    :=|.         This program is free software; you can
00007 .> <`_,   >  .   <=         redistribute it and/or  modify it under
00008 :`=1 )Y*s>-.--   :          the terms of the GNU Library General Public
00009 .="- .-=="i,     .._        License as published by the Free Software
00010 - .   .-<_>     .<>         Foundation; version 2 of the License.
00011     ._= =}       :
00012    .%`+i>       _;_.
00013    .i_,=:_.      -<s.       This program is distributed in the hope that
00014     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00015    : ..    .:,     . . .    without even the implied warranty of
00016    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00018 ..}^=.=       =       ;     Library General Public License for more
00019 ++=   -.     .`     .:      details.
00020 :     =  ...= . :.=-
00021 -.   .:....=;==+<;          You should have received a copy of the GNU
00022  -_. . .   )=.  =           Library General Public License along with
00023    --        :-=`           this library; see the file COPYING.LIB.
00024                             If not, write to the Free Software Foundation,
00025                             Inc., 59 Temple Place - Suite 330,
00026                             Boston, MA 02111-1307, USA.
00027 */
00028 
00029 #ifndef OFILENOTIFY_H
00030 #define OFILENOTIFY_H
00031 #if defined (__GNUC__) && (__GNUC__ < 3)
00032 #define _GNU_SOURCE
00033 #endif
00034 
00035 #include "linux_inotify.h"
00036 
00037 /* QT */
00038 #include <qsocketnotifier.h>
00039 #include <qsignal.h>
00040 #include <qstring.h>
00041 #include <qobject.h>
00042 #include <qfile.h>
00043 
00044 namespace Opie {
00045 namespace Core {
00046 
00047 class OFile : public QObject, public QFile
00048 {
00049   Q_OBJECT
00050 
00051   public:
00052     OFile();
00053     OFile( const QString & name );
00054     virtual ~OFile();
00055 
00056   protected:
00057     virtual void connectNotify( const char* signal );
00058     virtual void disconnectNotify( const char* signal );
00059 
00060   private:
00061     int startWatch( int mode );
00062 
00063   signals:
00064     void accessed( const QString& );
00065     void modified( const QString& );
00066     void attributed( const QString& );
00067     void closed( const QString&, bool );
00068     void opened( const QString& );
00069     void deleted( const QString& );
00070     void unmounted( const QString& );
00071 };
00072 
00073 /*
00074     void movedTo( const QString&, const QString& );
00075     void movedFrom( const QString&, const QString& );
00076     void deletedSubdir( const QString&, const QString& );
00077     void deletedFile( const QString&, const QString& );
00078     void createdSubdir( const QString&, const QString& );
00079     void createdFile( const QString&, const QString& );
00080 */
00081 
00082 class OFileNotificationEvent;
00083 
00084 /*======================================================================================
00085  * OFileNotificationType
00086  *======================================================================================*/
00087 
00112 enum OFileNotificationType
00113 {
00114     Nothing         =   0,
00115     Access          =   IN_ACCESS,
00116     Modify          =   IN_MODIFY,
00117     Attrib          =   IN_ATTRIB,
00118     CloseWrite      =   IN_CLOSE_WRITE,
00119     CloseNoWrite    =   IN_CLOSE_NOWRITE,
00120     Open            =   IN_OPEN,
00121     MovedFrom       =   IN_MOVED_FROM,
00122     MovedTo         =   IN_MOVED_TO,
00123     DeleteSubdir    =   IN_DELETE_SUBDIR,
00124     DeleteFile      =   IN_DELETE_FILE,
00125     CreateSubdir    =   IN_CREATE_SUBDIR,
00126     CreateFile      =   IN_CREATE_FILE,
00127     DeleteSelf      =   IN_DELETE_SELF,
00128     Unmount         =   IN_UNMOUNT,
00129     _QueueOverflow  =   IN_Q_OVERFLOW,  /* Internal, don't use this in client code */
00130     _Ignored        =   IN_IGNORED,     /* Internal, don't use this in client code */
00131 };
00132 
00133 /*======================================================================================
00134  * OFileNotification
00135  *======================================================================================*/
00136 
00149 class OFileNotification : public QObject
00150 {
00151   Q_OBJECT
00152 
00153   public:
00154     OFileNotification( QObject* parent = 0, const char* name = 0 );
00155     ~OFileNotification();
00183     static bool singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify );
00188     int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
00192     void stop();
00196     OFileNotificationType type() const;
00200     QString path() const;
00204     bool isSingleShot() const;
00208     bool isActive() const;
00212     int startWatching( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
00213 
00214   signals:
00215     void triggered( const QString&, unsigned int, const QString& );
00216     void accessed( const QString& );
00217     void modified( const QString& );
00218     void attributed( const QString& );
00219     void closed( const QString&, bool );
00220     void opened( const QString& );
00221     void movedTo( const QString&, const QString& );
00222     void movedFrom( const QString&, const QString& );
00223     void deletedSubdir( const QString&, const QString& );
00224     void deletedFile( const QString&, const QString& );
00225     void createdSubdir( const QString&, const QString& );
00226     void createdFile( const QString&, const QString& );
00227     void deleted( const QString& );
00228     void unmounted( const QString& );
00229 
00230   protected:
00231     bool activate( const OFileNotificationEvent* e );
00232 
00233   private slots:
00234     void inotifyEventHandler();
00235 
00236   private:
00237     bool registerEventHandler();
00238     void unregisterEventHandler();
00239 
00240     QString _path;
00241     OFileNotificationType _type;
00242     QSignal _signal;
00243     bool _active;
00244     bool _multi;
00245     static QSocketNotifier* _sn;
00246     int _wd; // inotify watch descriptor
00247     static int _fd; // inotify device descriptor
00248 
00249     friend class OFileNotificationEvent;
00250 };
00251 
00252 /*======================================================================================
00253  * ODirNotification
00254  *======================================================================================*/
00255 
00269 class ODirNotification : public QObject
00270 {
00271   Q_OBJECT
00272 
00273   public:
00274     ODirNotification( QObject* parent = 0, const char* name = 0 );
00275     ~ODirNotification();
00281     int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify, int recurse = 0 );
00282 
00283   signals:
00287     void triggered( const QString&, unsigned int, const QString& );
00288     void accessed( const QString& );
00289     void modified( const QString& );
00290     void attributed( const QString& );
00291     void closed( const QString&, bool );
00292     void opened( const QString& );
00293     void movedTo( const QString&, const QString& );
00294     void movedFrom( const QString&, const QString& );
00295     void deletedSubdir( const QString&, const QString& );
00296     void deletedFile( const QString&, const QString& );
00297     void createdSubdir( const QString&, const QString& );
00298     void createdFile( const QString&, const QString& );
00299     void deleted( const QString& );
00300     void unmounted( const QString& );
00301 
00302   private slots:
00303     void subdirCreated( const QString&, const QString& );
00304 
00305   private:
00306     OFileNotification* _topfilenotification;
00307     OFileNotificationType _type;
00308     int _depth;
00309 };
00310 
00311 /*======================================================================================
00312  * OFileNotificationEvent
00313  *======================================================================================*/
00314 
00315 class OFileNotificationEvent
00316 {
00317   public:
00318     OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name );
00319     ~OFileNotificationEvent();
00320     OFileNotification* parent() const { return _parent; };
00321     int descriptor() const            { return _wd; };
00322     unsigned int mask() const         { return _mask; };
00323     unsigned int cookie() const       { return _cookie; };
00324     QString name() const              { return _name; };
00325     void activate()                   { _parent->activate( this ); };
00326 
00327   private:
00328     OFileNotification* _parent;
00329     int _wd;
00330     unsigned int _mask;
00331     unsigned int _cookie;
00332     QString _name;
00333 };
00334 
00335 
00336 }
00337 }
00338 
00339 #endif
00340 

Generated on Sat Nov 5 16:16:07 2005 for OPIE by  doxygen 1.4.2