wlanutilities/wlansniffer/engine/server/src/wsfwlanbearerconnectionmonitor.cpp
branchRCL_3
changeset 10 dff6ebfd236f
parent 1 d07e190ed096
child 11 8b0eae1b1d71
--- a/wlanutilities/wlansniffer/engine/server/src/wsfwlanbearerconnectionmonitor.cpp	Fri Feb 19 23:55:42 2010 +0200
+++ b/wlanutilities/wlansniffer/engine/server/src/wsfwlanbearerconnectionmonitor.cpp	Fri Mar 12 15:48:54 2010 +0200
@@ -18,6 +18,8 @@
 
 
 //  EXTERNAL INCLUDES
+#include <w32std.h> 
+#include <apgtask.h>
 #include <utf.h>
 #include <cmpluginwlandef.h>
 #include <commdbconnpref.h>
@@ -84,6 +86,11 @@
     { 0x101fD9C5 }          // DHCP server (dhcpserv.exe)
     };
 
+/**
+* Browser UID
+*/
+const TUid KCRUidBrowser   = {0x10008D39};
+
 
 
 //  CONSTRUCTION AND DESTRUCTION
@@ -730,49 +737,72 @@
     {
     LOG_ENTERFN( "CWsfWlanBearerConnectionMonitor::CheckClientCountL" );
     
-    CWsfActiveWaiter* waiter = CWsfActiveWaiter::NewL();
-    
-    TConnMonClientEnumBuf clientInfo;
-
-    iMonitor.GetPckgAttribute( iConnectionId, 0, 
-                               KClientInfo, 
-                               clientInfo, 
-                               waiter->iStatus );
-    waiter->WaitForRequest();
-    delete waiter;
+    RWsSession wsSession;
+    if ( KErrNone == wsSession.Connect() )
+        {
+        LOG_WRITE( "Find browser task" );
+        TApaTaskList taskList( wsSession );
+        TApaTask task = taskList.FindApp( KCRUidBrowser );
+        if ( task.Exists() )
+            {
+            LOG_WRITE( "Browser is running - auto disconnect to false" );
+            iAutoDisconnect = EFalse;
+            iInactivityStart.UniversalTime();
+            }
+        else
+            {
+            LOG_WRITE( "Browser is not running - auto disconnect to true" );
+            iAutoDisconnect = ETrue;
+            }
+        wsSession.Close();
+        }
+    else
+        {
+        LOG_WRITE( "Session connect failed" );
+        }
     
-    // get the client count
-    iClientCount = clientInfo().iCount;
-    
-    // decrease count by each trivial client (Sniffer server, DHCP etc)
-    for ( TInt i( 0 ); i < clientInfo().iCount; ++i )
+    if ( iAutoDisconnect )
         {
-        for ( TInt j( 0 ); j < KTrivialClientCount; ++j )
+        CWsfActiveWaiter* waiter = CWsfActiveWaiter::NewL();
+        
+        TConnMonClientEnumBuf clientInfo;
+    
+        iMonitor.GetPckgAttribute( iConnectionId, 0, 
+                                   KClientInfo, 
+                                   clientInfo, 
+                                   waiter->iStatus );
+        waiter->WaitForRequest();
+        delete waiter;
+    
+        // get the client count
+        iClientCount = clientInfo().iCount;
+        
+        // decrease count by each trivial client (Sniffer server, DHCP etc)
+        for ( TInt i( 0 ); i < clientInfo().iCount; ++i )
             {
-            if ( clientInfo().iUid[i] == KTrivialClientUids[j] )
+            for ( TInt j( 0 ); j < KTrivialClientCount; ++j )
                 {
-                --iClientCount;
-                LOG_WRITEF( "trivial client [0x%08X] discarded", 
-                            clientInfo().iUid[i].iUid );                
-                break;
+                if ( clientInfo().iUid[i] == KTrivialClientUids[j] )
+                    {
+                    --iClientCount;
+                    LOG_WRITEF( "trivial client [0x%08X] discarded", 
+                                clientInfo().iUid[i].iUid );                
+                    break;
+                    }
                 }
             }
-        }
-    
+        
+        LOG_WRITEF( "iClientCount = %d (trivial clients:%d)", 
+                    iClientCount,
+                    clientInfo().iCount - iClientCount );
     
-    LOG_WRITEF( "iClientCount = %d (trivial clients:%d)", 
-                iClientCount,
-                clientInfo().iCount - iClientCount );
-
-    if ( iAutoDisconnect )
-        {
         if ( iClientCount )
             {
+            LOG_WRITE( "reset the inactivity start time to current time" );
             // there are more clients than the default ones ->
             // connection is considered active ->
             // reset the inactivity start time to current time
             iInactivityStart.UniversalTime();
-            
             }
         else
             {
@@ -789,10 +819,11 @@
                 LOG_WRITE( "inactivity threshold reached, disconnecting..." );
                 DisconnectBearer();
                 }
+            
             }
         
         }
-
+    
     }
 
 
@@ -947,9 +978,6 @@
         {
         case ECsNotConnected:
             {
-#ifdef __WINSCW__
-            User::After(5000000);
-#endif
             LOG_WRITE( "<ENotConnected>" );
 
             TInt err( KErrNone );