emailuis/emailui/src/ceuiexitguardian.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     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:  FreestyleEmailUi exit guardian implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "FreestyleEmailUiAppui.h"
       
    19 #include "ceuiexitguardian.h"
       
    20 #include "emailtrace.h"
       
    21 
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // CEUiExitGuardian::NewL
       
    25 //
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CEUiExitGuardian* CEUiExitGuardian::NewL( CFreestyleEmailUiAppUi& aAppUi )
       
    29     {
       
    30     FUNC_LOG;
       
    31 
       
    32     CEUiExitGuardian* self = new (ELeave) CEUiExitGuardian( aAppUi );
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CEUiExitGuardian::CEUiExitGuardian
       
    41 //
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CEUiExitGuardian::CEUiExitGuardian( CFreestyleEmailUiAppUi& aAppUi )
       
    45     : iAppUi( aAppUi )
       
    46     {
       
    47     FUNC_LOG;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CEUiExitGuardian::~CEUiExitGuardian
       
    52 //
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CEUiExitGuardian::~CEUiExitGuardian()
       
    56     {
       
    57     FUNC_LOG;
       
    58 
       
    59     if ( iPeriodicTimer )
       
    60         {
       
    61         iPeriodicTimer->Cancel();
       
    62         delete iPeriodicTimer;
       
    63         }
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CEUiExitGuardian::ConstructL
       
    69 //
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CEUiExitGuardian::ConstructL()
       
    73     {
       
    74     FUNC_LOG;
       
    75 
       
    76     iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
    77     iPeriodicTimerStarted = EFalse;
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CEUiExitGuardian::PeriodicCallBack
       
    83 //
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 TInt CEUiExitGuardian::PeriodicCallBack( TAny* aPtr )
       
    87     {
       
    88     FUNC_LOG;
       
    89 
       
    90     reinterpret_cast<CEUiExitGuardian*>(aPtr)->TryExitApplication();
       
    91     return KErrNone;
       
    92     }
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CEUiExitGuardian::TryExitApplication
       
    97 //
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 TInt CEUiExitGuardian::TryExitApplication()
       
   101     {
       
   102     FUNC_LOG;
       
   103     const TInt KDelay = 200*1000; // 200 ms
       
   104     
       
   105     TInt ret = KRequestPending;
       
   106 
       
   107     CActiveScheduler* scheduler = CActiveScheduler::Current();
       
   108     TInt nestedLevelCount = scheduler->StackDepth();
       
   109     if ( nestedLevelCount == 1 )
       
   110         {
       
   111         iPeriodicTimer->Cancel();
       
   112         iAppUi.ExitNow();
       
   113         ret = KErrNone;
       
   114         }
       
   115     else if ( !iPeriodicTimerStarted )
       
   116         {
       
   117         iPeriodicTimer->Start( KDelay, KDelay, TCallBack(PeriodicCallBack, this) );
       
   118         iPeriodicTimerStarted = ETrue;
       
   119         }
       
   120     
       
   121     return ret;
       
   122     }
       
   123 
       
   124 // end of file