kio Library API Documentation

kdirwatch_p.h

00001 /* Private Header for class of KDirWatchPrivate
00002  *
00003  * this separate header file is needed for MOC processing
00004  * because KDirWatchPrivate has signals and slots
00005  */
00006 
00007 #ifndef _KDIRWATCH_P_H
00008 #define _KDIRWATCH_P_H
00009 
00010 #ifdef HAVE_FAM
00011 #include <fam.h>
00012 #endif
00013 
00014 #include <ctime>
00015 
00016 #define invalid_ctime ((time_t)-1)
00017 
00018 /* KDirWatchPrivate is a singleton and does the watching
00019  * for every KDirWatch instance in the application.
00020  */
00021 class KDirWatchPrivate : public QObject
00022 {
00023   Q_OBJECT
00024 public:
00025 
00026   enum entryStatus { Normal = 0, NonExistent };
00027   enum entryMode { UnknownMode = 0, StatMode, DNotifyMode, FAMMode };
00028   enum { NoChange=0, Changed=1, Created=2, Deleted=4 };
00029 
00030   struct Client {
00031     KDirWatch* instance;
00032     int count;
00033     // did the instance stop watching
00034     bool watchingStopped;
00035     // events blocked when stopped
00036     int pending;
00037   };
00038 
00039   class Entry
00040   {
00041   public:
00042     // the last observed modification time
00043     time_t m_ctime;
00044     // the last observed link count
00045     int m_nlink;
00046     entryStatus m_status;
00047     entryMode m_mode;
00048     bool isDir;
00049     // instances interested in events
00050     QPtrList<Client> m_clients;
00051     // nonexistent entries of this directory
00052     QPtrList<Entry> m_entries;
00053     QString path;
00054 
00055     int msecLeft, freq;
00056 
00057     void addClient(KDirWatch*);
00058     void removeClient(KDirWatch*);
00059     int clients();
00060     bool isValid() { return m_clients.count() || m_entries.count(); }
00061 
00062     bool dirty;
00063     void propagate_dirty();
00064 
00065 #ifdef HAVE_FAM
00066     FAMRequest fr;
00067 #endif
00068 
00069 #ifdef HAVE_DNOTIFY
00070     int dn_fd;
00071 #endif
00072   };
00073 
00074   typedef QMap<QString,Entry> EntryMap;
00075 
00076   KDirWatchPrivate();
00077   ~KDirWatchPrivate();
00078 
00079   void resetList (KDirWatch*,bool);
00080   void useFreq(Entry* e, int newFreq);
00081   void addEntry(KDirWatch*,const QString&, Entry*, bool);
00082   void removeEntry(KDirWatch*,const QString&, Entry*);
00083   bool stopEntryScan(KDirWatch*, Entry*);
00084   bool restartEntryScan(KDirWatch*, Entry*, bool );
00085   void stopScan(KDirWatch*);
00086   void startScan(KDirWatch*, bool, bool);
00087 
00088   void removeEntries(KDirWatch*);
00089   void statistics();
00090 
00091   Entry* entry(const QString&);
00092   int scanEntry(Entry* e);
00093   void emitEvent(Entry* e, int event, const QString &fileName = QString::null);
00094 
00095   // Memory management - delete when last KDirWatch gets deleted
00096   void ref() { m_ref++; }
00097   bool deref() { return ( --m_ref == 0 ); }
00098 
00099  static bool isNoisyFile( const char *filename );
00100 
00101 public slots:
00102   void slotRescan();
00103   void famEventReceived(); // for FAM
00104   void slotActivated(); // for DNOTIFY
00105   void slotRemoveDelayed();
00106 
00107 public:
00108   QTimer *timer;
00109   EntryMap m_mapEntries;
00110 
00111   int freq;
00112   int statEntries;
00113   int m_nfsPollInterval, m_PollInterval;
00114   int m_ref;
00115   bool useStat(Entry*);
00116 
00117   bool delayRemove;
00118   QPtrList<Entry> removeList;
00119 
00120   bool rescan_all;
00121   QTimer rescan_timer;
00122 
00123 #ifdef HAVE_FAM
00124   QSocketNotifier *sn;
00125   FAMConnection fc;
00126   bool use_fam;
00127 
00128   void checkFAMEvent(FAMEvent*);
00129   bool useFAM(Entry*);
00130 #endif
00131 
00132 #ifdef HAVE_DNOTIFY
00133   bool supports_dnotify;
00134   int mPipe[2];
00135   QSocketNotifier *mSn;
00136   QIntDict<Entry> fd_Entry;
00137 
00138   static void dnotify_handler(int, siginfo_t *si, void *);
00139   static void dnotify_sigio_handler(int, siginfo_t *si, void *);
00140   bool useDNotify(Entry*);
00141 #endif
00142 };
00143 
00144 #endif // KDIRWATCH_P_H
00145 
KDE Logo
This file is part of the documentation for kio Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jan 22 16:47:01 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003