|
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: Proxy class for Im app launcher. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <E32Math.h> |
|
22 #include "impsapplauncherproxy.h" |
|
23 #include "impsutils.h" |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 // MACROS |
|
28 #ifndef _DEBUG |
|
29 #define _NO_IMPS_LOGGING_ |
|
30 #endif |
|
31 |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CImpsAppLauncherProxy::CImpsAppLauncherProxy |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CImpsAppLauncherProxy::CImpsAppLauncherProxy( MImpsAppLaunchHandler* aLaunchObserver ) |
|
42 : CActive( EPriorityStandard ), |
|
43 iLaunchObserver( aLaunchObserver ), |
|
44 iRequestList( _FOFF( CLaunchRequest, iLink ) ) |
|
45 { |
|
46 CActiveScheduler::Add( this ); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CImpsAppLauncherProxy::ConstructL |
|
51 // Symbian 2nd phase constructor can leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CImpsAppLauncherProxy::ConstructL() |
|
55 { |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CImpsAppLauncherProxy::NewL |
|
60 // Two-phased constructor. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CImpsAppLauncherProxy* CImpsAppLauncherProxy::NewL( |
|
64 MImpsAppLaunchHandler* aLaunchObserver ) |
|
65 { |
|
66 CImpsAppLauncherProxy* self = new( ELeave ) CImpsAppLauncherProxy( |
|
67 aLaunchObserver ); |
|
68 |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(); |
|
72 |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 // Destructor |
|
78 CImpsAppLauncherProxy::~CImpsAppLauncherProxy() |
|
79 { |
|
80 // Free the request queue |
|
81 TDblQueIter<CLaunchRequest> iter( iRequestList ); |
|
82 iter.SetToFirst(); |
|
83 while ( iter ) |
|
84 { |
|
85 CLaunchRequest* request = iter; |
|
86 iter++; |
|
87 request->Destroy(); |
|
88 } |
|
89 |
|
90 Cancel(); |
|
91 delete iCurrentRequest; // just in case |
|
92 } |
|
93 |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CImpsAppLauncherProxy::LaunchApplication |
|
97 // The request function. Launches the application which is registered with |
|
98 // the given ApplicationID. |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TInt CImpsAppLauncherProxy::LaunchApplicationL( const TDesC& aApplicationId, |
|
102 const TDesC& aSAP, |
|
103 const TDesC& aUserID ) |
|
104 { |
|
105 #ifndef _NO_IMPS_LOGGING_ |
|
106 CImpsClientLogger::Log( _L( "CImpsAppLauncherProxy: LaunchApplication (appId: %S, SAP: %S, user: %S)" ), &aApplicationId, &aSAP, &aUserID ); |
|
107 #endif |
|
108 |
|
109 CLaunchRequest* launchRequest = CLaunchRequest::NewL( aApplicationId, aSAP, aUserID ); |
|
110 |
|
111 |
|
112 if ( IsActive() ) |
|
113 { |
|
114 if ( !iCurrentRequest ) |
|
115 { |
|
116 delete launchRequest; |
|
117 User::Leave( KErrCorrupt ); |
|
118 } |
|
119 |
|
120 if ( !( *iCurrentRequest == *launchRequest ) ) |
|
121 { |
|
122 // Different request |
|
123 // Queue this aApplicationId it for later handling |
|
124 #ifndef _NO_IMPS_LOGGING_ |
|
125 CImpsClientLogger::Log( _L( "CImpsAppLauncherProxy: Active with different request " ) ); |
|
126 #endif |
|
127 QueueRequest( *launchRequest ); |
|
128 } |
|
129 else |
|
130 { |
|
131 #ifndef _NO_IMPS_LOGGING_ |
|
132 CImpsClientLogger::Log( _L( "CImpsAppLauncherProxy: Active with same request " ) ); |
|
133 #endif |
|
134 |
|
135 } |
|
136 } |
|
137 else // not active |
|
138 { |
|
139 #ifndef _NO_IMPS_LOGGING_ |
|
140 CImpsClientLogger::Log( _L( "CImpsAppLauncherProxy: Not active. Starting." ) ); |
|
141 #endif |
|
142 // Assign a new request to current |
|
143 delete iCurrentRequest; |
|
144 iCurrentRequest = NULL; |
|
145 iCurrentRequest = launchRequest; |
|
146 |
|
147 // return ImLauncher process starting error code |
|
148 TInt err = DoStartProcess( *iCurrentRequest ); |
|
149 if ( err ) |
|
150 { |
|
151 delete iCurrentRequest; |
|
152 iCurrentRequest = NULL; |
|
153 } |
|
154 |
|
155 return err; |
|
156 } |
|
157 return KErrNone; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CImpsAppLauncherProxy::RunL |
|
162 // Called when the launcher process exited |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CImpsAppLauncherProxy::RunL() |
|
166 { |
|
167 // Here comes the control when the ImLauncher.exe (or dll) finished |
|
168 #ifndef _NO_IMPS_LOGGING_ |
|
169 CImpsClientLogger::Log( _L( "CImpsAppLauncherProxy: RunL %d" ), iStatus.Int() ); |
|
170 #endif |
|
171 |
|
172 // Notify the observer if any |
|
173 if ( iLaunchObserver != NULL ) |
|
174 { |
|
175 iLaunchObserver->HandleAppLaunch( iCurrentRequest->ApplicationId(), iStatus.Int() ); |
|
176 } |
|
177 |
|
178 // Delete the current Client ID |
|
179 delete iCurrentRequest; |
|
180 iCurrentRequest = NULL; |
|
181 |
|
182 ProcessNextRequestL(); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CImpsAppLauncherProxy::DoCancel |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CImpsAppLauncherProxy::DoCancel() |
|
190 { |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CImpsAppLauncherProxy::RunError |
|
195 // Called when the RunL leaved |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CImpsAppLauncherProxy::RunError( TInt /*aError*/ ) |
|
199 { |
|
200 return KErrNone; |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CImpsAppLauncherProxy::DoStartProcess |
|
205 // Starts the ImLauncher process |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 TInt CImpsAppLauncherProxy::DoStartProcess( CLaunchRequest& aRequest ) |
|
209 { |
|
210 TInt result; |
|
211 |
|
212 RProcess launcher; |
|
213 const TDesC& appId = aRequest.ApplicationId(); |
|
214 const TDesC& sap = aRequest.Sap(); |
|
215 const TDesC& userId = aRequest.UserId(); |
|
216 TImpsLaunchParams params( appId, sap, userId ); |
|
217 _LIT( KLauncherFilenameExe, "ImLauncher.exe" ); |
|
218 TPtrC paramsDes = params.Get(); |
|
219 result = launcher.Create( KLauncherFilenameExe, paramsDes ); |
|
220 if ( result != KErrNone ) |
|
221 { |
|
222 #ifndef _NO_IMPS_LOGGING_ |
|
223 CImpsClientLogger::Log( _L( "CImpsAppLauncherProxy: Create process failed: %d " ), result ); |
|
224 #endif |
|
225 return result; |
|
226 } |
|
227 |
|
228 // When the launcher exits we'll get the exit code in iStatus |
|
229 iStatus = KRequestPending; |
|
230 SetActive(); |
|
231 launcher.Logon( iStatus ); |
|
232 |
|
233 launcher.Resume(); |
|
234 launcher.Close(); |
|
235 |
|
236 #ifndef _NO_IMPS_LOGGING_ |
|
237 CImpsClientLogger::Log( _L( "CImpsAppLauncherProxy: Create process success" ) ); |
|
238 #endif |
|
239 return KErrNone; |
|
240 } |
|
241 |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CImpsAppLauncherProxy::QueueRequest |
|
245 // Adds the request to the queue. No duplicates are queued. |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 void CImpsAppLauncherProxy::QueueRequest( CLaunchRequest& aRequest ) |
|
249 { |
|
250 // Check for duplicate requests |
|
251 if ( !IsDuplicate( aRequest ) ) |
|
252 { |
|
253 #ifndef _NO_IMPS_LOGGING_ |
|
254 CImpsClientLogger::Log( _L( "Queued" ) ); |
|
255 #endif |
|
256 iRequestList.AddLast( aRequest ); |
|
257 } |
|
258 else |
|
259 { |
|
260 #ifndef _NO_IMPS_LOGGING_ |
|
261 CImpsClientLogger::Log( _L( "Request already exists" ) ); |
|
262 #endif |
|
263 } |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CImpsAppLauncherProxy::ProcessNextRequest |
|
268 // Gets the next request from the queue and processes it. |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 void CImpsAppLauncherProxy::ProcessNextRequestL() |
|
272 { |
|
273 // Check for queued |
|
274 TDblQueIter<CLaunchRequest> iter ( iRequestList ); |
|
275 iter.SetToFirst(); |
|
276 if ( iter ) |
|
277 { |
|
278 // There is request to handle |
|
279 CLaunchRequest* request = iter; |
|
280 delete iCurrentRequest; |
|
281 iCurrentRequest = NULL; |
|
282 iCurrentRequest = request; |
|
283 request->iLink.Deque(); // remove it from the queue |
|
284 |
|
285 #ifndef _NO_IMPS_LOGGING_ |
|
286 CImpsClientLogger::Log( |
|
287 _L( "CImpsAppLauncherProxy: Processing the next request: \"%S\"" ), |
|
288 &( iCurrentRequest->ApplicationId() ) ); |
|
289 #endif |
|
290 |
|
291 TInt err( DoStartProcess( *iCurrentRequest ) ); |
|
292 if ( ( err != KErrNone ) ) |
|
293 { |
|
294 // if starting failed notify the observer |
|
295 if ( iLaunchObserver != NULL ) |
|
296 { |
|
297 iLaunchObserver->HandleAppLaunch( iCurrentRequest->ApplicationId(), err ); |
|
298 } |
|
299 } |
|
300 |
|
301 } |
|
302 else |
|
303 { |
|
304 #ifndef _NO_IMPS_LOGGING_ |
|
305 CImpsClientLogger::Log( |
|
306 _L( "CImpsAppLauncherProxy: No more requests to process" ) ); |
|
307 #endif |
|
308 |
|
309 } |
|
310 } |
|
311 |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CImpsAppLauncherProxy::IsDuplicate |
|
315 // Checks if the given ApplicationID is already in the queue. |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 TBool CImpsAppLauncherProxy::IsDuplicate( CLaunchRequest& aRequest ) |
|
319 { |
|
320 TDblQueIter<CLaunchRequest> iter ( iRequestList ); |
|
321 iter.SetToFirst(); |
|
322 while ( iter ) |
|
323 { |
|
324 CLaunchRequest* request = iter++; |
|
325 if ( aRequest == *request ) |
|
326 { |
|
327 return ETrue; |
|
328 } |
|
329 } |
|
330 |
|
331 return EFalse; |
|
332 } |
|
333 |
|
334 ////////////////////////////////////////////////////////////////////////// |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CLaunchRequest::CLaunchRequest |
|
338 // ----------------------------------------------------------------------------- |
|
339 |
|
340 CLaunchRequest::CLaunchRequest( ) |
|
341 { |
|
342 } |
|
343 |
|
344 |
|
345 CLaunchRequest* CLaunchRequest::NewL( const TDesC& aCID, |
|
346 const TDesC& aSAP, |
|
347 const TDesC& aUserId ) |
|
348 { |
|
349 CLaunchRequest* self = new( ELeave ) CLaunchRequest(); |
|
350 |
|
351 CleanupStack::PushL( self ); |
|
352 self->ConstructL( aCID, aSAP, aUserId ); |
|
353 CleanupStack::Pop(); |
|
354 |
|
355 return self; |
|
356 |
|
357 } |
|
358 |
|
359 void CLaunchRequest::ConstructL( const TDesC& aCID, |
|
360 const TDesC& aSAP, |
|
361 const TDesC& aUserId ) |
|
362 { |
|
363 iCID = aCID.AllocL(); |
|
364 iSAP = aSAP.AllocL(); |
|
365 iUserId = aUserId.AllocL(); |
|
366 } |
|
367 |
|
368 CLaunchRequest::~CLaunchRequest() |
|
369 { |
|
370 delete iCID; |
|
371 delete iSAP; |
|
372 delete iUserId; |
|
373 } //lint !e1540 iFields freed in Destroy |
|
374 |
|
375 void CLaunchRequest::Destroy() |
|
376 { |
|
377 iLink.Deque(); |
|
378 delete this; |
|
379 } |
|
380 |
|
381 |
|
382 const TDesC& CLaunchRequest::ApplicationId() |
|
383 { |
|
384 return *iCID; |
|
385 } |
|
386 |
|
387 const TDesC& CLaunchRequest::Sap() |
|
388 { |
|
389 return *iSAP; |
|
390 } |
|
391 |
|
392 const TDesC& CLaunchRequest::UserId() |
|
393 { |
|
394 return *iUserId; |
|
395 } |
|
396 |
|
397 bool CLaunchRequest::operator==( CLaunchRequest& rhs ) |
|
398 { |
|
399 if ( this->ApplicationId().Compare( rhs.ApplicationId() ) || |
|
400 this->Sap().Compare( rhs.Sap() ) || |
|
401 this->UserId().Compare( rhs.UserId() ) ) |
|
402 { |
|
403 return true; |
|
404 } |
|
405 else |
|
406 { |
|
407 return false; |
|
408 } |
|
409 } |
|
410 |
|
411 // End of File |