summaryrefslogtreecommitdiffabout
path: root/microkde/kio/kio/kdirwatch.cpp
Unidiff
Diffstat (limited to 'microkde/kio/kio/kdirwatch.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kio/kio/kdirwatch.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/microkde/kio/kio/kdirwatch.cpp b/microkde/kio/kio/kdirwatch.cpp
index 1596d1f..5f07c54 100644
--- a/microkde/kio/kio/kdirwatch.cpp
+++ b/microkde/kio/kio/kdirwatch.cpp
@@ -31,53 +31,55 @@ $Id$
31// Jan 28, 2000 - Usage of FAM service on IRIX (Josef.Weidendorfer@in.tum.de) 31// Jan 28, 2000 - Usage of FAM service on IRIX (Josef.Weidendorfer@in.tum.de)
32// May 24. 1998 - List of times introduced, and some bugs are fixed. (sven) 32// May 24. 1998 - List of times introduced, and some bugs are fixed. (sven)
33// May 23. 1998 - Removed static pointer - you can have more instances. 33// May 23. 1998 - Removed static pointer - you can have more instances.
34// It was Needed for KRegistry. KDirWatch now emits signals and doesn't 34// It was Needed for KRegistry. KDirWatch now emits signals and doesn't
35// call (or need) KFM. No more URL's - just plain paths. (sven) 35// call (or need) KFM. No more URL's - just plain paths. (sven)
36// Mar 29. 1998 - added docs, stop/restart for particular Dirs and 36// Mar 29. 1998 - added docs, stop/restart for particular Dirs and
37// deep copies for list of dirs. (sven) 37// deep copies for list of dirs. (sven)
38// Mar 28. 1998 - Created. (sven) 38// Mar 28. 1998 - Created. (sven)
39 39
40 40
41//US #include <config.h> 41//US #include <config.h>
42 42
43#ifdef HAVE_DNOTIFY 43#ifdef HAVE_DNOTIFY
44#include <unistd.h> 44#include <unistd.h>
45#include <time.h> 45#include <time.h>
46#include <fcntl.h> 46#include <fcntl.h>
47#include <signal.h> 47#include <signal.h>
48#include <errno.h> 48#include <errno.h>
49#endif 49#endif
50 50
51#include <sys/stat.h> 51#include <sys/stat.h>
52#include <assert.h> 52#include <assert.h>
53#include <qdir.h> 53#include <qdir.h>
54#include <qfile.h> 54#include <qfile.h>
55#include <qintdict.h> 55#include <q3intdict.h>
56#include <qptrlist.h> 56#include <q3ptrlist.h>
57#include <qsocketnotifier.h> 57#include <qsocketnotifier.h>
58#include <qstringlist.h> 58#include <qstringlist.h>
59#include <qtimer.h> 59#include <qtimer.h>
60//Added by qt3to4:
61#include <Q3CString>
60 62
61#include <kapplication.h> 63#include <kapplication.h>
62#include <kdebug.h> 64#include <kdebug.h>
63#include <kconfig.h> 65#include <kconfig.h>
64#include <kconfigbase.h> 66#include <kconfigbase.h>
65#include <kglobal.h> 67#include <kglobal.h>
66#include <kstaticdeleter.h> 68#include <kstaticdeleter.h>
67 69
68#include "kdirwatch.h" 70#include "kdirwatch.h"
69#include "kdirwatch_p.h" 71#include "kdirwatch_p.h"
70//US #include "global.h" // KIO::probably_slow_mounted 72//US #include "global.h" // KIO::probably_slow_mounted
71 73
72#define NO_NOTIFY (time_t) 0 74#define NO_NOTIFY (time_t) 0
73 75
74static KDirWatchPrivate* dwp_self = 0; 76static KDirWatchPrivate* dwp_self = 0;
75 77
76#ifdef HAVE_DNOTIFY 78#ifdef HAVE_DNOTIFY
77 79
78#include <sys/utsname.h> 80#include <sys/utsname.h>
79 81
80static int dnotify_signal = 0; 82static int dnotify_signal = 0;
81 83
82/* DNOTIFY signal handler 84/* DNOTIFY signal handler
83 * 85 *
@@ -163,49 +165,49 @@ void KDirWatchPrivate::dnotify_sigio_handler(int sig, siginfo_t *si, void *p)
163 * (IMON, sending change events to /dev/imon) and a user 165 * (IMON, sending change events to /dev/imon) and a user
164 * level damon (fam), to which applications connect for 166 * level damon (fam), to which applications connect for
165 * notification of file changes. For NFS, the fam damon 167 * notification of file changes. For NFS, the fam damon
166 * on the NFS server machine is used; if IMON is not built 168 * on the NFS server machine is used; if IMON is not built
167 * into the kernel, fam uses polling for local files. 169 * into the kernel, fam uses polling for local files.
168 * - DNOTIFY: In late LINUX 2.3.x, directory notification was 170 * - DNOTIFY: In late LINUX 2.3.x, directory notification was
169 * introduced. By opening a directory, you can request for 171 * introduced. By opening a directory, you can request for
170 * UNIX signals to be sent to the process when a directory 172 * UNIX signals to be sent to the process when a directory
171 * is changed. 173 * is changed.
172 */ 174 */
173 175
174KDirWatchPrivate::KDirWatchPrivate() 176KDirWatchPrivate::KDirWatchPrivate()
175{ 177{
176 timer = new QTimer(this); 178 timer = new QTimer(this);
177 connect (timer, SIGNAL(timeout()), this, SLOT(slotRescan())); 179 connect (timer, SIGNAL(timeout()), this, SLOT(slotRescan()));
178 freq = 3600000; // 1 hour as upper bound 180 freq = 3600000; // 1 hour as upper bound
179 statEntries = 0; 181 statEntries = 0;
180 delayRemove = false; 182 delayRemove = false;
181 m_ref = 0; 183 m_ref = 0;
182 184
183//US KConfigGroup config(KGlobal::config(), QCString("DirWatch")); 185//US KConfigGroup config(KGlobal::config(), QCString("DirWatch"));
184//US m_nfsPollInterval = config.readNumEntry("NFSPollInterval", 5000); 186//US m_nfsPollInterval = config.readNumEntry("NFSPollInterval", 5000);
185//US m_PollInterval = config.readNumEntry("PollInterval", 500); 187//US m_PollInterval = config.readNumEntry("PollInterval", 500);
186 KConfig *config = KGlobal::config(); 188 KConfig *config = KGlobal::config();
187 KConfigGroupSaver saver( config, QCString("DirWatch") ); 189 KConfigGroupSaver saver( config, Q3CString("DirWatch") );
188 190
189 m_nfsPollInterval = config->readNumEntry("NFSPollInterval", 5000); 191 m_nfsPollInterval = config->readNumEntry("NFSPollInterval", 5000);
190 m_PollInterval = config->readNumEntry("PollInterval", 500); 192 m_PollInterval = config->readNumEntry("PollInterval", 500);
191 193
192 194
193 QString available("Stat"); 195 QString available("Stat");
194 196
195#ifdef HAVE_FAM 197#ifdef HAVE_FAM
196 // It's possible that FAM server can't be started 198 // It's possible that FAM server can't be started
197 if (FAMOpen(&fc) ==0) { 199 if (FAMOpen(&fc) ==0) {
198 available += ", FAM"; 200 available += ", FAM";
199 use_fam=true; 201 use_fam=true;
200 sn = new QSocketNotifier( FAMCONNECTION_GETFD(&fc), 202 sn = new QSocketNotifier( FAMCONNECTION_GETFD(&fc),
201 QSocketNotifier::Read, this); 203 QSocketNotifier::Read, this);
202 connect( sn, SIGNAL(activated(int)), 204 connect( sn, SIGNAL(activated(int)),
203 this, SLOT(famEventReceived()) ); 205 this, SLOT(famEventReceived()) );
204 } 206 }
205 else { 207 else {
206 kdDebug(7001) << "Can't use FAM (fam daemon not running?)" << endl; 208 kdDebug(7001) << "Can't use FAM (fam daemon not running?)" << endl;
207 use_fam=false; 209 use_fam=false;
208 } 210 }
209#endif 211#endif
210 212
211#ifdef HAVE_DNOTIFY 213#ifdef HAVE_DNOTIFY
@@ -710,49 +712,49 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
710 } 712 }
711#endif 713#endif
712 714
713 if (e->m_mode == StatMode) { 715 if (e->m_mode == StatMode) {
714 statEntries--; 716 statEntries--;
715 if ( statEntries == 0 ) { 717 if ( statEntries == 0 ) {
716 timer->stop(); // stop timer if lists are empty 718 timer->stop(); // stop timer if lists are empty
717 kdDebug(7001) << " Stopped Polling Timer" << endl; 719 kdDebug(7001) << " Stopped Polling Timer" << endl;
718 } 720 }
719 } 721 }
720 722
721 kdDebug(7001) << "Removed " << (e->isDir ? "Dir ":"File ") << e->path 723 kdDebug(7001) << "Removed " << (e->isDir ? "Dir ":"File ") << e->path
722 << (sub_entry ? QString(" for %1").arg(sub_entry->path) : QString("")) 724 << (sub_entry ? QString(" for %1").arg(sub_entry->path) : QString(""))
723 << (instance ? QString(" [%1]").arg(instance->name()) : QString("")) 725 << (instance ? QString(" [%1]").arg(instance->name()) : QString(""))
724 << endl; 726 << endl;
725 m_mapEntries.remove( e->path ); // <e> not valid any more 727 m_mapEntries.remove( e->path ); // <e> not valid any more
726} 728}
727 729
728 730
729/* Called from KDirWatch destructor: 731/* Called from KDirWatch destructor:
730 * remove <instance> as client from all entries 732 * remove <instance> as client from all entries
731 */ 733 */
732void KDirWatchPrivate::removeEntries( KDirWatch* instance ) 734void KDirWatchPrivate::removeEntries( KDirWatch* instance )
733{ 735{
734 QPtrList<Entry> list; 736 Q3PtrList<Entry> list;
735 int minfreq = 3600000; 737 int minfreq = 3600000;
736 738
737 // put all entries where instance is a client in list 739 // put all entries where instance is a client in list
738 EntryMap::Iterator it = m_mapEntries.begin(); 740 EntryMap::Iterator it = m_mapEntries.begin();
739 for( ; it != m_mapEntries.end(); ++it ) { 741 for( ; it != m_mapEntries.end(); ++it ) {
740 Client* c = (*it).m_clients.first(); 742 Client* c = (*it).m_clients.first();
741 for(;c;c=(*it).m_clients.next()) 743 for(;c;c=(*it).m_clients.next())
742 if (c->instance == instance) break; 744 if (c->instance == instance) break;
743 if (c) { 745 if (c) {
744 c->count = 1; // forces deletion of instance as client 746 c->count = 1; // forces deletion of instance as client
745 list.append(&(*it)); 747 list.append(&(*it));
746 } 748 }
747 else if ( (*it).m_mode == StatMode && (*it).freq < minfreq ) 749 else if ( (*it).m_mode == StatMode && (*it).freq < minfreq )
748 minfreq = (*it).freq; 750 minfreq = (*it).freq;
749 } 751 }
750 752
751 for(Entry* e=list.first();e;e=list.next()) 753 for(Entry* e=list.first();e;e=list.next())
752 removeEntry(instance, e->path, 0); 754 removeEntry(instance, e->path, 0);
753 755
754 if (minfreq > freq) { 756 if (minfreq > freq) {
755 // we can decrease the global polling frequency 757 // we can decrease the global polling frequency
756 freq = minfreq; 758 freq = minfreq;
757 if (timer->isActive()) timer->changeInterval(freq); 759 if (timer->isActive()) timer->changeInterval(freq);
758 kdDebug(7001) << "Poll Freq now " << freq << " msec" << endl; 760 kdDebug(7001) << "Poll Freq now " << freq << " msec" << endl;
@@ -986,49 +988,49 @@ void KDirWatchPrivate::slotRemoveDelayed()
986 for(e=removeList.first();e;e=removeList.next()) 988 for(e=removeList.first();e;e=removeList.next())
987 removeEntry(0, e->path, 0); 989 removeEntry(0, e->path, 0);
988 removeList.clear(); 990 removeList.clear();
989} 991}
990 992
991/* Scan all entries to be watched for changes. This is done regularly 993/* Scan all entries to be watched for changes. This is done regularly
992 * when polling and once after a DNOTIFY signal. This is NOT used by FAM. 994 * when polling and once after a DNOTIFY signal. This is NOT used by FAM.
993 */ 995 */
994void KDirWatchPrivate::slotRescan() 996void KDirWatchPrivate::slotRescan()
995{ 997{
996 EntryMap::Iterator it; 998 EntryMap::Iterator it;
997 999
998 // People can do very long things in the slot connected to dirty(), 1000 // People can do very long things in the slot connected to dirty(),
999 // like showing a message box. We don't want to keep polling during 1001 // like showing a message box. We don't want to keep polling during
1000 // that time, otherwise the value of 'delayRemove' will be reset. 1002 // that time, otherwise the value of 'delayRemove' will be reset.
1001 bool timerRunning = timer->isActive(); 1003 bool timerRunning = timer->isActive();
1002 if ( timerRunning ) 1004 if ( timerRunning )
1003 timer->stop(); 1005 timer->stop();
1004 1006
1005 // We delay deletions of entries this way. 1007 // We delay deletions of entries this way.
1006 // removeDir(), when called in slotDirty(), can cause a crash otherwise 1008 // removeDir(), when called in slotDirty(), can cause a crash otherwise
1007 delayRemove = true; 1009 delayRemove = true;
1008 1010
1009#ifdef HAVE_DNOTIFY 1011#ifdef HAVE_DNOTIFY
1010 QPtrList<Entry> dList, cList; 1012 Q3PtrList<Entry> dList, cList;
1011 1013
1012 // for DNotify method, 1014 // for DNotify method,
1013 if (rescan_all) 1015 if (rescan_all)
1014 { 1016 {
1015 // mark all as dirty 1017 // mark all as dirty
1016 it = m_mapEntries.begin(); 1018 it = m_mapEntries.begin();
1017 for( ; it != m_mapEntries.end(); ++it ) 1019 for( ; it != m_mapEntries.end(); ++it )
1018 (*it).dn_dirty = true; 1020 (*it).dn_dirty = true;
1019 rescan_all = false; 1021 rescan_all = false;
1020 } 1022 }
1021 else 1023 else
1022 { 1024 {
1023 // progate dirty flag to dependant entries (e.g. file watches) 1025 // progate dirty flag to dependant entries (e.g. file watches)
1024 it = m_mapEntries.begin(); 1026 it = m_mapEntries.begin();
1025 for( ; it != m_mapEntries.end(); ++it ) 1027 for( ; it != m_mapEntries.end(); ++it )
1026 if ( ((*it).m_mode == DNotifyMode) && (*it).dn_dirty ) 1028 if ( ((*it).m_mode == DNotifyMode) && (*it).dn_dirty )
1027 (*it).propagate_dirty(); 1029 (*it).propagate_dirty();
1028 } 1030 }
1029 1031
1030#endif 1032#endif
1031 1033
1032 it = m_mapEntries.begin(); 1034 it = m_mapEntries.begin();
1033 for( ; it != m_mapEntries.end(); ++it ) { 1035 for( ; it != m_mapEntries.end(); ++it ) {
1034 // we don't check invalid entries (i.e. remove delayed) 1036 // we don't check invalid entries (i.e. remove delayed)