callcontinuity/vcchotrigger/src/vccsignallevelhandler.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:   Implementation of the base class of signal level handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "vccsignallevelhandler.h"
       
    21 #include "vccsignallevelobserver.h"
       
    22 #include "rubydebug.h"
       
    23 
       
    24 
       
    25 // Min. signal strength in absolut dBm, i.e. the value
       
    26 // in real world is -110 dBm (so quite weak).
       
    27 static const TInt32 KStrengthMin = 110;
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // C++ destructor.
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CVccSignalLevelHandler::~CVccSignalLevelHandler()
       
    34     {
       
    35     // Cancel any outstanding requests.
       
    36     Cancel();
       
    37 
       
    38     iStrength = 0;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Symbian second-phase constructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 void CVccSignalLevelHandler::ConstructL()
       
    46     {
       
    47     CTimer::ConstructL();
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // C++ constructor.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CVccSignalLevelHandler::CVccSignalLevelHandler(
       
    55     MVccSignalLevelObserver& aObserver,
       
    56     const TSignalLevelParams& aParams )
       
    57     : CTimer( EPriorityStandard ),
       
    58     iObserver( aObserver ),
       
    59     iParams( aParams )
       
    60     {
       
    61     CActiveScheduler::Add( this );
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Star signal level observing.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CVccSignalLevelHandler::StartL()
       
    69     {
       
    70     RUBY_DEBUG_BLOCK( "CVccSignalLevelHandler::StartL" );
       
    71 
       
    72     if ( !iNotificationsOn )
       
    73         {
       
    74         EnableNotificationsL();
       
    75         iNotificationsOn = ETrue;
       
    76         }
       
    77 
       
    78     RUBY_DEBUG0( " -call Cancel()" );
       
    79     Cancel();
       
    80 
       
    81     RUBY_DEBUG0( " -call GetStrength()" );
       
    82     GetStrength();
       
    83 
       
    84     RUBY_DEBUG1( " -iStrength = %d, set op = EOperationGet \
       
    85                  state = EStrengthUnknown", iStrength );
       
    86     
       
    87     iOperation = EOperationGet;
       
    88 
       
    89     iState = EStrengthUnknown;
       
    90 
       
    91     RUBY_DEBUG0( " -call SetActive()" );
       
    92     SetActive();
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Stop signal level observing.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CVccSignalLevelHandler::Stop()
       
   100     {
       
   101     RUBY_DEBUG_BLOCK( "CVccSignalLevelHandler::Stop ");
       
   102 
       
   103     DisableNotifications();
       
   104 
       
   105     iNotificationsOn = EFalse;
       
   106 
       
   107     iStrength = 0;
       
   108 
       
   109     Cancel();
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Set new parameters.
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CVccSignalLevelHandler::SetParams( const TSignalLevelParams& aParams )
       
   117     {
       
   118     RUBY_DEBUG_BLOCK( "CVccSignalLevelHandler::SetParams" );
       
   119     iParams = aParams;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Handles getting the signal strength and notifying the observer about
       
   124 // strength changes.
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CVccSignalLevelHandler::RunL()
       
   128     {
       
   129     RUBY_DEBUG_BLOCK( "CVccSignalLevelHandler::RunL" );
       
   130 
       
   131     // Zero (0) is not acceptable.
       
   132     if ( !iStrength )
       
   133         {
       
   134         RUBY_DEBUG0( " -0 strength not acceptable, setting to KStrengthMin");
       
   135         iStrength = KStrengthMin;
       
   136         }
       
   137 
       
   138     RUBY_DEBUG3( " -iStrength = %d iState = %d iOp = %d", iStrength, iState, iOperation );
       
   139 
       
   140     switch ( iOperation )
       
   141         {
       
   142         case EOperationGet:
       
   143             {
       
   144 
       
   145             // We are in the Get-mode to get the signal strength.
       
   146             // If the strength is < than the high level (== the strength
       
   147             // is good), start timer to check if we are still in good level
       
   148             // after the timer completes.
       
   149             // The same is done if we have a low level (== bad).
       
   150 
       
   151             RUBY_DEBUG0( " -EOperationGet");
       
   152 
       
   153             if ( iStrength <= iParams.iHighLevel && iStrength > 0 )
       
   154                 {
       
   155                 RUBY_DEBUG0( "  set state = EStrengthHigh, op = EOperationWait" );
       
   156 
       
   157                 After( iParams.iHighTimeout );
       
   158                 iState = EStrengthHigh;
       
   159                 iOperation = EOperationWait;
       
   160                 }
       
   161             else if ( iStrength >= iParams.iLowLevel )
       
   162                 {
       
   163                 RUBY_DEBUG0( "  set state = EStrengtLow, op = EOperationWait" );
       
   164                 After( iParams.iLowTimeout );
       
   165                 iState = EStrengthLow;
       
   166                 iOperation = EOperationWait;
       
   167                 }
       
   168             else
       
   169                 {
       
   170                 RUBY_DEBUG0( "  strength between low and high, set op = EOperationNone" );
       
   171 
       
   172                 iOperation = EOperationNone;
       
   173                 // PCLint
       
   174                 }
       
   175             break;
       
   176             }
       
   177 
       
   178         case EOperationWait:
       
   179             {
       
   180 
       
   181             // Timer has completed. Check the signal level again.
       
   182 
       
   183             RUBY_DEBUG0( " -EOperationWait" );
       
   184             RUBY_DEBUG0( "  set op = EOperationComplete" );
       
   185             GetStrength();
       
   186 
       
   187             SetActive();
       
   188 
       
   189             iOperation = EOperationComplete;
       
   190 
       
   191             break;
       
   192             }
       
   193 
       
   194         case EOperationComplete:
       
   195             {
       
   196             // Checking signal strength is now done.
       
   197             // Notify our observer (if needed).
       
   198 
       
   199             RUBY_DEBUG1( " -EOperationComplete, iStrength = %d", iStrength );
       
   200 
       
   201             // Do we have a good signal level?
       
   202             if ( iStrength <= iParams.iHighLevel && iStrength > 0 && iState == EStrengthHigh )
       
   203                 {
       
   204                 RUBY_DEBUG0( " -if ( iStrength <= iParams.iHighLevel" );
       
   205                 NotifyChanges( iStrength, MVccSignalLevelObserver::ESignalClassNormal );
       
   206                 }
       
   207             // Or do we have a bad signal level?
       
   208             else if ( iStrength >= iParams.iHighLevel && iState == EStrengthLow )
       
   209                 {
       
   210                 RUBY_DEBUG0( " -else if ( iStrength >= iParams.iHighLevel" );
       
   211                 NotifyChanges( iStrength, MVccSignalLevelObserver::ESignalClassWeak );
       
   212                 }
       
   213             else
       
   214                 {
       
   215                 // PCLint
       
   216                 }
       
   217 
       
   218             iOperation = EOperationNone;
       
   219 
       
   220             break;
       
   221             }
       
   222 
       
   223         default:
       
   224             {
       
   225             break;
       
   226             }
       
   227         }
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // Handles signal strength changes notified by the subsystem
       
   232 // (either the WLAN or the GSM).
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CVccSignalLevelHandler::StrengthChanged()
       
   236     {
       
   237 
       
   238     RUBY_DEBUG_BLOCK( "CVccSignalLevelHandler::StrengthChanged" );
       
   239 
       
   240     // The zero (0) is not good.
       
   241     if ( !iStrength )
       
   242         {
       
   243         iStrength = KStrengthMin;
       
   244         }
       
   245 
       
   246     RUBY_DEBUG3( " -iStrength = %d, iState = %d, iOp = %d",
       
   247                              iStrength, iState, iOperation);
       
   248 
       
   249     // Check in which direction the signal strength changed
       
   250     // and start the timeout timer to see if the signal level
       
   251     // stays at that (new) level.
       
   252 
       
   253     RUBY_DEBUG1( " -iHighLevel = %d", iParams.iHighLevel );
       
   254     RUBY_DEBUG1( " -iLowLevel = %d", iParams.iLowLevel );
       
   255     if ( iStrength <= iParams.iHighLevel && iStrength > 0 )  // && 
       
   256         //( iState == EStrengthLow || iState == EStrengthUnknown ) )
       
   257         {
       
   258         // Cancel outstanding timer in all the cases
       
   259         Cancel();
       
   260         // We have a good level after a bad one.
       
   261 
       
   262         RUBY_DEBUG0( " -call After( hightimeout ), set state = High, op = Wait");
       
   263         After( iParams.iHighTimeout );
       
   264         iState = EStrengthHigh;
       
   265         iOperation = EOperationWait;
       
   266         }
       
   267     else if ( iStrength >= iParams.iLowLevel )  //&& 
       
   268             //( iState == EStrengthHigh || iState == EStrengthUnknown ) )
       
   269         {
       
   270         // Cancel outstanding timer in all the cases
       
   271         Cancel();
       
   272         // We have a bad level after a good one.
       
   273 
       
   274         RUBY_DEBUG0( " -call After( lowtimeout ), set state = Low, op = Wait");
       
   275 
       
   276         After ( iParams.iLowTimeout );
       
   277         iState = EStrengthLow;
       
   278         iOperation = EOperationWait;
       
   279         }
       
   280     else
       
   281         {
       
   282         RUBY_DEBUG0( "-EOperationNone ");
       
   283         iOperation = EOperationNone;
       
   284         }
       
   285     }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // Cancel outstanding requests.
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CVccSignalLevelHandler::DoCancel()
       
   292     {
       
   293     RUBY_DEBUG_BLOCK( "CVccSignalLevelHandler::DoCancel" );
       
   294     switch ( iOperation )
       
   295         {
       
   296         case EOperationWait:
       
   297             {
       
   298             RUBY_DEBUG0( "EOperationWait" );
       
   299             CTimer::DoCancel();
       
   300 
       
   301             break;
       
   302             }
       
   303 
       
   304         case EOperationGet:
       
   305             // fall-through intended here
       
   306         case EOperationComplete:
       
   307             {
       
   308             RUBY_DEBUG0( "EOperationGet / EOperationComplete" );
       
   309             CancelGetStrength();
       
   310 
       
   311             break;
       
   312             }
       
   313 
       
   314         default:
       
   315             {
       
   316             break;
       
   317             }
       
   318         }
       
   319     }