bearermanagement/mpm/src/mpmconnmonreqs.cpp
changeset 0 5a93021fdf25
child 15 4dc3bb0099b0
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: MPM ConnMon request handling
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @file mpmconnmonreqs.cpp
       
    20 Mobility Policy Manager ConnMon request handling.
       
    21 */
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include "mpmconnmonreqs.h"
       
    25 #include "mpmlogger.h"
       
    26 #include "mpmserversession.h"
       
    27 #include "mpmiapselection.h"
       
    28 
       
    29 // ============================= LOCAL FUNCTIONS ===============================
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CMPMConnMonReqs::NewL
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CMPMConnMonReqs* CMPMConnMonReqs::NewL(CMPMConnMonEvents& aParent,
       
    38                                        RConnectionMonitor& aConnMon,
       
    39                                        TUint aConnId, 
       
    40                                        CMPMServerSession& aSession )
       
    41     {
       
    42     CMPMConnMonReqs* self = new (ELeave) CMPMConnMonReqs(
       
    43                                 aParent, aConnMon, aConnId, aSession );
       
    44     CleanupStack::PushL(self);
       
    45     self->ConstructL();
       
    46     CleanupStack::Pop(self);
       
    47     return self;
       
    48     }
       
    49 
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CMPMConnMonReqs::CMPMConnMonReqs
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CMPMConnMonReqs::CMPMConnMonReqs(CMPMConnMonEvents& aParent,
       
    56                                  RConnectionMonitor& aConnMon,
       
    57                                  TUint aConnId, 
       
    58                                  CMPMServerSession& aSession )
       
    59     : CActive(CActive::EPriorityStandard), 
       
    60       iParent(aParent), 
       
    61       iConnMon(aConnMon), 
       
    62       iConnId(aConnId), 
       
    63       iSession(aSession), 
       
    64       iWlanScanCallback( EWlanScanCallbackNone ), 
       
    65       iConnectionCount( 0 )
       
    66     {
       
    67     }
       
    68 
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMPMConnMonReqs::~CMPMConnMonReqs
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CMPMConnMonReqs::~CMPMConnMonReqs()
       
    75     {
       
    76     MPMLOGSTRING( "CMPMConnMonReqs::~CMPMConnMonReqs" )
       
    77     Cancel();
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CMPMConnMonReqs::ConstructL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CMPMConnMonReqs::ConstructL()
       
    85     {
       
    86     MPMLOGSTRING( "CMPMConnMonReqs::ConstructL" )
       
    87     CActiveScheduler::Add(this);
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CMPMConnMonReqs::AvailableIapsSync
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CMPMConnMonReqs::AvailableIapsSync()
       
    95     {
       
    96     MPMLOGSTRING( "CMPMConnMonReqs::AvailableIapsSync" )
       
    97     iNextState = EGetIapAvailState;
       
    98     iLastCancelCode = EConnMonGetPckgAttribute;
       
    99     iConnMon.GetPckgAttribute( EBearerIdAll, 0, KIapAvailability,
       
   100                                iIapBuf, iStatus);
       
   101     SetActive();
       
   102     
       
   103     // Since CodeScanner does not recognise method IsStarted(), 
       
   104     // it claims that here is a problem:
       
   105     // 
       
   106     // Problem: Active object called without checking 
       
   107     // whether it is active or cancelling it first.
       
   108     // 
       
   109     if ( !iActiveSchedulerWait.IsStarted() )
       
   110         {
       
   111         iActiveSchedulerWait.Start();
       
   112         }
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CMPMConnMonReqs::RefreshAvailableIAPs
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CMPMConnMonReqs::RefreshAvailableIAPs( TWlanScanCallback aCallback, 
       
   120                                             TInt aForceRefreshIntervalSeconds )
       
   121     {
       
   122     MPMLOGSTRING2( "CMPMConnMonReqs::RefreshAvailableIAPs callback %d", aCallback )
       
   123     // set the type of callback to determine afterwards which function to call
       
   124     iWlanScanCallback = aCallback;
       
   125     iNextState      = EScanWLANNetworksState;   // Default value
       
   126     iLastCancelCode = EConnMonGetPckgAttribute;
       
   127 
       
   128     TTime time;
       
   129     time.UniversalTime();
       
   130     TTimeIntervalSeconds interval( 0 );
       
   131     
       
   132     TInt ret( KErrNone );
       
   133         
       
   134     // Calculate the elapsed time.
       
   135     ret = time.SecondsFrom( iParent.GetIAPRefreshTime(), interval );
       
   136     if ( ret != KErrNone )
       
   137         {
       
   138         MPMLOGSTRING2( "CMPMConnMonReqs::RefreshAvailableIAPs interval error %d ", ret )
       
   139         // problem with interval, force iapavailability.
       
   140         interval = 0;
       
   141         aForceRefreshIntervalSeconds = 0;
       
   142         }
       
   143     // Default behavior is to query KIapAvailability from ConnMon always
       
   144     // or if the availability information has aged at least aForceRefreshIntervalSeconds
       
   145     //
       
   146     if ( aForceRefreshIntervalSeconds == 0 || 
       
   147        ( interval.Int() >= aForceRefreshIntervalSeconds ) )
       
   148         {
       
   149         // Discard availability notifications from Connection Monitor 
       
   150         // until MPM initiated WLAN scan request has completed.
       
   151         // 
       
   152         iParent.EnableDiscarding();
       
   153 
       
   154         MPMLOGSTRING2( "CMPMConnMonReqs::RefreshAvailableIAPs interval %d, executing scan", 
       
   155             interval.Int() )
       
   156         iConnMon.GetPckgAttribute( EBearerIdAll, 0, KIapAvailability,
       
   157                                    iIapBuf, iStatus );
       
   158         SetActive();
       
   159         }
       
   160     // With consecutive calls we allow MPM to use cached value.
       
   161     //
       
   162     else
       
   163         {
       
   164         MPMLOGSTRING2( "CMPMConnMonReqs::RefreshAvailableIAPs interval %d, using cached value",
       
   165             interval.Int() )
       
   166 
       
   167         // iIapBuf is empty, thus we need a new state.
       
   168         iNextState = EScanWLANNetworksStateCached;
       
   169         TRequestStatus* statusPtr;
       
   170         statusPtr = &iStatus;
       
   171         // We can just complete the request.
       
   172         SetActive();
       
   173         User::RequestComplete( statusPtr, KErrNone );
       
   174         }
       
   175     }
       
   176 
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CMPMConnMonReqs::CompareConnIds
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 TBool CMPMConnMonReqs::CompareConnIds( const CMPMConnMonReqs& aReq1,
       
   183                                        const CMPMConnMonReqs& aReq2 )
       
   184     {
       
   185     if ( aReq1.iConnId == aReq2.iConnId )
       
   186         {
       
   187         return ETrue;
       
   188         }
       
   189     else
       
   190         {
       
   191         return EFalse;
       
   192         }
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CMPMConnMonReqs::MyCancel()
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CMPMConnMonReqs::MyCancel()
       
   200     {
       
   201     // Handle cancellation here.
       
   202     MPMLOGSTRING( "CMPMConnMonReqs::MyCancel()" )
       
   203     ASSERT( iNextState != EGetIapAvailState && iNextState != EObsolete );
       
   204     // Allow the availability update when the connmon request completes.
       
   205     iNextState = EObsolete;
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CMPMConnMonReqs::ErrorCallbackL()
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CMPMConnMonReqs::ErrorCallbackL( TInt aStatus )
       
   213     {
       
   214     switch ( iNextState )
       
   215         {
       
   216         case EGetIapAvailState:
       
   217         case EGetConnectionCountState: 
       
   218             {
       
   219             MPMLOGSTRING( "CMPMConnMonReqs::ErrorCallbackL: EGetIapAvailState failed" )
       
   220             if ( iActiveSchedulerWait.IsStarted() )
       
   221                 {
       
   222                 iActiveSchedulerWait.AsyncStop();
       
   223                 }
       
   224             break;
       
   225             }
       
   226         case EScanWLANNetworksState:
       
   227         case EScanWLANNetworksStateCached:
       
   228             {
       
   229             MPMLOGSTRING( "CMPMConnMonReqs::ErrorCallbackL: EScanWLANNetworksState failed" )
       
   230 
       
   231             // Disable discarding availability notifications from Connection Monitor.
       
   232             // 
       
   233             iParent.DisableDiscarding(); 
       
   234 
       
   235             // check which callback function to use and continue
       
   236             // handling the request if possible.
       
   237             // 
       
   238             if( iWlanScanCallback == EWlanScanCallbackChooseIap )
       
   239                 {
       
   240                 iSession.IapSelectionL()->ChooseIapWLANScanCompletedL( aStatus );
       
   241                 }
       
   242             else if( iWlanScanCallback == EWlanScanCallbackProcessErr )
       
   243                 {
       
   244                 iSession.ProcessErrorWlanScanCompletedL();
       
   245                 }
       
   246             else if( iWlanScanCallback == EWlanScanCallbackCarrierRejected )
       
   247                 {
       
   248                 // No fresh IAP info available but try to select new IAP
       
   249                 // based on whatever existing info there is
       
   250                 // 
       
   251                 iSession.CompleteCarrierRejected();
       
   252                 }
       
   253             else if( iWlanScanCallback == EWlanScanCallbackSortSnap )
       
   254                 {
       
   255                 // SortSnap was called with old availability information.
       
   256                 iSession.CompleteServerSortSNAP();
       
   257                 }
       
   258             else
       
   259                 {
       
   260                 MPMLOGSTRING(
       
   261                     "CMPMConnMonReqs::ErrorCallbackL: iWlanScanCallback EWlanScanCallbackNone" )
       
   262                 }
       
   263             // reset callback type
       
   264             //
       
   265             iWlanScanCallback = EWlanScanCallbackNone;
       
   266             break;
       
   267             }
       
   268         case EObsolete:
       
   269             MPMLOGSTRING( "CMPMConnMonReqs::ErrorCallbackL: EObsolete" )
       
   270             break;
       
   271         }
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CMPMConnMonReqs::RunL
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CMPMConnMonReqs::RunL()
       
   279     {
       
   280     MPMLOGSTRING( "CMPMConnMonReqs::RunL" )
       
   281     if ( iStatus != KErrNone )
       
   282         {
       
   283         // Nok
       
   284         MPMLOGSTRING2( "CMPMConnMonReqs::RunL: \
       
   285 ConnMon request completed with error code = %i", iStatus.Int() )
       
   286 
       
   287         // Does nothing if state is obsolete.
       
   288         ErrorCallbackL( iStatus.Int() );
       
   289 
       
   290         // RemoveReqPtr is safe if "this" doesn't exist
       
   291         iParent.RemoveReqPtr( this );
       
   292         delete this;
       
   293         }
       
   294     else
       
   295         {
       
   296         // Ok
       
   297         switch (iNextState)
       
   298             {
       
   299             case EGetIapAvailState:
       
   300                 {
       
   301                 MPMLOGSTRING( "CMPMConnMonReqs::RunL: EGetIapAvailState" )
       
   302                 iParent.SetAvailableIAPs( iIapBuf() );
       
   303 
       
   304                 if ( iActiveSchedulerWait.IsStarted() )
       
   305                     {
       
   306                     iActiveSchedulerWait.AsyncStop();
       
   307                     }
       
   308 
       
   309                 iNextState      = EGetConnectionCountState;
       
   310                 iLastCancelCode = EConnMonGetConnectionCount;
       
   311                 iConnMon.GetConnectionCount( iConnectionCount, iStatus );
       
   312                 SetActive();
       
   313                 break;
       
   314                 }
       
   315             case EGetConnectionCountState: 
       
   316                 {
       
   317                 MPMLOGSTRING( "CMPMConnMonReqs::RunL: EGetConnectionCountState" )
       
   318                 MPMLOGSTRING2( "CMPMConnMonReqs::RunL: Connection Count: %i", 
       
   319                     iConnectionCount )
       
   320                 iParent.SetConnectionCounter( iConnectionCount );
       
   321                 iParent.RemoveReqPtr( this );
       
   322                 delete this;
       
   323                 break;
       
   324                 }
       
   325             case EScanWLANNetworksState:
       
   326             case EScanWLANNetworksStateCached:
       
   327                 {
       
   328                 MPMLOGSTRING( "CMPMConnMonReqs::RunL: EScanWLANNetworksState and EScanWLANNetworksStateCached" )
       
   329                 if ( iNextState == EScanWLANNetworksState )
       
   330                     {
       
   331                     MPMLOGSTRING( "CMPMConnMonReqs::RunL: EScanWLANNetworksState fresh data available from ConnMon" )
       
   332                     iParent.SetAvailableIAPs( iIapBuf() );
       
   333 
       
   334                     // Disable discarding availability notifications from Connection Monitor.
       
   335                     // 
       
   336                     iParent.DisableDiscarding(); 
       
   337 
       
   338                     // Generate event only if we got new iaps from ConnMon.
       
   339                     // 
       
   340                     if ( iWlanScanCallback == EWlanScanCallbackGenerateEvent )
       
   341                         {
       
   342                         MPMLOGSTRING( "CMPMConnMonReqs::RunL: iWlanScanCallback EWlanScanCallbackGenerateEvent" )
       
   343                         // Generate event only if not 
       
   344                         //
       
   345                         iParent.IapAvailabilityChange();
       
   346                         }
       
   347                     }
       
   348                 // check which callback function to use
       
   349                 // 
       
   350                 if( iWlanScanCallback == EWlanScanCallbackChooseIap )
       
   351                     {
       
   352                     iSession.IapSelectionL()->ChooseIapWLANScanCompletedL( iStatus.Int() );
       
   353                     }
       
   354                 else if( iWlanScanCallback == EWlanScanCallbackProcessErr )
       
   355                     {
       
   356                     iSession.ProcessErrorWlanScanCompletedL();
       
   357                     }
       
   358                 else if( iWlanScanCallback == EWlanScanCallbackCarrierRejected )
       
   359                     {
       
   360                     iSession.CompleteCarrierRejected();
       
   361                     }
       
   362                 else if( iWlanScanCallback == EWlanScanCallbackSortSnap )
       
   363                     {
       
   364                     iSession.CompleteServerSortSNAP();
       
   365                     }
       
   366                 else
       
   367                     {
       
   368                     MPMLOGSTRING(
       
   369                     "CMPMConnMonReqs::RunL: iWlanScanCallback default processing" )
       
   370                     }
       
   371                 // reset callback type
       
   372                 //
       
   373                 iWlanScanCallback = EWlanScanCallbackNone;
       
   374                 
       
   375                 iParent.RemoveReqPtr( this );
       
   376                 delete this;
       
   377                 break;
       
   378                 }
       
   379             case EObsolete:
       
   380                 iParent.SetAvailableIAPs( iIapBuf() );
       
   381                 delete this;
       
   382                 break;
       
   383             default:
       
   384                 {
       
   385                 MPMLOGSTRING( "CMPMConnMonReqs::RunL: default" )
       
   386                 PanicServer( KErrNotSupported );
       
   387                 break;
       
   388                 }
       
   389             }
       
   390         }
       
   391     }
       
   392 
       
   393 
       
   394 // -----------------------------------------------------------------------------
       
   395 // CMPMConnMonReqs::RunError
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 
       
   399 TInt CMPMConnMonReqs::RunError( TInt aError )
       
   400     {
       
   401     MPMLOGSTRING2(
       
   402         "CMPMConnMonReqs::RunError: RunL made a leave with error = %i", 
       
   403         aError )
       
   404 
       
   405     // Disable discarding availability notifications from Connection Monitor.
       
   406     // 
       
   407     iParent.DisableDiscarding(); 
       
   408 
       
   409     // check which callback function was used when leave occurred
       
   410     // 
       
   411     if( iWlanScanCallback == EWlanScanCallbackChooseIap )
       
   412         {
       
   413         iSession.ChooseIapComplete( aError, NULL );
       
   414         }
       
   415     else if( iWlanScanCallback == EWlanScanCallbackProcessErr )
       
   416         {
       
   417         TBMNeededAction neededAction( EPropagateError );
       
   418         iSession.ProcessErrorComplete( KErrNone, &aError, &neededAction );
       
   419         }
       
   420     else
       
   421         {
       
   422         MPMLOGSTRING(
       
   423         "CMPMConnMonReqs::RunError: iWlanScanCallback EWlanScanCallbackNone" )
       
   424         }
       
   425 
       
   426     // We are done
       
   427     iParent.RemoveReqPtr( this );
       
   428     delete this;
       
   429 
       
   430     // Return KErrNone to prevent panic 
       
   431     return KErrNone;
       
   432     }
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CMPMConnMonReqs::DoCancel
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CMPMConnMonReqs::DoCancel()
       
   439     {
       
   440     MPMLOGSTRING( "CMPMConnMonReqs::DoCancel" )
       
   441 
       
   442     // Disable discarding availability notifications from Connection Monitor.
       
   443     // 
       
   444     iParent.DisableDiscarding(); 
       
   445 
       
   446     iConnMon.CancelAsyncRequest( iLastCancelCode );
       
   447     
       
   448     if ( iActiveSchedulerWait.IsStarted() )
       
   449         {
       
   450         iActiveSchedulerWait.AsyncStop();
       
   451         }
       
   452     }
       
   453 
       
   454 //  End of File