convergedconnectionhandler/cchserver/src/cchconnmonhandler.cpp
branchRCL_3
changeset 14 be41ab7b952f
parent 0 a4daefaec16c
child 18 8c9c07ad8b6b
equal deleted inserted replaced
12:876a3df1f464 14:be41ab7b952f
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include "cchconnmonhandler.h"
    20 #include "cchconnmonhandler.h"
    21 #include "cchserverbase.h"
    21 #include "cchserverbase.h"
    22 #include "cchlogger.h"
    22 #include "cchlogger.h"
    23 #include "cchservicehandler.h"
    23 #include "cchservicehandler.h"
       
    24 #include "cchconnmonhandlernotifier.h"
    24 
    25 
    25 // EXTERNAL DATA STRUCTURES
    26 // EXTERNAL DATA STRUCTURES
    26 // None
    27 // None
    27 
    28 
    28 // EXTERNAL FUNCTION PROTOTYPES
    29 // EXTERNAL FUNCTION PROTOTYPES
    33 
    34 
    34 // MACROS
    35 // MACROS
    35 // None
    36 // None
    36 
    37 
    37 // LOCAL CONSTANTS AND MACROS
    38 // LOCAL CONSTANTS AND MACROS
    38 // None
    39 const TInt KPeriodicTimerInterval( 5000000 ); // 5sec.
    39 
    40 
    40 // MODULE DATA STRUCTURES
    41 // MODULE DATA STRUCTURES
    41 // None
    42 // None
    42 
    43 
    43 // LOCAL FUNCTION PROTOTYPES
    44 // LOCAL FUNCTION PROTOTYPES
    70 //
    71 //
    71 void CCCHConnMonHandler::ConstructL()
    72 void CCCHConnMonHandler::ConstructL()
    72     {
    73     {
    73     User::LeaveIfError( iConnMon.ConnectL() );
    74     User::LeaveIfError( iConnMon.ConnectL() );
    74     NotifyL();
    75     NotifyL();
       
    76     iConnChangeListenerTimer = CPeriodic::NewL( CActive::EPriorityIdle );
    75     }
    77     }
    76 
    78 
    77 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    78 // CCCHConnMonHandler::NewL
    80 // CCCHConnMonHandler::NewL
    79 // Two-phased constructor.
    81 // Two-phased constructor.
   101 
   103 
   102 // Destructor
   104 // Destructor
   103 CCCHConnMonHandler::~CCCHConnMonHandler()
   105 CCCHConnMonHandler::~CCCHConnMonHandler()
   104     {
   106     {
   105     CCHLOGSTRING( "CCCHConnMonHandler::~CCCHConnMonHandler" );
   107     CCHLOGSTRING( "CCCHConnMonHandler::~CCCHConnMonHandler" );
   106     
   108     iConnChangeListenerTimer->Cancel();
       
   109     delete iConnChangeListenerTimer;
   107     StopNotify();
   110     StopNotify();
   108     Cancel();
   111     Cancel();
       
   112     iPendingRequests.Close();
       
   113 	iUnsolvedConnIds.Close();
       
   114     iConnIapIds.Close();
   109     iAvailableSNAPs.Close();
   115     iAvailableSNAPs.Close();
   110     iAvailableIAPs.Close();
   116     iAvailableIAPs.Close();
   111     iConnMon.Close();
   117     iConnMon.Close();
   112     }
   118     }
   113 
   119 
   114 // ---------------------------------------------------------------------------
   120 // ---------------------------------------------------------------------------
   115 // CCCHConnMonHandler::ScanNetworks
   121 // CCCHConnMonHandler::ScanNetworks
   116 // (other items were commented in a header).
   122 // (other items were commented in a header).
   117 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   118 //
   124 //
   119 void CCCHConnMonHandler::ScanNetworks( TBool aWlanScan )
   125 void CCCHConnMonHandler::ScanNetworks(
       
   126     TBool aWlanScan, MCCHConnMonHandlerNotifier* aObserver )
   120     {
   127     {
   121     CCHLOGSTRING( "CCCHConnMonHandler::ScanNetworks: IN" );
   128     CCHLOGSTRING( "CCCHConnMonHandler::ScanNetworks: IN" );
   122     
   129     
   123     if ( aWlanScan )
   130     if ( aWlanScan )
   124         {
   131         {
       
   132         iNetworkScanningObserver = aObserver;
   125         GetIaps( EBearerIdAll );
   133         GetIaps( EBearerIdAll );
   126         }
   134         }
   127             
   135             
   128     CCHLOGSTRING( "CCCHConnMonHandler::ScanNetworks: OUT" );
   136     CCHLOGSTRING( "CCCHConnMonHandler::ScanNetworks: OUT" );
   129     }
   137     }
   156 //
   164 //
   157 TBool CCCHConnMonHandler::IsIapAvailable( TUint aIapId ) const
   165 TBool CCCHConnMonHandler::IsIapAvailable( TUint aIapId ) const
   158     {
   166     {
   159     return ( KErrNotFound == iAvailableIAPs.Find( aIapId ) ) 
   167     return ( KErrNotFound == iAvailableIAPs.Find( aIapId ) ) 
   160         ? EFalse : ETrue; 
   168         ? EFalse : ETrue; 
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CCCHConnMonHandler::SetSNAPsAvailabilityChangeListener
       
   173 // (other items were commented in a header).
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CCCHConnMonHandler::SetSNAPsAvailabilityChangeListener(
       
   177     MCCHConnMonHandlerNotifier* aObserver )
       
   178     {
       
   179     CCHLOGSTRING( "CCCHConnMonHandler::SetSNAPsAvailabilityChangeListener" );
       
   180     iSNAPsAvailabilityObserver = aObserver;
       
   181     if ( iSNAPsAvailabilityObserver )
       
   182         {
       
   183         iConnChangeListenerTimer->Start(
       
   184             KPeriodicTimerInterval,
       
   185             KPeriodicTimerInterval,
       
   186             TCallBack( PeriodicTimerCallBack, this ) );
       
   187         }
   161     }
   188     }
   162 
   189 
   163 // ---------------------------------------------------------------------------
   190 // ---------------------------------------------------------------------------
   164 // CCCHConnMonHandler::GetIaps
   191 // CCCHConnMonHandler::GetIaps
   165 // (other items were commented in a header).
   192 // (other items were commented in a header).
   276 void CCCHConnMonHandler::StopNotify()
   303 void CCCHConnMonHandler::StopNotify()
   277     {
   304     {
   278     iConnMon.CancelNotifications();
   305     iConnMon.CancelNotifications();
   279     }
   306     }
   280 
   307 
       
   308 // ----------------------------------------------------------------------------
       
   309 // CCCHConnMonHandler::PeriodicTimerCallBack
       
   310 // The call back function.
       
   311 // ----------------------------------------------------------------------------
       
   312 //
       
   313 TInt CCCHConnMonHandler::PeriodicTimerCallBack( TAny* aAny )
       
   314     {
       
   315     CCHLOGSTRING( "CCCHConnMonHandler::PeriodicTimerCallBack" );
       
   316     
       
   317     CCCHConnMonHandler* self = static_cast<CCCHConnMonHandler*>( aAny );
       
   318     self->iConnChangeListenerTimer->Cancel();
       
   319     
       
   320     if ( self->iSNAPsAvailabilityObserver )
       
   321         {
       
   322         self->iSNAPsAvailabilityObserver->
       
   323             SNAPsAvailabilityChanged( KErrTimedOut );
       
   324         }
       
   325     
       
   326     return KErrNone;
       
   327     }
       
   328 
   281 // ---------------------------------------------------------------------------
   329 // ---------------------------------------------------------------------------
   282 // CCCHConnMonHandler::RunL
   330 // CCCHConnMonHandler::RunL
   283 // (other items were commented in a header).
   331 // (other items were commented in a header).
   284 // ---------------------------------------------------------------------------
   332 // ---------------------------------------------------------------------------
   285 //
   333 //
   294             case EGetIAPS:
   342             case EGetIAPS:
   295                 {
   343                 {
   296                 UpdateIapArray( iIapsBuf() );
   344                 UpdateIapArray( iIapsBuf() );
   297                 GetSNAPs();
   345                 GetSNAPs();
   298                 }
   346                 }
   299             break;
   347                 break;
       
   348             
   300             case EGetSNAPs:
   349             case EGetSNAPs:
   301                 {
   350                 {
   302                 UpdateSnapArray( iSNAPbuf() );
   351                 UpdateSnapArray( iSNAPbuf() );
   303                 }
   352                 if ( iNetworkScanningObserver )
   304             break;
   353                     {
       
   354                     iNetworkScanningObserver->NetworkScanningCompletedL(
       
   355                         iSNAPbuf(), KErrNone );
       
   356                     iNetworkScanningObserver = NULL;
       
   357                     }
       
   358                 }
       
   359                 break;
       
   360             
       
   361             case EGetIAP:
       
   362                 {
       
   363                 CCHLOGSTRING2( "CCCHConnMonHandler::RunL: iap: %d", iConnIapId );
       
   364                 TCCHConnectionInfo info;
       
   365                 info.iIapId  = iConnIapId;
       
   366                 info.iConnId = iConnId;
       
   367                                     
       
   368                 if ( KErrNotFound == iConnIapIds.Find( info ) )
       
   369                     {
       
   370                     iConnIapIds.Append( info );
       
   371                     }
       
   372                 iConnId    = 0;
       
   373                 iConnIapId = 0;
       
   374                 
       
   375                 CCHLOGSTRING2( "CCCHConnMonHandler::RunL: unsolved conn count: %d", iUnsolvedConnIds.Count() );
       
   376                 if ( iUnsolvedConnIds.Count() )
       
   377                     {
       
   378                     GetIapId();
       
   379                     }
       
   380                 }
       
   381                 break;
       
   382                 
       
   383             case EGetConnectionCount:
       
   384                 {
       
   385                 CCHLOGSTRING2( "CCCHConnMonHandler::RunL: conn count: %d", iConnCount );
       
   386                 TBool familiar( EFalse );
       
   387                 TUint connId( KErrNone );
       
   388                 TUint subConnCount( KErrNone );
       
   389                 for ( TInt i( 1 ); i <= iConnCount; i++ )
       
   390                     {
       
   391                     if ( !iConnMon.GetConnectionInfo( i, connId, subConnCount ) )
       
   392                         {
       
   393                         familiar = EFalse;
       
   394                         for ( TInt j( 0 ); j < iConnIapIds.Count(); j++ )
       
   395                             {
       
   396                             if ( connId == iConnIapIds[ j ].iConnId )
       
   397                                 {
       
   398                                 CCHLOGSTRING2( "CCCHConnMonHandler::RunL: iap %d is familiar connection", iConnIapIds[ j ].iIapId );
       
   399                                 familiar = ETrue;
       
   400                                 break;
       
   401                                 }
       
   402                             }
       
   403                         
       
   404                         if ( !familiar && KErrNotFound == iUnsolvedConnIds.Find( connId ) )
       
   405                             {
       
   406                             iUnsolvedConnIds.Append( connId );
       
   407                             }
       
   408                         }
       
   409                     }
       
   410                 iConnCount = 0;
       
   411                 
       
   412                 CCHLOGSTRING2( "CCCHConnMonHandler::RunL: unsolved conn count: %d", iUnsolvedConnIds.Count() );
       
   413                 if ( iUnsolvedConnIds.Count() )
       
   414                     {
       
   415                     GetIapId();
       
   416                     }
       
   417                 }
       
   418                 break;
       
   419                 
   305             default:
   420             default:
   306                 break;
   421                 break;
   307             }
   422             }
       
   423         
       
   424         
       
   425         if ( iPendingRequests.Count() && !IsActive() )
       
   426             {
       
   427             CCHLOGSTRING2( "CCCHConnMonHandler::RunL: request pending : %d", 
       
   428                 iPendingRequests[ 0 ] );
       
   429             switch ( iPendingRequests[ 0 ] )
       
   430                 {
       
   431                 case EGetIAP:
       
   432                     {
       
   433                     GetIapId();
       
   434                     }
       
   435                     break;
       
   436                         
       
   437                 case EGetConnectionCount:
       
   438                     {
       
   439                     GetConnectionCount();
       
   440                     }
       
   441                     break;
       
   442                         
       
   443                 default:
       
   444                     break;
       
   445                 }
       
   446             
       
   447             iPendingRequests.Remove( 0 );
       
   448             iPendingRequests.Compress();
       
   449             }
       
   450         }
       
   451     else
       
   452         {
       
   453         if ( iNetworkScanningObserver )
       
   454             {
       
   455             iNetworkScanningObserver->NetworkScanningCompletedL(
       
   456                 iSNAPbuf(), iStatus.Int() );
       
   457             iNetworkScanningObserver = NULL;
       
   458             }
   308         }
   459         }
   309             
   460             
   310     CCHLOGSTRING( "CCCHConnMonHandler::RunL: OUT" );
   461     CCHLOGSTRING( "CCCHConnMonHandler::RunL: OUT" );
   311     }
   462     }
   312 
   463 
   313 // ---------------------------------------------------------------------------
   464 // ---------------------------------------------------------------------------
       
   465 // CCCHConnMonHandler::StartMonitoringConnectionChanges
       
   466 // (other items were commented in a header).
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CCCHConnMonHandler::StartMonitoringConnectionChanges()
       
   470     {
       
   471     iConnIapIds.Reset();
       
   472     
       
   473     if ( !IsActive() )
       
   474         {
       
   475         GetConnectionCount();
       
   476         }
       
   477     else
       
   478         {
       
   479         iPendingRequests.Append( EGetConnectionCount );
       
   480         }
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // CCCHConnMonHandler::StopMonitoringConnectionChanges
       
   485 // (other items were commented in a header).
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 void CCCHConnMonHandler::StopMonitoringConnectionChanges( 
       
   489     RArray<TUint>& aIapIds )
       
   490     {
       
   491     aIapIds.Reset();
       
   492     for ( TInt i( 0 ); i < iConnIapIds.Count(); i++ )
       
   493         {
       
   494         if ( KErrNotFound == aIapIds.Find( iConnIapIds[ i ].iIapId ) )
       
   495             {
       
   496             aIapIds.Append( iConnIapIds[ i ].iIapId );
       
   497             }
       
   498         }
       
   499     }
       
   500 	
       
   501 // ---------------------------------------------------------------------------
       
   502 // CCCHConnMonHandler::GetConnectionCount
       
   503 // (other items were commented in a header).
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 void CCCHConnMonHandler::GetConnectionCount()
       
   507     {
       
   508     iState = EGetConnectionCount;
       
   509     iConnMon.GetConnectionCount( iConnCount, iStatus ); 
       
   510     SetActive(); 
       
   511     }
       
   512      
       
   513 // ---------------------------------------------------------------------------
       
   514 // CCCHConnMonHandler::GetIapId
       
   515 // (other items were commented in a header).
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 void CCCHConnMonHandler::GetIapId()
       
   519     {
       
   520     if ( iUnsolvedConnIds.Count() )
       
   521         {
       
   522         iConnId = iUnsolvedConnIds[ 0 ];
       
   523         iUnsolvedConnIds.Remove( 0 );
       
   524         iUnsolvedConnIds.Compress();
       
   525         
       
   526         iState = EGetIAP;
       
   527         iConnMon.GetUintAttribute( iConnId, 0, KIAPId, iConnIapId, iStatus );
       
   528         SetActive();
       
   529         }
       
   530     }
       
   531             
       
   532 // ---------------------------------------------------------------------------
       
   533 // CCCHConnMonHandler::RemoveIapId
       
   534 // (other items were commented in a header).
       
   535 // ---------------------------------------------------------------------------
       
   536 //
       
   537 void CCCHConnMonHandler::RemoveIapId(
       
   538     TUint aConnId )
       
   539     {
       
   540     for ( TInt i( 0 ); i < iConnIapIds.Count(); i++ )
       
   541         {
       
   542         if ( aConnId == iConnIapIds[ i ].iConnId )
       
   543             {
       
   544             iConnIapIds.Remove( i );
       
   545             iConnIapIds.Compress();
       
   546             break;
       
   547             }
       
   548         }
       
   549     }
       
   550 	
       
   551 // ---------------------------------------------------------------------------
   314 // CCCHConnMonHandler::DoCancel
   552 // CCCHConnMonHandler::DoCancel
   315 // (other items were commented in a header).
   553 // (other items were commented in a header).
   316 // ---------------------------------------------------------------------------
   554 // ---------------------------------------------------------------------------
   317 //
   555 //
   318 void CCCHConnMonHandler::DoCancel()
   556 void CCCHConnMonHandler::DoCancel()
   319     {
   557     {
   320     iConnMon.CancelAsyncRequest( EConnMonGetPckgAttribute );
   558     iConnMon.CancelAsyncRequest( EConnMonGetPckgAttribute );
       
   559     if ( iNetworkScanningObserver )
       
   560         {
       
   561         iNetworkScanningObserver->NetworkScanningCompletedL(
       
   562             iSNAPbuf(), KErrCancel );
       
   563         iNetworkScanningObserver = NULL;
       
   564         }
       
   565     if ( iSNAPsAvailabilityObserver )
       
   566         {
       
   567         iSNAPsAvailabilityObserver->SNAPsAvailabilityChanged( KErrCancel );
       
   568         iSNAPsAvailabilityObserver = NULL;
       
   569         }
   321     }
   570     }
   322 
   571 
   323 // ---------------------------------------------------------------------------
   572 // ---------------------------------------------------------------------------
   324 // CCCHConnMonHandler::EventL
   573 // CCCHConnMonHandler::EventL
   325 // (other items were commented in a header).
   574 // (other items were commented in a header).
   350             eventSNAP = static_cast< const CConnMonSNAPsAvailabilityChange* >(
   599             eventSNAP = static_cast< const CConnMonSNAPsAvailabilityChange* >(
   351                  &aConnMonEvent );
   600                  &aConnMonEvent );
   352 
   601 
   353             TConnMonSNAPInfo snaps  = eventSNAP->SNAPAvailability();
   602             TConnMonSNAPInfo snaps  = eventSNAP->SNAPAvailability();
   354             UpdateSnapArray( snaps );
   603             UpdateSnapArray( snaps );
       
   604             
       
   605             if ( iSNAPsAvailabilityObserver )
       
   606                 {
       
   607                 iConnChangeListenerTimer->Cancel();
       
   608                 iSNAPsAvailabilityObserver->SNAPsAvailabilityChanged( KErrNone );
       
   609                 }
   355             }
   610             }
   356             break;
   611             break;
       
   612 			
       
   613         case EConnMonCreateConnection:
       
   614             {
       
   615             const CConnMonCreateConnection* eventCreate = NULL; 
       
   616             eventCreate = static_cast< const CConnMonCreateConnection* >(
       
   617                 &aConnMonEvent );
       
   618             iUnsolvedConnIds.Append( eventCreate->ConnectionId() );
       
   619                         
       
   620             if ( !IsActive() )
       
   621                 {
       
   622                 GetIapId();
       
   623                 }
       
   624             else
       
   625                 {
       
   626                 iPendingRequests.Append( EGetIAP );
       
   627                 }
       
   628             }
       
   629             break;
       
   630             
       
   631         case EConnMonDeleteConnection:
       
   632             {
       
   633             const CConnMonDeleteConnection* eventDelete = NULL; 
       
   634             eventDelete = static_cast< const CConnMonDeleteConnection* >(
       
   635                 &aConnMonEvent );
       
   636             TUint connId = eventDelete->ConnectionId();
       
   637              
       
   638             RemoveIapId( connId );
       
   639             }
       
   640             break;
       
   641             
   357         default:
   642         default:
   358             break;
   643             break;
   359         }
   644         }
   360     CCHLOGSTRING( "CCCHConnMonHandler::EventL: OUT" );
   645     CCHLOGSTRING( "CCCHConnMonHandler::EventL: OUT" );
   361     }
   646     }