|
1 /* |
|
2 * Copyright (c) 2004 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: Client application plugin loader. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <imlauncherplugin.h> |
|
22 #include "imlauncher.h" |
|
23 #include "logutils.h" |
|
24 |
|
25 |
|
26 // Default start wait time in sec |
|
27 static const TInt KDefaultTimeOut = 60; |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CImLauncher::CImLauncher |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CImLauncher::CImLauncher() |
|
38 : CActive( EPriorityStandard ), |
|
39 iPlugin( NULL ), |
|
40 iReturnValue( KErrNone ) |
|
41 { |
|
42 CActiveScheduler::Add( this ); |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CImLauncher::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CImLauncher::ConstructL() |
|
51 { |
|
52 iTimer = CImShutDownTimer::NewL( this, EPriorityStandard ); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CImLauncher::NewL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CImLauncher* CImLauncher::NewL() |
|
61 { |
|
62 CImLauncher* self = new( ELeave ) CImLauncher; |
|
63 |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop(); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 // Destructor |
|
73 CImLauncher::~CImLauncher() |
|
74 { |
|
75 Cancel(); |
|
76 delete iTimer; |
|
77 if ( iPlugin ) // extra security check |
|
78 { |
|
79 delete iPlugin; |
|
80 } |
|
81 } |
|
82 |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CImLauncher::Panic |
|
86 // Panics the thread |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CImLauncher::Panic( TLauncherPanic aPanicCode ) |
|
90 { |
|
91 User::Panic( KLauncherPanic, aPanicCode ); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CImLauncher::RunL |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CImLauncher::RunL() |
|
99 { |
|
100 #ifdef _DEBUG |
|
101 CImApiLogger::Log( _L( "Application start status: %d" ), iStatus.Int() ); |
|
102 #endif |
|
103 iReturnValue = iStatus.Int(); |
|
104 // We're finished |
|
105 iTimer->Cancel(); |
|
106 CActiveScheduler::Stop(); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CImLauncher::DoCancel |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CImLauncher::DoCancel() |
|
114 { |
|
115 if ( iPlugin ) // extra security check |
|
116 { |
|
117 iPlugin->CancelStartApplication(); |
|
118 } |
|
119 iTimer->Cancel(); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CImLauncher::DoShutDown |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CImLauncher::TimedOut() |
|
127 { |
|
128 #ifdef _DEBUG |
|
129 CImApiLogger::Log( _L( "Application starting timed out" ) ); |
|
130 #endif |
|
131 Cancel(); |
|
132 iReturnValue = KErrTimedOut; |
|
133 |
|
134 CActiveScheduler::Stop(); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CImLauncher::RunError |
|
139 // Handles the RunL leave errors |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 TInt CImLauncher::RunError( TInt /*aError*/ ) |
|
143 { |
|
144 return KErrNone; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CImLauncher::StartL() |
|
149 // Loads the application launcher plugin and waits for the completition |
|
150 // ----------------------------------------------------------------------------- |
|
151 void CImLauncher::StartL( TImpsLaunchParams& aThreadParams ) |
|
152 { |
|
153 |
|
154 /* |
|
155 * Convert the 16bit descriptor to 8bit. |
|
156 * This should not be a problem as ClientID should not contain |
|
157 * non ASCII chars. |
|
158 * If there will be a problem the ECom default resolver should be changed! |
|
159 */ |
|
160 |
|
161 TBuf8<KImpsMaxClientId> applicationId; |
|
162 if ( aThreadParams.iApplicationId.Length() > KImpsMaxClientId ) |
|
163 { |
|
164 User::Leave( KErrArgument ); |
|
165 } |
|
166 else |
|
167 { |
|
168 applicationId.Copy( aThreadParams.iApplicationId ); |
|
169 } |
|
170 |
|
171 #ifdef _DEBUG |
|
172 // NOTICE: this accepts only 16bit descriptor to log :-( |
|
173 CImApiLogger::Log( _L( "Loading 3rd party launcher plugin: %S" ), &aThreadParams.iApplicationId ); |
|
174 #endif |
|
175 // ECom loading |
|
176 iPlugin = CImLauncherPlugin::NewL( applicationId ); |
|
177 |
|
178 #ifdef _DEBUG |
|
179 CImApiLogger::Log( _L( "Loading successfull" ) ); |
|
180 #endif |
|
181 |
|
182 // Make a request |
|
183 iStatus = KRequestPending; |
|
184 SetActive(); |
|
185 iPlugin->StartApplicationL( iStatus, aThreadParams.iSAP, aThreadParams.iUserId ); |
|
186 |
|
187 |
|
188 #ifdef _DEBUG |
|
189 CImApiLogger::Log( _L( "Timer started: %d sec" ), KDefaultTimeOut ); |
|
190 #endif |
|
191 iTimer->After( KDefaultTimeOut * 1000000 ); |
|
192 |
|
193 CActiveScheduler::Start(); |
|
194 |
|
195 // if the request failed return the fail code to thread starter |
|
196 User::LeaveIfError( iReturnValue ); |
|
197 |
|
198 delete iPlugin; |
|
199 iPlugin = NULL; |
|
200 |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // ThreadFunction() |
|
205 // Static function. Installs the CleanupsStack and ActiveScheduler |
|
206 // then initiates the application launching. |
|
207 // ----------------------------------------------------------------------------- |
|
208 TInt CImLauncher::ThreadFunction( TImpsLaunchParams& aThreadParams ) |
|
209 { |
|
210 |
|
211 #ifdef _DEBUG |
|
212 CImApiLogger::Log( _L( "ThreadFunction start" ) ); |
|
213 __UHEAP_MARK; |
|
214 #endif |
|
215 |
|
216 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
217 if ( cleanupStack == NULL ) |
|
218 { |
|
219 Panic( ECreateTrapCleanup ); |
|
220 } |
|
221 |
|
222 // Construct active scheduler |
|
223 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
224 // Install active scheduler |
|
225 // We don't need to check whether an active scheduler is already installed |
|
226 // as this is a new thread, so there won't be one |
|
227 CActiveScheduler::Install( activeScheduler ); |
|
228 |
|
229 CImLauncher* launcher = NULL; |
|
230 TRAPD( err, launcher = CImLauncher::NewL() ); |
|
231 if ( err == KErrNone ) |
|
232 { |
|
233 TRAP( err, launcher->StartL( aThreadParams ) ); |
|
234 } |
|
235 |
|
236 delete launcher; |
|
237 delete activeScheduler; |
|
238 delete cleanupStack; |
|
239 cleanupStack = NULL; |
|
240 REComSession::FinalClose(); |
|
241 |
|
242 #ifdef _DEBUG |
|
243 CImApiLogger::Log( _L( "ThreadFunction end %d" ), err ); |
|
244 __UHEAP_MARKEND; |
|
245 CImApiLogger::Log( _L( "MEM TEST OK" ) ); |
|
246 #endif |
|
247 |
|
248 return err; |
|
249 } |
|
250 |
|
251 |
|
252 /* |
|
253 * Main function |
|
254 */ |
|
255 TInt E32Main() |
|
256 { |
|
257 #ifdef _DEBUG |
|
258 CImApiLogger::Log( _L( "EXE Started" ) ); |
|
259 #endif |
|
260 // |
|
261 TBuf < sizeof( TImpsLaunchParams ) > paramsDes; |
|
262 |
|
263 User::CommandLine( paramsDes ); |
|
264 |
|
265 TImpsLaunchParams params; |
|
266 params.Set( paramsDes ); |
|
267 |
|
268 return CImLauncher::ThreadFunction( params ); |
|
269 } |
|
270 |
|
271 |
|
272 //********************************** |
|
273 // CImShutDownTimer |
|
274 //********************************** |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CImShutDownTimer::CImShutDownTimer() |
|
278 // Constructor |
|
279 // ----------------------------------------------------------------------------- |
|
280 CImShutDownTimer::CImShutDownTimer( CImLauncher* aLauncher, TInt aPriority ) |
|
281 : CTimer( aPriority ), |
|
282 iLauncher( aLauncher ) |
|
283 { |
|
284 CActiveScheduler::Add( this ); |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CImShutDownTimer::ConstructL() |
|
289 // 2nd phase Constructor |
|
290 // ----------------------------------------------------------------------------- |
|
291 void CImShutDownTimer::ConstructL() |
|
292 { |
|
293 CTimer::ConstructL(); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CImShutDownTimer::NewL() |
|
298 // Factory function |
|
299 // ----------------------------------------------------------------------------- |
|
300 CImShutDownTimer* CImShutDownTimer::NewL( CImLauncher* aLauncher, TInt aPriority ) |
|
301 { |
|
302 CImShutDownTimer* self = new( ELeave ) CImShutDownTimer( aLauncher, aPriority ); |
|
303 |
|
304 CleanupStack::PushL( self ); |
|
305 self->ConstructL(); |
|
306 CleanupStack::Pop(); |
|
307 |
|
308 return self; |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CImShutDownTimer::~CImShutDownTimer() |
|
313 // Destructor |
|
314 // ----------------------------------------------------------------------------- |
|
315 CImShutDownTimer::~CImShutDownTimer() |
|
316 { |
|
317 Cancel(); |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CImShutDownTimer::RunL() |
|
322 // Signals the timeout to the timer user |
|
323 // ----------------------------------------------------------------------------- |
|
324 void CImShutDownTimer::RunL() |
|
325 { |
|
326 iLauncher->TimedOut(); |
|
327 } |
|
328 |
|
329 // End of File |