emailuis/emailui/inc/ceuiexitguardian.h
changeset 0 8466d47a6819
child 17 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.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_EUIEXITGUARDIAN_H
       
    19 #define C_EUIEXITGUARDIAN_H
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 // FORWARD DECLARATIONS
       
    24 class CFreestyleEmailUiAppUi;
       
    25 class CIdle;
       
    26 
       
    27 /**
       
    28  * Application exit guardian for email UI. This is needed because some routines
       
    29  * in email framework create nested scheduler loops to hide asynchronity in
       
    30  * them. When application is shutdown these nested levels may cause crashes
       
    31  * as resources are freed while they are still being used on other recursion
       
    32  * levels.
       
    33  *
       
    34  * Usage:
       
    35  *
       
    36  * void CClass::RoutineThatMayCreatedNestedLevelL()
       
    37  *    {
       
    38  *    iExitGuardian->EnterLC();
       
    39  *    // call or execute code that may create nested sceduler loop
       
    40  *    ...
       
    41  *    // and finally popup and destroy cleanup item
       
    42  *    CleanupStack::PopAndDestroy(); // iExitGuardian->EnterLC()
       
    43  *    }
       
    44  *
       
    45  * @since S60 5.1
       
    46  */
       
    47 class CEUiExitGuardian : public CBase
       
    48   	{
       
    49 
       
    50 public:
       
    51 
       
    52     /**
       
    53      * Leave safe construction for CEuiExitGuardian.
       
    54      * @return Newly created instance of CEuiExitGuardian
       
    55      */
       
    56     static CEUiExitGuardian* NewL(CFreestyleEmailUiAppUi& aAppUi);
       
    57 
       
    58     /**
       
    59      * Destructor.
       
    60      */
       
    61     ~CEUiExitGuardian();
       
    62 
       
    63     /**
       
    64      * Called before executing code that may cause new nested level in
       
    65      * active scheduler. Leaves cleanup item in cleanup stack and this item
       
    66      * must be purged by the caller after code execution. Cleanup item is used
       
    67      * to make level counter leavesafe.
       
    68      */
       
    69     void EnterLC();
       
    70 
       
    71     /**
       
    72      * Called by the application to inform that application is ready to
       
    73      * exit. If there is any nested active scheduler levels (i.e. recursion),
       
    74      * exit execution will be delayed until every nested level has returned.
       
    75      *
       
    76      * @return KRequestPending if the exit execution is delayed because of
       
    77      * nesting, KErrNone otherwise.
       
    78      */
       
    79     TInt ExitApplication();
       
    80 
       
    81 private:
       
    82 
       
    83     /**
       
    84      * Constructor.
       
    85      */
       
    86     CEUiExitGuardian(CFreestyleEmailUiAppUi& aAppUi);
       
    87 
       
    88     /**
       
    89      * Pass 2 constructor, may leave.
       
    90      */
       
    91 	void ConstructL();
       
    92 
       
    93     /**
       
    94      * Static exit method that is given to cleanup item.
       
    95      */
       
    96     static void Exit(TAny* aPtr);
       
    97 
       
    98     /**
       
    99      * Non static exit method that is called from static Exit.
       
   100      */
       
   101     void DoExit();
       
   102 
       
   103     /**
       
   104      * Static callback method for CIdle. This is run when recursion is rewinded
       
   105      * and appication can be closed.
       
   106      */
       
   107     static TInt IdleCallBack(TAny* aPtr);
       
   108 
       
   109 private:
       
   110 
       
   111     // Reference to application UI
       
   112     CFreestyleEmailUiAppUi& iAppUi;
       
   113 
       
   114     // Recursion depth (nested level count)
       
   115     TInt iEnterCount;
       
   116 
       
   117     // ETrue if the application is ready to exit.
       
   118     TBool iExitPending;
       
   119 
       
   120     // Idle class instance to rewind final level of recursion before calling the
       
   121     // exit
       
   122     CIdle* iIdle;
       
   123 
       
   124     };
       
   125 
       
   126 #endif // C_EUIEXITGUARDIAN_H