config option for KDirWatch method

Andreas Pakulat apaku at gmx.de
Mon Aug 6 21:34:08 BST 2007


On 06.08.07 01:59:48, Andreas Pakulat wrote:
> Hi,
> 
> in a KDirWatch related thread some time ago the issue was raised that
> currently there's no way to change the method this class uses for
> watching, because the order is hardcoded (fam, inotify, stat for linux).
> As the available fam-methods are not yet fully stable and one of the
> alternative's can't even be shut down (except by removing the
> server-binary) I'd like to apply the attached patch after discussion.
> 
> What it does is simply reading a value from a new group in the
> kdeglobals file (hope I have the KConfig code to get to that config file
> right) and determines which method to prefer based on that.
> 
> If a QString is too costly for the key I can change that to an int or
> something else, but I thought this way its easier for a possible kcm to
> be implemented because you don't have to keep the int-values in sync
> with kdirwatch.
> 
> This doesn't change API in any way, its BC and SC.

Here's an updated patch, which doesn't suffer from changes to the config
variables while an app is running.

Also it uses an enum to store the preferred method instead of a qstring,
which should be much faster. If somebody knows how to remove those if(
method == "Fam") with KConfig::readEntry I'm all ears, but I don't think
putting plain int's into the config is a good idea as its rather
cryptic.

I tested this locally this time and I don't see any FAM messages here
anymore after changing kdeglobals to INotify.

There's one drawback though: Due to the use of KGlobal::config() its
possible to have different methods per app. Yes, a user would have to
hand-edit files for that and should know what he does, it also shouldn't
be a problem for the class itself. But still I think it would be good to
restrict this and also the polling interval settings to kdeglobals by
using 

KConfig("kdeglobals") instead of KGlobal::config();

Andreas

-- 
Tonight you will pay the wages of sin; Don't forget to leave a tip.
-------------- next part --------------
Index: kio/kio/kdirwatch.cpp
===================================================================
--- kio/kio/kdirwatch.cpp	(Revision 695925)
+++ kio/kio/kdirwatch.cpp	(Arbeitskopie)
@@ -115,8 +115,20 @@
   m_nfsPollInterval = config.readEntry("NFSPollInterval", 5000);
   m_PollInterval = config.readEntry("PollInterval", 500);
 
+  QString method = config.readEntry("PreferredMethod", "INotify");
+  if(method == "Fam")
+  {
+    m_preferredMethod = Fam;
+  }else if(method == "Poll")
+  {
+    m_preferredMethod = Poll;
+  }else
+  {
+    m_preferredMethod = INotify;
+  }
   QString available("Stat");
 
+
   // used for FAM
   rescan_timer.setObjectName( "KDirWatchPrivate::rescan_timer" );
   rescan_timer.setSingleShot( true );
@@ -594,15 +606,40 @@
   if ( isNoisyFile( tpath ) )
     return;
 
+  //First try the preferred method, if that fails use the usual order: fam,inotify,stat
+  bool entryUsed = false;
 #if defined(HAVE_FAM)
-  if (useFAM(e)) return;
+  if (m_preferredMethod == Fam)
+  {
+    entryUsed = useFAM(e);
+  }else
 #endif
 
 #if defined(HAVE_SYS_INOTIFY_H)
-  if (useINotify(e)) return;
+  if (m_preferredMethod == INotify )
+  {
+    entryUsed = useINotify(e);
+  }else
 #endif
+  if (m_preferredMethod == Poll)
+  {
+    entryUsed = useStat(e);
+  }
 
-  useStat(e);
+  if (entryUsed)
+  {
+    return;
+  }else
+  {
+    #if defined(HAVE_FAM)
+    if (useFAM(e)) return;
+    #endif
+
+    #if defined(HAVE_SYS_INOTIFY_H)
+    if (useINotify(e)) return;
+    #endif
+    useStat(e);
+  }
 }
 
 
Index: kio/kio/kdirwatch_p.h
===================================================================
--- kio/kio/kdirwatch_p.h	(Revision 695925)
+++ kio/kio/kdirwatch_p.h	(Arbeitskopie)
@@ -64,6 +64,9 @@
   enum entryMode { UnknownMode = 0, StatMode, DNotifyMode, INotifyMode, FAMMode };
   enum { NoChange=0, Changed=1, Created=2, Deleted=4 };
 
+
+  enum WatchMethod { Poll, Fam, INotify };
+
   struct Client {
     KDirWatch* instance;
     int count;
@@ -146,6 +149,7 @@
   QTimer timer;
   EntryMap m_mapEntries;
 
+  WatchMethod m_preferredMethod;
   int freq;
   int statEntries;
   int m_nfsPollInterval, m_PollInterval;


More information about the kde-core-devel mailing list