From 8cbb0586482ec650d7ff4fa9b6a7390b8b050793 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Mon, 02 May 2005 13:49:14 +0000 Subject: Rewrite OFileNotification to use the upcoming inotify (kernel 2.6) interface instead of the deprecated dnotify --- (limited to 'libopie2/opiecore/ofilenotify.h') 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 @@ -1,14 +1,14 @@ /*                 This file is part of the Opie Project - =. Copyright (C) 2004 Michael 'Mickey' Lauer + =. Copyright (C) 2004-2005 Michael 'Mickey' Lauer .=l. Copyright (C) The Opie Team          .>+-= _;:,     .>    :=|. 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; either version 2 of the License, -    ._= =}       : or (at your option) any later version. +- .   .-<_>     .<> Foundation; version 2 of the License. +    ._= =}       :   .%`+i>       _;_.   .i_,=:_.      -    :=|. This program is free software; you can #endif /* QT */ -#include +#include #include #include /* STD */ -#include -#include +#include "inotify.h" namespace Opie { namespace Core { @@ -56,22 +55,41 @@ namespace Core { *
    *
  • Access: The file was accessed (read) *
  • Modify The file was modified (write,truncate) - *
  • Create = The file was created in the directory - *
  • Delete = The file was unlinked from directory - *
  • Rename = The file was renamed *
  • Attrib = The file had its attributes changed (chmod,chown,chgrp) + *
  • CloseWrite = Writable file was closed + *
  • CloseNoWrite = Unwritable file was closed + *
  • Open = File was opened + *
  • MovedFrom = File was moved from X + *
  • MovedTo = File was moved to Y + *
  • DeleteSubdir = Subdir was deleted + *
  • DeleteFile = Subfile was deleted + *
  • CreateSubdir = Subdir was created + *
  • CreateFile = Subfile was created + *
  • DeleteSelf = Self was deleted + *
  • Unmount = The backing filesystem was unmounted *
* **/ -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 */ +}; /*====================================================================================== * OFileNotification @@ -81,9 +99,9 @@ enum OFileNotificationType { Single = 0x0000000, * @brief Represents a file notification * * 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 + * @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/ * * @author Michael 'Mickey' Lauer * @@ -106,7 +124,7 @@ class OFileNotification : public QObject *
      *
      *     #include 
-     *     #include 
+     *     #include 
      *     using namespace Opie::Core;
      *
      *     int main( int argc, char **argv )
@@ -118,7 +136,7 @@ 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. * * * The @a receiver is the receiving object and the @a member is the slot. @@ -128,7 +146,7 @@ class OFileNotification : public QObject * 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 start( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); + int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); /** * Stop watching for file events. **/ @@ -142,10 +160,6 @@ class OFileNotification : public QObject **/ QString path() const; /** - * @returns the UNIX file descriptor for the file being watched. - **/ - int fileno() const; - /** * @returns if a file is currently being watched. **/ bool isActive() const; @@ -158,31 +172,24 @@ class OFileNotification : public QObject protected: 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; OFileNotificationType _type; 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 - } } -- cgit v0.9.0.2