wlanutilities/wlansniffer/engine/server/src/wsfwlanbearerconnectionmonitor.cpp
branchRCL_3
changeset 15 dff6ebfd236f
parent 1 d07e190ed096
child 16 8b0eae1b1d71
equal deleted inserted replaced
8:c2bc3f8c7777 15:dff6ebfd236f
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
    19 
    20 //  EXTERNAL INCLUDES
    20 //  EXTERNAL INCLUDES
       
    21 #include <w32std.h> 
       
    22 #include <apgtask.h>
    21 #include <utf.h>
    23 #include <utf.h>
    22 #include <cmpluginwlandef.h>
    24 #include <cmpluginwlandef.h>
    23 #include <commdbconnpref.h>
    25 #include <commdbconnpref.h>
    24 #include <wlanerrorcodes.h>
    26 #include <wlanerrorcodes.h>
    25 #include <cmconnectionmethodext.h>
    27 #include <cmconnectionmethodext.h>
    81 static const TUid KTrivialClientUids[KTrivialClientCount] = 
    83 static const TUid KTrivialClientUids[KTrivialClientCount] = 
    82     {
    84     {
    83     { 0x10281CAB },         // Sniffer server (wsfserver.exe)
    85     { 0x10281CAB },         // Sniffer server (wsfserver.exe)
    84     { 0x101fD9C5 }          // DHCP server (dhcpserv.exe)
    86     { 0x101fD9C5 }          // DHCP server (dhcpserv.exe)
    85     };
    87     };
       
    88 
       
    89 /**
       
    90 * Browser UID
       
    91 */
       
    92 const TUid KCRUidBrowser   = {0x10008D39};
    86 
    93 
    87 
    94 
    88 
    95 
    89 //  CONSTRUCTION AND DESTRUCTION
    96 //  CONSTRUCTION AND DESTRUCTION
    90 
    97 
   728 //
   735 //
   729 void CWsfWlanBearerConnectionMonitor::CheckClientCountL()
   736 void CWsfWlanBearerConnectionMonitor::CheckClientCountL()
   730     {
   737     {
   731     LOG_ENTERFN( "CWsfWlanBearerConnectionMonitor::CheckClientCountL" );
   738     LOG_ENTERFN( "CWsfWlanBearerConnectionMonitor::CheckClientCountL" );
   732     
   739     
   733     CWsfActiveWaiter* waiter = CWsfActiveWaiter::NewL();
   740     RWsSession wsSession;
   734     
   741     if ( KErrNone == wsSession.Connect() )
   735     TConnMonClientEnumBuf clientInfo;
   742         {
   736 
   743         LOG_WRITE( "Find browser task" );
   737     iMonitor.GetPckgAttribute( iConnectionId, 0, 
   744         TApaTaskList taskList( wsSession );
   738                                KClientInfo, 
   745         TApaTask task = taskList.FindApp( KCRUidBrowser );
   739                                clientInfo, 
   746         if ( task.Exists() )
   740                                waiter->iStatus );
   747             {
   741     waiter->WaitForRequest();
   748             LOG_WRITE( "Browser is running - auto disconnect to false" );
   742     delete waiter;
   749             iAutoDisconnect = EFalse;
   743     
   750             iInactivityStart.UniversalTime();
   744     // get the client count
   751             }
   745     iClientCount = clientInfo().iCount;
   752         else
   746     
   753             {
   747     // decrease count by each trivial client (Sniffer server, DHCP etc)
   754             LOG_WRITE( "Browser is not running - auto disconnect to true" );
   748     for ( TInt i( 0 ); i < clientInfo().iCount; ++i )
   755             iAutoDisconnect = ETrue;
   749         {
   756             }
   750         for ( TInt j( 0 ); j < KTrivialClientCount; ++j )
   757         wsSession.Close();
   751             {
   758         }
   752             if ( clientInfo().iUid[i] == KTrivialClientUids[j] )
   759     else
   753                 {
   760         {
   754                 --iClientCount;
   761         LOG_WRITE( "Session connect failed" );
   755                 LOG_WRITEF( "trivial client [0x%08X] discarded", 
   762         }
   756                             clientInfo().iUid[i].iUid );                
   763     
   757                 break;
   764     if ( iAutoDisconnect )
       
   765         {
       
   766         CWsfActiveWaiter* waiter = CWsfActiveWaiter::NewL();
       
   767         
       
   768         TConnMonClientEnumBuf clientInfo;
       
   769     
       
   770         iMonitor.GetPckgAttribute( iConnectionId, 0, 
       
   771                                    KClientInfo, 
       
   772                                    clientInfo, 
       
   773                                    waiter->iStatus );
       
   774         waiter->WaitForRequest();
       
   775         delete waiter;
       
   776     
       
   777         // get the client count
       
   778         iClientCount = clientInfo().iCount;
       
   779         
       
   780         // decrease count by each trivial client (Sniffer server, DHCP etc)
       
   781         for ( TInt i( 0 ); i < clientInfo().iCount; ++i )
       
   782             {
       
   783             for ( TInt j( 0 ); j < KTrivialClientCount; ++j )
       
   784                 {
       
   785                 if ( clientInfo().iUid[i] == KTrivialClientUids[j] )
       
   786                     {
       
   787                     --iClientCount;
       
   788                     LOG_WRITEF( "trivial client [0x%08X] discarded", 
       
   789                                 clientInfo().iUid[i].iUid );                
       
   790                     break;
       
   791                     }
   758                 }
   792                 }
   759             }
   793             }
   760         }
   794         
   761     
   795         LOG_WRITEF( "iClientCount = %d (trivial clients:%d)", 
   762     
   796                     iClientCount,
   763     LOG_WRITEF( "iClientCount = %d (trivial clients:%d)", 
   797                     clientInfo().iCount - iClientCount );
   764                 iClientCount,
   798     
   765                 clientInfo().iCount - iClientCount );
       
   766 
       
   767     if ( iAutoDisconnect )
       
   768         {
       
   769         if ( iClientCount )
   799         if ( iClientCount )
   770             {
   800             {
       
   801             LOG_WRITE( "reset the inactivity start time to current time" );
   771             // there are more clients than the default ones ->
   802             // there are more clients than the default ones ->
   772             // connection is considered active ->
   803             // connection is considered active ->
   773             // reset the inactivity start time to current time
   804             // reset the inactivity start time to current time
   774             iInactivityStart.UniversalTime();
   805             iInactivityStart.UniversalTime();
   775             
       
   776             }
   806             }
   777         else
   807         else
   778             {
   808             {
   779             // there are only trivial clients of the connection
   809             // there are only trivial clients of the connection
   780             // this means inactivity, so check the time elapsed
   810             // this means inactivity, so check the time elapsed
   787                 {
   817                 {
   788                 // inactivity time limit elapsed, connection should be stopped
   818                 // inactivity time limit elapsed, connection should be stopped
   789                 LOG_WRITE( "inactivity threshold reached, disconnecting..." );
   819                 LOG_WRITE( "inactivity threshold reached, disconnecting..." );
   790                 DisconnectBearer();
   820                 DisconnectBearer();
   791                 }
   821                 }
   792             }
   822             
   793         
   823             }
   794         }
   824         
   795 
   825         }
       
   826     
   796     }
   827     }
   797 
   828 
   798 
   829 
   799 // ---------------------------------------------------------------------------
   830 // ---------------------------------------------------------------------------
   800 // CWsfWlanBearerConnectionMonitor::ControlDisconnectTimer
   831 // CWsfWlanBearerConnectionMonitor::ControlDisconnectTimer
   945        
   976        
   946     switch ( iConnectingState )
   977     switch ( iConnectingState )
   947         {
   978         {
   948         case ECsNotConnected:
   979         case ECsNotConnected:
   949             {
   980             {
   950 #ifdef __WINSCW__
       
   951             User::After(5000000);
       
   952 #endif
       
   953             LOG_WRITE( "<ENotConnected>" );
   981             LOG_WRITE( "<ENotConnected>" );
   954 
   982 
   955             TInt err( KErrNone );
   983             TInt err( KErrNone );
   956             err = iSocketServ.Connect();
   984             err = iSocketServ.Connect();
   957             
   985