|
1 /* |
|
2 * Copyright (c) 2007-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 the License "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: This Class provides the interface for |
|
15 * calling the functionality to Application Manager SAPI. |
|
16 * Interafce |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #include <Liwcommon.h> |
|
23 #include <Liwbufferextension.h> |
|
24 #include <utf.h> |
|
25 |
|
26 #include "appmanagerinterface.h" |
|
27 #include "appmanagerservice.h" |
|
28 #include "appitemslist.h" |
|
29 #include "appserviceobserver.h" |
|
30 #include "serviceerrno.h" |
|
31 #include "appserviceerrmsg.hrh" |
|
32 |
|
33 |
|
34 #define KMAXCONTENTLENGTH 32 |
|
35 #define KMAXPATHLENGTH 255 |
|
36 |
|
37 //Supported Operation |
|
38 _LIT8(KGetList, "GetList"); |
|
39 _LIT8(KCancel, "Cancel"); |
|
40 _LIT8(KLaunchApp,"LaunchApp"); |
|
41 _LIT8(KLaunchDoc,"LaunchDoc"); |
|
42 |
|
43 //Input Keys/arguments |
|
44 |
|
45 // Data source name |
|
46 _LIT8(KType,"Type"); |
|
47 _LIT8(KApplicationID,"ApplicationID"); |
|
48 _LIT8(KCmdLine,"CmdLine"); |
|
49 _LIT8(KOptions,"Options"); |
|
50 _LIT8(KDocument,"Document"); |
|
51 _LIT8(KMimeType,"MimeType"); |
|
52 |
|
53 // Filter Map |
|
54 _LIT8(KFilter,"Filter"); |
|
55 |
|
56 |
|
57 //Filter criteria |
|
58 _LIT8(KDocumentPath,"DocumentPath"); |
|
59 _LIT8(KMode,"Mode"); |
|
60 _LIT8(KPosition,"Position"); |
|
61 //_LIT8(KPath ,"Path"); |
|
62 _LIT8(KHandle,"Handle"); |
|
63 _LIT8(KDocumentName,"DocumentName"); |
|
64 |
|
65 |
|
66 //Possible Content |
|
67 //_LIT(KUserInstalledPackage,"UserInstalledPackage"); |
|
68 //_LIT(KApplication,"Application"); |
|
69 |
|
70 |
|
71 //Output Keys/arguments |
|
72 _LIT8(KResponse,"ReturnValue"); |
|
73 _LIT8(KErrorCode,"ErrorCode"); |
|
74 _LIT8(KTransactionID,"TransactionID"); |
|
75 |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CAppManagerInterface::NewLC |
|
80 // Returns the instance of CAppManagerInterface. |
|
81 // ----------------------------------------------------------------------------- |
|
82 CAppManagerInterface* CAppManagerInterface::NewL() |
|
83 { |
|
84 |
|
85 CAppManagerInterface* self = new ( ELeave )CAppManagerInterface(); |
|
86 CleanupStack::PushL( self ); |
|
87 self->ConstructL(); |
|
88 CleanupStack::Pop( self ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CAppManagerInterface::~CAppManagerInterface |
|
95 // Destructor of class |
|
96 // ----------------------------------------------------------------------------- |
|
97 CAppManagerInterface::~CAppManagerInterface() |
|
98 { |
|
99 //Release the instance of core class |
|
100 delete iCoreClass; |
|
101 iCoreClass = NULL; |
|
102 } |
|
103 |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CAppManagerService::ExecuteCmdL |
|
107 // Request handler method of interface class |
|
108 // ----------------------------------------------------------------------------- |
|
109 |
|
110 void CAppManagerInterface::ExecuteCmdL(const TDesC8& aCmdName, |
|
111 const CLiwGenericParamList& aInParamList, |
|
112 CLiwGenericParamList& aOutParamList, |
|
113 TUint aCmdOptions , |
|
114 MLiwNotifyCallback* aCallBack) |
|
115 { |
|
116 |
|
117 TInt32 transactionID = 0; |
|
118 TInt errCode = 0; |
|
119 TInt pos = 0; |
|
120 const TLiwGenericParam* param = NULL; |
|
121 TLiwGenericParam posbasedparam; |
|
122 |
|
123 if( (aCmdOptions & KLiwOptCancel ) && (0== aCmdName.CompareF( KCancel ))) // for cancel asynchronous request |
|
124 { |
|
125 |
|
126 param = aInParamList.FindFirst( pos, KTransactionID ); |
|
127 if( !param ) |
|
128 { |
|
129 |
|
130 if( aInParamList.Count() > 0 ) |
|
131 { |
|
132 pos = 0; |
|
133 aInParamList.AtL( pos, posbasedparam ); |
|
134 if (posbasedparam.Value().IsEmpty() ) |
|
135 { |
|
136 param = NULL; |
|
137 } |
|
138 else |
|
139 { |
|
140 param = &posbasedparam; |
|
141 } |
|
142 } |
|
143 |
|
144 } |
|
145 |
|
146 |
|
147 if( param ) |
|
148 { |
|
149 param->Value().Get( transactionID ); |
|
150 errCode = iCoreClass->Cancel( transactionID ); |
|
151 if ( KErrNone != errCode ) |
|
152 { |
|
153 TInt sapiErr = SapiError(errCode); |
|
154 aOutParamList.AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)sapiErr))); |
|
155 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KIncorrectTransactionId ) ) ); |
|
156 } |
|
157 } |
|
158 else |
|
159 { |
|
160 aOutParamList.AppendL( TLiwGenericParam ( KErrorCode,TLiwVariant( TInt32( SErrMissingArgument ) ) ) ); |
|
161 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KTransactionIdMissing ) ) ); |
|
162 } |
|
163 |
|
164 return; |
|
165 |
|
166 } |
|
167 |
|
168 |
|
169 |
|
170 // Check the command name;Cmd name should be GetList,LaunchApp or LaunchDoc |
|
171 if( 0 == aCmdName.CompareF( KGetList ) ) |
|
172 { |
|
173 //Call GetListAPI |
|
174 if( (aCmdOptions & KLiwOptASyncronous ) && ( NULL != aCallBack ) ) //Asynchronous request |
|
175 { |
|
176 //No Asynch version of getlist is supported |
|
177 aOutParamList.AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiError(KErrNotSupported)))); |
|
178 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant(KAsynchVersionNotSupported ) ) ); |
|
179 } |
|
180 else if( (!aCmdOptions) && ( NULL == aCallBack ) ) //Synchronous request |
|
181 { |
|
182 GetListL( aInParamList, aOutParamList ); |
|
183 } |
|
184 else |
|
185 { |
|
186 aOutParamList.AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiError(KErrArgument)))); |
|
187 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KAsynchRequestNotProper ) ) ); |
|
188 } |
|
189 } |
|
190 else if( 0 == aCmdName.CompareF( KLaunchApp ) ) |
|
191 { |
|
192 //Call LaunchApp API |
|
193 if( (aCmdOptions & KLiwOptASyncronous ) && ( NULL != aCallBack ) ) //Asynchronous request |
|
194 { |
|
195 |
|
196 //Asynch Call |
|
197 transactionID = aCallBack->GetTransactionID(); |
|
198 LaunchAppL( aInParamList, aOutParamList, aCallBack , transactionID ); |
|
199 |
|
200 } |
|
201 else if( (!aCmdOptions) && ( NULL == aCallBack ) ) //Synchronous request |
|
202 { |
|
203 //Synchronous Call |
|
204 LaunchAppL( aInParamList, aOutParamList); |
|
205 } |
|
206 else |
|
207 { |
|
208 aOutParamList.AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiError(KErrArgument)))); |
|
209 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KAsynchRequestNotProper ) ) ); |
|
210 } |
|
211 |
|
212 } |
|
213 |
|
214 else if( 0 == aCmdName.CompareF( KLaunchDoc ) ) |
|
215 { |
|
216 //Call LaunchDoc API |
|
217 if( (aCmdOptions & KLiwOptASyncronous ) && ( NULL != aCallBack ) ) //Asynchronous request |
|
218 { |
|
219 //Asynch Call |
|
220 transactionID = aCallBack->GetTransactionID(); |
|
221 LaunchDocL( aInParamList, aOutParamList, aCallBack , transactionID ); |
|
222 |
|
223 } |
|
224 else if( (!aCmdOptions) && ( NULL == aCallBack ) ) //Synchronous request |
|
225 { |
|
226 //Synchronous Call |
|
227 LaunchDocL( aInParamList, aOutParamList); |
|
228 } |
|
229 else |
|
230 { |
|
231 aOutParamList.AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiError(KErrArgument)))); |
|
232 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KAsynchRequestNotProper ) ) ); |
|
233 } |
|
234 } |
|
235 else |
|
236 { |
|
237 //error code = command not supported |
|
238 aOutParamList.AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiError(KErrNotSupported)))); |
|
239 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KCommandNotSupported ) ) ); |
|
240 } |
|
241 |
|
242 |
|
243 if( (aCmdOptions & KLiwOptASyncronous ) && ( NULL != aCallBack ) ) //Asynchronous request |
|
244 { |
|
245 aOutParamList.AppendL( TLiwGenericParam( KTransactionID, TLiwVariant( transactionID ) ) ); |
|
246 } |
|
247 } |
|
248 |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CAppManagerInterface::CAppManagerInterface |
|
252 // Constructor of class |
|
253 // ----------------------------------------------------------------------------- |
|
254 |
|
255 CAppManagerInterface::CAppManagerInterface() |
|
256 :iCoreClass( NULL ) |
|
257 |
|
258 { |
|
259 |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CAppManagerInterface::ConstructL |
|
265 // Two-phased constructor of class |
|
266 // ----------------------------------------------------------------------------- |
|
267 |
|
268 void CAppManagerInterface::ConstructL() |
|
269 { |
|
270 // Create the instance of core class |
|
271 iCoreClass = CAppManagerService::NewL(); |
|
272 |
|
273 } |
|
274 |
|
275 |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CAppManagerInterface::GetListL |
|
279 // This function will send the request to Core class |
|
280 // ----------------------------------------------------------------------------- |
|
281 |
|
282 void CAppManagerInterface::GetListL(const CLiwGenericParamList& aInParamList , CLiwGenericParamList& aOutParamList ) |
|
283 |
|
284 { |
|
285 |
|
286 |
|
287 |
|
288 TLiwGenericParam posbasedparam; |
|
289 TBool postionbasedsearching = EFalse; |
|
290 const TLiwGenericParam* param = NULL; |
|
291 TInt pos = 0; |
|
292 param = aInParamList.FindFirst( pos, KType ); |
|
293 |
|
294 if(!param) |
|
295 { |
|
296 |
|
297 if( aInParamList.Count() > 0 ) |
|
298 { |
|
299 pos = 0; |
|
300 aInParamList.AtL( pos,posbasedparam ); |
|
301 |
|
302 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
303 { |
|
304 param = NULL; |
|
305 } |
|
306 else |
|
307 { |
|
308 param = &posbasedparam; |
|
309 postionbasedsearching = ETrue; |
|
310 } |
|
311 } |
|
312 } |
|
313 TBuf<KMAXCONTENTLENGTH> content; |
|
314 if( param ) |
|
315 { |
|
316 |
|
317 // content present : Mandatory Argument |
|
318 if (param->Value().TypeId() != LIW::EVariantTypeDesC || param->Value().AsDes().Length() > KMAXCONTENTLENGTH || !param->Value().Get( content ) ) |
|
319 { |
|
320 //content type is different: append error and return |
|
321 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ((TInt32)SErrBadArgumentType) )); |
|
322 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KContentTypeMismatch ) ) ); |
|
323 |
|
324 posbasedparam.Reset(); |
|
325 |
|
326 return; |
|
327 } |
|
328 |
|
329 HBufC8* heapBuffer = NULL; |
|
330 param = NULL; |
|
331 if ( postionbasedsearching && ( aInParamList.Count() > 1) ) |
|
332 { |
|
333 pos = 1; |
|
334 aInParamList.AtL( pos,posbasedparam ); |
|
335 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
336 { |
|
337 param = NULL; |
|
338 } |
|
339 else |
|
340 { |
|
341 param = &posbasedparam; |
|
342 } |
|
343 } |
|
344 else |
|
345 { |
|
346 pos=0;//Search from starting point |
|
347 //filter map |
|
348 param = aInParamList.FindFirst( pos, KFilter ); |
|
349 } |
|
350 CFilterParam* filter = NULL; |
|
351 TLiwVariant documentname; |
|
352 TLiwVariant mimetype; |
|
353 |
|
354 |
|
355 //Filter is prsent |
|
356 if ( param && (param->Value().TypeId() != LIW::EVariantTypeNull ) ) |
|
357 { |
|
358 |
|
359 filter = CFilterParam::NewL(); |
|
360 CleanupStack::PushL( filter ); |
|
361 const CLiwMap* filtermap; |
|
362 |
|
363 TPtrC val; |
|
364 filtermap = param->Value().AsMap(); |
|
365 |
|
366 if (filtermap ) |
|
367 { |
|
368 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &documentname) ); |
|
369 |
|
370 if (filtermap->FindL( KDocumentPath, documentname ) && (documentname.TypeId() != LIW::EVariantTypeNull ) ) |
|
371 { |
|
372 if ((documentname.AsDes().Length() < KMAXPATHLENGTH ) && documentname.Get(val)) |
|
373 { |
|
374 filter->SetDocName(val); |
|
375 val.Set(NULL,0); |
|
376 } |
|
377 else |
|
378 { |
|
379 //content type is different: do cleanup, append error and return |
|
380 CleanupStack::Pop(&documentname); |
|
381 documentname.Reset(); |
|
382 |
|
383 if( filter ) |
|
384 { |
|
385 CleanupStack::PopAndDestroy( filter ); |
|
386 } |
|
387 |
|
388 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
389 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KFilterTypeMismatch ) ) ); |
|
390 |
|
391 posbasedparam.Reset(); |
|
392 |
|
393 return; |
|
394 } |
|
395 } |
|
396 |
|
397 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &mimetype) ); |
|
398 if (filtermap->FindL( KMimeType, mimetype ) && (mimetype.TypeId() != LIW::EVariantTypeNull ) ) |
|
399 { |
|
400 |
|
401 if ((mimetype.AsDes().Length() < KMAXPATHLENGTH ) && mimetype.Get(val)) |
|
402 { |
|
403 //Before sending convert 16 bit to 8 Bit |
|
404 heapBuffer = HBufC8::NewL(val.Length()); |
|
405 TPtr8 val8(heapBuffer->Des()); |
|
406 val8.Copy(val); |
|
407 filter->SetmimeType(val8); |
|
408 } |
|
409 else |
|
410 { |
|
411 //content type is different: do cleanup, append error and return |
|
412 |
|
413 CleanupStack::Pop(&mimetype); |
|
414 mimetype.Reset(); |
|
415 |
|
416 CleanupStack::Pop(&documentname); |
|
417 documentname.Reset(); |
|
418 |
|
419 if( filter ) |
|
420 { |
|
421 CleanupStack::PopAndDestroy( filter ); |
|
422 } |
|
423 |
|
424 delete heapBuffer; |
|
425 |
|
426 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
427 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KFilterTypeMismatch ) ) ); |
|
428 |
|
429 posbasedparam.Reset(); |
|
430 |
|
431 return; |
|
432 } |
|
433 } |
|
434 CleanupStack::Pop(2); |
|
435 } |
|
436 else |
|
437 { |
|
438 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType ) )); |
|
439 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KFilterTypeMismatch ) ) ); |
|
440 CleanupStack::PopAndDestroy( filter ); |
|
441 posbasedparam.Reset(); |
|
442 return; |
|
443 } |
|
444 |
|
445 } |
|
446 |
|
447 //Call GetList of Core class |
|
448 MIterator* iter = NULL; |
|
449 TRAPD ( errCode, iCoreClass->GetListL( iter, content, filter ) ); |
|
450 |
|
451 TInt sapiErr = SErrNone; |
|
452 if (errCode) |
|
453 { |
|
454 sapiErr = SapiError(errCode); |
|
455 } |
|
456 |
|
457 aOutParamList.AppendL( TLiwGenericParam ( KErrorCode,TLiwVariant( ( TInt32 )sapiErr ) ) ); |
|
458 |
|
459 |
|
460 if( errCode == KErrNone ) |
|
461 |
|
462 { |
|
463 // Fill the Iterator in Generic Paaram List |
|
464 TLiwVariant response; |
|
465 |
|
466 // Iterator will accept the MIterator * and will become the owner |
|
467 CAppItemsList *iterator = CAppItemsList::NewL( iter ); |
|
468 CleanupClosePushL( *iterator ); |
|
469 response.Set( iterator ); |
|
470 aOutParamList.AppendL( TLiwGenericParam ( KResponse, response ) ); |
|
471 CleanupStack::Pop( iterator ); |
|
472 iterator->DecRef(); |
|
473 |
|
474 } |
|
475 |
|
476 if( filter ) |
|
477 { |
|
478 CleanupStack::PopAndDestroy( filter ); |
|
479 } |
|
480 |
|
481 mimetype.Reset(); |
|
482 documentname.Reset(); |
|
483 |
|
484 delete heapBuffer; |
|
485 |
|
486 } |
|
487 else |
|
488 { |
|
489 //content type missig : Mandatory Argument |
|
490 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrMissingArgument))); |
|
491 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KContentMissing ) ) ); |
|
492 } |
|
493 |
|
494 posbasedparam.Reset(); |
|
495 |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CAppManagerInterface::LaunchAppL |
|
500 // This function will send the request to Core class |
|
501 // ----------------------------------------------------------------------------- |
|
502 |
|
503 void CAppManagerInterface::LaunchAppL(const CLiwGenericParamList& aInParamList , |
|
504 CLiwGenericParamList& aOutParamList, |
|
505 MLiwNotifyCallback* aCallBack, |
|
506 TInt32 aTransactionID ) |
|
507 |
|
508 { |
|
509 TLiwGenericParam posbasedparam; |
|
510 TBool postionbasedsearching = EFalse; |
|
511 TOptions options; |
|
512 const TLiwGenericParam* param = NULL; |
|
513 TInt pos = 0; |
|
514 |
|
515 |
|
516 |
|
517 param = aInParamList.FindFirst( pos, KApplicationID ); |
|
518 |
|
519 if( !param ) |
|
520 { |
|
521 |
|
522 if( aInParamList.Count() > 0 ) |
|
523 { |
|
524 pos = 0; |
|
525 aInParamList.AtL( pos,posbasedparam ); |
|
526 |
|
527 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
528 { |
|
529 param = NULL; |
|
530 } |
|
531 else |
|
532 { |
|
533 param = &posbasedparam; |
|
534 postionbasedsearching = ETrue; |
|
535 } |
|
536 } |
|
537 } |
|
538 TBuf<KMAXCONTENTLENGTH> appId; |
|
539 if( param ) |
|
540 { |
|
541 |
|
542 // content present : Mandatory Argument |
|
543 if (param->Value().TypeId() != LIW::EVariantTypeDesC || param->Value().AsDes().Length() > KMAXCONTENTLENGTH || !param->Value().Get( appId )) |
|
544 { |
|
545 //content type is different: append error and return |
|
546 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ((TInt32)SErrBadArgumentType) )); |
|
547 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KApplicationIDMismatch ) ) ); |
|
548 |
|
549 posbasedparam.Reset(); |
|
550 |
|
551 return; |
|
552 } |
|
553 |
|
554 TPtrC cmdline; |
|
555 // TBuf<KMAXCONTENTLENGTH> cmdline; |
|
556 TLiwVariant mode; |
|
557 TLiwVariant postion; |
|
558 TLiwVariant document; |
|
559 |
|
560 param = NULL; |
|
561 if ( postionbasedsearching && ( aInParamList.Count() > 1) ) |
|
562 { |
|
563 pos = 1; |
|
564 aInParamList.AtL( pos,posbasedparam ); |
|
565 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
566 { |
|
567 param = NULL; |
|
568 } |
|
569 else |
|
570 { |
|
571 param = &posbasedparam; |
|
572 } |
|
573 } |
|
574 else |
|
575 { |
|
576 pos=0;//Search from starting point |
|
577 //filter map |
|
578 param = aInParamList.FindFirst( pos, KCmdLine ); |
|
579 } |
|
580 |
|
581 //CommandLine is prsent |
|
582 if ( param && (param->Value().TypeId() != LIW::EVariantTypeNull ) ) |
|
583 { |
|
584 if( !param->Value().Get( cmdline ) ) |
|
585 { |
|
586 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( (TInt32)SErrBadArgumentType ) ) ); |
|
587 aOutParamList.AppendL( TLiwGenericParam( KErrorMsg, TLiwVariant( KCommandLineMismatch ) ) ); |
|
588 posbasedparam.Reset(); |
|
589 return; |
|
590 } |
|
591 } |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 param = NULL; |
|
600 if ( postionbasedsearching && ( aInParamList.Count() > 2) ) |
|
601 { |
|
602 pos = 2; |
|
603 aInParamList.AtL( pos,posbasedparam ); |
|
604 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
605 { |
|
606 param = NULL; |
|
607 } |
|
608 else |
|
609 { |
|
610 param = &posbasedparam; |
|
611 } |
|
612 } |
|
613 else |
|
614 { |
|
615 pos=0;//Search from starting point |
|
616 //filter map |
|
617 param = aInParamList.FindFirst( pos, KOptions ); |
|
618 } |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 //Options is prsent |
|
624 if ( param && (param->Value().TypeId() != LIW::EVariantTypeNull ) ) |
|
625 { |
|
626 if( (param->Value().TypeId() != LIW::EVariantTypeMap ) && |
|
627 (param->Value().TypeId() != LIW::EVariantTypeNull )) |
|
628 { |
|
629 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( (TInt32)SErrBadArgumentType ) ) ); |
|
630 aOutParamList.AppendL( TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchAppOptionsTypeMismatch ) ) ); |
|
631 posbasedparam.Reset(); |
|
632 return; |
|
633 } |
|
634 |
|
635 const CLiwMap* optionsmap = param->Value().AsMap(); |
|
636 |
|
637 if ( optionsmap ) |
|
638 { |
|
639 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &mode) ); |
|
640 |
|
641 if (optionsmap->FindL( KMode, mode ) && (mode.TypeId() != LIW::EVariantTypeNull )) |
|
642 { |
|
643 if (( mode.AsDes().Length() > KMAXCONTENTLENGTH ) || !mode.Get( options.iMode )) |
|
644 { |
|
645 //content type is different: do cleanup, append error and return |
|
646 |
|
647 CleanupStack::Pop(&mode); |
|
648 mode.Reset() ; |
|
649 |
|
650 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
651 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchAppOptionsTypeMismatch ) ) ); |
|
652 |
|
653 posbasedparam.Reset(); |
|
654 return; |
|
655 } |
|
656 |
|
657 } |
|
658 |
|
659 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &postion) ); |
|
660 |
|
661 if (optionsmap->FindL( KPosition, postion ) && (postion.TypeId() != LIW::EVariantTypeNull )) |
|
662 { |
|
663 if (( postion.AsDes().Length() > KMAXCONTENTLENGTH ) || !postion.Get( options.iPostion )) |
|
664 { |
|
665 //content type is different: do cleanup, append error and return |
|
666 CleanupStack::Pop(&postion); |
|
667 CleanupStack::Pop(&mode); |
|
668 |
|
669 mode.Reset() ; |
|
670 postion.Reset() ; |
|
671 |
|
672 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
673 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchAppOptionsTypeMismatch ) ) ); |
|
674 |
|
675 posbasedparam.Reset(); |
|
676 return; |
|
677 } |
|
678 } |
|
679 |
|
680 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &document) ); |
|
681 |
|
682 if (optionsmap->FindL( KDocumentPath, document ) || (document.TypeId() != LIW::EVariantTypeNull ) ) |
|
683 { |
|
684 if ( ( document.AsDes().Length() > KMAXPATHLENGTH ) || !document.Get( options.iDocument ) ) |
|
685 { |
|
686 //content type is different: do cleanup, append error and return |
|
687 CleanupStack::Pop(3); //document, position, mode |
|
688 |
|
689 mode.Reset() ; |
|
690 postion.Reset() ; |
|
691 document.Reset(); |
|
692 |
|
693 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
694 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchAppOptionsTypeMismatch ) ) ); |
|
695 |
|
696 posbasedparam.Reset(); |
|
697 return; |
|
698 } |
|
699 } |
|
700 |
|
701 CleanupStack::Pop(3); //document, position, mode |
|
702 |
|
703 } |
|
704 |
|
705 } |
|
706 |
|
707 |
|
708 |
|
709 TInt errCode; |
|
710 |
|
711 //Converting command line form 16 to 8-bit |
|
712 |
|
713 HBufC8* heapBuffer = HBufC8::NewL( cmdline.Length() ); |
|
714 CleanupStack::PushL( heapBuffer ); |
|
715 TPtr8 cmdline8( heapBuffer->Des() ); |
|
716 cmdline8.Copy( cmdline ); |
|
717 |
|
718 if( aCallBack ) |
|
719 { |
|
720 //Asynch Call |
|
721 CAppServiceObserver* observer = CAppServiceObserver::NewL( aCallBack ); |
|
722 CleanupStack::PushL( observer ); |
|
723 TRAP ( errCode, iCoreClass->LaunchApplicationL( appId, cmdline8, options, observer, aTransactionID ) ); |
|
724 CleanupStack::Pop( observer ); |
|
725 } |
|
726 else |
|
727 { |
|
728 TRAP ( errCode, iCoreClass->LaunchApplicationL( appId, cmdline8, options ) ); |
|
729 } |
|
730 |
|
731 CleanupStack::PopAndDestroy( heapBuffer ); |
|
732 |
|
733 mode.Reset(); |
|
734 postion.Reset(); |
|
735 document.Reset(); |
|
736 |
|
737 TInt sapiErr = SErrNone; |
|
738 if (errCode) |
|
739 { |
|
740 sapiErr = SapiError( errCode ); |
|
741 } |
|
742 |
|
743 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( ( TInt32 ) sapiErr ) )); |
|
744 |
|
745 } |
|
746 else |
|
747 { |
|
748 //content type missig : Mandatory Argument |
|
749 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( (TInt32)SErrMissingArgument) ) ); |
|
750 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KApplicationIDMissing ) ) ); |
|
751 } |
|
752 |
|
753 posbasedparam.Reset(); |
|
754 |
|
755 } |
|
756 |
|
757 |
|
758 |
|
759 // ----------------------------------------------------------------------------- |
|
760 // CAppManagerInterface::GetListL |
|
761 // This function will send the request to Core class |
|
762 // ----------------------------------------------------------------------------- |
|
763 |
|
764 void CAppManagerInterface::LaunchDocL(const CLiwGenericParamList& aInParamList, |
|
765 CLiwGenericParamList& aOutParamList, |
|
766 MLiwNotifyCallback* aCallBack, |
|
767 TInt32 aTransactionID ) |
|
768 |
|
769 { |
|
770 |
|
771 TLiwGenericParam posbasedparam; |
|
772 TBool postionbasedsearching = EFalse; |
|
773 TDocument document; |
|
774 TOptions options; |
|
775 const TLiwGenericParam* param = NULL; |
|
776 TInt pos = 0; |
|
777 const CLiwMap* documentmap = NULL; |
|
778 TLiwVariant mode; |
|
779 TLiwVariant path; |
|
780 TLiwVariant handle; |
|
781 |
|
782 param = aInParamList.FindFirst( pos, KDocument ); |
|
783 |
|
784 if( !param ) |
|
785 { |
|
786 |
|
787 if( aInParamList.Count() > 0 ) |
|
788 { |
|
789 pos = 0; |
|
790 aInParamList.AtL( pos,posbasedparam ); |
|
791 |
|
792 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
793 { |
|
794 param = NULL; |
|
795 } |
|
796 else |
|
797 { |
|
798 param = &posbasedparam; |
|
799 postionbasedsearching = ETrue; |
|
800 } |
|
801 } |
|
802 } |
|
803 |
|
804 if ( param ) |
|
805 { |
|
806 documentmap = param->Value().AsMap(); |
|
807 if ((param->Value().TypeId() != LIW::EVariantTypeNull) && |
|
808 (!documentmap && !postionbasedsearching)) |
|
809 { |
|
810 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( (TInt32)SErrBadArgumentType ) ) ); |
|
811 aOutParamList.AppendL( TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchDocMapTypeMismatch ) ) ); |
|
812 posbasedparam.Reset(); |
|
813 return; |
|
814 } |
|
815 |
|
816 } |
|
817 |
|
818 |
|
819 param = aInParamList.FindFirst( pos, KMimeType ); |
|
820 |
|
821 if( !param ) |
|
822 { |
|
823 |
|
824 if( aInParamList.Count() > 1 ) |
|
825 { |
|
826 pos = 1; |
|
827 aInParamList.AtL( pos,posbasedparam ); |
|
828 |
|
829 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
830 { |
|
831 param = NULL; |
|
832 } |
|
833 else |
|
834 { |
|
835 param = &posbasedparam; |
|
836 postionbasedsearching = ETrue; |
|
837 } |
|
838 } |
|
839 } |
|
840 |
|
841 |
|
842 if ((param) && (param->Value().TypeId() != LIW::EVariantTypeNull) && (param->Value().TypeId() != LIW::EVariantTypeDesC) ) |
|
843 { |
|
844 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( (TInt32)SErrBadArgumentType ) ) ); |
|
845 aOutParamList.AppendL( TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchDocMimeTypeMismatch ) ) ); |
|
846 posbasedparam.Reset(); |
|
847 return; |
|
848 } |
|
849 |
|
850 |
|
851 // present : Mandatory Argument |
|
852 TBuf<KMAXCONTENTLENGTH> mimetype; |
|
853 if( ( (param) && ( param->Value().AsDes().Length() < KMAXCONTENTLENGTH ) && (param->Value().Get( mimetype )) ) || ( documentmap ) ) |
|
854 { |
|
855 |
|
856 |
|
857 |
|
858 param = NULL; |
|
859 if ( postionbasedsearching && ( aInParamList.Count() > 2) ) |
|
860 { |
|
861 pos = 2; |
|
862 aInParamList.AtL( pos,posbasedparam ); |
|
863 if ( (posbasedparam.Name().CompareF(KNullDesC8) != 0 ) || posbasedparam.Value().IsEmpty() ) |
|
864 { |
|
865 param = NULL; |
|
866 } |
|
867 else |
|
868 { |
|
869 param = &posbasedparam; |
|
870 } |
|
871 } |
|
872 else |
|
873 { |
|
874 pos=0;//Search from starting point |
|
875 //filter map |
|
876 param = aInParamList.FindFirst( pos, KOptions ); |
|
877 } |
|
878 |
|
879 |
|
880 //Options is prsent |
|
881 if ( param ) |
|
882 { |
|
883 if( (param->Value().TypeId() != LIW::EVariantTypeMap ) && |
|
884 (param->Value().TypeId() != LIW::EVariantTypeNull ) ) |
|
885 { |
|
886 //Option Type MisMatch |
|
887 |
|
888 mode.Reset(); |
|
889 |
|
890 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( (TInt32)SErrBadArgumentType ) ) ); |
|
891 aOutParamList.AppendL( TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchOptionsTypeMismatch ) ) ); |
|
892 posbasedparam.Reset(); |
|
893 return; |
|
894 } |
|
895 |
|
896 const CLiwMap* optionsmap = param->Value().AsMap(); |
|
897 |
|
898 if(optionsmap) |
|
899 |
|
900 { |
|
901 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &mode) ); |
|
902 optionsmap->FindL( KMode, mode ); |
|
903 if (( mode.AsDes().Length() > KMAXCONTENTLENGTH ) || !mode.Get( options.iMode )) |
|
904 { |
|
905 |
|
906 CleanupStack::Pop(&mode); |
|
907 mode.Reset() ; |
|
908 |
|
909 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
910 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchAppOptionsTypeMismatch ) ) ); |
|
911 |
|
912 posbasedparam.Reset(); |
|
913 return; |
|
914 } |
|
915 CleanupStack::Pop(&mode); |
|
916 } |
|
917 } |
|
918 |
|
919 |
|
920 //Document is prsent |
|
921 if ( documentmap ) |
|
922 { |
|
923 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &path) ); |
|
924 if (documentmap->FindL( KDocumentPath, path )) |
|
925 { |
|
926 |
|
927 if ( ( path.AsDes().Length() > KMAXPATHLENGTH ) || !path.Get( document.iPath ) ) |
|
928 { |
|
929 //content type is different: do cleanup, append error and return |
|
930 CleanupStack::Pop(&path);//path |
|
931 path.Reset(); |
|
932 |
|
933 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
934 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchAppOptionsTypeMismatch ) ) ); |
|
935 |
|
936 posbasedparam.Reset(); |
|
937 return; |
|
938 } |
|
939 |
|
940 } |
|
941 CleanupStack::Pop(); |
|
942 |
|
943 CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &handle) ); |
|
944 if (documentmap->FindL( KHandle, handle ) && (handle.TypeId() != LIW::EVariantTypeNull )) |
|
945 { |
|
946 if (!handle.Get( document.iHandle )) |
|
947 { |
|
948 //do cleanup, append error and return |
|
949 CleanupStack::Pop(&handle); |
|
950 handle.Reset() ; |
|
951 |
|
952 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant ( (TInt32)SErrBadArgumentType) ) ); |
|
953 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KLaunchAppOptionsTypeMismatch ) ) ); |
|
954 |
|
955 posbasedparam.Reset(); |
|
956 return; |
|
957 } |
|
958 |
|
959 } |
|
960 |
|
961 CleanupStack::Pop(); |
|
962 /* |
|
963 // The follwing code will be introduced once default file buffer is created |
|
964 CLiwBuffer* buffer = NULL; |
|
965 buffer = handle.AsBuffer(); |
|
966 if ( KLiwBufferFile == buffer->TypeID() ) |
|
967 { |
|
968 CLiwFileBuffer* filebuffer = ( CLiwFileBuffer* ) buffer; |
|
969 document.iHandle = filebuffer->AsFile(); |
|
970 } |
|
971 */ |
|
972 } |
|
973 |
|
974 |
|
975 TInt errCode; |
|
976 //Converting command line form 16 to 8-bit |
|
977 |
|
978 HBufC8* heapBuffer = HBufC8::NewL( mimetype.Length() ); |
|
979 CleanupStack::PushL( heapBuffer ); |
|
980 TPtr8 mimetype8( heapBuffer->Des() ); |
|
981 mimetype8.Copy( mimetype ); |
|
982 TPtrC filename; |
|
983 |
|
984 if( aCallBack ) |
|
985 { |
|
986 //Asynch Call |
|
987 CAppServiceObserver* observer = CAppServiceObserver::NewL( aCallBack ); |
|
988 CleanupStack::PushL( observer ); |
|
989 TRAP ( errCode, iCoreClass->LaunchDocumentL( document, mimetype8, options , filename, observer, aTransactionID ) ); |
|
990 CleanupStack::Pop( observer ); |
|
991 } |
|
992 else |
|
993 { |
|
994 TRAP ( errCode, iCoreClass->LaunchDocumentL(document, mimetype8, options , filename ) ); |
|
995 } |
|
996 |
|
997 CleanupStack::PopAndDestroy( heapBuffer ); |
|
998 path.Reset(); |
|
999 handle.Reset(); |
|
1000 mode.Reset(); |
|
1001 |
|
1002 TInt sapiErr = SErrNone; |
|
1003 if (errCode) |
|
1004 { |
|
1005 sapiErr = SapiError( errCode ); |
|
1006 } |
|
1007 |
|
1008 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( ( TInt32 ) sapiErr ) )); |
|
1009 |
|
1010 if( filename.Length() != 0) |
|
1011 { |
|
1012 aOutParamList.AppendL( TLiwGenericParam( KDocumentName, TLiwVariant( filename ) )); |
|
1013 } |
|
1014 |
|
1015 } |
|
1016 else |
|
1017 { |
|
1018 //missig : Mandatory Argument |
|
1019 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, TLiwVariant( ( TInt32 ) SErrMissingArgument ) ) ); |
|
1020 aOutParamList.AppendL(TLiwGenericParam( KErrorMsg, TLiwVariant( KDocumentMissing ) ) ); |
|
1021 } |
|
1022 |
|
1023 posbasedparam.Reset(); |
|
1024 |
|
1025 } |
|
1026 |
|
1027 |
|
1028 |
|
1029 // ----------------------------------------------------------------------------- |
|
1030 // CAppManagerInterface::SapiError |
|
1031 // This function is called by the user to get mapped SAPI generic error code |
|
1032 // from symbian error codes . |
|
1033 // ----------------------------------------------------------------------------- |
|
1034 |
|
1035 TInt CAppManagerInterface::SapiError( TInt aSymbianErr ) |
|
1036 { |
|
1037 TInt sapiErr(SErrGeneralError); |
|
1038 |
|
1039 switch (aSymbianErr) |
|
1040 { |
|
1041 case KErrArgument: |
|
1042 { |
|
1043 sapiErr = SErrBadArgumentType; |
|
1044 break; |
|
1045 } |
|
1046 case KErrNotSupported: |
|
1047 { |
|
1048 sapiErr = SErrServiceNotSupported; |
|
1049 break; |
|
1050 } |
|
1051 case KErrServerBusy: |
|
1052 { |
|
1053 sapiErr = SErrServerBusy; |
|
1054 break; |
|
1055 } |
|
1056 case KErrGeneral: |
|
1057 case KErrBadName: |
|
1058 { |
|
1059 sapiErr = SErrGeneralError; |
|
1060 break; |
|
1061 } |
|
1062 case KErrCancel: |
|
1063 { |
|
1064 sapiErr = SErrCancelSuccess; |
|
1065 break; |
|
1066 } |
|
1067 case KErrNone: |
|
1068 { |
|
1069 sapiErr= SErrNone; |
|
1070 break; |
|
1071 } |
|
1072 case KErrNotFound: |
|
1073 { |
|
1074 sapiErr= SErrMissingArgument; |
|
1075 break; |
|
1076 } |
|
1077 case KErrNoMemory: |
|
1078 { |
|
1079 sapiErr = SErrNoMemory; |
|
1080 break; |
|
1081 } |
|
1082 case KErrInUse: |
|
1083 { |
|
1084 sapiErr = SErrServiceInUse; |
|
1085 break; |
|
1086 } |
|
1087 case KErrNotReady: |
|
1088 { |
|
1089 sapiErr = SErrServiceNotReady; |
|
1090 break; |
|
1091 } |
|
1092 case KErrPathNotFound: |
|
1093 { |
|
1094 sapiErr = SErrPathNotFound ; |
|
1095 break; |
|
1096 } |
|
1097 } |
|
1098 return sapiErr; |
|
1099 } |