Diffstat (limited to 'libopie2/opiecore/ofilenotify.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/ofilenotify.h | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h index d820f7c..e3621cf 100644 --- a/libopie2/opiecore/ofilenotify.h +++ b/libopie2/opiecore/ofilenotify.h @@ -2,3 +2,3 @@ This file is part of the Opie Project - =. Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de> + =. Copyright (C) 2004-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org> @@ -9,4 +9,4 @@ _;:, .> :=|. This program is free software; you can .="- .-=="i, .._ License as published by the Free Software -- . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. +- . .-<_> .<> Foundation; version 2 of the License. + ._= =} : .%`+i> _;_. @@ -35,3 +35,3 @@ _;:, .> :=|. This program is free software; you can /* QT */ -#include <qobject.h> +#include <qsocketnotifier.h> #include <qsignal.h> @@ -40,4 +40,3 @@ _;:, .> :=|. This program is free software; you can /* STD */ -#include <signal.h> -#include <fcntl.h> +#include "inotify.h" @@ -58,6 +57,14 @@ namespace Core { * <li>Modify The file was modified (write,truncate) - * <li>Create = The file was created in the directory - * <li>Delete = The file was unlinked from directory - * <li>Rename = The file was renamed * <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> @@ -66,10 +73,21 @@ namespace Core { -enum OFileNotificationType { Single = 0x0000000, - Multi = DN_MULTISHOT, - Access = DN_ACCESS, - Modify = DN_MODIFY, - Create = DN_CREATE, - Delete = DN_DELETE, - Rename = DN_RENAME, - Attrib = DN_ATTRIB }; +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 */ +}; @@ -83,5 +101,5 @@ enum OFileNotificationType { Single = 0x0000000, * This class allows to watch for events happening to files. - * It uses the dnotify kernel interface which is a very efficient signalling interface. + * It uses the inotify kernel interface * - * @see <file:///usr/src/linux/Documentation/dnotify.txt> + * @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/ * @@ -108,3 +126,3 @@ class OFileNotification : public QObject * #include <opie2/oapplication.h> - * #include <opie2/onitify.h> + * #include <opie2/ofilenotify.h> * using namespace Opie::Core; @@ -120,3 +138,3 @@ class OFileNotification : public QObject * - * This sample program automatically terminates when the file "/tmp/quite" has been created. + * This sample program automatically terminates when the file "/tmp/quit" has been created. * @@ -130,3 +148,3 @@ class OFileNotification : public QObject **/ - int start( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); + int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); /** @@ -144,6 +162,2 @@ class OFileNotification : public QObject /** - * @returns the UNIX file descriptor for the file being watched. - **/ - int fileno() const; - /** * @returns if a file is currently being watched. @@ -160,8 +174,10 @@ class OFileNotification : public QObject bool activate(); - virtual bool hasChanged(); - static bool registerSignalHandler(); - static void unregisterSignalHandler(); - static void __signalHandler( int sig, siginfo_t *si, void *data ); + + private slots: + void inotifyEventHandler(); private: + bool registerEventHandler(); + void unregisterEventHandler(); + QString _path; @@ -169,18 +185,9 @@ class OFileNotification : public QObject QSignal _signal; - int _fd; bool _active; - struct stat _stat; -}; - -#if 0 - -class ODirectoryNotification : public OFileNotification -{ - - public: - virtual bool hasChanged() { return true; }; + bool _multi; + static QSocketNotifier* _sn; + int _wd; // inotify watch descriptor + static int _fd; // inotify device descriptor }; -#endif - } |