20 |
20 |
21 #include <e32base.h> |
21 #include <e32base.h> |
22 |
22 |
23 // FORWARD DECLARATIONS |
23 // FORWARD DECLARATIONS |
24 class CFreestyleEmailUiAppUi; |
24 class CFreestyleEmailUiAppUi; |
25 class CIdle; |
|
26 |
|
27 /** |
25 /** |
28 * Application exit guardian for email UI. This is needed because some routines |
26 * Application exit guardian for email UI. This is needed because some routines |
29 * in email framework create nested scheduler loops to hide asynchronity in |
27 * in email framework create nested scheduler loops to hide asynchronity in |
30 * them. When application is shutdown these nested levels may cause crashes |
28 * 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 |
29 * as resources are freed while they are still being used on other recursion |
32 * levels. |
30 * levels. |
33 * |
31 * |
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 * |
32 * |
45 * @since S60 5.1 |
33 * @since S60 5.1 |
46 */ |
34 */ |
47 class CEUiExitGuardian : public CBase |
35 class CEUiExitGuardian : public CBase |
48 { |
36 { |
49 |
37 |
50 public: |
38 public: |
51 |
39 |
52 /** |
40 /** |
53 * Leave safe construction for CEuiExitGuardian. |
41 * Leave safe construction for CEuiExitGuardian. |
58 /** |
46 /** |
59 * Destructor. |
47 * Destructor. |
60 */ |
48 */ |
61 ~CEUiExitGuardian(); |
49 ~CEUiExitGuardian(); |
62 |
50 |
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 |
51 |
71 /** |
52 /** |
72 * Called by the application to inform that application is ready to |
53 * Called by the application to inform that application is ready to |
73 * exit. If there is any nested active scheduler levels (i.e. recursion), |
54 * exit. If there is any nested active scheduler levels (i.e. recursion), |
74 * exit execution will be delayed until every nested level has returned. |
55 * exit execution will be delayed until every nested level has returned. |
75 * |
56 * |
76 * @return KRequestPending if the exit execution is delayed because of |
57 * @return KRequestPending if the exit execution is delayed because of |
77 * nesting, KErrNone otherwise. |
58 * nesting, KErrNone otherwise. |
78 */ |
59 */ |
79 TInt ExitApplication(); |
60 TInt TryExitApplication(); |
80 |
61 |
81 private: |
62 private: |
82 |
|
83 /** |
63 /** |
84 * Constructor. |
64 * Constructor. |
85 */ |
65 */ |
86 CEUiExitGuardian(CFreestyleEmailUiAppUi& aAppUi); |
66 CEUiExitGuardian( CFreestyleEmailUiAppUi& aAppUi ); |
87 |
67 |
88 /** |
68 /** |
89 * Pass 2 constructor, may leave. |
69 * Pass 2 constructor, may leave. |
90 */ |
70 */ |
91 void ConstructL(); |
71 void ConstructL(); |
92 |
72 |
93 /** |
73 /** |
94 * Static exit method that is given to cleanup item. |
74 * Static callback method for CPeriodic. |
95 */ |
75 */ |
96 static void Exit(TAny* aPtr); |
76 static TInt PeriodicCallBack( 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 |
77 |
109 private: |
78 private: |
110 |
|
111 // Reference to application UI |
79 // Reference to application UI |
112 CFreestyleEmailUiAppUi& iAppUi; |
80 CFreestyleEmailUiAppUi& iAppUi; |
113 |
81 TBool iPeriodicTimerStarted; |
114 // Recursion depth (nested level count) |
82 CPeriodic* iPeriodicTimer; |
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 }; |
83 }; |
125 |
84 |
126 #endif // C_EUIEXITGUARDIAN_H |
85 #endif // C_EUIEXITGUARDIAN_H |