[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/network/smb4k/core
From:       Alexander Reinholdt <alexander.reinholdt () kdemail ! net>
Date:       2013-06-29 17:41:56
Message-ID: E1Usz9o-0007j4-L6 () scm ! kde ! org
[Download RAW message or body]

SVN commit 1358569 by areinholdt:

Improved periodic scanning.


 M  +40 -42    smb4kscanner.cpp  


--- trunk/playground/network/smb4k/core/smb4kscanner.cpp #1358568:1358569
@@ -947,64 +947,42 @@
   {
     if ( d->elapsedTimePS == 0 )
     {
-      if ( d->periodicJobs.isEmpty() )
-      {
-        // This case occurs when the user enables periodic scanning during
-        // runtime. We need to fill the list of periodic jobs here, so that
-        // we can immediately start periodic scanning.
+      // Fill the list of periodic jobs.
         d->periodicJobs << LookupDomains;
         d->periodicJobs << LookupDomainMembers;
         d->periodicJobs << LookupShares;
       }
+    else if ( d->elapsedTimePS >= (Smb4KSettings::scanInterval() * 60000 /* \
milliseconds */)  ) +    {
+      // Reset interval.
+      // To get the correct behavior, we need to set the time to -TIMER_INTERVAL!
+      d->elapsedTimePS = -TIMER_INTERVAL;      
+    }
       else
       {
-        // This is the regular case. We do not need to do anything.
+      // Do nothing
       }
 
+    if ( !d->periodicJobs.isEmpty() )
+    {
+      // Periodic scanning is only done if there are no subjobs
+      // in the queue and scanning is allowed.
+      if ( !hasSubjobs() && d->scanningAllowed )
+      {
+        // Get the process and initiate the periodic scanning.
       Process p = d->periodicJobs.takeFirst();
 
       switch ( p )
       {
         case LookupDomains:
         {
-          d->scanningAllowed = false;
           lookupDomains();
           break;
         }
-        default:
-        {
-          break;
-        }
-      }
-    }
-    else
-    {
-      if ( d->elapsedTimePS >= (Smb4KSettings::scanInterval() * 60000 /* \
                milliseconds */) )
-      {
-        // Reset interval. 
-        // To get the correct behavior, we need to set the time to -TIMER_INTERVAL!
-        d->elapsedTimePS = -TIMER_INTERVAL;
-
-        // Fill list
-        d->periodicJobs << LookupDomains;
-        d->periodicJobs << LookupDomainMembers;
-        d->periodicJobs << LookupShares;
-      }
-      else
-      {
-        // Check if we need to do something.
-        // Do not start any process before the previous has not finished.
-        if ( !d->periodicJobs.isEmpty() && d->scanningAllowed )
-        {
-          Process p = d->periodicJobs.takeFirst();
-
-          switch ( p )
-          {
             case LookupDomainMembers:
             {
               for ( int i = 0; i < workgroupsList().size(); ++i )
               {
-                d->scanningAllowed = false;
                 lookupDomainMembers( workgroupsList()[i] );
               }
               break;
@@ -1013,7 +991,6 @@
             {
               for ( int i = 0; i < hostsList().size(); ++i )
               {
-                d->scanningAllowed = false;
                 lookupShares( hostsList()[i] );
               }
               break;
@@ -1022,13 +999,16 @@
             {
               break;
             }
-          };
         }
+      }
         else
         {
           // Do nothing
         }
       }
+    else
+    {
+      // Do nothing
     }
 
     d->elapsedTimePS += TIMER_INTERVAL;
@@ -1136,6 +1116,11 @@
 
 void Smb4KScanner::slotAuthError( Smb4KQueryMasterJob *job )
 {
+  // Do not allow periodic scanning when an authentication
+  // error occurred. We do not want to operate on a network
+  // item that might get invalidated during periodic scanning.
+  d->scanningAllowed = false;
+  
   Smb4KHost master_browser;
   
   if ( !job->masterBrowser().isEmpty() )
@@ -1188,11 +1173,18 @@
   {
     // Do nothing
   }
+
+  d->scanningAllowed = true;
 }
 
 
 void Smb4KScanner::slotAuthError( Smb4KLookupDomainMembersJob *job )
 {
+  // Do not allow periodic scanning when an authentication
+  // error occurred. We do not want to operate on a network
+  // item that might get invalidated during periodic scanning.
+  d->scanningAllowed = false;
+
   Smb4KHost *master_browser = findHost( job->workgroup()->masterBrowserName(), \
job->workgroup()->workgroupName() );  
   if ( master_browser )
@@ -1212,11 +1204,18 @@
   {
     // Do nothing
   }
+
+  d->scanningAllowed = true;
 }
 
 
 void Smb4KScanner::slotAuthError( Smb4KLookupSharesJob *job )
 {
+  // Do not allow periodic scanning when an authentication
+  // error occurred. We do not want to operate on a network
+  // item that might get invalidated during periodic scanning.
+  d->scanningAllowed = false;
+  
   Smb4KHost *host = findHost( job->host()->hostName(), job->host()->workgroupName() \
);  
   if ( host )
@@ -1236,6 +1235,8 @@
   {
     // Do nothing
   }
+
+  d->scanningAllowed = true;
 }
 
 
@@ -1250,7 +1251,6 @@
 {
   Smb4KBasicNetworkItem item;
   emit finished( &item, LookupDomains );
-  d->scanningAllowed = true;
 }
 
 
@@ -1263,7 +1263,6 @@
 void Smb4KScanner::slotHostsLookupFinished( Smb4KWorkgroup *workgroup )
 {
   emit finished( workgroup, LookupDomainMembers );
-  d->scanningAllowed = true;
 }
 
 
@@ -1276,7 +1275,6 @@
 void Smb4KScanner::slotSharesLookupFinished( Smb4KHost *host )
 {
   emit finished( host, LookupShares );
-  d->scanningAllowed = true;
 }
 
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic