author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 27 Aug 2009 07:43:07 +0300 | |
changeset 10 | fc9cf246af83 |
parent 5 | 989d2f495d90 |
child 23 | 50974a8b132e |
permissions | -rw-r--r-- |
5 | 1 |
/* |
2 |
* Copyright (c) 2002 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: CLandmarkInterface class implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
//INCLUDES |
|
19 |
#include <e32math.h> |
|
20 |
#include <liwcommon.h> |
|
21 |
#include <epos_cposlandmarkparser.h> |
|
22 |
#include <epos_cposlandmarkencoder.h> |
|
23 |
#include <epos_cposlandmarksearch.h> |
|
24 |
#include <epos_cposlmcompositecriteria.h> |
|
25 |
#include <epos_cposlmnearestcriteria.h> |
|
26 |
#include <epos_cposlmtextcriteria.h> |
|
27 |
#include <epos_cposlmareacriteria.h> |
|
28 |
#include <epos_cposlmcategorycriteria.h> |
|
29 |
#include <epos_cposlmcatnamecriteria.h> |
|
30 |
#include <epos_cposlmdatabasemanager.h> |
|
31 |
#include <epos_tposlmdatabasesettings.h> |
|
32 |
#include <utf.h> |
|
33 |
#include "landmarkliwparams.hrh" |
|
34 |
#include "landmarkinterface.h" |
|
35 |
#include "landmarkservice.h" |
|
36 |
#include "clandmarkfilter.h" |
|
37 |
#include "clandmarkiterable.h" |
|
38 |
#include "clandmarkcategoryiterable.h" |
|
39 |
#include "clandmarkdatabaseiterable.h" |
|
40 |
#include "clandmarkobserver.h" |
|
41 |
#include "clandmarkcallbackmap.h" |
|
42 |
#include "../../inc/serviceerrno.h" |
|
43 |
||
44 |
// ============================ MEMBER FUNCTIONS ============================= |
|
45 |
||
46 |
// --------------------------------------------------------------------------- |
|
47 |
// CLandmarkInterface::NewL() |
|
48 |
// Two-phased constructor. |
|
49 |
// --------------------------------------------------------------------------- |
|
50 |
// |
|
51 |
CLandmarkInterface* CLandmarkInterface::NewL( ) |
|
52 |
{ |
|
53 |
CLandmarkInterface* self = new (ELeave) CLandmarkInterface(); |
|
54 |
CleanupStack::PushL (self ); |
|
55 |
self->ConstructL ( ); |
|
56 |
CleanupStack::Pop (self ); |
|
57 |
return self; |
|
58 |
} |
|
59 |
||
60 |
// --------------------------------------------------------------------------- |
|
61 |
// CLandmarkInterface::~CLandmarkInterface() |
|
62 |
// Destructor. |
|
63 |
// --------------------------------------------------------------------------- |
|
64 |
// |
|
65 |
CLandmarkInterface::~CLandmarkInterface( ) |
|
66 |
{ |
|
67 |
delete iService; |
|
68 |
delete iObserver; |
|
69 |
delete iErrMsg; |
|
70 |
delete iId; |
|
71 |
iCallbackMap.ResetAndDestroy ( ); |
|
72 |
iCallbackMap.Close ( ); |
|
73 |
ReleaseLandmarkResources ( ); |
|
74 |
} |
|
75 |
||
76 |
// --------------------------------------------------------------------------- |
|
77 |
// CLandmarkInterface::CLandmarkInterface() |
|
78 |
// C++ default constructor can NOT contain any code, that might leave. |
|
79 |
// --------------------------------------------------------------------------- |
|
80 |
// |
|
81 |
CLandmarkInterface::CLandmarkInterface( ) |
|
82 |
{ |
|
83 |
} |
|
84 |
||
85 |
// --------------------------------------------------------------------------- |
|
86 |
// CLandmarkFilter::ConstructL() |
|
87 |
// Symbian 2nd phase constructor can leave. |
|
88 |
// --------------------------------------------------------------------------- |
|
89 |
// |
|
90 |
void CLandmarkInterface::ConstructL( ) |
|
91 |
{ |
|
92 |
//instantiate the service class |
|
93 |
iService = CLandmarkService::NewL ( ); |
|
94 |
//register observer for async requests |
|
95 |
iObserver = CLandmarkObserver::NewL ( this ); |
|
96 |
iService->RegisterObserver (iObserver ); |
|
97 |
} |
|
98 |
||
99 |
// --------------------------------------------------------------------------- |
|
100 |
// CLandmarkInterface::ExecuteCmdL( const TDesC8& aCmdName, |
|
101 |
// const CLiwGenericParamList& aInParamList, |
|
102 |
// CLiwGenericParamList& aOutParamList, |
|
103 |
// TUint aCmdOptions, |
|
104 |
// MLiwNotifyCallback* aCallback ) |
|
105 |
// This function is called by the user to handle the service commands. |
|
106 |
// --------------------------------------------------------------------------- |
|
107 |
// |
|
108 |
void CLandmarkInterface::ExecuteCmdL( const TDesC8& aCmdName, |
|
109 |
const CLiwGenericParamList& aInParamList, |
|
110 |
CLiwGenericParamList& aOutParamList, TUint aCmdOptions, |
|
111 |
MLiwNotifyCallback* aCallback ) |
|
112 |
{ |
|
113 |
if ( iErrMsg ) |
|
114 |
{ |
|
115 |
delete iErrMsg; |
|
116 |
iErrMsg = NULL; |
|
117 |
} |
|
118 |
if( iId ) |
|
119 |
{ |
|
120 |
delete iId; |
|
121 |
iId = NULL; |
|
122 |
} |
|
123 |
//check if any of the service API's leave |
|
124 |
TRAPD(err,SwitchCmdL(aCmdName,aInParamList,aOutParamList, |
|
125 |
aCmdOptions,aCallback)) |
|
126 |
; |
|
127 |
TInt SapiErr = SErrNone; |
|
128 |
if (err ) |
|
129 |
{ |
|
130 |
SapiErr = SapiError (err ); |
|
131 |
} |
|
132 |
||
133 |
aOutParamList.AppendL (TLiwGenericParam (KErrorCode, TLiwVariant ((TInt32)SapiErr ) ) ); |
|
134 |
if ( iErrMsg ) |
|
135 |
{ |
|
136 |
aOutParamList.AppendL (TLiwGenericParam (KErrorMsg, |
|
137 |
TLiwVariant (iErrMsg ) ) ); |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
// --------------------------------------------------------------------------- |
|
142 |
// CLandmarkInterface::SapiError( ) |
|
143 |
// This function is called by the user to get mapped SAPI generic error code |
|
144 |
// from symbian error codes . |
|
145 |
// --------------------------------------------------------------------------- |
|
146 |
// |
|
147 |
TInt CLandmarkInterface::SapiError( TInt aSymbianErr ) |
|
148 |
{ |
|
149 |
TInt sapiErr(aSymbianErr); |
|
150 |
||
151 |
switch ( sapiErr ) |
|
152 |
{ |
|
153 |
//case EPosLmInvalidArgument: |
|
154 |
case KErrBadName: |
|
155 |
case KErrArgument: |
|
156 |
{ |
|
157 |
sapiErr = SErrBadArgumentType; |
|
158 |
break; |
|
159 |
} |
|
160 |
case KErrNotSupported: |
|
161 |
{ |
|
162 |
sapiErr = SErrServiceNotSupported; |
|
163 |
break; |
|
164 |
} |
|
165 |
case KErrLocked: |
|
166 |
case KErrInUse: |
|
167 |
{ |
|
168 |
sapiErr = SErrServiceInUse; |
|
169 |
break; |
|
170 |
} |
|
171 |
case KErrAccessDenied: |
|
172 |
{ |
|
173 |
sapiErr = SErrAccessDenied; |
|
174 |
break; |
|
175 |
} |
|
176 |
case KErrAlreadyExists: |
|
177 |
{ |
|
178 |
sapiErr = SErrEntryExists; |
|
179 |
break; |
|
180 |
} |
|
181 |
case KErrNotReady: |
|
182 |
{ |
|
183 |
sapiErr = SErrServiceNotReady; |
|
184 |
break; |
|
185 |
} |
|
186 |
case KErrNotFound: |
|
187 |
{ |
|
188 |
sapiErr = SErrNotFound; |
|
189 |
break; |
|
190 |
} |
|
191 |
case KErrPosLmUnknownFormat: |
|
192 |
{ |
|
193 |
sapiErr = SErrUnknownFormat; |
|
194 |
break; |
|
195 |
} |
|
196 |
case KErrPathNotFound: |
|
197 |
{ |
|
198 |
sapiErr = SErrPathNotFound; |
|
199 |
break; |
|
200 |
} |
|
201 |
case KErrGeneral: |
|
202 |
{ |
|
203 |
sapiErr = SErrGeneralError; |
|
204 |
break; |
|
205 |
} |
|
206 |
case SErrInvalidServiceArgument: |
|
207 |
break; |
|
208 |
case SErrMissingArgument: |
|
209 |
break; |
|
210 |
default: |
|
211 |
sapiErr = SErrGeneralError; |
|
212 |
break; |
|
213 |
} |
|
214 |
return sapiErr; |
|
215 |
} |
|
216 |
||
217 |
// --------------------------------------------------------------------------- |
|
218 |
// CLandmarkInterface::Close( ) |
|
219 |
// This function is called by the user to close the interface. |
|
220 |
// --------------------------------------------------------------------------- |
|
221 |
// |
|
222 |
void CLandmarkInterface::Close( ) |
|
223 |
{ |
|
224 |
delete this; |
|
225 |
} |
|
226 |
||
227 |
// --------------------------------------------------------------------------- |
|
228 |
// CLandmarkInterface::Callback( TInt32 aTransactionId ) |
|
229 |
// This function returns the callback for the given transaction id and removes it from the list. |
|
230 |
// --------------------------------------------------------------------------- |
|
231 |
// |
|
232 |
MLiwNotifyCallback* CLandmarkInterface::Callback( TInt32 aTransactionId ) |
|
233 |
{ |
|
234 |
MLiwNotifyCallback* callback= NULL; |
|
235 |
TInt count = iCallbackMap.Count ( ); |
|
236 |
for (TInt i = 0; i < count; ++i ) |
|
237 |
{ |
|
238 |
if ( iCallbackMap[i]->Get (aTransactionId, callback ) ) |
|
239 |
{ |
|
240 |
delete(iCallbackMap[i]); |
|
241 |
iCallbackMap.Remove (i ); |
|
242 |
break; |
|
243 |
} |
|
244 |
} |
|
245 |
return callback; |
|
246 |
} |
|
247 |
||
248 |
// --------------------------------------------------------------------------- |
|
249 |
// CLandmarkInterface::SetActiveL( const CLiwGenericParamList& aInParamList ) |
|
250 |
// This calls the appropriate service function for setting active database. |
|
251 |
// --------------------------------------------------------------------------- |
|
252 |
// |
|
253 |
void CLandmarkInterface::SetActiveL( const CLiwGenericParamList& aInParamList ) |
|
254 |
{ |
|
255 |
TInt index = 0; |
|
256 |
const TLiwGenericParam* database = aInParamList.FindFirst ( index, KDbUri ); |
|
257 |
if ( !database ) |
|
258 |
{ |
|
259 |
// If position based parsing is implemented then |
|
260 |
// the name of parameter will be empty CHECK |
|
261 |
index = 0; |
|
262 |
database = aInParamList.FindFirst ( index, KNullDesC8 ); |
|
263 |
} |
|
264 |
if ( database ) |
|
265 |
{ |
|
266 |
const TLiwVariant& variant = database->Value ( ); |
|
267 |
if ( variant.TypeId ( )== LIW::EVariantTypeDesC ) |
|
268 |
{ |
|
269 |
iService->SetActiveL ( variant.AsDes ( ) ); |
|
270 |
} |
|
271 |
else |
|
272 |
{ |
|
273 |
User::Leave (SErrBadArgumentType ); |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
// --------------------------------------------------------------------------- |
|
279 |
// CLandmarkInterface::SwitchCmdL( const TDesC8& aCmdName, |
|
280 |
// const CLiwGenericParamList& aInParamList, |
|
281 |
// CLiwGenericParamList& aOutParamList, |
|
282 |
// TUint aCmdOptions, |
|
283 |
// MLiwNotifyCallback* aCallback ) |
|
284 |
// This function calls the appropriate functions based on the command id. |
|
285 |
// --------------------------------------------------------------------------- |
|
286 |
// |
|
287 |
void CLandmarkInterface::SwitchCmdL( const TDesC8& aCmdName, |
|
288 |
const CLiwGenericParamList& aInParamList, |
|
289 |
CLiwGenericParamList& aOutParamList, TUint aCmdOptions, |
|
290 |
MLiwNotifyCallback* aCallback ) |
|
291 |
{ |
|
292 |
if ( ( (KLiwOptASyncronous & aCmdOptions) && !aCallback) ||( !(KLiwOptASyncronous & aCmdOptions) && aCallback) ) |
|
293 |
{ |
|
294 |
iErrMsg = KIncorrectAsyncReq().AllocL ( ); |
|
295 |
User::Leave (SErrInvalidServiceArgument ); |
|
296 |
} |
|
297 |
||
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
298 |
if ( !aCmdName.CompareF(KCancel) && (KLiwOptCancel & aCmdOptions) ) |
5 | 299 |
{ |
300 |
Cancel (aInParamList, aOutParamList, aCmdOptions, aCallback ); |
|
301 |
} |
|
302 |
else |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
303 |
if ( !aCmdName.CompareF(KGetList) ) |
5 | 304 |
{ |
305 |
GetListL (aInParamList, aOutParamList, aCmdOptions, aCallback ); |
|
306 |
} |
|
307 |
else |
|
308 |
//since no other APIs support async return error if callback is |
|
309 |
//provide |
|
310 |
if ( aCallback ) |
|
311 |
{ |
|
312 |
iErrMsg = KAsyncNotSupported().AllocL ( ); |
|
313 |
User::Leave (SErrInvalidServiceArgument ); |
|
314 |
} |
|
315 |
else |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
316 |
if ( !aCmdName.CompareF(KAdd) ) |
5 | 317 |
{ |
318 |
AddL (aInParamList, aOutParamList, aCmdOptions, aCallback ); |
|
319 |
} |
|
320 |
else |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
321 |
if ( !aCmdName.CompareF(KRemove) ) |
5 | 322 |
{ |
323 |
RemoveL (aInParamList, aOutParamList, aCmdOptions, |
|
324 |
aCallback ); |
|
325 |
} |
|
326 |
else |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
327 |
if ( !aCmdName.CompareF(KOrganise) ) |
5 | 328 |
{ |
329 |
OrganiseL (aInParamList, aOutParamList, |
|
330 |
aCmdOptions, aCallback ); |
|
331 |
} |
|
332 |
else |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
333 |
if ( !aCmdName.CompareF(KImport) ) |
5 | 334 |
{ |
335 |
ImportL (aInParamList, aOutParamList, |
|
336 |
aCmdOptions, aCallback ); |
|
337 |
} |
|
338 |
else |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
339 |
if ( !aCmdName.CompareF(KExport) ) |
5 | 340 |
{ |
341 |
ExportL (aInParamList, aOutParamList, |
|
342 |
aCmdOptions, aCallback ); |
|
343 |
} |
|
344 |
else |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
345 |
if ( !aCmdName.CompareF(KNew) ) |
5 | 346 |
{ |
347 |
NewTemplateL (aInParamList, |
|
348 |
aOutParamList, aCmdOptions, |
|
349 |
aCallback ); |
|
350 |
} |
|
351 |
else |
|
352 |
{ |
|
353 |
// invalid command return error in outparam list |
|
354 |
iErrMsg = KInvalidServiceCmd().AllocL ( ); |
|
355 |
User::Leave (SErrInvalidServiceArgument ); |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
// --------------------------------------------------------------------------- |
|
360 |
// CLandmarkInterface::GetListL(const CLiwGenericParamList& aInParamList, |
|
361 |
// CLiwGenericParamList& aOutParamList, |
|
362 |
// TUint aCmdOptions, |
|
363 |
// MLiwNotifyCallback* aCallback ) |
|
364 |
// This function calls the appropriate functions based on the content type. |
|
365 |
// --------------------------------------------------------------------------- |
|
366 |
// |
|
367 |
void CLandmarkInterface::GetListL( const CLiwGenericParamList& aInParamList, |
|
368 |
CLiwGenericParamList& aOutParamList, TUint aCmdOptions, |
|
369 |
MLiwNotifyCallback* aCallback ) |
|
370 |
{ |
|
371 |
//Input param List must have Type specified |
|
372 |
if ( !aInParamList.Count() ) |
|
373 |
{ |
|
374 |
ErrorMessageL (KGetList, KContentType ); |
|
375 |
iErrMsg->Des().Append ( KMissing ); |
|
376 |
//leave since argument is improper |
|
377 |
User::Leave (SErrMissingArgument ); |
|
378 |
} |
|
379 |
//position to start search in input params |
|
380 |
TInt index = 0; |
|
381 |
//get content type |
|
382 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
383 |
//check whether pos based or value based |
|
384 |
if ( param->Name ( )!= KNullDesC8 ) |
|
385 |
{ |
|
386 |
param = aInParamList.FindFirst (index, KContentType ); |
|
387 |
if ( !param ) |
|
388 |
{ |
|
389 |
ErrorMessageL (KGetList, KContentType ); |
|
390 |
iErrMsg->Des().Append (KMissing ); |
|
391 |
//leave since argument is improper |
|
392 |
User::Leave (SErrMissingArgument ); |
|
393 |
} |
|
394 |
} |
|
395 |
TLiwVariant variant(param->Value ( )); |
|
396 |
ValidateParamL (KGetList, KContentType, variant, LIW::EVariantTypeDesC ); |
|
397 |
TPtrC contentType(variant.AsDes ( )); |
|
398 |
||
399 |
//Content type is Landmark. |
|
400 |
if ( contentType == KLandmark ) |
|
401 |
{ |
|
402 |
GetLandmarksL (aInParamList, aOutParamList, aCmdOptions, aCallback ); |
|
403 |
} |
|
404 |
//Content type is Category. |
|
405 |
else |
|
406 |
if ( contentType == KCategory ) |
|
407 |
{ |
|
408 |
GetCategoriesL (aInParamList, aOutParamList, aCmdOptions, aCallback ); |
|
409 |
} |
|
410 |
//Content type is Database. |
|
411 |
else |
|
412 |
if ( contentType == KDatabase ) |
|
413 |
{ |
|
414 |
//Async not supported for databases |
|
415 |
if( !aCallback ) |
|
416 |
GetListDatabasesL (aInParamList, aOutParamList ); |
|
417 |
else |
|
418 |
{ |
|
419 |
iErrMsg = KAsyncNotSupported().AllocL ( ); |
|
420 |
User::Leave (SErrInvalidServiceArgument ); |
|
421 |
} |
|
422 |
} |
|
423 |
else |
|
424 |
{ |
|
425 |
ErrorMessageL (KGetList, KContentType ); |
|
426 |
iErrMsg->Des().Append (KInvalid ); |
|
427 |
//leave since argument is improper |
|
428 |
User::Leave (SErrInvalidServiceArgument ); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
// --------------------------------------------------------------------------- |
|
433 |
// CLandmarkInterface::AddL(const CLiwGenericParamList& aInParamList, |
|
434 |
// CLiwGenericParamList& aOutParamList, |
|
435 |
// TUint /*aCmdOptions*/, |
|
436 |
// MLiwNotifyCallback* /*aCallback*/ ) |
|
437 |
// This function calls the appropriate functions based on the content type. |
|
438 |
// --------------------------------------------------------------------------- |
|
439 |
// |
|
440 |
void CLandmarkInterface::AddL( const CLiwGenericParamList& aInParamList, |
|
441 |
CLiwGenericParamList& aOutParamList, TUint /*aCmdOptions*/, |
|
442 |
MLiwNotifyCallback* /*aCallback*/) |
|
443 |
{ |
|
444 |
//Input param List must have contentType and data specified |
|
445 |
if ( aInParamList.Count ( )< EIndex2 ) |
|
446 |
{ |
|
447 |
ErrorMessageL (KAdd, KArgsMissing ); |
|
448 |
iErrMsg->Des().Append (KMissing ); |
|
449 |
//leave since argument is improper |
|
450 |
User::Leave (SErrMissingArgument ); |
|
451 |
} |
|
452 |
||
453 |
//position to start search in input params |
|
454 |
TInt index = 0; |
|
455 |
//get content type |
|
456 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
457 |
//check whether pos based or value based |
|
458 |
if ( param->Name ( )!= KNullDesC8 ) |
|
459 |
{ |
|
460 |
param = aInParamList.FindFirst (index, KContentType ); |
|
461 |
if ( !param ) |
|
462 |
{ |
|
463 |
ErrorMessageL (KAdd, KContentType ); |
|
464 |
iErrMsg->Des().Append (KMissing ); |
|
465 |
//leave since argument is improper |
|
466 |
User::Leave (SErrMissingArgument ); |
|
467 |
} |
|
468 |
} |
|
469 |
||
470 |
TLiwVariant variant(param->Value ( )); |
|
471 |
ValidateParamL (KAdd, KContentType, variant, LIW::EVariantTypeDesC ); |
|
472 |
TPtrC contentType(variant.AsDes ( )); |
|
473 |
||
474 |
//Content type is Landmark |
|
475 |
if ( contentType == KLandmark ) |
|
476 |
{ |
|
477 |
AddLandmarksL (aInParamList,aOutParamList ); |
|
478 |
} |
|
479 |
//Content type is Category. |
|
480 |
else |
|
481 |
if ( contentType == KCategory ) |
|
482 |
{ |
|
483 |
AddCategoryL (aInParamList,aOutParamList ); |
|
484 |
} |
|
485 |
else |
|
486 |
{ |
|
487 |
ErrorMessageL (KAdd, KContentType ); |
|
488 |
iErrMsg->Des().Append (KInvalid ); |
|
489 |
//leave since argument is improper |
|
490 |
User::Leave (SErrInvalidServiceArgument ); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
// --------------------------------------------------------------------------- |
|
495 |
// CLandmarkInterface::RemoveL(const CLiwGenericParamList& aInParamList, |
|
496 |
// CLiwGenericParamList& /*aOutParamList*/, |
|
497 |
// TUint /*aCmdOptions*/, |
|
498 |
// MLiwNotifyCallback* /*aCallback*/ ) |
|
499 |
// This calls the appropriate service function based on the content type. |
|
500 |
// --------------------------------------------------------------------------- |
|
501 |
// |
|
502 |
void CLandmarkInterface::RemoveL( const CLiwGenericParamList& aInParamList, |
|
503 |
CLiwGenericParamList& /*aOutParamList*/, TUint /*aCmdOptions*/, |
|
504 |
MLiwNotifyCallback* /*aCallback*/) |
|
505 |
{ |
|
506 |
//Input param List must have contentType and data specified |
|
507 |
if ( aInParamList.Count ( )< EIndex2 ) |
|
508 |
{ |
|
509 |
ErrorMessageL (KAdd, KArgsMissing ); |
|
510 |
iErrMsg->Des().Append (KMissing ); |
|
511 |
//leave since argument is improper |
|
512 |
User::Leave (SErrMissingArgument ); |
|
513 |
} |
|
514 |
||
515 |
//position to start search in input params |
|
516 |
TInt index = 0; |
|
517 |
//Flag for pos based |
|
518 |
TBool posBased = EFalse; |
|
519 |
//get content type |
|
520 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
521 |
//check whether pos based or value based |
|
522 |
if ( param->Name ( )== KNullDesC8 ) |
|
523 |
{ |
|
524 |
posBased = ETrue; |
|
525 |
} |
|
526 |
else |
|
527 |
{ |
|
528 |
param = aInParamList.FindFirst (index, KContentType ); |
|
529 |
if ( !param ) |
|
530 |
{ |
|
531 |
ErrorMessageL (KRemove, KContentType ); |
|
532 |
iErrMsg->Des().Append (KMissing ); |
|
533 |
//leave since argument is improper |
|
534 |
User::Leave (SErrMissingArgument ); |
|
535 |
} |
|
536 |
} |
|
537 |
||
538 |
TLiwVariant variant(param->Value ( )); |
|
539 |
ValidateParamL (KRemove, KContentType, variant, LIW::EVariantTypeDesC ); |
|
540 |
TPtrC contentType(variant.AsDes ( )); |
|
541 |
||
542 |
TPtrC dbUri; |
|
543 |
//Content type is Landmark. |
|
544 |
if ( contentType == KLandmark ) |
|
545 |
{ |
|
546 |
index = 0; |
|
547 |
if ( posBased ) |
|
548 |
{ |
|
549 |
param = &aInParamList[EIndex1]; |
|
550 |
} |
|
551 |
else |
|
552 |
{ |
|
553 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
554 |
if ( !param ) |
|
555 |
{ |
|
556 |
ErrorMessageL (KRemove, KDataFields ); |
|
557 |
iErrMsg->Des().Append (KMissing ); |
|
558 |
//leave since argument is improper |
|
559 |
User::Leave (SErrMissingArgument ); |
|
560 |
} |
|
561 |
} |
|
562 |
variant = param->Value ( ); |
|
563 |
ValidateParamL (KRemove, KDataFields, variant, LIW::EVariantTypeMap ); |
|
564 |
const CLiwMap* landmarkMap = variant.AsMap ( ); |
|
565 |
CleanupStack::PushL( |
|
566 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
567 |
ValidateParamL (KRemove, KId, landmarkMap, |
|
568 |
LIW::EVariantTypeDesC, ETrue, variant ); |
|
569 |
TPtrC lmPtr(variant.AsDes ( )); |
|
570 |
TLex lmparseString(lmPtr); //Get Id as string and convert to TUint32 |
|
571 |
TPosLmItemId lmid; |
|
572 |
TInt parseErr = lmparseString.Val (lmid, EDecimal ); |
|
573 |
TBuf<KMaxIDStringLength> lmIdString(KNullDesC ( )); |
|
574 |
if ( !parseErr ) |
|
575 |
{ |
|
576 |
lmIdString.Num (lmid ); |
|
577 |
} |
|
578 |
if ( parseErr || lmIdString != lmPtr ) |
|
579 |
{ |
|
580 |
ErrorMessageL (KRemove, KId ); |
|
581 |
iErrMsg->Des().Append (KInvalid ); |
|
582 |
User::Leave (SErrInvalidServiceArgument ); |
|
583 |
} |
|
584 |
||
585 |
if (ValidateParamL (KRemove, KDbUri, landmarkMap, |
|
586 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
587 |
{ |
|
588 |
dbUri.Set (variant.AsDes ( ) ); |
|
589 |
} |
|
590 |
iService->RemoveItemL (lmid, CLandmarkService::ELandmark, dbUri ); |
|
591 |
CleanupStack::PopAndDestroy(&variant); |
|
592 |
} |
|
593 |
//Content type is Category. |
|
594 |
else |
|
595 |
if ( contentType == KCategory ) |
|
596 |
{ |
|
597 |
index = 0; |
|
598 |
if ( posBased ) |
|
599 |
{ |
|
600 |
param = &aInParamList[EIndex1]; |
|
601 |
} |
|
602 |
else |
|
603 |
{ |
|
604 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
605 |
if ( !param ) |
|
606 |
{ |
|
607 |
ErrorMessageL (KRemove, KDataFields ); |
|
608 |
iErrMsg->Des().Append (KMissing ); |
|
609 |
//leave since argument is improper |
|
610 |
User::Leave (SErrMissingArgument ); |
|
611 |
} |
|
612 |
} |
|
613 |
variant = param->Value ( ); |
|
614 |
ValidateParamL (KRemove, KDataFields, variant, LIW::EVariantTypeMap ); |
|
615 |
const CLiwMap* categoryMap = variant.AsMap ( ); |
|
616 |
CleanupStack::PushL( |
|
617 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
618 |
ValidateParamL (KRemove, KId, categoryMap, |
|
619 |
LIW::EVariantTypeDesC, ETrue, variant ); |
|
620 |
TPtrC catPtr(variant.AsDes ( )); |
|
621 |
TLex catparseString(catPtr); //Get Id as string and convert to TUint32 |
|
622 |
TPosLmItemId catid; |
|
623 |
TInt parseErr = catparseString.Val (catid, EDecimal ); |
|
624 |
TBuf<KMaxIDStringLength> catIdString(KNullDesC ( )); |
|
625 |
if ( !parseErr ) |
|
626 |
{ |
|
627 |
catIdString.Num (catid ); |
|
628 |
} |
|
629 |
if ( parseErr || catIdString != catPtr ) |
|
630 |
{ |
|
631 |
ErrorMessageL (KRemove, KId ); |
|
632 |
iErrMsg->Des().Append (KInvalid ); |
|
633 |
User::Leave (SErrInvalidServiceArgument ); |
|
634 |
} |
|
635 |
||
636 |
if (ValidateParamL (KRemove, KDbUri, categoryMap, |
|
637 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
638 |
{ |
|
639 |
dbUri.Set (variant.AsDes ( ) ); |
|
640 |
} |
|
641 |
iService->RemoveItemL (catid, CLandmarkService::ECategory, dbUri ); |
|
642 |
CleanupStack::PopAndDestroy(&variant); |
|
643 |
} |
|
644 |
else |
|
645 |
{ |
|
646 |
ErrorMessageL (KRemove, KContentType ); |
|
647 |
iErrMsg->Des().Append (KInvalid ); |
|
648 |
//leave since argument is improper |
|
649 |
User::Leave (SErrInvalidServiceArgument ); |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
// --------------------------------------------------------------------------- |
|
654 |
// CLandmarkInterface::ImportL(const CLiwGenericParamList& aInParamList, |
|
655 |
// CLiwGenericParamList& /*aOutParamList*/, |
|
656 |
// TUint /*aCmdOptions*/, |
|
657 |
// MLiwNotifyCallback* /*aCallback*/ ) |
|
658 |
// This calls the appropriate service function for importing landmarks. |
|
659 |
// --------------------------------------------------------------------------- |
|
660 |
// |
|
661 |
void CLandmarkInterface::ImportL( const CLiwGenericParamList& aInParamList, |
|
662 |
CLiwGenericParamList& aOutParamList, TUint /*aCmdOptions*/, |
|
663 |
MLiwNotifyCallback* /*aCallback*/) |
|
664 |
{ |
|
665 |
//Input param List must have contentType and importData specified |
|
666 |
if ( aInParamList.Count ( )< EIndex2 ) |
|
667 |
{ |
|
668 |
ErrorMessageL (KAdd, KArgsMissing ); |
|
669 |
iErrMsg->Des().Append (KMissing ); |
|
670 |
//leave since argument is improper |
|
671 |
User::Leave (SErrMissingArgument ); |
|
672 |
} |
|
673 |
//position to start search in input params |
|
674 |
TInt index = 0; |
|
675 |
//Flag for pos based |
|
676 |
TBool posBased = EFalse; |
|
677 |
//get content type |
|
678 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
679 |
//check whether pos based or value based |
|
680 |
if ( param->Name ( )== KNullDesC8 ) |
|
681 |
{ |
|
682 |
posBased = ETrue; |
|
683 |
} |
|
684 |
else |
|
685 |
{ |
|
686 |
param = aInParamList.FindFirst (index, KContentType ); |
|
687 |
if ( !param ) |
|
688 |
{ |
|
689 |
ErrorMessageL (KImport, KContentType ); |
|
690 |
iErrMsg->Des().Append (KMissing ); |
|
691 |
//leave since argument is improper |
|
692 |
User::Leave (SErrMissingArgument ); |
|
693 |
} |
|
694 |
} |
|
695 |
||
696 |
TLiwVariant variant(param->Value ( )); |
|
697 |
ValidateParamL (KImport, KContentType, variant, LIW::EVariantTypeDesC ); |
|
698 |
TPtrC contentType(variant.AsDes ( )); |
|
699 |
//Content type is Landmark. |
|
700 |
if ( contentType == KLandmark ) |
|
701 |
{ |
|
702 |
index = 0; |
|
703 |
if ( posBased ) |
|
704 |
{ |
|
705 |
param = &aInParamList[EIndex1]; |
|
706 |
} |
|
707 |
else |
|
708 |
{ |
|
709 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
710 |
if ( !param ) |
|
711 |
{ |
|
712 |
ErrorMessageL (KImport, KDataFields ); |
|
713 |
iErrMsg->Des().Append (KMissing ); |
|
714 |
//leave since argument is improper |
|
715 |
User::Leave (SErrMissingArgument ); |
|
716 |
} |
|
717 |
} |
|
718 |
variant = param->Value ( ); |
|
719 |
ValidateParamL (KImport, KDataFields, variant, LIW::EVariantTypeMap ); |
|
720 |
const CLiwMap* importData = variant.AsMap ( ); |
|
721 |
CleanupStack::PushL( |
|
722 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
723 |
ValidateParamL (KImport, KMimeType, importData, LIW::EVariantTypeDesC, |
|
724 |
ETrue, variant ); |
|
725 |
if( variant.AsDes() == KNullDesC ) |
|
726 |
{ |
|
727 |
ErrorMessageL (KImport, KMimeType ); |
|
728 |
iErrMsg->Des().Append (KInvalid ); |
|
729 |
//leave since argument is improper |
|
730 |
User::Leave (SErrInvalidServiceArgument ); |
|
731 |
} |
|
732 |
//Construct the parser |
|
733 |
HBufC8* mimeType8 = |
|
734 |
CnvUtfConverter::ConvertFromUnicodeToUtf8L ( variant.AsDes ( ) ); |
|
735 |
CleanupStack::PushL( mimeType8 ); |
|
736 |
CPosLandmarkParser* parser = CPosLandmarkParser::NewL (*mimeType8 ); |
|
737 |
CleanupStack::PushL (parser ); |
|
738 |
||
739 |
ValidateParamL (KImport, KSourceFile, importData, |
|
740 |
LIW::EVariantTypeDesC, ETrue, variant ); |
|
741 |
if( variant.AsDes() == KNullDesC ) |
|
742 |
{ |
|
743 |
ErrorMessageL (KImport, KSourceFile ); |
|
744 |
iErrMsg->Des().Append (KInvalid ); |
|
745 |
//leave since argument is improper |
|
746 |
User::Leave (SErrInvalidServiceArgument ); |
|
747 |
} |
|
748 |
parser->SetInputFileL (variant.AsDes ( ) ); |
|
749 |
//check if complete file is ok |
|
750 |
CPosLmOperation* op = parser->ParseContentL ( ); |
|
751 |
CleanupStack::PushL (op ); |
|
752 |
op->ExecuteL ( ); |
|
753 |
CleanupStack::PopAndDestroy (op ); |
|
754 |
//getdb |
|
755 |
TPtrC dbUri; |
|
756 |
if (ValidateParamL (KImport, KDbUri, importData, LIW::EVariantTypeDesC, |
|
757 |
EFalse, variant ) ) |
|
758 |
{ |
|
759 |
dbUri.Set (variant.AsDes ( ) ); |
|
760 |
} |
|
761 |
CPosLmItemIterator* iterator= NULL; |
|
762 |
//call the service function for import |
|
763 |
iService->ImportL (iterator, *parser, dbUri ); |
|
764 |
CleanupStack::PopAndDestroy (parser ); |
|
765 |
CleanupStack::PopAndDestroy (mimeType8 ); |
|
766 |
CleanupStack::PushL(iterator); |
|
767 |
// if dbURI is not specified retrieve default databse URI |
|
768 |
if ( dbUri == KNullDesC ) |
|
769 |
{ |
|
770 |
iService->GetDefaultDbUriL (dbUri ); |
|
771 |
} |
|
772 |
//instantiate CLandmarkIterable |
|
773 |
CLiwIterable* iterable = CLandmarkIterable::NewL (iterator, dbUri ); |
|
774 |
CleanupStack::Pop(iterator); |
|
775 |
CleanupClosePushL(*iterable); |
|
776 |
aOutParamList.AppendL (TLiwGenericParam (KReturnValue, |
|
777 |
TLiwVariant (iterable ) ) ); |
|
778 |
CleanupStack::PopAndDestroy(iterable); |
|
779 |
CleanupStack::PopAndDestroy(&variant); |
|
780 |
} |
|
781 |
else |
|
782 |
{ |
|
783 |
ErrorMessageL (KImport, KContentType ); |
|
784 |
iErrMsg->Des().Append (KInvalid ); |
|
785 |
//leave since argument is improper |
|
786 |
User::Leave (SErrInvalidServiceArgument ); |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
// --------------------------------------------------------------------------- |
|
791 |
// CLandmarkInterface::ExportL(const CLiwGenericParamList& aInParamList, |
|
792 |
// CLiwGenericParamList& /*aOutParamList*/, |
|
793 |
// TUint /*aCmdOptions*/, |
|
794 |
// MLiwNotifyCallback* /*aCallback*/ ) |
|
795 |
// This calls the appropriate service function for exporting landmarks. |
|
796 |
// --------------------------------------------------------------------------- |
|
797 |
// |
|
798 |
void CLandmarkInterface::ExportL( const CLiwGenericParamList& aInParamList, |
|
799 |
CLiwGenericParamList& /*aOutParamList*/, TUint /*aCmdOptions*/, |
|
800 |
MLiwNotifyCallback* /*aCallback*/) |
|
801 |
{ |
|
802 |
//Input param List must have contentType and exportData specified |
|
803 |
if ( aInParamList.Count ( )< EIndex2 ) |
|
804 |
{ |
|
805 |
ErrorMessageL (KAdd, KArgsMissing ); |
|
806 |
iErrMsg->Des().Append (KMissing ); |
|
807 |
//leave since argument is improper |
|
808 |
User::Leave (SErrMissingArgument ); |
|
809 |
} |
|
810 |
||
811 |
//position to start search in input params |
|
812 |
TInt index = 0; |
|
813 |
//Flag for pos based |
|
814 |
TBool posBased = EFalse; |
|
815 |
//get content type |
|
816 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
817 |
//check whether pos based or value based |
|
818 |
if ( param->Name ( )== KNullDesC8 ) |
|
819 |
{ |
|
820 |
posBased = ETrue; |
|
821 |
} |
|
822 |
else |
|
823 |
{ |
|
824 |
param = aInParamList.FindFirst (index, KContentType ); |
|
825 |
if ( !param ) |
|
826 |
{ |
|
827 |
ErrorMessageL (KExport, KContentType ); |
|
828 |
iErrMsg->Des().Append (KMissing ); |
|
829 |
//leave since argument is improper |
|
830 |
User::Leave (SErrMissingArgument ); |
|
831 |
} |
|
832 |
} |
|
833 |
||
834 |
TLiwVariant variant(param->Value ( )); |
|
835 |
ValidateParamL (KExport, KContentType, variant, LIW::EVariantTypeDesC ); |
|
836 |
TPtrC contentType(variant.AsDes ( )); |
|
837 |
//Content type is Landmark. |
|
838 |
if ( contentType == KLandmark ) |
|
839 |
{ |
|
840 |
index = 0; |
|
841 |
if ( posBased ) |
|
842 |
{ |
|
843 |
param = &aInParamList[EIndex1]; |
|
844 |
} |
|
845 |
else |
|
846 |
{ |
|
847 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
848 |
if ( !param ) |
|
849 |
{ |
|
850 |
ErrorMessageL (KExport, KDataFields ); |
|
851 |
iErrMsg->Des().Append (KMissing ); |
|
852 |
//leave since argument is improper |
|
853 |
User::Leave (SErrMissingArgument ); |
|
854 |
} |
|
855 |
} |
|
856 |
variant = param->Value ( ); |
|
857 |
ValidateParamL (KExport, KDataFields, variant, LIW::EVariantTypeMap ); |
|
858 |
const CLiwMap* exportData = variant.AsMap ( ); |
|
859 |
CleanupStack::PushL( |
|
860 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
861 |
ValidateParamL (KExport, KDestinationFile, exportData, |
|
862 |
LIW::EVariantTypeDesC, ETrue, variant ); |
|
863 |
if( variant.AsDes() == KNullDesC ) |
|
864 |
{ |
|
865 |
ErrorMessageL (KExport, KDestinationFile ); |
|
866 |
iErrMsg->Des().Append (KInvalid ); |
|
867 |
//leave since argument is improper |
|
868 |
User::Leave (SErrInvalidServiceArgument ); |
|
869 |
} |
|
870 |
ValidateParamL (KExport, KMimeType, exportData, LIW::EVariantTypeDesC, |
|
871 |
ETrue, variant ); |
|
872 |
if( variant.AsDes() == KNullDesC ) |
|
873 |
{ |
|
874 |
ErrorMessageL (KExport, KMimeType ); |
|
875 |
iErrMsg->Des().Append (KInvalid ); |
|
876 |
//leave since argument is improper |
|
877 |
User::Leave (SErrInvalidServiceArgument ); |
|
878 |
} |
|
879 |
//instantiate CPosLandmarkEncoder based on mime type. |
|
880 |
HBufC8* mimeType8 = |
|
881 |
CnvUtfConverter::ConvertFromUnicodeToUtf8L ( variant.AsDes ( ) ); |
|
882 |
CleanupStack::PushL( mimeType8 ); |
|
883 |
CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL ( *mimeType8 ); |
|
884 |
CleanupStack::PushL (encoder ); |
|
885 |
CBufBase* exportBuffer = encoder->SetUseOutputBufferL(); |
|
886 |
CleanupStack::PushL(exportBuffer); |
|
887 |
ValidateParamL (KExport, KIdList, exportData, |
|
888 |
LIW::EVariantTypeList, ETrue, variant ); |
|
889 |
const CLiwList* lmList = variant.AsList ( ); |
|
890 |
TInt lmcount = lmList->Count ( ); |
|
891 |
if ( !lmcount ) |
|
892 |
{ |
|
893 |
ErrorMessageL (KExport, KIdList ); |
|
894 |
iErrMsg->Des().Append (KEmpty ); |
|
895 |
//leave since argument is improper |
|
896 |
User::Leave (KErrNotFound ); |
|
897 |
} |
|
898 |
//array of landmark ids to be exported. |
|
899 |
RArray<TPosLmItemId> landmarkIdArray; |
|
900 |
CleanupClosePushL (landmarkIdArray ); |
|
901 |
for (TInt index = 0; index < lmcount; ++index ) |
|
902 |
{ |
|
903 |
if ( lmList->AtL (index, variant ) ) |
|
904 |
{ |
|
905 |
ValidateParamL (KExport, KId, variant, |
|
906 |
LIW::EVariantTypeDesC ); |
|
907 |
TPtrC lmPtr(variant.AsDes ( )); |
|
908 |
TLex lmparseString(lmPtr); //Get Id as string and convert to TUint32 |
|
909 |
TPosLmItemId lmid; |
|
910 |
TInt parseErr = lmparseString.Val (lmid, EDecimal ); |
|
911 |
||
912 |
TBuf<KMaxIDStringLength> lmIdString(KNullDesC ( )); |
|
913 |
if ( !parseErr ) |
|
914 |
{ |
|
915 |
lmIdString.Num (lmid ); |
|
916 |
} |
|
917 |
if ( parseErr || lmIdString != lmPtr ) |
|
918 |
{ |
|
919 |
ErrorMessageL (KExport, KId ); |
|
920 |
iErrMsg->Des().Append (KInvalid ); |
|
921 |
User::Leave (SErrInvalidServiceArgument ); |
|
922 |
} |
|
923 |
landmarkIdArray.AppendL (lmid ); |
|
924 |
} |
|
925 |
} |
|
926 |
TPtrC dbUri; |
|
927 |
if (ValidateParamL (KExport, KDbUri, exportData, LIW::EVariantTypeDesC, |
|
928 |
EFalse, variant ) ) |
|
929 |
{ |
|
930 |
dbUri.Set (variant.AsDes ( ) ); |
|
931 |
} |
|
932 |
iService->ExportL (*encoder, landmarkIdArray, dbUri ); |
|
933 |
ExecuteAndDeleteLD (encoder->FinalizeEncodingL ( ) ); |
|
934 |
//Write to file |
|
935 |
ValidateParamL (KExport, KDestinationFile, exportData, |
|
936 |
LIW::EVariantTypeDesC, ETrue, variant ); |
|
937 |
RFs fs; |
|
938 |
User::LeaveIfError(fs.Connect()); |
|
939 |
CleanupClosePushL(fs); |
|
940 |
RFile file; |
|
941 |
CleanupClosePushL(file); |
|
942 |
User::LeaveIfError(file.Create(fs, variant.AsDes(), |
|
943 |
EFileShareExclusive | EFileStreamText | EFileWrite)); |
|
944 |
TInt size = exportBuffer->Size(); |
|
945 |
for( TInt i = 0; i < size; ++i ) |
|
946 |
{ |
|
947 |
file.Write(i,exportBuffer->Ptr(i)); |
|
948 |
} |
|
949 |
CleanupStack::PopAndDestroy(&file); |
|
950 |
CleanupStack::PopAndDestroy(&fs); |
|
951 |
CleanupStack::PopAndDestroy (&landmarkIdArray ); |
|
952 |
CleanupStack::PopAndDestroy (exportBuffer); |
|
953 |
CleanupStack::PopAndDestroy (encoder ); |
|
954 |
CleanupStack::PopAndDestroy (mimeType8 ); |
|
955 |
CleanupStack::PopAndDestroy(&variant); |
|
956 |
} |
|
957 |
else |
|
958 |
{ |
|
959 |
ErrorMessageL (KExport, KContentType ); |
|
960 |
iErrMsg->Des().Append (KInvalid ); |
|
961 |
//leave since argument is improper |
|
962 |
User::Leave (SErrInvalidServiceArgument ); |
|
963 |
} |
|
964 |
} |
|
965 |
||
966 |
// --------------------------------------------------------------------------- |
|
967 |
// CLandmarkInterface::OrganiseL(const CLiwGenericParamList& aInParamList, |
|
968 |
// CLiwGenericParamList& /*aOutParamList*/, |
|
969 |
// TUint /*aCmdOptions*/, |
|
970 |
// MLiwNotifyCallback* /*aCallback*/ ) |
|
971 |
// This calls the appropriate service function for organising landmarks. |
|
972 |
// --------------------------------------------------------------------------- |
|
973 |
// |
|
974 |
void CLandmarkInterface::OrganiseL( const CLiwGenericParamList& aInParamList, |
|
975 |
CLiwGenericParamList& /*aOutParamList*/, TUint /*aCmdOptions*/, |
|
976 |
MLiwNotifyCallback* /*aCallback*/) |
|
977 |
{ |
|
978 |
//Input param List must have contentType, filter and operationType specified |
|
979 |
if ( aInParamList.Count ( )< EIndex3 ) |
|
980 |
{ |
|
981 |
ErrorMessageL (KAdd, KOrganiseArgsMissing ); |
|
982 |
iErrMsg->Des().Append (KMissing ); |
|
983 |
//leave since argument is improper |
|
984 |
User::Leave (SErrMissingArgument ); |
|
985 |
} |
|
986 |
//position to start search in input params |
|
987 |
TInt index = 0; |
|
988 |
//Flag for pos based |
|
989 |
TBool posBased = EFalse; |
|
990 |
//get content type |
|
991 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
992 |
//check whether pos based or value based |
|
993 |
if ( param->Name ( )== KNullDesC8 ) |
|
994 |
{ |
|
995 |
posBased = ETrue; |
|
996 |
} |
|
997 |
else |
|
998 |
{ |
|
999 |
param = aInParamList.FindFirst (index, KContentType ); |
|
1000 |
if ( !param ) |
|
1001 |
{ |
|
1002 |
ErrorMessageL (KOrganise, KContentType ); |
|
1003 |
iErrMsg->Des().Append (KMissing ); |
|
1004 |
//leave since argument is improper |
|
1005 |
User::Leave (SErrMissingArgument ); |
|
1006 |
} |
|
1007 |
} |
|
1008 |
||
1009 |
TLiwVariant variant(param->Value ( )); |
|
1010 |
ValidateParamL (KOrganise, KContentType, variant, LIW::EVariantTypeDesC ); |
|
1011 |
TPtrC contentType(variant.AsDes ( )); |
|
1012 |
||
1013 |
//Content type is Landmark |
|
1014 |
if ( contentType == KLandmark ) |
|
1015 |
{ |
|
1016 |
index = 0; |
|
1017 |
if ( posBased ) |
|
1018 |
{ |
|
1019 |
param = &aInParamList[EIndex1]; |
|
1020 |
} |
|
1021 |
else |
|
1022 |
{ |
|
1023 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
1024 |
if ( !param ) |
|
1025 |
{ |
|
1026 |
ErrorMessageL (KOrganise, KDataFields ); |
|
1027 |
iErrMsg->Des().Append (KMissing ); |
|
1028 |
//leave since argument is improper |
|
1029 |
User::Leave (SErrMissingArgument ); |
|
1030 |
} |
|
1031 |
} |
|
1032 |
variant = param->Value ( ); |
|
1033 |
ValidateParamL (KOrganise, KDataFields, variant, LIW::EVariantTypeMap ); |
|
1034 |
const CLiwMap* filter = variant.AsMap ( ); |
|
1035 |
CleanupStack::PushL( |
|
1036 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1037 |
ValidateParamL (KOrganise, KId, filter, LIW::EVariantTypeDesC, |
|
1038 |
ETrue, variant ); |
|
1039 |
TPtrC catPtr(variant.AsDes ( )); |
|
1040 |
TLex catparseString(catPtr); //Get Id as string and convert to TUint32 |
|
1041 |
TPosLmItemId catid; |
|
1042 |
TInt parseErr = catparseString.Val (catid, EDecimal ); |
|
1043 |
||
1044 |
TBuf<KMaxIDStringLength> catIdString(KNullDesC ( )); |
|
1045 |
if ( !parseErr ) |
|
1046 |
{ |
|
1047 |
catIdString.Num (catid ); |
|
1048 |
} |
|
1049 |
if ( parseErr || catIdString != catPtr ) |
|
1050 |
{ |
|
1051 |
ErrorMessageL (KOrganise, KId ); |
|
1052 |
iErrMsg->Des().Append (KInvalid ); |
|
1053 |
User::Leave (SErrInvalidServiceArgument ); |
|
1054 |
} |
|
1055 |
ValidateParamL (KOrganise, KIdList, filter, |
|
1056 |
LIW::EVariantTypeList, ETrue, variant ); |
|
1057 |
const CLiwList* lmList = variant.AsList ( ); |
|
1058 |
TInt count = lmList->Count ( ); |
|
1059 |
if ( !count ) |
|
1060 |
{ |
|
1061 |
ErrorMessageL (KOrganise, KIdList ); |
|
1062 |
iErrMsg->Des().Append (KEmpty ); |
|
1063 |
//leave since argument is improper |
|
1064 |
User::Leave (KErrNotFound ); |
|
1065 |
} |
|
1066 |
//array of landmark ids to be organised. |
|
1067 |
RArray<TPosLmItemId> landmarkIdArray; |
|
1068 |
CleanupClosePushL (landmarkIdArray ); |
|
1069 |
for (TInt pos = 0; pos < count; ++pos ) |
|
1070 |
{ |
|
1071 |
if ( lmList->AtL (pos, variant ) ) |
|
1072 |
{ |
|
1073 |
ValidateParamL (KOrganise, KId, variant, |
|
1074 |
LIW::EVariantTypeDesC ); |
|
1075 |
TPtrC lmPtr(variant.AsDes ( )); |
|
1076 |
TLex lmparseString(lmPtr); //Get Id as string and convert to TUint32 |
|
1077 |
TPosLmItemId lmid; |
|
1078 |
TInt parseErr = lmparseString.Val (lmid, EDecimal ); |
|
1079 |
||
1080 |
TBuf<KMaxIDStringLength> lmIdString(KNullDesC ( )); |
|
1081 |
if ( !parseErr ) |
|
1082 |
{ |
|
1083 |
lmIdString.Num (lmid ); |
|
1084 |
} |
|
1085 |
if ( parseErr || lmIdString != lmPtr ) |
|
1086 |
{ |
|
1087 |
ErrorMessageL (KOrganise, KId ); |
|
1088 |
iErrMsg->Des().Append (KInvalid ); |
|
1089 |
User::Leave (SErrInvalidServiceArgument ); |
|
1090 |
} |
|
1091 |
landmarkIdArray.AppendL (lmid ); |
|
1092 |
} |
|
1093 |
} |
|
1094 |
TPtrC dbUri; |
|
1095 |
TLiwVariant variantDb; |
|
1096 |
CleanupStack::PushL( |
|
1097 |
TCleanupItem( TLiwVariant::VariantCleanup , &variantDb ) ); |
|
1098 |
if (ValidateParamL (KOrganise, KDbUri, filter, LIW::EVariantTypeDesC, |
|
1099 |
EFalse, variantDb ) ) |
|
1100 |
{ |
|
1101 |
variantDb.Get (dbUri ); |
|
1102 |
} |
|
1103 |
index = 0; |
|
1104 |
if ( posBased ) |
|
1105 |
{ |
|
1106 |
//Position based parsing |
|
1107 |
param = &aInParamList[EIndex2]; |
|
1108 |
} |
|
1109 |
else |
|
1110 |
{ |
|
1111 |
param = aInParamList.FindFirst (index, KOperationType ); |
|
1112 |
if ( !param ) |
|
1113 |
{ |
|
1114 |
ErrorMessageL (KOrganise, KOperationType ); |
|
1115 |
iErrMsg->Des().Append (KMissing ); |
|
1116 |
//leave since argument is improper |
|
1117 |
User::Leave (SErrMissingArgument ); |
|
1118 |
} |
|
1119 |
} |
|
1120 |
variant = param->Value ( ); |
|
1121 |
ValidateParamL (KOrganise, KOperationType, variant, |
|
1122 |
LIW::EVariantTypeDesC ); |
|
1123 |
TPtrC operationType = variant.AsDes ( ); |
|
1124 |
if ( operationType == KAssociate ) |
|
1125 |
{ |
|
1126 |
iService->LinkCategoryToLandmarksL (catid, landmarkIdArray, dbUri ); |
|
1127 |
} |
|
1128 |
else |
|
1129 |
if ( operationType == KDisassociate ) |
|
1130 |
{ |
|
1131 |
iService->UnlinkCategoryToLandmarksL (catid, landmarkIdArray, |
|
1132 |
dbUri ); |
|
1133 |
} |
|
1134 |
else |
|
1135 |
{ |
|
1136 |
ErrorMessageL (KOrganise, KOperationType ); |
|
1137 |
iErrMsg->Des().Append (KInvalid ); |
|
1138 |
//leave since argument is improper |
|
1139 |
User::Leave (SErrInvalidServiceArgument ); |
|
1140 |
} |
|
1141 |
CleanupStack::PopAndDestroy(&variantDb); |
|
1142 |
CleanupStack::PopAndDestroy (&landmarkIdArray ); |
|
1143 |
CleanupStack::PopAndDestroy(&variant); |
|
1144 |
} |
|
1145 |
else |
|
1146 |
{ |
|
1147 |
ErrorMessageL (KOrganise, KContentType ); |
|
1148 |
iErrMsg->Des().Append (KInvalid ); |
|
1149 |
//leave since argument is improper |
|
1150 |
User::Leave (SErrInvalidServiceArgument ); |
|
1151 |
} |
|
1152 |
} |
|
1153 |
||
1154 |
// --------------------------------------------------------------------------- |
|
1155 |
// CLandmarkInterface::Cancel(const CLiwGenericParamList& aInParamList, |
|
1156 |
// CLiwGenericParamList& /*aOutParamList*/, |
|
1157 |
// TUint /*aCmdOptions*/, |
|
1158 |
// MLiwNotifyCallback* aCallback ) |
|
1159 |
// This cancels the ongoing async call. |
|
1160 |
// --------------------------------------------------------------------------- |
|
1161 |
// |
|
1162 |
void CLandmarkInterface::Cancel( const CLiwGenericParamList& aInParamList, |
|
1163 |
CLiwGenericParamList& aOutParamList, TUint /*aCmdOptions*/, |
|
1164 |
MLiwNotifyCallback* aCallback ) |
|
1165 |
{ |
|
1166 |
//Input param List must have transactionID specified |
|
1167 |
if ( aInParamList.Count ( ) ) |
|
1168 |
{ |
|
1169 |
//position to start search in input params |
|
1170 |
TInt index = 0; |
|
1171 |
//get content type |
|
1172 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
1173 |
//check whether pos based or value based |
|
1174 |
if ( param->Name ( )!= KNullDesC8 ) |
|
1175 |
{ |
|
1176 |
param = aInParamList.FindFirst (index, KTransactionId ); |
|
1177 |
if ( !param ) |
|
1178 |
{ |
|
1179 |
ErrorMessageL (KCancel, KTransactionId ); |
|
1180 |
iErrMsg->Des().Append (KMissing ); |
|
1181 |
//leave since argument is improper |
|
1182 |
User::Leave (SErrMissingArgument ); |
|
1183 |
} |
|
1184 |
} |
|
1185 |
||
1186 |
TLiwVariant variant(param->Value ( )); |
|
1187 |
ValidateParamL (KCancel, KTransactionId, variant, |
|
1188 |
LIW::EVariantTypeTInt32 ); |
|
1189 |
TInt32 transactionId = variant.AsTInt32 ( ); |
|
1190 |
iService->Cancel (transactionId ); |
|
1191 |
if (!aCallback ) |
|
1192 |
{ |
|
1193 |
//retrieve the stored callback if callback not explicitly passed |
|
1194 |
aCallback = Callback (transactionId ); |
|
1195 |
} |
|
1196 |
else |
|
1197 |
{ |
|
1198 |
// remove the stored callback since the async request has been cancelled |
|
1199 |
Callback (transactionId ); |
|
1200 |
} |
|
1201 |
if ( aCallback ) |
|
1202 |
{ |
|
1203 |
TRAP_IGNORE(aCallback->HandleNotifyL(transactionId,KLiwEventCanceled,aOutParamList,aInParamList)); |
|
1204 |
} |
|
1205 |
} |
|
1206 |
else |
|
1207 |
{ |
|
1208 |
ErrorMessageL (KCancel, KTransactionId ); |
|
1209 |
iErrMsg->Des().Append (KMissing ); |
|
1210 |
User::Leave (SErrMissingArgument ); |
|
1211 |
} |
|
1212 |
||
1213 |
} |
|
1214 |
||
1215 |
// --------------------------------------------------------------------------- |
|
1216 |
// CLandmarkInterface::NewTemplateL(const CLiwGenericParamList& aInParamList, |
|
1217 |
// CLiwGenericParamList& aOutParamList, |
|
1218 |
// TUint aCmdOptions, |
|
1219 |
// MLiwNotifyCallback* aCallback ) |
|
1220 |
// This function calls the appropriate functions based on the content type. |
|
1221 |
// --------------------------------------------------------------------------- |
|
1222 |
// |
|
1223 |
void CLandmarkInterface::NewTemplateL(const CLiwGenericParamList& aInParamList, |
|
1224 |
CLiwGenericParamList& aOutParamList, TUint /*aCmdOptions*/, |
|
1225 |
MLiwNotifyCallback* /*aCallback*/) |
|
1226 |
{ |
|
1227 |
//Input param List must have Type specified |
|
1228 |
if ( !aInParamList.Count() ) |
|
1229 |
{ |
|
1230 |
ErrorMessageL (KNew, KContentType ); |
|
1231 |
iErrMsg->Des().Append (KMissing ); |
|
1232 |
//leave since argument is improper |
|
1233 |
User::Leave (SErrMissingArgument ); |
|
1234 |
} |
|
1235 |
//position to start search in input params |
|
1236 |
TInt index = 0; |
|
1237 |
//get content type |
|
1238 |
const TLiwGenericParam* param = &aInParamList[EIndex0]; |
|
1239 |
//check whether pos based or value based |
|
1240 |
if ( param->Name ( )!= KNullDesC8 ) |
|
1241 |
{ |
|
1242 |
param = aInParamList.FindFirst (index, KContentType ); |
|
1243 |
if ( !param ) |
|
1244 |
{ |
|
1245 |
ErrorMessageL (KNew, KContentType ); |
|
1246 |
iErrMsg->Des().Append (KMissing ); |
|
1247 |
//leave since argument is improper |
|
1248 |
User::Leave (SErrMissingArgument ); |
|
1249 |
} |
|
1250 |
} |
|
1251 |
||
1252 |
TLiwVariant variant(param->Value ( )); |
|
1253 |
ValidateParamL (KNew, KContentType, variant, LIW::EVariantTypeDesC ); |
|
1254 |
TPtrC contentType(variant.AsDes ( )); |
|
1255 |
||
1256 |
CLiwMap* contentMap = CLiwDefaultMap::NewL ( ); |
|
1257 |
CleanupClosePushL ( *contentMap ); |
|
1258 |
//Content type is Landmark. |
|
1259 |
if ( contentType == KLandmark ) |
|
1260 |
{ |
|
1261 |
contentMap->InsertL (KLandmarkName, TLiwVariant (KNullDesC ) ); |
|
1262 |
contentMap->InsertL (KLandmarkDesc, TLiwVariant (KNullDesC ) ); |
|
1263 |
||
1264 |
CLiwMap* location = CLiwDefaultMap::NewL ( ); |
|
1265 |
CleanupClosePushL(*location); |
|
1266 |
location->InsertL (KDbUri, TLiwVariant (KNullDesC ) ); |
|
1267 |
location->InsertL (KLatitude, TLiwVariant (TReal64 (0.0 ) ) ); |
|
1268 |
location->InsertL (KLongitude, TLiwVariant (TReal64 (0.0 ) ) ); |
|
1269 |
location->InsertL (KAltitude, TLiwVariant (TReal32 (0.0 ) ) ); |
|
1270 |
location->InsertL (KHAccuracy, TLiwVariant (TReal32 (0.0 ) ) ); |
|
1271 |
location->InsertL (KVAccuracy, TLiwVariant (TReal32 (0.0 ) ) ); |
|
1272 |
//location->InsertL (KTStamp, TLiwVariant (TInt32 (0 ) ) ); |
|
1273 |
contentMap->InsertL (KLandmarkPosition, TLiwVariant (location ) ); |
|
1274 |
CleanupStack::PopAndDestroy (location ); |
|
1275 |
||
1276 |
contentMap->InsertL (KCoverageRadius, TLiwVariant (TReal32 (0.0 ) ) ); |
|
1277 |
||
1278 |
CLiwList* categoryInfo = CLiwDefaultList::NewL ( ); |
|
1279 |
CleanupClosePushL ( *categoryInfo ); |
|
1280 |
contentMap->InsertL (KCategoryInfo, TLiwVariant (categoryInfo ) ); |
|
1281 |
CleanupStack::PopAndDestroy (categoryInfo );; |
|
1282 |
||
1283 |
contentMap->InsertL (KIconFile, TLiwVariant (KNullDesC ) ); |
|
1284 |
contentMap->InsertL (KIconIndex, TLiwVariant (TInt32 (0 ) ) ); |
|
1285 |
contentMap->InsertL (KIconMaskIndex, |
|
1286 |
TLiwVariant (KPosLmIconMaskNotUsed ) ); |
|
1287 |
||
1288 |
CLiwMap* landmarkFields = CLiwDefaultMap::NewL ( ); |
|
1289 |
CleanupClosePushL ( *landmarkFields ); |
|
1290 |
landmarkFields->InsertL (KLandmarkCountry, TLiwVariant (KNullDesC ) ); |
|
1291 |
landmarkFields->InsertL (KLandmarkAreaCode, TLiwVariant (KNullDesC ) ); |
|
1292 |
landmarkFields->InsertL (KLandmarkCity, TLiwVariant (KNullDesC ) ); |
|
1293 |
landmarkFields->InsertL (KLandmarkDistrict, TLiwVariant (KNullDesC ) ); |
|
1294 |
landmarkFields->InsertL (KLandmarkBuildingName, TLiwVariant (KNullDesC ) ); |
|
1295 |
landmarkFields->InsertL (KLandmarkStreet, TLiwVariant (KNullDesC ) ); |
|
1296 |
landmarkFields->InsertL (KLandmarkTelephone, TLiwVariant (KNullDesC ) ); |
|
1297 |
contentMap->InsertL (KLandmarkFields, TLiwVariant (landmarkFields ) ); |
|
1298 |
CleanupStack::PopAndDestroy (landmarkFields ); |
|
1299 |
} |
|
1300 |
//Content type is Category. |
|
1301 |
else |
|
1302 |
if ( contentType == KCategory ) |
|
1303 |
{ |
|
1304 |
contentMap->InsertL (KCategoryName, TLiwVariant (KNullDesC ) ); |
|
1305 |
contentMap->InsertL (KIconFile, TLiwVariant (KNullDesC ) ); |
|
1306 |
contentMap->InsertL (KIconIndex, TLiwVariant (TInt32 (0 ) ) ); |
|
1307 |
contentMap->InsertL (KIconMaskIndex, |
|
1308 |
TLiwVariant (KPosLmIconMaskNotUsed ) ); |
|
1309 |
} |
|
1310 |
//Content type is Database. |
|
1311 |
else |
|
1312 |
if ( contentType == KDatabase ) |
|
1313 |
{ |
|
1314 |
contentMap->InsertL (KDbUri, TLiwVariant (KNullDesC ) ); |
|
1315 |
contentMap->InsertL (KDbName, TLiwVariant (KNullDesC ) ); |
|
1316 |
} |
|
1317 |
else |
|
1318 |
{ |
|
1319 |
||
1320 |
//leave since argument is improper |
|
1321 |
ErrorMessageL (KNew, KContentType ); |
|
1322 |
iErrMsg->Des().Append (KInvalid ); |
|
1323 |
User::Leave (SErrInvalidServiceArgument ); |
|
1324 |
} |
|
1325 |
||
1326 |
aOutParamList.AppendL (TLiwGenericParam (KReturnValue, |
|
1327 |
TLiwVariant (contentMap ) ) ); |
|
1328 |
CleanupStack::PopAndDestroy (contentMap ); |
|
1329 |
} |
|
1330 |
||
1331 |
// --------------------------------------------------------------------------- |
|
1332 |
// CLandmarkInterface::GetLandmarksL(const CLiwGenericParamList& aInParamList, |
|
1333 |
// CLiwGenericParamList& aOutParamList, |
|
1334 |
// TUint aCmdOptions, |
|
1335 |
// MLiwNotifyCallback* aCallback ) |
|
1336 |
// This calls the appropriate service function for retrieving landmarks. |
|
1337 |
// --------------------------------------------------------------------------- |
|
1338 |
// |
|
1339 |
void CLandmarkInterface::GetLandmarksL( |
|
1340 |
const CLiwGenericParamList& aInParamList, |
|
1341 |
CLiwGenericParamList& aOutParamList, TUint /*aCmdOptions*/, |
|
1342 |
MLiwNotifyCallback* aCallback ) |
|
1343 |
{ |
|
1344 |
CLandmarkFilter |
|
1345 |
* lmFilter = CLandmarkFilter::NewLC (CLandmarkFilter::ELandmark ); |
|
1346 |
TLiwVariant variantDb; |
|
1347 |
CleanupStack::PushL( |
|
1348 |
TCleanupItem( TLiwVariant::VariantCleanup, &variantDb ) ); |
|
1349 |
TPtrC dbUri; |
|
1350 |
//position to start search in input params |
|
1351 |
TInt index = 0; |
|
1352 |
//Flag for pos based |
|
1353 |
TBool posBased = EFalse; |
|
1354 |
//get filter if specified |
|
1355 |
const TLiwGenericParam* param= NULL; |
|
1356 |
if ( aInParamList.Count ( )> EIndex1 ) |
|
1357 |
{ |
|
1358 |
param = &aInParamList[EIndex1]; |
|
1359 |
//check whether pos based or value based |
|
1360 |
if ( param->Name ( )== KNullDesC8 ) |
|
1361 |
{ |
|
1362 |
posBased = ETrue; |
|
1363 |
} |
|
1364 |
} |
|
1365 |
if ( !posBased ) |
|
1366 |
{ |
|
1367 |
param = aInParamList.FindFirst (index, KFilter ); |
|
1368 |
} |
|
1369 |
||
1370 |
if ( param ) |
|
1371 |
{ |
|
1372 |
TLiwVariant variant(param->Value ( )); |
|
1373 |
ValidateParamL (KGetList, KFilter, variant, LIW::EVariantTypeMap ); |
|
1374 |
const CLiwMap* filter = variant.AsMap ( ); |
|
1375 |
if ( filter->Count ( ) ) |
|
1376 |
{ |
|
1377 |
CPosLmCompositeCriteria* criteria = CPosLmCompositeCriteria::NewLC (CPosLmCompositeCriteria::ECompositionAND ); |
|
1378 |
//for different criteria create and append to composite criteria class. |
|
1379 |
CleanupStack::PushL( |
|
1380 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1381 |
if ( ValidateParamL (KGetList, KLandmarkName, filter, |
|
1382 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
1383 |
{ |
|
1384 |
TPtrC name( variant.AsDes ( ) ); |
|
1385 |
if( name != KNullDesC ) |
|
1386 |
{ |
|
1387 |
CPosLmTextCriteria* crit = CPosLmTextCriteria::NewLC ( ); |
|
1388 |
crit->SetTextL(name); |
|
1389 |
crit->SetAttributesToSearch (CPosLandmark::ELandmarkName ); |
|
1390 |
User::LeaveIfError (criteria->AddArgument (crit ) ); |
|
1391 |
CleanupStack::Pop (crit ); |
|
1392 |
} |
|
1393 |
else |
|
1394 |
{ |
|
1395 |
//Do whatever is default |
|
1396 |
} |
|
1397 |
} |
|
1398 |
if ( ValidateParamL (KGetList, KCategoryName, filter, |
|
1399 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
1400 |
{ |
|
1401 |
TPtrC name( variant.AsDes( ) ); |
|
1402 |
if( name != KNullDesC ) |
|
1403 |
{ |
|
1404 |
CPosLmCategoryCriteria* crit = CPosLmCategoryCriteria::NewLC ( ); |
|
1405 |
crit->SetCategoryNameL (name); |
|
1406 |
User::LeaveIfError (criteria->AddArgument (crit ) ); |
|
1407 |
CleanupStack::Pop (crit ); |
|
1408 |
} |
|
1409 |
else |
|
1410 |
{ |
|
1411 |
//Do whatever is default |
|
1412 |
} |
|
1413 |
} |
|
1414 |
if ( ValidateParamL (KGetList, KLandmarkDesc, filter, |
|
1415 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
1416 |
{ |
|
1417 |
TPtrC description( variant.AsDes( ) ); |
|
1418 |
if( description != KNullDesC ) |
|
1419 |
{ |
|
1420 |
CPosLmTextCriteria* crit = CPosLmTextCriteria::NewLC ( ); |
|
1421 |
crit->SetTextL (variant.AsDes ( ) ); |
|
1422 |
crit->SetAttributesToSearch (CPosLandmark::EDescription ); |
|
1423 |
User::LeaveIfError (criteria->AddArgument (crit ) ); |
|
1424 |
CleanupStack::Pop (crit ); |
|
1425 |
} |
|
1426 |
else |
|
1427 |
{ |
|
1428 |
//Do whatever is default |
|
1429 |
} |
|
1430 |
} |
|
1431 |
if ( ValidateParamL (KGetList, KLandmarkPosition, filter, |
|
1432 |
LIW::EVariantTypeMap, EFalse, variant ) ) |
|
1433 |
{ |
|
1434 |
const CLiwMap* position = variant.AsMap ( ); |
|
1435 |
TReal64 latitude(0); |
|
1436 |
TReal64 longitude(0); |
|
1437 |
TBool coverageRadiusOption = EFalse; |
|
1438 |
ValidateParamL (KGetList, KLatitude, position, |
|
1439 |
LIW::EVariantTypeTReal, ETrue, variant ); |
|
1440 |
latitude = variant.AsTReal ( ); |
|
1441 |
ValidateParamL (KGetList, KLongitude, position, |
|
1442 |
LIW::EVariantTypeTReal, ETrue, variant ); |
|
1443 |
longitude = variant.AsTReal ( ); |
|
1444 |
if ( ValidateParamL (KGetList, KCoverageRadiusOption, filter, |
|
1445 |
LIW::EVariantTypeTBool, EFalse, variant ) ) |
|
1446 |
{ |
|
1447 |
coverageRadiusOption = variant.AsTBool ( ); |
|
1448 |
} |
|
1449 |
CPosLmNearestCriteria* crit = CPosLmNearestCriteria::NewLC ( |
|
1450 |
TCoordinate (latitude, longitude ), |
|
1451 |
coverageRadiusOption ); |
|
1452 |
if ( ValidateParamL (KGetList, KMaximumDistance, filter, |
|
1453 |
LIW::EVariantTypeTReal, EFalse, variant ) ) |
|
1454 |
{ |
|
1455 |
TReal maxDist = variant.AsTReal ( ); |
|
1456 |
if ( maxDist < 0 ) |
|
1457 |
{ |
|
1458 |
ErrorMessageL (KGetList, KMaximumDistance ); |
|
1459 |
iErrMsg->Des().Append (KInvalid ); |
|
1460 |
User::Leave (SErrInvalidServiceArgument ); |
|
1461 |
} |
|
1462 |
crit->SetMaxDistance (maxDist ); |
|
1463 |
} |
|
1464 |
User::LeaveIfError (criteria->AddArgument (crit ) ); |
|
1465 |
CleanupStack::Pop (crit ); |
|
1466 |
} |
|
1467 |
if ( ValidateParamL (KGetList, KBoundedArea, filter, |
|
1468 |
LIW::EVariantTypeMap, EFalse, variant ) ) |
|
1469 |
{ |
|
1470 |
const CLiwMap* boundedArea = variant.AsMap ( ); |
|
1471 |
TReal northLatitude; |
|
1472 |
TReal southLatitude; |
|
1473 |
TReal eastLongitude; |
|
1474 |
TReal westLongitude; |
|
1475 |
ValidateParamL (KGetList, KNorthLatitude, boundedArea, |
|
1476 |
LIW::EVariantTypeTReal, ETrue, variant ); |
|
1477 |
northLatitude = variant.AsTReal ( ); |
|
1478 |
ValidateParamL (KGetList, KSouthLatitude, boundedArea, |
|
1479 |
LIW::EVariantTypeTReal, ETrue, variant ); |
|
1480 |
southLatitude = variant.AsTReal ( ); |
|
1481 |
ValidateParamL (KGetList, KEastLongitude, boundedArea, |
|
1482 |
LIW::EVariantTypeTReal, ETrue, variant ); |
|
1483 |
eastLongitude = variant.AsTReal ( ); |
|
1484 |
ValidateParamL (KGetList, KWestLongitude, boundedArea, |
|
1485 |
LIW::EVariantTypeTReal, ETrue, variant ); |
|
1486 |
westLongitude = variant.AsTReal ( ); |
|
1487 |
CPosLmAreaCriteria* crit = CPosLmAreaCriteria::NewLC ( |
|
1488 |
southLatitude,northLatitude,westLongitude, |
|
1489 |
eastLongitude ); |
|
1490 |
User::LeaveIfError (criteria->AddArgument (crit ) ); |
|
1491 |
CleanupStack::Pop (crit ); |
|
1492 |
} |
|
1493 |
if ( ValidateParamL (KGetList, KMaximumMatches, filter, |
|
1494 |
LIW::EVariantTypeTInt32, EFalse, variant ) ) |
|
1495 |
{ |
|
1496 |
TInt32 count = variant.AsTInt32 ( ); |
|
1497 |
if ( count > 0 ) |
|
1498 |
{ |
|
1499 |
lmFilter->SetMaximumMatches (count ); |
|
1500 |
} |
|
1501 |
else |
|
1502 |
{ |
|
1503 |
ErrorMessageL (KGetList, KMaximumMatches ); |
|
1504 |
iErrMsg->Des().Append (KInvalid ); |
|
1505 |
//leave since argument is improper |
|
1506 |
User::Leave (SErrInvalidServiceArgument ); |
|
1507 |
} |
|
1508 |
} |
|
1509 |
if ( ValidateParamL (KGetList, KPrevMatchesOnly, filter, |
|
1510 |
LIW::EVariantTypeTBool, EFalse, variant ) ) |
|
1511 |
{ |
|
1512 |
lmFilter->SetPreviousMatches (variant.AsTBool ( ) ); |
|
1513 |
} |
|
1514 |
||
1515 |
CleanupStack::PopAndDestroy(&variant); |
|
1516 |
//Set criteria only if it contains one or more criterion |
|
1517 |
if ( criteria->NumOfArguments ( ) ) |
|
1518 |
{ |
|
1519 |
lmFilter->SetCriteria (criteria ); |
|
1520 |
CleanupStack::Pop (criteria ); |
|
1521 |
} |
|
1522 |
else |
|
1523 |
{ |
|
1524 |
CleanupStack::PopAndDestroy( criteria ); |
|
1525 |
} |
|
1526 |
||
1527 |
||
1528 |
if ( ValidateParamL (KGetList, KDbUri, filter, |
|
1529 |
LIW::EVariantTypeDesC, EFalse, variantDb ) ) |
|
1530 |
{ |
|
1531 |
variantDb.Get (dbUri ); |
|
1532 |
} |
|
1533 |
||
1534 |
} |
|
1535 |
} |
|
1536 |
param = NULL; |
|
1537 |
index = 0; |
|
1538 |
if ( posBased && aInParamList.Count ( )> EIndex2 ) |
|
1539 |
{ |
|
1540 |
param = &aInParamList[EIndex2]; |
|
1541 |
} |
|
1542 |
if ( !posBased ) |
|
1543 |
{ |
|
1544 |
param = aInParamList.FindFirst (index, KSort ); |
|
1545 |
} |
|
1546 |
if ( param ) |
|
1547 |
{ |
|
1548 |
TLiwVariant variant(param->Value ( )); |
|
1549 |
ValidateParamL (KGetList, KSort, variant, LIW::EVariantTypeMap ); |
|
1550 |
const CLiwMap* sort = variant.AsMap ( ); |
|
1551 |
CleanupStack::PushL( |
|
1552 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1553 |
if ( ValidateParamL (KGetList, KSortOrder, sort, LIW::EVariantTypeDesC, |
|
1554 |
ETrue, variant ) ) |
|
1555 |
{ |
|
1556 |
//by default sort is ascending |
|
1557 |
if ( variant.AsDes() == KDescending ) |
|
1558 |
{ |
|
1559 |
lmFilter->SetLmSortPref (TPosLmSortPref ( |
|
1560 |
CPosLandmark::ELandmarkName, |
|
1561 |
TPosLmSortPref::EDescending ) ); |
|
1562 |
} |
|
1563 |
else |
|
1564 |
if ( variant.AsDes() != KAscending && variant.AsDes() != KNullDesC ) |
|
1565 |
{ |
|
1566 |
ErrorMessageL (KGetList, KSortOrder ); |
|
1567 |
iErrMsg->Des().Append (KInvalid ); |
|
1568 |
//leave since argument is improper |
|
1569 |
User::Leave (SErrInvalidServiceArgument ); |
|
1570 |
} |
|
1571 |
} |
|
1572 |
CleanupStack::PopAndDestroy(&variant); |
|
1573 |
} |
|
1574 |
//Async Call |
|
1575 |
if ( aCallback ) |
|
1576 |
{ |
|
1577 |
//Get the transaction ID |
|
1578 |
TInt32 transactionId(aCallback->GetTransactionID ( )); |
|
1579 |
CLandmarkCallbackMap* map = new (ELeave) CLandmarkCallbackMap(transactionId,aCallback); |
|
1580 |
CleanupStack::PushL (map ); |
|
1581 |
iCallbackMap.AppendL (map ); |
|
1582 |
CleanupStack::Pop (map ); |
|
1583 |
iService->GetListL (transactionId, *lmFilter, dbUri ); |
|
1584 |
aOutParamList.AppendL (TLiwGenericParam (KTransactionId, |
|
1585 |
TLiwVariant (TInt32 (transactionId ) ) ) ); |
|
1586 |
} |
|
1587 |
else //sync call |
|
1588 |
{ |
|
1589 |
CPosLmItemIterator* iterator = NULL; |
|
1590 |
iService->GetListL (iterator, *lmFilter, dbUri ); |
|
1591 |
CleanupStack::PushL (iterator ); |
|
1592 |
// if dbURI is not specified retrieve default databse URI |
|
1593 |
if ( dbUri == KNullDesC ) |
|
1594 |
{ |
|
1595 |
iService->GetDefaultDbUriL (dbUri ); |
|
1596 |
} |
|
1597 |
||
1598 |
//instantiate CLandmarkIterable |
|
1599 |
CLiwIterable* iterable = CLandmarkIterable::NewL (iterator, dbUri ); |
|
1600 |
CleanupStack::Pop (iterator ); |
|
1601 |
CleanupClosePushL(*iterable); |
|
1602 |
//pack to aOutParamList |
|
1603 |
aOutParamList.AppendL (TLiwGenericParam (KReturnValue, |
|
1604 |
TLiwVariant (iterable ) ) ); |
|
1605 |
CleanupStack::PopAndDestroy(iterable); |
|
1606 |
} |
|
1607 |
CleanupStack::PopAndDestroy(&variantDb); |
|
1608 |
CleanupStack::PopAndDestroy (lmFilter ); |
|
1609 |
} |
|
1610 |
||
1611 |
// --------------------------------------------------------------------------- |
|
1612 |
// CLandmarkInterface::GetCategoriesL(const CLiwGenericParamList& aInParamList, |
|
1613 |
// CLiwGenericParamList& aOutParamList, |
|
1614 |
// TUint aCmdOptions, |
|
1615 |
// MLiwNotifyCallback* aCallback ) |
|
1616 |
// This calls the appropriate service function for retrieving landmarks. |
|
1617 |
// --------------------------------------------------------------------------- |
|
1618 |
// |
|
1619 |
void CLandmarkInterface::GetCategoriesL( |
|
1620 |
const CLiwGenericParamList& aInParamList, |
|
1621 |
CLiwGenericParamList& aOutParamList, TUint /*aCmdOptions*/, |
|
1622 |
MLiwNotifyCallback* aCallback ) |
|
1623 |
{ |
|
1624 |
CLandmarkFilter |
|
1625 |
* lmFilter = CLandmarkFilter::NewLC (CLandmarkFilter::ECategory ); |
|
1626 |
TLiwVariant variantDb; |
|
1627 |
CleanupStack::PushL( |
|
1628 |
TCleanupItem( TLiwVariant::VariantCleanup, &variantDb ) ); |
|
1629 |
TPtrC dbUri; |
|
1630 |
//position to start search in input params |
|
1631 |
TInt index = 0; |
|
1632 |
//Flag for pos based |
|
1633 |
TBool posBased = EFalse; |
|
1634 |
//get filter if specified |
|
1635 |
const TLiwGenericParam* param= NULL; |
|
1636 |
if ( aInParamList.Count ( )> EIndex1 ) |
|
1637 |
{ |
|
1638 |
param = &aInParamList[EIndex1]; |
|
1639 |
//check whether pos based or value based |
|
1640 |
if ( param->Name ( )== KNullDesC8 ) |
|
1641 |
{ |
|
1642 |
posBased = ETrue; |
|
1643 |
} |
|
1644 |
} |
|
1645 |
if ( !posBased ) |
|
1646 |
{ |
|
1647 |
param = aInParamList.FindFirst (index, KFilter ); |
|
1648 |
} |
|
1649 |
||
1650 |
if ( param ) |
|
1651 |
{ |
|
1652 |
TLiwVariant variant(param->Value ( )); |
|
1653 |
ValidateParamL (KGetList, KFilter, variant, LIW::EVariantTypeMap ); |
|
1654 |
const CLiwMap* filter = variant.AsMap ( ); |
|
1655 |
||
1656 |
if ( filter->Count ( ) ) |
|
1657 |
{ |
|
1658 |
CleanupStack::PushL( |
|
1659 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1660 |
if ( ValidateParamL (KGetList, KCategoryName, filter, |
|
1661 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
1662 |
{ |
|
1663 |
TPtrC name( variant.AsDes ( ) ); |
|
1664 |
if( name != KNullDesC ) |
|
1665 |
{ |
|
1666 |
CPosLmCatNameCriteria* criteria = CPosLmCatNameCriteria::NewLC ( ); |
|
1667 |
criteria->SetSearchPatternL (variant.AsDes ( ) ); |
|
1668 |
lmFilter->SetCriteria (criteria ); |
|
1669 |
CleanupStack::Pop (criteria ); |
|
1670 |
} |
|
1671 |
} |
|
1672 |
if ( ValidateParamL (KGetList, KMaximumMatches, filter, |
|
1673 |
LIW::EVariantTypeTInt32, EFalse, variant ) ) |
|
1674 |
{ |
|
1675 |
TInt32 count = variant.AsTInt32 ( ); |
|
1676 |
if ( count > 0 ) |
|
1677 |
{ |
|
1678 |
lmFilter->SetMaximumMatches (count ); |
|
1679 |
} |
|
1680 |
else |
|
1681 |
{ |
|
1682 |
ErrorMessageL (KGetList, KMaximumMatches ); |
|
1683 |
iErrMsg->Des().Append (KInvalid ); |
|
1684 |
//leave since argument is improper |
|
1685 |
User::Leave ( SErrInvalidServiceArgument ); |
|
1686 |
} |
|
1687 |
} |
|
1688 |
if ( ValidateParamL (KGetList, KPrevMatchesOnly, filter, |
|
1689 |
LIW::EVariantTypeTBool, EFalse, variant ) ) |
|
1690 |
{ |
|
1691 |
lmFilter->SetPreviousMatches (variant.AsTBool ( ) ); |
|
1692 |
} |
|
1693 |
if ( ValidateParamL (KGetList, KDbUri, filter, |
|
1694 |
LIW::EVariantTypeDesC, EFalse, variantDb ) ) |
|
1695 |
{ |
|
1696 |
variantDb.Get (dbUri ); |
|
1697 |
} |
|
1698 |
CleanupStack::PopAndDestroy(&variant); |
|
1699 |
} |
|
1700 |
} |
|
1701 |
||
1702 |
param = NULL; |
|
1703 |
index = 0; |
|
1704 |
if ( posBased && aInParamList.Count ( )> EIndex2 ) |
|
1705 |
{ |
|
1706 |
param = &aInParamList[EIndex2]; |
|
1707 |
} |
|
1708 |
if ( !posBased ) |
|
1709 |
{ |
|
1710 |
param = aInParamList.FindFirst (index, KSort ); |
|
1711 |
} |
|
1712 |
||
1713 |
if ( param ) |
|
1714 |
{ |
|
1715 |
TLiwVariant variant(param->Value ( )); |
|
1716 |
ValidateParamL (KGetList, KSort, variant, LIW::EVariantTypeMap ); |
|
1717 |
const CLiwMap* sort = param->Value().AsMap ( ); |
|
1718 |
CleanupStack::PushL( |
|
1719 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1720 |
if ( ValidateParamL (KGetList, KSortOrder, sort, LIW::EVariantTypeDesC, |
|
1721 |
ETrue, variant ) ) |
|
1722 |
{ |
|
1723 |
TPtrC sortOrder = variant.AsDes ( ); |
|
1724 |
if ( sortOrder == KDescending ) |
|
1725 |
{ |
|
1726 |
lmFilter->SetCatSortPref (CPosLmCategoryManager::ECategorySortOrderNameDescending ); |
|
1727 |
} |
|
1728 |
else |
|
1729 |
if ( sortOrder == KAscending ) |
|
1730 |
{ |
|
1731 |
lmFilter->SetCatSortPref (CPosLmCategoryManager::ECategorySortOrderNameAscending ); |
|
1732 |
} |
|
1733 |
else |
|
1734 |
{ |
|
1735 |
ErrorMessageL (KGetList, KSortOrder ); |
|
1736 |
iErrMsg->Des().Append (KInvalid ); |
|
1737 |
//leave since argument is improper |
|
1738 |
User::Leave (SErrInvalidServiceArgument ); |
|
1739 |
} |
|
1740 |
} |
|
1741 |
CleanupStack::PopAndDestroy(&variant); |
|
1742 |
} |
|
1743 |
||
1744 |
//Async Call |
|
1745 |
if ( aCallback ) |
|
1746 |
{ |
|
1747 |
//Get the transaction ID |
|
1748 |
TInt32 transactionId(aCallback->GetTransactionID ( )); |
|
1749 |
CLandmarkCallbackMap* map = new (ELeave) CLandmarkCallbackMap(transactionId,aCallback); |
|
1750 |
CleanupStack::PushL (map ); |
|
1751 |
iCallbackMap.AppendL (map ); |
|
1752 |
CleanupStack::Pop (map ); |
|
1753 |
iService->GetListL (transactionId, *lmFilter, dbUri ); |
|
1754 |
||
1755 |
aOutParamList.AppendL (TLiwGenericParam (KTransactionId, |
|
1756 |
TLiwVariant (TInt32 (transactionId ) ) ) ); |
|
1757 |
} |
|
1758 |
else //sync call |
|
1759 |
{ |
|
1760 |
CPosLmItemIterator* iterator = NULL; |
|
1761 |
iService->GetListL (iterator, *lmFilter, dbUri ); |
|
1762 |
CleanupStack::PushL (iterator ); |
|
1763 |
// if dbURI is not specified retrieve default databse URI |
|
1764 |
if ( dbUri == KNullDesC ) |
|
1765 |
{ |
|
1766 |
iService->GetDefaultDbUriL (dbUri ); |
|
1767 |
} |
|
1768 |
||
1769 |
//instantiate CLandmarkIterable |
|
1770 |
CLiwIterable* iterable = CLandmarkCategoryIterable::NewL (iterator, |
|
1771 |
dbUri ); |
|
1772 |
CleanupStack::Pop (iterator ); |
|
1773 |
CleanupClosePushL (*iterable ); |
|
1774 |
//pack to aOutParamList |
|
1775 |
aOutParamList.AppendL (TLiwGenericParam (KReturnValue, |
|
1776 |
TLiwVariant (iterable ) ) ); |
|
1777 |
CleanupStack::PopAndDestroy(iterable); |
|
1778 |
} |
|
1779 |
CleanupStack::PopAndDestroy(&variantDb); |
|
1780 |
CleanupStack::PopAndDestroy (lmFilter ); |
|
1781 |
} |
|
1782 |
||
1783 |
// --------------------------------------------------------------------------- |
|
1784 |
// CLandmarkInterface::GetListDatabasesL(const CLiwGenericParamList& aInParamList |
|
1785 |
// CLiwGenericParamList& aOutParamList) |
|
1786 |
// This calls the appropriate service function for Getting List of |
|
1787 |
// available Databases. |
|
1788 |
// --------------------------------------------------------------------------- |
|
1789 |
// |
|
1790 |
void CLandmarkInterface::GetListDatabasesL( |
|
1791 |
const CLiwGenericParamList& aInParamList, |
|
1792 |
CLiwGenericParamList& aOutParamList ) |
|
1793 |
{ |
|
1794 |
CDesCArray* DbList= NULL; |
|
1795 |
//position to start search in input params |
|
1796 |
TInt index = 0; |
|
1797 |
//Flag for pos based |
|
1798 |
TBool posBased = EFalse; |
|
1799 |
//get filter if specified |
|
1800 |
const TLiwGenericParam* param= NULL; |
|
1801 |
if ( aInParamList.Count ( )> EIndex1 ) |
|
1802 |
{ |
|
1803 |
param = &aInParamList[EIndex1]; |
|
1804 |
//check whether pos based or value based |
|
1805 |
if ( param->Name ( )== KNullDesC8 ) |
|
1806 |
{ |
|
1807 |
posBased = ETrue; |
|
1808 |
} |
|
1809 |
} |
|
1810 |
if ( !posBased ) |
|
1811 |
{ |
|
1812 |
param = aInParamList.FindFirst (index, KFilter ); |
|
1813 |
} |
|
1814 |
if ( !param ) |
|
1815 |
{ |
|
1816 |
iService->GetListL (DbList ); |
|
1817 |
} |
|
1818 |
else |
|
1819 |
{ |
|
1820 |
TLiwVariant variant(param->Value ( )); |
|
1821 |
ValidateParamL (KGetList, KFilter, variant, LIW::EVariantTypeMap ); |
|
1822 |
const CLiwMap* CriteriaMap = variant.AsMap ( ); |
|
1823 |
CleanupStack::PushL( |
|
1824 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1825 |
if ( ValidateParamL (KGetList, KDbProtocol, CriteriaMap, |
|
1826 |
LIW::EVariantTypeDesC, ETrue, variant ) ) |
|
1827 |
{ |
|
1828 |
iService->GetListL (DbList, variant.AsDes ( ) ); |
|
1829 |
} |
|
1830 |
else |
|
1831 |
{ |
|
1832 |
iService->GetListL (DbList ); |
|
1833 |
} |
|
1834 |
CleanupStack::PopAndDestroy(&variant); |
|
1835 |
} |
|
1836 |
CleanupStack::PushL (DbList ); |
|
1837 |
param = NULL; |
|
1838 |
index = 0; |
|
1839 |
if ( posBased && aInParamList.Count ( )> EIndex2 ) |
|
1840 |
{ |
|
1841 |
param = &aInParamList[EIndex2]; |
|
1842 |
} |
|
1843 |
if ( !posBased ) |
|
1844 |
{ |
|
1845 |
param = aInParamList.FindFirst (index, KSort ); |
|
1846 |
} |
|
1847 |
||
1848 |
if ( param ) |
|
1849 |
{ |
|
1850 |
TLiwVariant variant(param->Value ( )); |
|
1851 |
ValidateParamL (KGetList, KSort, variant, LIW::EVariantTypeMap ); |
|
1852 |
const CLiwMap* sort = param->Value().AsMap ( ); |
|
1853 |
CleanupStack::PushL( |
|
1854 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1855 |
if ( ValidateParamL (KGetList, KSortOrder, sort, LIW::EVariantTypeDesC, |
|
1856 |
ETrue, variant ) ) |
|
1857 |
{ |
|
1858 |
TPtrC sortOrder = variant.AsDes ( ); |
|
1859 |
TBool compare = EFalse; |
|
1860 |
if ( sortOrder == KDescending ) |
|
1861 |
{ |
|
1862 |
index = DbList->Count(); |
|
1863 |
for(TInt i = 0 ; i<index ; i++) |
|
1864 |
{ |
|
1865 |
compare = EFalse; |
|
1866 |
for(TInt j = 0; j<(index-1); j++ ) |
|
1867 |
{ |
|
1868 |
TPtrC temp1(DbList->MdcaPoint(j)); |
|
1869 |
TPtrC temp2(DbList->MdcaPoint(j+1)); |
|
1870 |
if(temp1.Compare(temp2) < 1 ) |
|
1871 |
{ |
|
1872 |
DbList->InsertL(j,temp2); |
|
1873 |
DbList->InsertL(j+1,temp1); |
|
1874 |
DbList->Delete(j+2,2); |
|
1875 |
DbList->Compress(); |
|
1876 |
compare = ETrue; |
|
1877 |
} |
|
1878 |
} |
|
1879 |
if( !compare ) |
|
1880 |
{ |
|
1881 |
break; |
|
1882 |
} |
|
1883 |
} |
|
1884 |
} |
|
1885 |
else |
|
1886 |
if ( sortOrder != KAscending ) |
|
1887 |
{ |
|
1888 |
ErrorMessageL (KGetList, KSortOrder ); |
|
1889 |
iErrMsg->Des().Append (KInvalid ); |
|
1890 |
//leave since argument is improper |
|
1891 |
User::Leave (SErrInvalidServiceArgument ); |
|
1892 |
} |
|
1893 |
else |
|
1894 |
{ |
|
1895 |
index = DbList->Count(); |
|
1896 |
for(TInt i = 0 ; i<index ; i++) |
|
1897 |
{ |
|
1898 |
compare = EFalse; |
|
1899 |
for(TInt j = 0; j<(index-1); j++ ) |
|
1900 |
{ |
|
1901 |
TPtrC temp1(DbList->MdcaPoint(j)); |
|
1902 |
TPtrC temp2(DbList->MdcaPoint(j+1)); |
|
1903 |
if(temp1.Compare(temp2) > 1 ) |
|
1904 |
{ |
|
1905 |
DbList->InsertL(j,temp2); |
|
1906 |
DbList->InsertL(j+1,temp1); |
|
1907 |
DbList->Delete(j+2,2); |
|
1908 |
DbList->Compress(); |
|
1909 |
compare = ETrue; |
|
1910 |
} |
|
1911 |
} |
|
1912 |
if( !compare ) |
|
1913 |
{ |
|
1914 |
break; |
|
1915 |
} |
|
1916 |
} |
|
1917 |
} |
|
1918 |
} |
|
1919 |
CleanupStack::PopAndDestroy(&variant); |
|
1920 |
} |
|
1921 |
||
1922 |
CLiwIterable* iterable = CDatabaseIterable::NewL (DbList ); |
|
1923 |
CleanupStack::Pop (DbList ); |
|
1924 |
CleanupClosePushL(*iterable); |
|
1925 |
aOutParamList.AppendL (TLiwGenericParam (KReturnValue, |
|
1926 |
TLiwVariant (iterable ) ) ); |
|
1927 |
CleanupStack::PopAndDestroy(iterable); |
|
1928 |
} |
|
1929 |
||
1930 |
// --------------------------------------------------------------------------- |
|
1931 |
// CLandmarkInterface::AddLandmarksL(const CLiwGenericParamList& aInParamList ) |
|
1932 |
// This calls the appropriate service function for adding landmarks. |
|
1933 |
// --------------------------------------------------------------------------- |
|
1934 |
// |
|
1935 |
void CLandmarkInterface::AddLandmarksL( const CLiwGenericParamList& aInParamList, |
|
1936 |
CLiwGenericParamList& aOutParamList ) |
|
1937 |
{ |
|
1938 |
//position to start search in input params |
|
1939 |
TInt index = 0; |
|
1940 |
//find if filter is specified |
|
1941 |
const TLiwGenericParam* param = &aInParamList[EIndex1]; |
|
1942 |
if ( param->Name ( )!= KNullDesC8 ) |
|
1943 |
{ |
|
1944 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
1945 |
if ( !param ) |
|
1946 |
{ |
|
1947 |
ErrorMessageL (KAdd, KDataFields ); |
|
1948 |
iErrMsg->Des().Append (KMissing ); |
|
1949 |
//leave since argument is improper |
|
1950 |
User::Leave (SErrMissingArgument ); |
|
1951 |
} |
|
1952 |
} |
|
1953 |
TLiwVariant variant = param->Value ( ); |
|
1954 |
ValidateParamL (KAdd, KDataFields, variant, LIW::EVariantTypeMap ); |
|
1955 |
const CLiwMap* dataFields = variant.AsMap ( ); |
|
1956 |
CPosLandmark* landmark = NULL; |
|
1957 |
TBool update = EFalse; |
|
1958 |
TPtrC dbUri; |
|
1959 |
TLiwVariant variantDb; |
|
1960 |
TPosLmItemId lmid; |
|
1961 |
CleanupStack::PushL( |
|
1962 |
TCleanupItem( TLiwVariant::VariantCleanup, &variantDb ) ); |
|
1963 |
if ( ValidateParamL (KAdd, KDbUri, dataFields, LIW::EVariantTypeDesC, |
|
1964 |
EFalse, variantDb ) ) |
|
1965 |
{ |
|
1966 |
variantDb.Get (dbUri ); |
|
1967 |
} |
|
1968 |
CleanupStack::PushL( |
|
1969 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
1970 |
if ( ValidateParamL (KAdd, KId, dataFields, LIW::EVariantTypeDesC, |
|
1971 |
EFalse, variant ) ) |
|
1972 |
{ |
|
1973 |
update = ETrue; |
|
1974 |
TPtrC lmPtr(variant.AsDes ( )); |
|
1975 |
TLex lmparseString(lmPtr); //Get Id as string and convert to TUint32 |
|
1976 |
TInt parseErr = lmparseString.Val (lmid, EDecimal ); |
|
1977 |
TBuf<KMaxIDStringLength> lmIdString(KNullDesC ( )); |
|
1978 |
if ( !parseErr ) |
|
1979 |
{ |
|
1980 |
lmIdString.Num (lmid ); |
|
1981 |
} |
|
1982 |
if ( parseErr || lmIdString != lmPtr ) |
|
1983 |
{ |
|
1984 |
ErrorMessageL (KAdd, KId ); |
|
1985 |
iErrMsg->Des().Append (KInvalid ); |
|
1986 |
User::Leave (SErrInvalidServiceArgument ); |
|
1987 |
} |
|
1988 |
landmark = iService->LandmarkLC (lmid, dbUri ); |
|
1989 |
if ( !landmark ) |
|
1990 |
{ |
|
1991 |
//leave since landmark not found |
|
1992 |
User::Leave (KErrNotFound ); |
|
1993 |
} |
|
1994 |
} |
|
1995 |
else |
|
1996 |
{ |
|
1997 |
landmark = CPosLandmark::NewLC ( ); |
|
1998 |
} |
|
1999 |
if ( ValidateParamL (KAdd, KLandmarkName, dataFields, |
|
2000 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2001 |
{ |
|
2002 |
landmark->SetLandmarkNameL (variant.AsDes ( ) ); |
|
2003 |
} |
|
2004 |
if ( ValidateParamL (KAdd, KLandmarkPosition, dataFields, |
|
2005 |
LIW::EVariantTypeMap, EFalse, variant ) ) |
|
2006 |
{ |
|
2007 |
const CLiwMap* location = variant.AsMap ( ); |
|
2008 |
TLocality locale; |
|
2009 |
TReal latitude(0); |
|
2010 |
TReal longitude(0); |
|
2011 |
ValidateParamL (KAdd, KLatitude, location, LIW::EVariantTypeTReal, |
|
2012 |
ETrue, variant ); |
|
2013 |
latitude = variant.AsTReal ( ); |
|
2014 |
ValidateParamL (KAdd, KLongitude, location, |
|
2015 |
LIW::EVariantTypeTReal, ETrue, variant ); |
|
2016 |
longitude = variant.AsTReal ( ); |
|
2017 |
||
2018 |
if ( ValidateParamL (KAdd, KAltitude, location, LIW::EVariantTypeTReal, |
|
2019 |
EFalse, variant ) ) |
|
2020 |
{ |
|
2021 |
locale.SetCoordinate (latitude, longitude, variant.AsTReal ( ) ); |
|
2022 |
} |
|
2023 |
else |
|
2024 |
{ |
|
2025 |
locale.SetCoordinate (latitude, longitude ); |
|
2026 |
} |
|
2027 |
if ( ValidateParamL (KAdd, KHAccuracy, location, |
|
2028 |
LIW::EVariantTypeTReal, EFalse, variant ) ) |
|
2029 |
{ |
|
2030 |
TReal hacc(variant.AsTReal ( )); |
|
2031 |
if ( hacc < 0 ) |
|
2032 |
{ |
|
2033 |
ErrorMessageL (KAdd, KHAccuracy ); |
|
2034 |
iErrMsg->Des().Append (KInvalid ); |
|
2035 |
User::Leave (SErrInvalidServiceArgument ); |
|
2036 |
} |
|
2037 |
locale.SetHorizontalAccuracy (hacc ); |
|
2038 |
} |
|
2039 |
if ( ValidateParamL (KAdd, KVAccuracy, location, |
|
2040 |
LIW::EVariantTypeTReal, EFalse, variant ) ) |
|
2041 |
{ |
|
2042 |
TReal vacc(variant.AsTReal ( )); |
|
2043 |
if ( vacc < 0 ) |
|
2044 |
{ |
|
2045 |
ErrorMessageL (KAdd, KVAccuracy ); |
|
2046 |
iErrMsg->Des().Append (KInvalid ); |
|
2047 |
User::Leave (SErrInvalidServiceArgument ); |
|
2048 |
} |
|
2049 |
locale.SetVerticalAccuracy (vacc ); |
|
2050 |
} |
|
2051 |
landmark->SetPositionL (locale ); |
|
2052 |
} |
|
2053 |
if ( ValidateParamL (KAdd, KCoverageRadius, dataFields, |
|
2054 |
LIW::EVariantTypeTReal, EFalse, variant ) ) |
|
2055 |
{ |
|
2056 |
TReal covRad = variant.AsTReal ( ); |
|
2057 |
if ( covRad < 0 ) |
|
2058 |
{ |
|
2059 |
ErrorMessageL (KAdd, KCoverageRadius ); |
|
2060 |
iErrMsg->Des().Append (KInvalid ); |
|
2061 |
User::Leave (SErrInvalidServiceArgument ); |
|
2062 |
} |
|
2063 |
landmark->SetCoverageRadius (covRad ); |
|
2064 |
} |
|
2065 |
if ( ValidateParamL (KAdd, KCategoryInfo, dataFields, |
|
2066 |
LIW::EVariantTypeList, EFalse, variant ) ) |
|
2067 |
{ |
|
2068 |
const CLiwList* category = variant.AsList ( ); |
|
2069 |
TInt count = category->Count ( ); |
|
2070 |
for (TInt index = 0; index < count; ++index ) |
|
2071 |
{ |
|
2072 |
if ( category->AtL (index, variant ) ) |
|
2073 |
{ |
|
2074 |
ValidateParamL (KAdd, KId, variant, |
|
2075 |
LIW::EVariantTypeDesC ); |
|
2076 |
TPtrC catPtr(variant.AsDes ( )); |
|
2077 |
TLex catparseString(catPtr); //Get Id as string and convert to TUint32 |
|
2078 |
TPosLmItemId catid; |
|
2079 |
TInt parseErr = catparseString.Val (catid, EDecimal ); |
|
2080 |
TBuf<KMaxIDStringLength> catIdString(KNullDesC ( )); |
|
2081 |
if ( !parseErr ) |
|
2082 |
{ |
|
2083 |
catIdString.Num (catid ); |
|
2084 |
} |
|
2085 |
if ( parseErr || catIdString != catPtr ) |
|
2086 |
{ |
|
2087 |
ErrorMessageL (KAdd, KId ); |
|
2088 |
iErrMsg->Des().Append (KInvalid ); |
|
2089 |
User::Leave (SErrInvalidServiceArgument ); |
|
2090 |
} |
|
2091 |
landmark->AddCategoryL (catid ); |
|
2092 |
} |
|
2093 |
} |
|
2094 |
} |
|
2095 |
if ( ValidateParamL (KAdd, KIconFile, dataFields, LIW::EVariantTypeDesC, |
|
2096 |
EFalse, variant ) ) |
|
2097 |
{ |
|
2098 |
TPtrC iconFile = variant.AsDes ( ); |
|
2099 |
if ( iconFile == KNullDesC ) |
|
2100 |
{ |
|
2101 |
ErrorMessageL (KAdd, KIconFile ); |
|
2102 |
iErrMsg->Des().Append (KInvalid ); |
|
2103 |
User::Leave (SErrInvalidServiceArgument ); |
|
2104 |
} |
|
2105 |
TLiwVariant iconVariant; |
|
2106 |
CleanupStack::PushL( |
|
2107 |
TCleanupItem( TLiwVariant::VariantCleanup, &iconVariant ) ); |
|
2108 |
ValidateParamL (KAdd, KIconIndex, dataFields, LIW::EVariantTypeTInt32, |
|
2109 |
ETrue, iconVariant ); |
|
2110 |
TInt32 iconIndex = iconVariant.AsTInt32 ( ); |
|
2111 |
if ( iconIndex < 0 ) |
|
2112 |
{ |
|
2113 |
ErrorMessageL (KAdd, KIconIndex ); |
|
2114 |
iErrMsg->Des().Append (KInvalid ); |
|
2115 |
User::Leave (SErrInvalidServiceArgument ); |
|
2116 |
} |
|
2117 |
TInt32 iconMaskIndex = KPosLmIconMaskNotUsed; |
|
2118 |
if ( ValidateParamL (KAdd, KIconMaskIndex, dataFields, |
|
2119 |
LIW::EVariantTypeTInt32, ETrue, iconVariant ) ) |
|
2120 |
{ |
|
2121 |
iconMaskIndex = iconVariant.AsTInt32 ( ); |
|
2122 |
if ( iconMaskIndex < KPosLmIconMaskNotUsed ) |
|
2123 |
{ |
|
2124 |
ErrorMessageL (KAdd, KIconMaskIndex ); |
|
2125 |
iErrMsg->Des().Append (KInvalid ); |
|
2126 |
User::Leave (SErrInvalidServiceArgument ); |
|
2127 |
} |
|
2128 |
} |
|
2129 |
landmark->SetIconL (iconFile, iconIndex, iconMaskIndex ); |
|
2130 |
CleanupStack::PopAndDestroy(&iconVariant); |
|
2131 |
} |
|
2132 |
if ( ValidateParamL (KAdd, KLandmarkDesc, dataFields, |
|
2133 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2134 |
{ |
|
2135 |
landmark->SetLandmarkDescriptionL (variant.AsDes ( ) ); |
|
2136 |
} |
|
2137 |
if ( ValidateParamL (KAdd, KLandmarkFields, dataFields, |
|
2138 |
LIW::EVariantTypeMap, EFalse, variant ) ) |
|
2139 |
{ |
|
2140 |
const CLiwMap* lmFields = variant.AsMap ( ); |
|
2141 |
if ( ValidateParamL (KAdd, KLandmarkCountry, lmFields, |
|
2142 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2143 |
{ |
|
2144 |
landmark->SetPositionFieldL (EPositionFieldCountry, |
|
2145 |
variant.AsDes ( ) ); |
|
2146 |
} |
|
2147 |
if ( ValidateParamL (KAdd, KLandmarkAreaCode, lmFields, |
|
2148 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2149 |
{ |
|
2150 |
landmark->SetPositionFieldL (EPositionFieldPostalCode, |
|
2151 |
variant.AsDes ( ) ); |
|
2152 |
} |
|
2153 |
if ( ValidateParamL (KAdd, KLandmarkCity, lmFields, |
|
2154 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2155 |
{ |
|
2156 |
landmark->SetPositionFieldL (EPositionFieldCity, variant.AsDes ( ) ); |
|
2157 |
} |
|
2158 |
if ( ValidateParamL (KAdd, KLandmarkDistrict, lmFields, |
|
2159 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2160 |
{ |
|
2161 |
landmark->SetPositionFieldL (EPositionFieldDistrict, |
|
2162 |
variant.AsDes ( ) ); |
|
2163 |
} |
|
2164 |
if ( ValidateParamL (KAdd, KLandmarkBuildingName, lmFields, |
|
2165 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2166 |
{ |
|
2167 |
landmark->SetPositionFieldL (EPositionFieldBuildingName, |
|
2168 |
variant.AsDes ( ) ); |
|
2169 |
} |
|
2170 |
if ( ValidateParamL (KAdd, KLandmarkStreet, lmFields, |
|
2171 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2172 |
{ |
|
2173 |
landmark->SetPositionFieldL (EPositionFieldStreet, variant.AsDes ( ) ); |
|
2174 |
} |
|
2175 |
if ( ValidateParamL (KAdd, KLandmarkTelephone, lmFields, |
|
2176 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2177 |
{ |
|
2178 |
landmark->SetPositionFieldL (EPositionFieldBuildingTelephone, |
|
2179 |
variant.AsDes ( ) ); |
|
2180 |
} |
|
2181 |
} |
|
2182 |
//checks if the landmark passed is to update an existing lanmark or add a |
|
2183 |
//new landmark. |
|
2184 |
if ( update ) |
|
2185 |
{ |
|
2186 |
iService->UpdateItemL (*landmark, dbUri ); |
|
2187 |
} |
|
2188 |
else |
|
2189 |
{ |
|
2190 |
lmid = iService->AddItemL (*landmark, dbUri ); |
|
2191 |
} |
|
2192 |
CleanupStack::PopAndDestroy (landmark ); |
|
2193 |
CleanupStack::PopAndDestroy(&variant); |
|
2194 |
CleanupStack::PopAndDestroy(&variantDb); |
|
2195 |
||
2196 |
iId = HBufC::NewL(KMaxIDStringLength); |
|
2197 |
iId->Des().Num(lmid,EDecimal); |
|
2198 |
aOutParamList.AppendL (TLiwGenericParam (KReturnValue, |
|
2199 |
TLiwVariant (iId ) ) ); |
|
2200 |
} |
|
2201 |
||
2202 |
// --------------------------------------------------------------------------- |
|
2203 |
// CLandmarkInterface::AddCategoryL(const CLiwGenericParamList& aInParamList) |
|
2204 |
// This calls the appropriate service function for adding a category. |
|
2205 |
// --------------------------------------------------------------------------- |
|
2206 |
// |
|
2207 |
void CLandmarkInterface::AddCategoryL(const CLiwGenericParamList& aInParamList, |
|
2208 |
CLiwGenericParamList& aOutParamList ) |
|
2209 |
{ |
|
2210 |
//position to start search in input params |
|
2211 |
TInt index = 0; |
|
2212 |
//find if filter is specified |
|
2213 |
const TLiwGenericParam* param = &aInParamList[EIndex1]; |
|
2214 |
if ( param->Name ( )!= KNullDesC8 ) |
|
2215 |
{ |
|
2216 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
2217 |
if ( !param ) |
|
2218 |
{ |
|
2219 |
ErrorMessageL (KAdd, KDataFields ); |
|
2220 |
iErrMsg->Des().Append (KMissing ); |
|
2221 |
//leave since argument is improper |
|
2222 |
User::Leave (SErrMissingArgument ); |
|
2223 |
} |
|
2224 |
} |
|
2225 |
TLiwVariant variant = param->Value ( ); |
|
2226 |
ValidateParamL (KAdd, KDataFields, variant, LIW::EVariantTypeMap ); |
|
2227 |
const CLiwMap* dataFields = variant.AsMap ( ); |
|
2228 |
CPosLandmarkCategory* category= NULL; |
|
2229 |
TBool update = EFalse; |
|
2230 |
TPtrC dbUri; |
|
2231 |
TLiwVariant variantDb; |
|
2232 |
TPosLmItemId catid; |
|
2233 |
CleanupStack::PushL( |
|
2234 |
TCleanupItem( TLiwVariant::VariantCleanup, &variantDb ) ); |
|
2235 |
if ( ValidateParamL (KAdd, KDbUri, dataFields, LIW::EVariantTypeDesC, |
|
2236 |
EFalse, variantDb ) ) |
|
2237 |
{ |
|
2238 |
variantDb.Get (dbUri ); |
|
2239 |
} |
|
2240 |
CleanupStack::PushL( |
|
2241 |
TCleanupItem( TLiwVariant::VariantCleanup, &variant ) ); |
|
2242 |
/*if ( ValidateParamL (KAdd, KGlobalCategory, dataFields, |
|
2243 |
LIW::EVariantTypeDesC, EFalse, variant ) ) |
|
2244 |
{ |
|
2245 |
ErrorMessageL (KAdd, KGlobalCategory ); |
|
2246 |
iErrMsg->Des().Append (KInvalid ); |
|
2247 |
//leave since argument is improper |
|
2248 |
User::Leave (SErrInvalidServiceArgument ); |
|
2249 |
}*/ |
|
2250 |
if ( ValidateParamL (KAdd, KId, dataFields, LIW::EVariantTypeDesC, |
|
2251 |
EFalse, variant ) ) |
|
2252 |
{ |
|
2253 |
update = ETrue; |
|
2254 |
TPtrC catPtr(variant.AsDes ( )); |
|
2255 |
TLex catparseString(catPtr); //Get Id as string and convert to TUint32 |
|
2256 |
TInt parseErr = catparseString.Val (catid, EDecimal ); |
|
2257 |
||
2258 |
TBuf<KMaxIDStringLength> catIdString(KNullDesC ( )); |
|
2259 |
if ( !parseErr ) |
|
2260 |
{ |
|
2261 |
catIdString.Num (catid ); |
|
2262 |
} |
|
2263 |
if ( parseErr || catIdString != catPtr ) |
|
2264 |
{ |
|
2265 |
ErrorMessageL (KAdd, KId ); |
|
2266 |
iErrMsg->Des().Append (KInvalid ); |
|
2267 |
User::Leave (SErrInvalidServiceArgument ); |
|
2268 |
} |
|
2269 |
category = iService->CategoryLC (catid, dbUri ); |
|
2270 |
if ( !category ) |
|
2271 |
{ |
|
2272 |
//leave since landmark not found |
|
2273 |
User::Leave (KErrNotFound ); |
|
2274 |
} |
|
2275 |
} |
|
2276 |
else |
|
2277 |
{ |
|
2278 |
category = CPosLandmarkCategory::NewLC ( ); |
|
2279 |
} |
|
2280 |
ValidateParamL (KAdd, KCategoryName, dataFields, LIW::EVariantTypeDesC, |
|
2281 |
ETrue, variant ); |
|
2282 |
category->SetCategoryNameL (variant.AsDes ( ) ); |
|
2283 |
if ( ValidateParamL (KAdd, KIconFile, dataFields, LIW::EVariantTypeDesC, |
|
2284 |
EFalse, variant ) ) |
|
2285 |
{ |
|
2286 |
TPtrC iconFile = variant.AsDes ( ); |
|
2287 |
if ( iconFile == KNullDesC ) |
|
2288 |
{ |
|
2289 |
ErrorMessageL (KAdd, KIconFile ); |
|
2290 |
iErrMsg->Des().Append (KInvalid ); |
|
2291 |
User::Leave (SErrInvalidServiceArgument ); |
|
2292 |
} |
|
2293 |
TLiwVariant iconVariant; |
|
2294 |
CleanupStack::PushL( |
|
2295 |
TCleanupItem( TLiwVariant::VariantCleanup, &iconVariant ) ); |
|
2296 |
ValidateParamL (KAdd, KIconIndex, dataFields, LIW::EVariantTypeTInt32, |
|
2297 |
ETrue, iconVariant ); |
|
2298 |
TInt32 iconIndex = iconVariant.AsTInt32 ( ); |
|
2299 |
if ( iconIndex < 0 ) |
|
2300 |
{ |
|
2301 |
ErrorMessageL (KAdd, KIconIndex ); |
|
2302 |
iErrMsg->Des().Append (KInvalid ); |
|
2303 |
User::Leave (SErrInvalidServiceArgument ); |
|
2304 |
} |
|
2305 |
TInt32 iconMaskIndex = KPosLmIconMaskNotUsed; |
|
2306 |
if ( ValidateParamL (KAdd, KIconMaskIndex, dataFields, |
|
2307 |
LIW::EVariantTypeTInt32, ETrue, iconVariant ) ) |
|
2308 |
{ |
|
2309 |
iconMaskIndex = iconVariant.AsTInt32 ( ); |
|
2310 |
if ( iconMaskIndex < KPosLmIconMaskNotUsed ) |
|
2311 |
{ |
|
2312 |
ErrorMessageL (KAdd, KIconMaskIndex ); |
|
2313 |
iErrMsg->Des().Append (KInvalid ); |
|
2314 |
User::Leave (SErrInvalidServiceArgument ); |
|
2315 |
} |
|
2316 |
} |
|
2317 |
category->SetIconL (iconFile, iconIndex, iconMaskIndex ); |
|
2318 |
CleanupStack::PopAndDestroy(&iconVariant); |
|
2319 |
} |
|
2320 |
||
2321 |
if ( update ) |
|
2322 |
{ |
|
2323 |
iService->UpdateItemL (*category, dbUri ); |
|
2324 |
} |
|
2325 |
else |
|
2326 |
{ |
|
2327 |
catid = iService->AddItemL (*category, dbUri ); |
|
2328 |
} |
|
2329 |
||
2330 |
CleanupStack::PopAndDestroy (category ); |
|
2331 |
CleanupStack::PopAndDestroy(&variant); |
|
2332 |
CleanupStack::PopAndDestroy(&variantDb); |
|
2333 |
||
2334 |
iId = HBufC::NewL(KMaxIDStringLength); |
|
2335 |
iId->Des().Num(catid,EDecimal); |
|
2336 |
aOutParamList.AppendL (TLiwGenericParam (KReturnValue, |
|
2337 |
TLiwVariant (iId ) ) ); |
|
2338 |
} |
|
2339 |
||
2340 |
// --------------------------------------------------------------------------- |
|
2341 |
// CLandmarkInterface::AddDatabaseL(const CLiwGenericParamList& aInParamList) |
|
2342 |
// This calls the appropriate service function for adding a database. |
|
2343 |
// --------------------------------------------------------------------------- |
|
2344 |
// |
|
2345 |
void CLandmarkInterface::AddDatabaseL(const CLiwGenericParamList& aInParamList ) |
|
2346 |
{ |
|
2347 |
//position to start search in input params |
|
2348 |
TInt index = 0; |
|
2349 |
//find if filter is specified |
|
2350 |
const TLiwGenericParam* param = &aInParamList[EIndex1]; |
|
2351 |
if ( param->Name ( )!= KNullDesC8 ) |
|
2352 |
{ |
|
2353 |
param = aInParamList.FindFirst (index, KDataFields ); |
|
2354 |
if ( !param ) |
|
2355 |
{ |
|
2356 |
ErrorMessageL (KAdd, KDataFields ); |
|
2357 |
iErrMsg->Des().Append (KMissing ); |
|
2358 |
//leave since argument is improper |
|
2359 |
User::Leave (SErrMissingArgument ); |
|
2360 |
} |
|
2361 |
} |
|
2362 |
TLiwVariant variant = param->Value ( ); |
|
2363 |
ValidateParamL (KAdd, KDataFields, variant, LIW::EVariantTypeMap ); |
|
2364 |
const CLiwMap* dataFields = variant.AsMap ( ); |
|
2365 |
TLiwVariant dbname; |
|
2366 |
TLiwVariant dburi; |
|
2367 |
CleanupStack::PushL( |
|
2368 |
TCleanupItem( TLiwVariant::VariantCleanup, &dburi ) ); |
|
2369 |
ValidateParamL (KAdd, KDbUri, dataFields, LIW::EVariantTypeDesC, ETrue, |
|
2370 |
dburi ); |
|
2371 |
TRAPD(err,iService->AddItemL (dburi.AsDes())); |
|
2372 |
if ( err && (err != KErrAlreadyExists) ) |
|
2373 |
{ |
|
2374 |
User::Leave (err ); |
|
2375 |
} |
|
2376 |
//existing database will be updated. |
|
2377 |
CleanupStack::PushL( |
|
2378 |
TCleanupItem( TLiwVariant::VariantCleanup, &dbname ) ); |
|
2379 |
if ( ValidateParamL (KAdd, KDbName, dataFields, LIW::EVariantTypeDesC, |
|
2380 |
EFalse, dbname ) ) |
|
2381 |
{ |
|
2382 |
TPosLmDatabaseSettings settings; |
|
2383 |
TPosLmDatabaseName name(dbname.AsDes ( )); |
|
2384 |
settings.SetDatabaseName (name ); |
|
2385 |
iService->UpdateItemL (settings, dburi.AsDes ( ) ); |
|
2386 |
} |
|
2387 |
CleanupStack::PopAndDestroy(&dbname); |
|
2388 |
CleanupStack::PopAndDestroy(&dburi); |
|
2389 |
} |
|
2390 |
||
2391 |
void CLandmarkInterface::ErrorMessageL( const TDesC8& aServiceCmd, |
|
2392 |
const TDesC8& aKey ) |
|
2393 |
{ |
|
2394 |
iErrMsg = HBufC::NewL (KMaxMsgSize ); |
|
2395 |
*iErrMsg = KModule ( ); |
|
2396 |
TPtr ptr(iErrMsg->Des ( )); |
|
2397 |
TBuf<KMaxKeySize> buf; |
|
2398 |
buf.Copy (aServiceCmd ); |
|
2399 |
ptr.Append (buf ); |
|
2400 |
ptr.Append (KColon ( ) ); |
|
2401 |
buf.Copy (aKey ); |
|
2402 |
ptr.Append (buf ); |
|
2403 |
} |
|
2404 |
||
2405 |
void CLandmarkInterface::ValidateParamL( const TDesC8& aServiceCmd, |
|
2406 |
const TDesC8& aKey, const TLiwVariant& aVariant, |
|
2407 |
LIW::TVariantTypeId aType ) |
|
2408 |
{ |
|
2409 |
if ( aVariant.TypeId ( )!= aType ) |
|
2410 |
{ |
|
2411 |
//Number handling relaxation |
|
2412 |
if( !(LIW::EVariantTypeTReal == aType && LIW::EVariantTypeTInt32 == aVariant.TypeId ()) ) |
|
2413 |
{ |
|
2414 |
ErrorMessageL ( aServiceCmd, aKey ); |
|
2415 |
TPtr ptr(iErrMsg->Des ( )); |
|
2416 |
ptr.Append (KInvalid ( ) ); |
|
2417 |
User::Leave (KErrArgument ); |
|
2418 |
} |
|
2419 |
} |
|
2420 |
} |
|
2421 |
||
2422 |
TBool CLandmarkInterface::ValidateParamL( const TDesC8& aServiceCmd, |
|
2423 |
const TDesC8& aKey, const CLiwMap* aMap, LIW::TVariantTypeId aType, |
|
2424 |
TBool isMandatory, TLiwVariant& aOutVariant ) |
|
2425 |
{ |
|
2426 |
TBool status = ETrue; |
|
2427 |
TBool present = aMap->FindL (aKey, aOutVariant ); |
|
2428 |
if ( !present && isMandatory ) |
|
2429 |
{ |
|
2430 |
ErrorMessageL ( aServiceCmd, aKey ); |
|
2431 |
TPtr ptr(iErrMsg->Des ( )); |
|
2432 |
ptr.Append (KMissing ( ) ); |
|
2433 |
User::Leave (SErrMissingArgument ); |
|
2434 |
} |
|
2435 |
else |
|
2436 |
if ( !present && !isMandatory ) |
|
2437 |
{ |
|
2438 |
status = EFalse; |
|
2439 |
} |
|
2440 |
if ( status ) |
|
2441 |
{ |
|
2442 |
ValidateParamL (aServiceCmd, aKey, aOutVariant, aType ); |
|
2443 |
} |
|
2444 |
return status; |
|
2445 |
} |
|
2446 |
||
2447 |
//end of file |