emailuis/emailui/src/ceuiexitguardian.cpp
changeset 0 8466d47a6819
child 26 67369d1b217f
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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 // CEUiExitGuardian::NewL
       
    24 //
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CEUiExitGuardian* CEUiExitGuardian::NewL( CFreestyleEmailUiAppUi& aAppUi )
       
    28 	{
       
    29     FUNC_LOG;
       
    30 
       
    31     CEUiExitGuardian* self = new (ELeave) CEUiExitGuardian(aAppUi);
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36 	}
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CEUiExitGuardian::CEUiExitGuardian
       
    40 //
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CEUiExitGuardian::CEUiExitGuardian( CFreestyleEmailUiAppUi& aAppUi )
       
    44     : iAppUi(aAppUi)
       
    45     {
       
    46     FUNC_LOG;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CEUiExitGuardian::~CEUiExitGuardian
       
    51 //
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CEUiExitGuardian::~CEUiExitGuardian()
       
    55     {
       
    56     FUNC_LOG;
       
    57 
       
    58     delete iIdle;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CEUiExitGuardian::ConstructL
       
    63 //
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CEUiExitGuardian::ConstructL()
       
    67     {
       
    68     FUNC_LOG;
       
    69 
       
    70     iIdle = CIdle::NewL(CActive::EPriorityStandard);
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CEUiExitGuardian::EnterLC
       
    75 //
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CEUiExitGuardian::EnterLC()
       
    79     {
       
    80     FUNC_LOG;
       
    81 
       
    82     if (iExitPending)
       
    83         {
       
    84         User::Leave(KErrNotReady);
       
    85         }
       
    86     iEnterCount++;
       
    87     CleanupStack::PushL(TCleanupItem(Exit, this));
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CEUiExitGuardian::Exit
       
    92 //
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CEUiExitGuardian::Exit(TAny* aPtr)
       
    96     {
       
    97     FUNC_LOG;
       
    98 
       
    99     reinterpret_cast<CEUiExitGuardian*>(aPtr)->DoExit();
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CEUiExitGuardian::DoExit
       
   104 //
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CEUiExitGuardian::DoExit()
       
   108     {
       
   109     FUNC_LOG;
       
   110 
       
   111     iEnterCount--;
       
   112     if (iExitPending && !iEnterCount && !iIdle->IsActive())
       
   113         {
       
   114         // Start async exit processing to rewind recursion before the actual
       
   115         // exit
       
   116         iIdle->Start( TCallBack( IdleCallBack, this ) );
       
   117         }
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CEUiExitGuardian::IdleCallBack
       
   122 //
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 TInt CEUiExitGuardian::IdleCallBack( TAny* aPtr )
       
   126     {
       
   127     FUNC_LOG;
       
   128 
       
   129     reinterpret_cast<CEUiExitGuardian*>( aPtr )->iAppUi.ExitNow();
       
   130     return KErrNone;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CEUiExitGuardian::ExitApplication
       
   135 //
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 TInt CEUiExitGuardian::ExitApplication()
       
   139     {
       
   140     FUNC_LOG;
       
   141 
       
   142     TInt result( KRequestPending );
       
   143     iExitPending = ETrue;
       
   144     if (!iEnterCount)
       
   145         {
       
   146         result = KErrNone;
       
   147         iAppUi.ExitNow();
       
   148         }
       
   149     return result;
       
   150     }
       
   151 
       
   152 // end of file