|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Provides interface between the Liw FrameWork and Service Provider. |
|
15 * |
|
16 */ |
|
17 |
|
18 //system include |
|
19 #include <LiwVariant.h> |
|
20 #include <LiwGenericParam.h> |
|
21 #include <LiwCommon.h> |
|
22 #include <sensrvchannelinfo.h> |
|
23 #include <sensrvtypes.h> |
|
24 |
|
25 // User Includes |
|
26 #include "sensorservice.h" |
|
27 #include "sensorinterface.h" |
|
28 #include "sensorservice.hrh" |
|
29 #include "sensorcallback.h" |
|
30 #include "storeasyncinfo.h" |
|
31 |
|
32 inline void CSensorInterface::CheckInputTypeL |
|
33 ( const TLiwVariant* aSource, |
|
34 LIW::TVariantTypeId aExpectedtype, |
|
35 const TDesC8* aErrorArgument ) |
|
36 { |
|
37 if( aSource->TypeId() != aExpectedtype ) |
|
38 { |
|
39 iErrorString = HBufC::NewL(KMaxMsgSize); |
|
40 TPtr ptr(iErrorString->Des()); |
|
41 TBuf<KMaxKeySize> buf; |
|
42 buf.Copy( *aErrorArgument ); |
|
43 ptr.Append(buf); |
|
44 ptr.Append( KTypeErr.operator()()); |
|
45 ptr.Append( KInvalid.operator()()); |
|
46 User::Leave( KErrArgument ); |
|
47 } |
|
48 } |
|
49 |
|
50 inline void CSensorInterface::MissingValueL( const TDesC8* aErrorArgument ) |
|
51 { |
|
52 iErrorString = HBufC::NewL(KMaxMsgSize); |
|
53 TPtr ptr(iErrorString->Des()); |
|
54 TBuf<KMaxKeySize> buf; |
|
55 buf.Copy( *aErrorArgument ); |
|
56 ptr.Append(buf); |
|
57 ptr.Append( KMissing.operator()()); |
|
58 User::Leave( SErrMissingArgument ); |
|
59 } |
|
60 |
|
61 |
|
62 /* |
|
63 ----------------------------------------------------------------------------- |
|
64 CSensorInterface::CSensorInterface() |
|
65 Description : Constructor |
|
66 Return values : N/A |
|
67 ----------------------------------------------------------------------------- |
|
68 */ |
|
69 CSensorInterface::CSensorInterface() |
|
70 : iSensorService( NULL ) |
|
71 { |
|
72 } |
|
73 |
|
74 /* |
|
75 ----------------------------------------------------------------------------- |
|
76 void CSensorInterface::ConstructL() |
|
77 Description : Symbian 2nd phase constructor can leave. |
|
78 Return values : N/A |
|
79 ----------------------------------------------------------------------------- |
|
80 */ |
|
81 void CSensorInterface::ConstructL() |
|
82 { |
|
83 iSensorService = CSensorService::NewL(); |
|
84 } |
|
85 |
|
86 |
|
87 /* |
|
88 ----------------------------------------------------------------------------- |
|
89 CSensorInterface::ExecuteServiceCommandL() |
|
90 Description : This is called by the consumer with command to execute. |
|
91 Return values : N/A |
|
92 ----------------------------------------------------------------------------- |
|
93 */ |
|
94 void CSensorInterface::ExecuteServiceCommandL |
|
95 ( const TDesC8& aCmdName, |
|
96 const CLiwGenericParamList& aInParamList, |
|
97 CLiwGenericParamList& aOutParamList, |
|
98 TUint aCmdOptions, |
|
99 MLiwNotifyCallback* aCallback ) |
|
100 { |
|
101 |
|
102 aOutParamList.Reset(); |
|
103 |
|
104 TInt position = 0; |
|
105 TInt32 transId = 0; |
|
106 |
|
107 // Start of FindSensorChannel |
|
108 if ( (aCmdName.CompareF( KCmdFindChannel ) == 0) ) |
|
109 { |
|
110 if( aCallback ) |
|
111 { |
|
112 iErrorString = KErrSensorInvalidReq.operator()().Alloc(); |
|
113 User::Leave( SErrInvalidServiceArgument ); |
|
114 } |
|
115 |
|
116 TPtrC searchString; |
|
117 const TLiwGenericParam* findString = NULL; |
|
118 findString = aInParamList.FindFirst( position, KSearchCriterion ); |
|
119 |
|
120 if ( !findString ) |
|
121 { |
|
122 //Position based parsing |
|
123 if( aInParamList.Count() != 0 ) |
|
124 { |
|
125 findString = &aInParamList[EParamIndex0]; |
|
126 } |
|
127 else |
|
128 { |
|
129 iErrorString = KErrFindSensorChannelMissingSearchCrit.operator()().Alloc(); |
|
130 User::Leave( SErrMissingArgument ); |
|
131 } |
|
132 } |
|
133 |
|
134 TInt searchCriterion = 0; |
|
135 |
|
136 CheckInputTypeL( &findString->Value(), |
|
137 LIW::EVariantTypeDesC, |
|
138 KErrFindSensorChannelBadSrchType.operator&() ); |
|
139 |
|
140 // Retrieve channel search condition specified in input parameter list |
|
141 findString->Value().Get( searchString ); |
|
142 |
|
143 if ( searchString == KAll ) |
|
144 searchCriterion = EFindAll; |
|
145 else if ( searchString == KAcclmtrAxis ) |
|
146 searchCriterion = EFindAccelerometerXYZAxisData; |
|
147 else if ( searchString == KAcclmtrDoubleTapping ) |
|
148 searchCriterion = EFindAccelerometerDoubleTappingData; |
|
149 else if ( searchString == KOrientation ) |
|
150 searchCriterion = EFindOrientationData; |
|
151 else if ( searchString == KRotation ) |
|
152 searchCriterion = EFindRotationData; |
|
153 else |
|
154 { |
|
155 iErrorString = KErrFindSensorChannelInvalidSrch.operator()().Alloc(); |
|
156 User::Leave( SErrInvalidServiceArgument ); |
|
157 } |
|
158 |
|
159 // channelInfoList will be populated by core class API |
|
160 RSensrvChannelInfoList channelInfoList; |
|
161 CleanupClosePushL( channelInfoList ); |
|
162 |
|
163 iSensorService->FindSensorChannelsL( searchCriterion , |
|
164 channelInfoList ); |
|
165 |
|
166 // Create list instance |
|
167 CLiwDefaultList* chnlList = CLiwDefaultList::NewL(); |
|
168 CleanupStack::PushL( chnlList ); |
|
169 // Obtain channel info list |
|
170 |
|
171 AppendChannelInfoL( channelInfoList ,chnlList ); |
|
172 |
|
173 // Appending result to the output parameter list |
|
174 aOutParamList.AppendL( TLiwGenericParam( KReturnValue, |
|
175 TLiwVariant( chnlList ) ) ); |
|
176 |
|
177 CleanupStack::Pop( chnlList ); |
|
178 CleanupStack::PopAndDestroy( &channelInfoList ); |
|
179 chnlList->DecRef(); |
|
180 |
|
181 }//end of FindSensorChannel |
|
182 //Start of RegisterForNotification |
|
183 else if ( ( aCmdName.CompareF( KCmdRegisterForNotification ) == 0 ) ) |
|
184 { |
|
185 |
|
186 if( ( aCallback && ( KLiwOptASyncronous & aCmdOptions ) ) ) |
|
187 { |
|
188 |
|
189 transId = aCallback->GetTransactionID(); |
|
190 |
|
191 TPtrC listeningStrPtr; |
|
192 const TLiwGenericParam* listeningString = NULL; |
|
193 const TLiwGenericParam* chnlInfoParam = NULL; |
|
194 CStoreAsyncInfo* info = NULL; |
|
195 TSensrvChannelInfo channelInfo; |
|
196 |
|
197 if( aInParamList.Count() < 2 ) |
|
198 { |
|
199 iErrorString = KErrRegNotEnoughParams.operator()().Alloc(); |
|
200 User::Leave( SErrMissingArgument ); |
|
201 } |
|
202 |
|
203 position = 0; |
|
204 listeningString = aInParamList.FindFirst( position, KListeningType ); |
|
205 position = 0; |
|
206 chnlInfoParam = aInParamList.FindFirst( position, KChnlInfoMap ); |
|
207 if( !listeningString ) |
|
208 { |
|
209 //position based parsing |
|
210 listeningString = &aInParamList[EParamIndex0]; |
|
211 if ( ( !listeningString ) ) |
|
212 { |
|
213 iErrorString = KErrRegNotifyMissingListening.operator()().Alloc(); |
|
214 User::Leave( SErrMissingArgument ); |
|
215 } |
|
216 |
|
217 chnlInfoParam = &aInParamList[EParamIndex1]; |
|
218 if ( ( !chnlInfoParam ) ) |
|
219 { |
|
220 iErrorString = KErrMissingChnlMap.operator()().Alloc(); |
|
221 User::Leave( SErrMissingArgument ); |
|
222 } |
|
223 } |
|
224 |
|
225 CheckInputTypeL( &listeningString->Value(), |
|
226 LIW::EVariantTypeDesC, |
|
227 KErrRegNotifyInvalidListeningType.operator&() ); |
|
228 |
|
229 CheckInputTypeL( &chnlInfoParam->Value(), |
|
230 LIW::EVariantTypeMap, |
|
231 KChnlInfoMap.operator&() ); |
|
232 |
|
233 // Retrieve Listening Type |
|
234 listeningString->Value().Get( listeningStrPtr ); |
|
235 |
|
236 //Leave if there is no listening type or is invalid |
|
237 if( listeningStrPtr != KChnlData ) |
|
238 { |
|
239 iErrorString = KErrRegNotifyInvalidListening.operator()().Alloc(); |
|
240 User::Leave( SErrInvalidServiceArgument ); |
|
241 } |
|
242 |
|
243 const CLiwMap* chnlInfoMap = ( chnlInfoParam->Value() ).AsMap(); |
|
244 //Retrieve channel information from input List |
|
245 GetChannelInfoL( channelInfo ,chnlInfoMap ); |
|
246 |
|
247 //Create CallBack |
|
248 CSensorCallback* callBack = CSensorCallback::NewL( aCallback, |
|
249 transId ); |
|
250 CleanupStack::PushL( callBack ); |
|
251 TAsyncType asyncType(EInvalid); |
|
252 TInt notificationErr(0); |
|
253 //Data notification |
|
254 if ( listeningStrPtr == KChnlData ) |
|
255 { |
|
256 TRAP( notificationErr, iSensorService->GetDataNotificationL |
|
257 ( channelInfo, |
|
258 callBack ) ); |
|
259 |
|
260 if( notificationErr != KErrNone ) |
|
261 { |
|
262 iErrorString = KErrInvalidNotif.operator()().Alloc(); |
|
263 User::Leave( KErrInUse ); |
|
264 } |
|
265 |
|
266 asyncType = EData; |
|
267 } |
|
268 else |
|
269 { |
|
270 iErrorString = KErrRegNotifyInvalidListening.operator()().Alloc(); |
|
271 User::Leave( SErrInvalidServiceArgument ); |
|
272 } |
|
273 |
|
274 // Store information about this async call |
|
275 info = CStoreAsyncInfo::NewL( asyncType, |
|
276 transId, |
|
277 callBack, |
|
278 channelInfo.iChannelId ); |
|
279 iAsyncInfo.Append( info ); |
|
280 |
|
281 //Appending trans id to the output parameter list |
|
282 aOutParamList.AppendL( TLiwGenericParam( KTransactionId , |
|
283 TLiwVariant ( ( TInt32 )transId ) ) ); |
|
284 |
|
285 CleanupStack::Pop( callBack ); |
|
286 |
|
287 } |
|
288 else |
|
289 { |
|
290 iErrorString = KErrRegNotifyAsyncbit.operator()().Alloc(); |
|
291 User::Leave( SErrMissingArgument ); |
|
292 } |
|
293 |
|
294 }//End of RegisterForNotification |
|
295 // Start of StopNotification |
|
296 else if ( ( aCmdName.CompareF( KStopNotification ) == 0 ) ) |
|
297 { |
|
298 |
|
299 if( aCallback ) |
|
300 { |
|
301 iErrorString = KErrSensorInvalidReq.operator()().Alloc(); |
|
302 User::Leave( SErrInvalidServiceArgument ); |
|
303 } |
|
304 |
|
305 if( ! ( KLiwOptCancel & aCmdOptions) ) |
|
306 { |
|
307 iErrorString = KErrStopNotifCancelBit.operator()().Alloc(); |
|
308 User::Leave( SErrMissingArgument ); |
|
309 } |
|
310 |
|
311 TInt32 transId = 0; |
|
312 const TLiwGenericParam* transIdParam = NULL; |
|
313 TAsyncType asyncType; |
|
314 TUint chnlId = 0; |
|
315 TInt asyncCount = 0; |
|
316 CStoreAsyncInfo* info = NULL; |
|
317 TInt i = 0; |
|
318 TBool transFound = FALSE; |
|
319 |
|
320 position = 0; |
|
321 transIdParam = aInParamList.FindFirst( position , KTransactionId ); |
|
322 position = 0; |
|
323 |
|
324 if ( !transIdParam ) |
|
325 { |
|
326 if( aInParamList.Count() != 0 ) |
|
327 { |
|
328 transIdParam = &aInParamList[EParamIndex0]; |
|
329 } |
|
330 else |
|
331 { |
|
332 iErrorString = KErrStopNotifMissingTransId.operator()().Alloc(); |
|
333 User::Leave( SErrMissingArgument ); |
|
334 } |
|
335 } |
|
336 |
|
337 CheckInputTypeL( &transIdParam->Value(), |
|
338 LIW::EVariantTypeTInt32, |
|
339 KTransactionId.operator&() ); |
|
340 |
|
341 // Obtain transaction id from input list |
|
342 transIdParam->Value().Get( transId ); |
|
343 |
|
344 // Get count of async calls |
|
345 asyncCount = iAsyncInfo.Count(); |
|
346 |
|
347 // Search within the async call list for the transaction ID |
|
348 for( i = 0; i < asyncCount; i++ ) |
|
349 { |
|
350 info = iAsyncInfo[i]; |
|
351 if( transId == ( info->iTransactionId ) ) |
|
352 { |
|
353 // Transaction id is found |
|
354 transFound = TRUE; |
|
355 break; |
|
356 } |
|
357 } |
|
358 // If found then cancel the request for notification on service class |
|
359 if( transFound ) |
|
360 { |
|
361 asyncType = info->iAsyncType; |
|
362 chnlId = info->ichnlId; |
|
363 |
|
364 switch( asyncType ) |
|
365 { |
|
366 case EData: // To stop data notification |
|
367 iSensorService->StopNotificationL( EStopData,chnlId ); |
|
368 break; |
|
369 } |
|
370 |
|
371 //Remove this from the store of async functions |
|
372 iAsyncInfo.Remove( i ); |
|
373 delete info->iCallback; |
|
374 delete info; |
|
375 info = NULL; |
|
376 } |
|
377 else |
|
378 { |
|
379 // Incorrect transaction id |
|
380 iErrorString = KErrStopNotifInvalidTransId.operator()().Alloc(); |
|
381 User::Leave( SErrInvalidServiceArgument ); |
|
382 } |
|
383 |
|
384 }//End of command StopNotification |
|
385 // Start of GetChannelProperty |
|
386 else if ( ( aCmdName.CompareF( KCmdGetChnlProperty ) == 0 ) ) |
|
387 { |
|
388 |
|
389 if( aCallback ) |
|
390 { |
|
391 iErrorString = KErrSensorInvalidReq.operator()().Alloc(); |
|
392 User::Leave( SErrInvalidServiceArgument ); |
|
393 } |
|
394 |
|
395 const TLiwGenericParam* channelParam = NULL; |
|
396 const TLiwGenericParam* propertyIdParam= NULL; |
|
397 //Retreive property id for filling output map |
|
398 TSensrvPropertyId propertyId = 0; |
|
399 TPtrC propertyIdStr; |
|
400 |
|
401 if( aInParamList.Count() < 2) |
|
402 { |
|
403 iErrorString = KErrRegNotEnoughParams.operator()().Alloc(); |
|
404 User::Leave( SErrMissingArgument ); |
|
405 } |
|
406 |
|
407 channelParam = aInParamList.FindFirst( position, KChnlInfoMap ); |
|
408 position = 0; |
|
409 propertyIdParam = aInParamList.FindFirst( position, KPropId ); |
|
410 |
|
411 if ( !channelParam ) |
|
412 { |
|
413 channelParam = &aInParamList[EParamIndex0]; |
|
414 if ( !channelParam ) |
|
415 { |
|
416 iErrorString = KErrMissingChnlMap.operator()().Alloc(); |
|
417 User::Leave( SErrMissingArgument ); |
|
418 } |
|
419 propertyIdParam = &aInParamList[EParamIndex1]; |
|
420 if ( !propertyIdParam ) |
|
421 { |
|
422 iErrorString = KErrMissingPropId.operator()().Alloc(); |
|
423 User::Leave( SErrMissingArgument ); |
|
424 } |
|
425 } |
|
426 |
|
427 // Obtain channel info from input map |
|
428 CheckInputTypeL( &channelParam->Value(), |
|
429 LIW::EVariantTypeMap, |
|
430 KChnlInfoMap.operator&() ); |
|
431 |
|
432 CheckInputTypeL( &propertyIdParam->Value(), |
|
433 LIW::EVariantTypeDesC, |
|
434 KPropId.operator&() ); |
|
435 |
|
436 TSensrvChannelInfo channelInfo; |
|
437 const CLiwMap* chnlInfoMap = ( channelParam->Value() ).AsMap(); |
|
438 //Retreive Channel Info |
|
439 GetChannelInfoL( channelInfo , chnlInfoMap ); |
|
440 |
|
441 propertyIdParam->Value().Get( propertyIdStr ); |
|
442 propertyId = PropertyIdInfoL( propertyIdStr ); |
|
443 |
|
444 // Obtain property list from service class |
|
445 RSensrvPropertyList propertyList; |
|
446 CleanupClosePushL( propertyList ); |
|
447 TRAPD( getPropErr, iSensorService->GetChannelPropertyL |
|
448 ( channelInfo, |
|
449 propertyList ) ); |
|
450 |
|
451 if( getPropErr != KErrNone ) |
|
452 { |
|
453 CleanupStack::PopAndDestroy( &propertyList ); |
|
454 iErrorString = KErrInvalidChnlMap.operator()().Alloc(); |
|
455 User::Leave(KErrArgument); |
|
456 } |
|
457 |
|
458 // Create output map |
|
459 CLiwDefaultMap* outMap = CLiwDefaultMap::NewL(); |
|
460 CleanupStack::PushL( outMap ); |
|
461 |
|
462 // Append property from list to output map |
|
463 TRAPD( findPropErr ,AppendPropertyToMapL( propertyList, |
|
464 outMap, |
|
465 propertyId ) ); |
|
466 |
|
467 if( findPropErr != KErrNone ) |
|
468 { |
|
469 iErrorString = KErrPropNotSupported.operator()().Alloc(); |
|
470 CleanupStack::Pop( outMap ); |
|
471 CleanupStack::PopAndDestroy( &propertyList ); |
|
472 outMap->DecRef(); |
|
473 User::Leave(KErrNotFound); |
|
474 } |
|
475 |
|
476 //Appending result to the output parameter list |
|
477 aOutParamList.AppendL( TLiwGenericParam( KReturnValue , |
|
478 TLiwVariant( outMap ) ) ); |
|
479 |
|
480 CleanupStack::Pop( outMap ); |
|
481 CleanupStack::PopAndDestroy( &propertyList ); |
|
482 outMap->DecRef(); |
|
483 |
|
484 }//end of GetChannelProperty |
|
485 else |
|
486 { |
|
487 iErrorString = KErrSensorInvalidCmd.operator()().Alloc(); |
|
488 User::Leave( KErrNotSupported ); |
|
489 } |
|
490 } |
|
491 |
|
492 /* |
|
493 ----------------------------------------------------------------------------- |
|
494 CSensorInterface* CSensorInterface::NewL() |
|
495 Description : Two-phased constructor. |
|
496 Return values : CSensorInterface object pointer |
|
497 |
|
498 ----------------------------------------------------------------------------- |
|
499 */ |
|
500 CSensorInterface* CSensorInterface::NewL() |
|
501 { |
|
502 CSensorInterface* self = new ( ELeave ) CSensorInterface(); |
|
503 CleanupStack::PushL( self ); |
|
504 self->ConstructL(); |
|
505 CleanupStack::Pop( self ); |
|
506 return self; |
|
507 } |
|
508 /* |
|
509 ----------------------------------------------------------------------------- |
|
510 CSensorInterface::~CSensorInterface() |
|
511 Description : Destructor, free allocated resources |
|
512 Return values : N/A |
|
513 ----------------------------------------------------------------------------- |
|
514 */ |
|
515 CSensorInterface::~CSensorInterface() |
|
516 { |
|
517 |
|
518 TInt count = iAsyncInfo.Count(); |
|
519 CStoreAsyncInfo* info = NULL; |
|
520 |
|
521 TAsyncType asyncType = EInvalid; |
|
522 TInt stopErr; |
|
523 TUint chnlId = 0; |
|
524 |
|
525 //Cleanup async info store |
|
526 for( TInt i = 0; i< count; i++) |
|
527 { |
|
528 info = iAsyncInfo[i]; |
|
529 if( info ) |
|
530 { |
|
531 asyncType = info->iAsyncType; |
|
532 chnlId = info->ichnlId; |
|
533 } |
|
534 |
|
535 switch( asyncType ) |
|
536 { |
|
537 case EData: // To stop data notification |
|
538 { |
|
539 if( iSensorService ) |
|
540 { |
|
541 TRAP( stopErr, |
|
542 iSensorService->StopNotificationL( EStopData, |
|
543 chnlId ) ); |
|
544 } |
|
545 break; |
|
546 } |
|
547 } |
|
548 |
|
549 if( info->iCallback ) |
|
550 { |
|
551 delete info->iCallback; |
|
552 info->iCallback = NULL; |
|
553 } |
|
554 |
|
555 |
|
556 if( info ) |
|
557 { |
|
558 delete info; |
|
559 info = NULL; |
|
560 } |
|
561 } |
|
562 |
|
563 iAsyncInfo.Reset(); |
|
564 |
|
565 if( iSensorService ) |
|
566 delete iSensorService; |
|
567 |
|
568 if( iErrorString ) |
|
569 delete iErrorString; |
|
570 |
|
571 } |
|
572 |
|
573 /* |
|
574 ----------------------------------------------------------------------------- |
|
575 CSensorInterface::GetSapiErrorCode() |
|
576 Description : Returns the Sapi Error Code. |
|
577 Return values : SapiErrors |
|
578 ----------------------------------------------------------------------------- |
|
579 */ |
|
580 SapiErrors CSensorInterface:: GetSapiErrorCode( TInt aError ) |
|
581 { |
|
582 SapiErrors sapiErr = SErrNone; |
|
583 switch ( aError ) |
|
584 { |
|
585 case KErrArgument: |
|
586 { |
|
587 sapiErr = SErrBadArgumentType; |
|
588 break; |
|
589 } |
|
590 case KErrNotSupported: |
|
591 { |
|
592 sapiErr = SErrServiceNotSupported; |
|
593 break; |
|
594 } |
|
595 case KErrNone: |
|
596 { |
|
597 sapiErr= SErrNone; |
|
598 break; |
|
599 } |
|
600 case KErrNotFound: |
|
601 { |
|
602 sapiErr= SErrNotFound; |
|
603 break; |
|
604 } |
|
605 case SErrMissingArgument: |
|
606 { |
|
607 sapiErr = SErrMissingArgument; |
|
608 break; |
|
609 } |
|
610 case SErrInvalidServiceArgument: |
|
611 { |
|
612 sapiErr = SErrInvalidServiceArgument; |
|
613 break; |
|
614 } |
|
615 case KErrInUse: |
|
616 { |
|
617 sapiErr = SErrServiceInUse; |
|
618 break; |
|
619 } |
|
620 } |
|
621 return sapiErr; |
|
622 } |
|
623 |
|
624 /* |
|
625 ----------------------------------------------------------------------------- |
|
626 CSensorInterface::ExecuteCmdL() |
|
627 Description : This is called by the consumer with command to execute. |
|
628 Return values : N/A |
|
629 ----------------------------------------------------------------------------- |
|
630 */ |
|
631 void CSensorInterface::ExecuteCmdL( const TDesC8& aCmdName, |
|
632 const CLiwGenericParamList& aInParamList, |
|
633 CLiwGenericParamList& aOutParamList, |
|
634 TUint aCmdOptions, |
|
635 MLiwNotifyCallback* aCallback ) |
|
636 { |
|
637 TRAPD( err, ExecuteServiceCommandL( aCmdName, |
|
638 aInParamList, |
|
639 aOutParamList, |
|
640 aCmdOptions, |
|
641 aCallback ) ); |
|
642 if( err != KErrNone ) |
|
643 { |
|
644 |
|
645 if( iErrorString ) |
|
646 { |
|
647 TBuf<KErrMessageLen> errorMessage; |
|
648 errorMessage.Append( KMsgErr.operator()() ); |
|
649 TBuf<KCmdLen> commandName; |
|
650 commandName.Copy( aCmdName ); |
|
651 errorMessage.Append( commandName ); |
|
652 errorMessage.Append( KColon.operator()()); |
|
653 errorMessage.Append( iErrorString->Des() ); |
|
654 |
|
655 aOutParamList.AppendL(TLiwGenericParam( KErrorMessage, |
|
656 TLiwVariant( errorMessage ))); |
|
657 } |
|
658 } |
|
659 |
|
660 TInt32 returnCode = CSensorInterface::GetSapiErrorCode( err ); |
|
661 aOutParamList.AppendL( TLiwGenericParam( KErrorCode, |
|
662 TLiwVariant( ( TInt32 ) returnCode ) ) ); |
|
663 |
|
664 } |
|
665 |
|
666 /* |
|
667 ----------------------------------------------------------------------------- |
|
668 CSensorInterface::Close() |
|
669 Description : This is called by the consumer to delete the handle. |
|
670 Return values : N/A |
|
671 ----------------------------------------------------------------------------- |
|
672 */ |
|
673 void CSensorInterface::Close() |
|
674 { |
|
675 delete this; |
|
676 } |
|
677 |
|
678 /* |
|
679 ----------------------------------------------------------------------------- |
|
680 CSensorInterface::AppendChannelInfoL() |
|
681 Description : Internal function used to append result of found sensor |
|
682 channel to the outputlist |
|
683 Return values : N/A |
|
684 ----------------------------------------------------------------------------- |
|
685 */ |
|
686 void CSensorInterface::AppendChannelInfoL |
|
687 ( const RSensrvChannelInfoList& aChannelInfoList, |
|
688 CLiwDefaultList* aList) |
|
689 { |
|
690 // Obtain channel count |
|
691 TInt channelCount = aChannelInfoList.Count(); |
|
692 |
|
693 for(TInt i = 0; i < channelCount; i++) |
|
694 { |
|
695 |
|
696 TInt32 chnlType = (TInt32)aChannelInfoList[i].iChannelType; |
|
697 |
|
698 switch(chnlType) |
|
699 { |
|
700 case EFindAccelerometerXYZAxisData: |
|
701 case EFindAccelerometerDoubleTappingData: |
|
702 case EFindOrientationData: |
|
703 case EFindRotationData: |
|
704 { |
|
705 // Map to be appended to the list |
|
706 CLiwDefaultMap* chnlMap = CLiwDefaultMap::NewL() ; |
|
707 CleanupStack::PushL( chnlMap ); |
|
708 |
|
709 //Retreive channel information |
|
710 TInt32 chnlId = (TInt32)aChannelInfoList[i].iChannelId; |
|
711 TInt32 contextType = aChannelInfoList[i].iContextType; |
|
712 TInt32 quantity = aChannelInfoList[i].iQuantity; |
|
713 TBuf8<KSensrvLocationLength> location( aChannelInfoList[i].iLocation ); |
|
714 TBuf8<KSensrvVendorIdLength> vendorId( aChannelInfoList[i].iVendorId ); |
|
715 TInt32 dataItemSize = aChannelInfoList[i].iDataItemSize; |
|
716 TInt32 chnlDataTypeId = (TInt32)aChannelInfoList[i].iChannelDataTypeId; |
|
717 |
|
718 _LIT( KDummyLoc, "Unknown" ); |
|
719 TBufC<KSensrvLocationLength> dummyLoc( KDummyLoc ); |
|
720 TPtr location16 = dummyLoc.Des(); |
|
721 CnvUtfConverter::ConvertToUnicodeFromUtf8( location16, location ); |
|
722 |
|
723 _LIT( KDummyVen, "Unknown" ); |
|
724 TBufC<KSensrvVendorIdLength> dummyVen( KDummyVen ); |
|
725 TPtr vendor16 = dummyVen.Des(); |
|
726 CnvUtfConverter::ConvertToUnicodeFromUtf8( vendor16, vendorId ); |
|
727 |
|
728 // Insert channel info to the map |
|
729 chnlMap->InsertL( KChnlId ,TLiwVariant( (TInt32)chnlId ) ); |
|
730 chnlMap->InsertL( KContextType ,TLiwVariant( (TInt32)contextType ) ); |
|
731 chnlMap->InsertL( KQuantity ,TLiwVariant( (TInt32)quantity ) ); |
|
732 chnlMap->InsertL( KChannelType ,TLiwVariant( (TInt32)chnlType ) ); |
|
733 chnlMap->InsertL( KLocation , TLiwVariant( location16 ) ); |
|
734 chnlMap->InsertL( KVendorId , TLiwVariant( vendor16 ) ); |
|
735 chnlMap->InsertL( KDataItemSize ,TLiwVariant( (TInt32)dataItemSize ) ); |
|
736 chnlMap->InsertL( KChnlDataTypeId ,TLiwVariant( (TInt32)chnlDataTypeId ) ); |
|
737 |
|
738 //Append it to the list |
|
739 aList->AppendL( TLiwVariant( chnlMap ) ); |
|
740 CleanupStack::Pop( chnlMap ); |
|
741 |
|
742 //done with the map |
|
743 chnlMap->DecRef(); |
|
744 break; |
|
745 } |
|
746 default: |
|
747 break; |
|
748 |
|
749 } |
|
750 } |
|
751 } |
|
752 |
|
753 /* |
|
754 ----------------------------------------------------------------------------- |
|
755 CSensorInterface::AppendPropertyToMapL() |
|
756 Description : Internal function used to append result of get property |
|
757 to the output map |
|
758 Return values : N/A |
|
759 ----------------------------------------------------------------------------- |
|
760 */ |
|
761 void CSensorInterface::AppendPropertyToMapL |
|
762 ( const RSensrvPropertyList& aPropertyList, |
|
763 CLiwDefaultMap* aMap, |
|
764 const TUint aPropertyId) |
|
765 { |
|
766 // Obtain property count |
|
767 TInt propCount = aPropertyList.Count(); |
|
768 |
|
769 // If no properties listed then leave with error - Not found |
|
770 if( propCount == 0 ) |
|
771 { |
|
772 User::Leave( KErrNotFound ); |
|
773 } |
|
774 |
|
775 TInt i = 0; // Loop variable |
|
776 TSensrvProperty tempProperty; // Property for copy from property list |
|
777 TSensrvProperty tempProperty1;// Property for obtaining value in array |
|
778 |
|
779 TBool found = FALSE; |
|
780 |
|
781 TInt propType = 0; |
|
782 TInt intVal; |
|
783 TReal rValue; |
|
784 TBuf8<KBufSize> bufValue; |
|
785 TInt32 itemIndex; |
|
786 |
|
787 // Search within property list and fill output map |
|
788 for ( i = 0; i < propCount; i++ ) |
|
789 { |
|
790 tempProperty = aPropertyList[i]; |
|
791 |
|
792 if( aPropertyId == ( tempProperty.GetPropertyId() ) ) |
|
793 { |
|
794 // Property has been found |
|
795 found = TRUE; |
|
796 TPtrC propertyStr = PropertyStrL( aPropertyId ); |
|
797 aMap->InsertL( KPropId ,TLiwVariant( propertyStr ) ); |
|
798 |
|
799 // Obtain item index,property type and read only |
|
800 itemIndex = tempProperty.PropertyItemIndex(); |
|
801 propType = tempProperty.PropertyType(); |
|
802 |
|
803 // Insert item index,property type and read only into output map |
|
804 aMap->InsertL( KPropertyDataType ,TLiwVariant( (TInt32) ( propType - 1 ) ) ); |
|
805 aMap->InsertL( KItemIndex ,TLiwVariant( (TInt32) itemIndex ) ); |
|
806 aMap->InsertL( KReadOnly ,TLiwVariant(1) ); |
|
807 |
|
808 // For single property,just fill the actual values |
|
809 if( ESensrvSingleProperty == ( tempProperty.GetArrayIndex() ) ) |
|
810 { |
|
811 |
|
812 // Obtain values for integer property |
|
813 if( propType == ESensrvIntProperty ) |
|
814 { |
|
815 tempProperty.GetValue( intVal ); |
|
816 aMap->InsertL( KPropertyValue ,TLiwVariant( (TInt32) intVal ) ); |
|
817 } |
|
818 // Obtain values for real property |
|
819 else if( propType == ESensrvRealProperty ) |
|
820 { |
|
821 tempProperty.GetValue( rValue ); |
|
822 aMap->InsertL( KPropertyValue ,TLiwVariant( rValue ) ); |
|
823 } |
|
824 // Obtain values for string property |
|
825 else if( propType == ESensrvBufferProperty ) |
|
826 { |
|
827 tempProperty.GetValue( bufValue ); |
|
828 _LIT( KDummyDesc, "Unknown" ); |
|
829 TBufC<KSensrvLocationLength> dummyDesc( KDummyDesc ); |
|
830 TPtr description16 = dummyDesc.Des(); |
|
831 CnvUtfConverter::ConvertToUnicodeFromUtf8( description16, bufValue ); |
|
832 |
|
833 aMap->InsertL( KPropertyValue ,TLiwVariant( description16 ) ); |
|
834 } |
|
835 break; |
|
836 } |
|
837 // If array property then get values from the actual listed props |
|
838 else if( ESensrvArrayPropertyInfo == ( tempProperty.GetArrayIndex() ) ) |
|
839 { |
|
840 // For integer property |
|
841 if( propType == ESensrvIntProperty ) |
|
842 { |
|
843 TInt indexVal; |
|
844 tempProperty.GetValue( indexVal ); |
|
845 tempProperty1 = aPropertyList[ i + indexVal ]; |
|
846 tempProperty1.GetValue( intVal ); |
|
847 aMap->InsertL( KPropertyValue ,TLiwVariant( (TInt32) intVal ) ); |
|
848 } |
|
849 // For real property |
|
850 else if( propType == ESensrvRealProperty ) |
|
851 { |
|
852 TReal indexVal; |
|
853 tempProperty.GetValue( indexVal ); |
|
854 tempProperty1 = aPropertyList[ i + indexVal ]; |
|
855 tempProperty1.GetValue( rValue ); |
|
856 aMap->InsertL( KPropertyValue ,TLiwVariant( rValue ) ); |
|
857 } |
|
858 break; |
|
859 } |
|
860 |
|
861 } |
|
862 else |
|
863 continue; |
|
864 } |
|
865 |
|
866 // If property not found then leave with error - not found |
|
867 if( found == FALSE ) |
|
868 { |
|
869 User::Leave( KErrNotFound ); |
|
870 } |
|
871 |
|
872 } |
|
873 |
|
874 |
|
875 /* |
|
876 ----------------------------------------------------------------------------- |
|
877 CSensorInterface::GetChannelInfoL() |
|
878 Description : Internal function used to extract channel info from the |
|
879 : Input |
|
880 Return values : N/A |
|
881 ----------------------------------------------------------------------------- |
|
882 */ |
|
883 void CSensorInterface::GetChannelInfoL( TSensrvChannelInfo& aChannelInfo, |
|
884 const CLiwMap* aChnlInfoMap ) |
|
885 { |
|
886 TLiwVariant infoVariant; |
|
887 |
|
888 if( aChnlInfoMap->FindL( KChnlId , infoVariant ) ) |
|
889 { |
|
890 CheckInputTypeL( &infoVariant, |
|
891 LIW::EVariantTypeTInt32, |
|
892 KChnlId.operator&() ); |
|
893 |
|
894 aChannelInfo.iChannelId = infoVariant.AsTInt32(); |
|
895 } |
|
896 else |
|
897 { |
|
898 infoVariant.Reset(); |
|
899 MissingValueL( KChnlId.operator&() ); |
|
900 } |
|
901 |
|
902 if( aChnlInfoMap->FindL( KContextType , infoVariant ) ) |
|
903 { |
|
904 CheckInputTypeL( &infoVariant, |
|
905 LIW::EVariantTypeTInt32, |
|
906 KContextType.operator&() ); |
|
907 |
|
908 aChannelInfo.iContextType = infoVariant.AsTInt32(); |
|
909 } |
|
910 else |
|
911 { |
|
912 infoVariant.Reset(); |
|
913 MissingValueL( KContextType.operator&() ); |
|
914 } |
|
915 |
|
916 if( aChnlInfoMap->FindL( KQuantity , infoVariant ) ) |
|
917 { |
|
918 CheckInputTypeL( &infoVariant, |
|
919 LIW::EVariantTypeTInt32, |
|
920 KQuantity.operator&() ); |
|
921 |
|
922 aChannelInfo.iQuantity = infoVariant.AsTInt32(); |
|
923 } |
|
924 else |
|
925 { |
|
926 infoVariant.Reset(); |
|
927 MissingValueL( KQuantity.operator&() ); |
|
928 } |
|
929 |
|
930 if( aChnlInfoMap->FindL( KChannelType , infoVariant ) ) |
|
931 { |
|
932 CheckInputTypeL( &infoVariant, |
|
933 LIW::EVariantTypeTInt32, |
|
934 KChannelType.operator&() ); |
|
935 |
|
936 aChannelInfo.iChannelType = infoVariant.AsTInt32(); |
|
937 } |
|
938 else |
|
939 { |
|
940 infoVariant.Reset(); |
|
941 MissingValueL( KChannelType.operator&() ); |
|
942 } |
|
943 |
|
944 if( aChnlInfoMap->FindL( KLocation , infoVariant ) ) |
|
945 { |
|
946 CheckInputTypeL( &infoVariant, |
|
947 LIW::EVariantTypeDesC, |
|
948 KLocation.operator&() ); |
|
949 |
|
950 TPtrC location16 = infoVariant.AsDes(); |
|
951 TBuf8<KSensrvLocationLength> location8; |
|
952 CnvUtfConverter::ConvertFromUnicodeToUtf8( location8, location16 ); |
|
953 |
|
954 aChannelInfo.iLocation = location8; |
|
955 } |
|
956 else |
|
957 { |
|
958 infoVariant.Reset(); |
|
959 MissingValueL( KLocation.operator&() ); |
|
960 } |
|
961 |
|
962 if( aChnlInfoMap->FindL( KVendorId , infoVariant ) ) |
|
963 { |
|
964 CheckInputTypeL( &infoVariant, |
|
965 LIW::EVariantTypeDesC, |
|
966 KVendorId.operator&() ); |
|
967 |
|
968 TPtrC vendorId16 = infoVariant.AsDes(); |
|
969 TBuf8<KSensrvVendorIdLength> vendorId8; |
|
970 CnvUtfConverter::ConvertFromUnicodeToUtf8( vendorId8, vendorId16 ); |
|
971 |
|
972 aChannelInfo.iVendorId = vendorId8; |
|
973 } |
|
974 else |
|
975 { |
|
976 infoVariant.Reset(); |
|
977 MissingValueL( KVendorId.operator&() ); |
|
978 } |
|
979 |
|
980 if( aChnlInfoMap->FindL( KDataItemSize , infoVariant ) ) |
|
981 { |
|
982 CheckInputTypeL( &infoVariant, |
|
983 LIW::EVariantTypeTInt32, |
|
984 KDataItemSize.operator&() ); |
|
985 |
|
986 aChannelInfo.iDataItemSize = infoVariant.AsTInt32(); |
|
987 } |
|
988 else |
|
989 { |
|
990 infoVariant.Reset(); |
|
991 MissingValueL( KDataItemSize.operator&() ); |
|
992 } |
|
993 |
|
994 if( aChnlInfoMap->FindL( KChnlDataTypeId , infoVariant ) ) |
|
995 { |
|
996 CheckInputTypeL( &infoVariant, |
|
997 LIW::EVariantTypeTInt32, |
|
998 KChnlDataTypeId.operator&() ); |
|
999 |
|
1000 aChannelInfo.iChannelDataTypeId = infoVariant.AsTInt32(); |
|
1001 } |
|
1002 else |
|
1003 { |
|
1004 infoVariant.Reset(); |
|
1005 MissingValueL( KChnlDataTypeId.operator&() ); |
|
1006 } |
|
1007 infoVariant.Reset(); |
|
1008 } |
|
1009 |
|
1010 /* |
|
1011 ----------------------------------------------------------------------------- |
|
1012 CSensorInterface::PropertyStr() |
|
1013 Description : Internal function used to extract property string from |
|
1014 : the input property id |
|
1015 Return values : N/A |
|
1016 ----------------------------------------------------------------------------- |
|
1017 */ |
|
1018 TPtrC CSensorInterface::PropertyStrL( TSensrvPropertyId aPropertyId ) |
|
1019 { |
|
1020 |
|
1021 TPtrC ptr; |
|
1022 |
|
1023 switch( aPropertyId ) |
|
1024 { |
|
1025 case KSensrvPropIdDataRate: |
|
1026 ptr.Set( KDataRate ); |
|
1027 break; |
|
1028 |
|
1029 case KSensrvPropIdAvailability: |
|
1030 ptr.Set( KAvailability ); |
|
1031 break; |
|
1032 |
|
1033 case KSensrvPropIdMeasureRange: |
|
1034 ptr.Set( KMeasureRange ); |
|
1035 break; |
|
1036 |
|
1037 case KSensrvPropIdChannelDataFormat: |
|
1038 ptr.Set( KChannelDataFormat ); |
|
1039 break; |
|
1040 |
|
1041 case KSensrvPropIdChannelAccuracy: |
|
1042 ptr.Set( KChannelAccuracy ); |
|
1043 break; |
|
1044 |
|
1045 case KSensrvPropIdChannelScale: |
|
1046 ptr.Set( KChannelScale ); |
|
1047 break; |
|
1048 |
|
1049 case KSensrvPropIdScaledRange: |
|
1050 ptr.Set( KScaledRange ); |
|
1051 break; |
|
1052 |
|
1053 case KSensrvPropIdChannelUnit: |
|
1054 ptr.Set( KChannelUnit ); |
|
1055 break; |
|
1056 |
|
1057 case KSensrvSensorModel: |
|
1058 ptr.Set( KSensorModel ); |
|
1059 break; |
|
1060 |
|
1061 case KSensrvSensorConnectionType: |
|
1062 ptr.Set( KConnectionType ); |
|
1063 break; |
|
1064 |
|
1065 case KSensrvSensorDescription: |
|
1066 ptr.Set( KSensorDescription ); |
|
1067 break; |
|
1068 |
|
1069 default: |
|
1070 User::Leave( KErrNotSupported ); |
|
1071 } |
|
1072 return ptr; |
|
1073 } |
|
1074 |
|
1075 /* |
|
1076 ----------------------------------------------------------------------------- |
|
1077 CSensorInterface::PropertyIdInfoL() |
|
1078 Description : Internal function used to extract property id info from |
|
1079 : the Input |
|
1080 Return values : N/A |
|
1081 ----------------------------------------------------------------------------- |
|
1082 */ |
|
1083 TSensrvPropertyId CSensorInterface::PropertyIdInfoL( const TDesC& aPropertyIdStr ) |
|
1084 { |
|
1085 TSensrvPropertyId propId = 0; |
|
1086 |
|
1087 if( aPropertyIdStr == KDataRate ) |
|
1088 propId = KSensrvPropIdDataRate; |
|
1089 else if( aPropertyIdStr == KAvailability ) |
|
1090 propId = KSensrvPropIdAvailability; |
|
1091 else if( aPropertyIdStr == KMeasureRange ) |
|
1092 propId = KSensrvPropIdMeasureRange; |
|
1093 else if( aPropertyIdStr == KChannelDataFormat ) |
|
1094 propId = KSensrvPropIdChannelDataFormat; |
|
1095 else if( aPropertyIdStr == KChannelAccuracy ) |
|
1096 propId = KSensrvPropIdChannelAccuracy; |
|
1097 else if( aPropertyIdStr == KChannelScale ) |
|
1098 propId = KSensrvPropIdChannelScale; |
|
1099 else if( aPropertyIdStr == KScaledRange ) |
|
1100 propId = KSensrvPropIdScaledRange; |
|
1101 else if( aPropertyIdStr == KChannelUnit ) |
|
1102 propId = KSensrvPropIdChannelUnit; |
|
1103 else if( aPropertyIdStr == KSensorModel ) |
|
1104 propId = KSensrvSensorModel; |
|
1105 else if( aPropertyIdStr == KConnectionType ) |
|
1106 propId = KSensrvSensorConnectionType; |
|
1107 else if( aPropertyIdStr == KSensorDescription ) |
|
1108 propId = KSensrvSensorDescription; |
|
1109 else |
|
1110 { |
|
1111 iErrorString = KErrPropInvalidPropId.operator()().Alloc(); |
|
1112 User::Leave( SErrInvalidServiceArgument ); |
|
1113 } |
|
1114 return propId; |
|
1115 } |