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