1 /* |
|
2 * Copyright (c) 2007 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: Class responsible for application exit. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cvtuiappshutter.h" |
|
20 #include "mvtuishutterobserver.h" |
|
21 #include "mvtuistatecontext.h" |
|
22 #include "mvtuinumbersource.h" |
|
23 #include "tvtuilocalvariation.h" |
|
24 #include <cvtlogger.h> |
|
25 #include <eikenv.h> |
|
26 #include <AknUtils.h> |
|
27 #include <aknnotewrappers.h> |
|
28 #include <StringLoader.h> |
|
29 |
|
30 // singleton instance |
|
31 static CVtUiAppShutter* iAppShutter = NULL; |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CVtUiAppShutter::InstanceL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CVtUiAppShutter* CVtUiAppShutter::InstanceL( |
|
38 MVtUiShutterObserver& aObserver ) |
|
39 { |
|
40 __VTPRINTENTER( "CVtUiAppShutter.InstanceL" ) |
|
41 if ( iAppShutter == NULL ) |
|
42 { |
|
43 iAppShutter = new ( ELeave ) |
|
44 CVtUiAppShutter( aObserver ); |
|
45 } |
|
46 __VTPRINTEXIT( "CVtUiAppShutter.InstanceL" ) |
|
47 return iAppShutter; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CVtUiAppShutter::CVtUiAppShutter |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CVtUiAppShutter::CVtUiAppShutter( |
|
55 MVtUiShutterObserver& aObserver ) : |
|
56 iPendingStateFlags( 0 ), |
|
57 iObserver( aObserver ) |
|
58 { |
|
59 iPendingStateFlags.Set( EShutterWaitingStart ); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CVtUiAppShutter::~CVtUiAppShutter |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CVtUiAppShutter::~CVtUiAppShutter() |
|
67 { |
|
68 __VTPRINTENTER( "CVtUiAppShutter.~" ) |
|
69 // mark singleton null |
|
70 iAppShutter = NULL; |
|
71 delete iCallback; |
|
72 __VTPRINTEXIT( "CVtUiAppShutter.~" ) |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CVtUiAppShutter::StartShutdown |
|
77 // Called when application may exit, i.e TVtUiStateResetting state receives |
|
78 // ShutdownDoneL message. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CVtUiAppShutter::StartShutdown() |
|
82 { |
|
83 __VTPRINTENTER( "CVtUiAppShutter.StartShutdown" ) |
|
84 iPendingStateFlags.Clear( EShutterWaitingStart ); |
|
85 ShutdownIfReadyAndDestroy(); |
|
86 __VTPRINTEXITR( "CVtUiAppShutter.StartShutdown flags %d", |
|
87 iPendingStateFlags.Value() ) |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CVtUiAppShutter::ShutdownWithEmergencyCallL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CVtUiAppShutter::ShutdownWithEmergencyCallL( |
|
95 MVtUiStateContext& aStateContext ) |
|
96 { |
|
97 // Leaves if other than emergency number is supplied... |
|
98 CEmergencyCaller* emergency = CEmergencyCaller::DialEmergencyL( *this, |
|
99 aStateContext ); |
|
100 // therefore the flag and member variable must not be set before above call. |
|
101 iPendingStateFlags.Set( EShutterWaitingEmergencyCallback ); |
|
102 iEmergencyCaller = emergency; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CVtUiAppShutter::EmergencyCallDoneL |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CVtUiAppShutter::EmergencyCallDoneL() |
|
110 { |
|
111 // Destruction of emergency handler is done asynchrounously to avoid |
|
112 // problems that might |
|
113 iPendingStateFlags.Clear( EShutterWaitingEmergencyCallback ); |
|
114 TCallBack cb( EmergencyResponseCallback, this ); |
|
115 EnqueCallbackL( cb ); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CVtUiAppShutter::EmergencyResponseCallback |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 TInt CVtUiAppShutter::EmergencyResponseCallback( TAny* aAny ) |
|
123 { |
|
124 CVtUiAppShutter* shutter = |
|
125 reinterpret_cast<CVtUiAppShutter*>( aAny ); |
|
126 // delete callback |
|
127 delete shutter->iCallback; |
|
128 shutter->iCallback = NULL; |
|
129 // delete emergency caller |
|
130 delete shutter->iEmergencyCaller; |
|
131 shutter->iEmergencyCaller = NULL; |
|
132 |
|
133 shutter->ShutdownIfReadyAndDestroy(); |
|
134 return KErrNone; |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CVtUiAppShutter::EnqueCallbackL |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CVtUiAppShutter::EnqueCallbackL( TCallBack& aCallback ) |
|
142 { |
|
143 __VTPRINTENTER( "CVtUiAppShutter.EnqueAsyncCommsCommandL" ) |
|
144 if ( !iCallback ) |
|
145 { |
|
146 iCallback = new ( ELeave ) CAsyncCallBack( aCallback, EPriorityHigh ); |
|
147 } |
|
148 iCallback->Call(); |
|
149 __VTPRINTEXIT( "CVtUiAppShutter.EnqueAsyncCommsCommandL" ) |
|
150 __VTPRINTEXIT( "CVtUiAppShutter.EnqueCallbackL" ) |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CVtUiAppShutter::ShutdownIfReadyAndDestroy |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CVtUiAppShutter::ShutdownIfReadyAndDestroy() |
|
158 { |
|
159 __VTPRINTENTER( "CVtUiAppShutter.ShutdownIfReadyAndDestroy" ) |
|
160 __VTPRINT2( DEBUG_GEN, " shutter flags %d", |
|
161 iPendingStateFlags.Value() ); |
|
162 if ( !iPendingStateFlags.Value() ) |
|
163 { |
|
164 iObserver.HandleShutdownReady(); |
|
165 delete this; |
|
166 } |
|
167 __VTPRINTEXIT( "CVtUiAppShutter.ShutdownIfReadyAndDestroy" ) |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CVtUiAppShutter::CEmergencyCaller::DialEmergencyL |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 CVtUiAppShutter::CEmergencyCaller* CVtUiAppShutter::CEmergencyCaller:: |
|
175 DialEmergencyL( |
|
176 CVtUiAppShutter& aObserver, |
|
177 MVtUiStateContext& aStateContext ) |
|
178 { |
|
179 __VTPRINTENTER( "CEmergencyCaller.DialEmergencyL" ) |
|
180 CVtUiAppShutter::CEmergencyCaller* self = new ( ELeave ) |
|
181 CVtUiAppShutter::CEmergencyCaller( aObserver, aStateContext ); |
|
182 CleanupStack::PushL( self ); |
|
183 self->ConstructL(); |
|
184 CleanupStack::Pop( self ); |
|
185 __VTPRINTEXIT( "CEmergencyCaller.DialEmergencyL" ) |
|
186 return self; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CVtUiAppShutter::CEmergencyCaller::ConstructL |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CVtUiAppShutter::CEmergencyCaller::ConstructL() |
|
194 { |
|
195 __VTPRINTENTER( "CEmergencyCaller.ConstructL" ) |
|
196 const MVtUiNumberSource* source = iStateContext.NumberSource(); |
|
197 if ( source ) |
|
198 { |
|
199 source->GetContents( iNumber ); |
|
200 AknTextUtils::ConvertDigitsTo( iNumber, EDigitTypeWestern ); |
|
201 User::LeaveIfError( iServer.Connect() ); |
|
202 iEmergency = CPhCltEmergencyCall::NewL( this ); |
|
203 TBool isEmergenyNumber = EFalse; |
|
204 const TInt err = |
|
205 iEmergency->FindEmergencyPhoneNumber( iNumber, isEmergenyNumber ); |
|
206 |
|
207 if ( err == KErrNone && isEmergenyNumber ) |
|
208 { |
|
209 __VTPRINT( DEBUG_GEN, "iEmergency->DialEmergencyCallL") |
|
210 iEmergency->DialEmergencyCallL( iNumber ); |
|
211 } |
|
212 if ( !isEmergenyNumber || err ) |
|
213 { |
|
214 __VTPRINT( DEBUG_GEN, " not EC number => leave" ) |
|
215 // Not an emergency call number. Abort emergency call process. |
|
216 User::Leave( KErrArgument ); |
|
217 } |
|
218 } |
|
219 __VTPRINTEXIT( "CEmergencyCaller.ConstructL" ) |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CVtUiAppShutter::CEmergencyCaller::CEmergencyCaller |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 CVtUiAppShutter::CEmergencyCaller::CEmergencyCaller( |
|
227 CVtUiAppShutter& aObserver, |
|
228 MVtUiStateContext& aStateContext ) : |
|
229 iObserver( aObserver ), |
|
230 iStateContext( aStateContext ) |
|
231 { |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CVtUiAppShutter::CEmergencyCaller::~CEmergencyCaller |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 CVtUiAppShutter::CEmergencyCaller::~CEmergencyCaller() |
|
239 { |
|
240 __VTPRINTENTER( "CEmergencyCaller.~" ) |
|
241 delete iEmergency; |
|
242 iServer.Close(); |
|
243 __VTPRINTEXIT( "CEmergencyCaller.~" ) |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CVtUiAppShutter::CEmergencyCaller::HandleEmergencyDialL |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void CVtUiAppShutter::CEmergencyCaller::HandleEmergencyDialL( |
|
251 const TInt ) |
|
252 { |
|
253 __VTPRINTENTER( "CEmergencyCaller.HandleEmergencyDialL" ) |
|
254 iObserver.EmergencyCallDoneL(); |
|
255 __VTPRINTEXIT( "CEmergencyCaller.HandleEmergencyDialL" ) |
|
256 } |
|
257 |
|