author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 17 Dec 2009 09:09:50 +0200 | |
changeset 37 | 5d0ec8b709be |
parent 33 | 50974a8b132e |
child 38 | 02682e02e51f |
permissions | -rw-r--r-- |
19 | 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 |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
19 |
#include <liwvariant.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
20 |
#include <liwgenericparam.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
21 |
#include <liwcommon.h> |
19 | 22 |
#include <sensrvchannelinfo.h> |
23 |
#include <sensrvtypes.h> |
|
37
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
24 |
#include<e32math.h> |
19 | 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 |
|
37
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
485 |
else if( ( aCmdName.CompareF( KCmdGetScaleFactor ) == 0 ) ) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
486 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
487 |
if( aCallback ) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
488 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
489 |
iErrorString = KErrSensorInvalidReq.operator()().Alloc(); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
490 |
User::Leave( SErrInvalidServiceArgument ); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
491 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
492 |
const TLiwGenericParam* channelInfoParam = NULL; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
493 |
channelInfoParam = aInParamList.FindFirst( position, KChnlInfoMap ); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
494 |
if ( !channelInfoParam ) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
495 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
496 |
//Position based parsing |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
497 |
if( aInParamList.Count() != 0 ) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
498 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
499 |
channelInfoParam = &aInParamList[EParamIndex0]; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
500 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
501 |
else |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
502 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
503 |
iErrorString = KErrMissingChnlMap.operator()().Alloc(); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
504 |
User::Leave( SErrMissingArgument ); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
505 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
506 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
507 |
CheckInputTypeL( &channelInfoParam->Value(), |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
508 |
LIW::EVariantTypeMap, |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
509 |
KChnlInfoMap.operator&() ); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
510 |
|
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
511 |
TSensrvChannelInfo channelInfo; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
512 |
const CLiwMap* chnlInfoMap = ( channelInfoParam->Value() ).AsMap(); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
513 |
//Retreive Channel Info |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
514 |
GetChannelInfoL( channelInfo , chnlInfoMap ); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
515 |
|
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
516 |
TSensrvProperty measureProperty; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
517 |
TSensrvProperty scaleProperty; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
518 |
TRAPD(anErr,iSensorService->GetScaleFactorL( channelInfo , |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
519 |
measureProperty,scaleProperty )); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
520 |
|
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
521 |
if( anErr != KErrNone ) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
522 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
523 |
iErrorString = KErrInvalidChnlMap.operator()().Alloc(); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
524 |
User::Leave(KErrArgument); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
525 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
526 |
TReal scaleFactor ; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
527 |
TReal measureValue; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
528 |
TInt scaleValue; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
529 |
measureProperty.GetValue( measureValue );// 0 or 1 |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
530 |
scaleProperty.GetValue( scaleValue); // 8 or 12 |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
531 |
TReal outputValue; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
532 |
TInt errPow; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
533 |
errPow = Math::Pow(outputValue,2,scaleValue-1); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
534 |
if( errPow == KErrNone ) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
535 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
536 |
if( measureValue == 0 ) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
537 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
538 |
scaleFactor = (2*9.8)/outputValue; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
539 |
aOutParamList.AppendL( TLiwGenericParam( KReturnValue , |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
540 |
TLiwVariant( scaleFactor ) ) ); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
541 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
542 |
else if(measureValue == 1) |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
543 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
544 |
scaleFactor = (8*9.8)/outputValue; |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
545 |
aOutParamList.AppendL( TLiwGenericParam( KReturnValue , |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
546 |
TLiwVariant( scaleFactor ) ) ); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
547 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
548 |
else |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
549 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
550 |
iErrorString = KErrInvalidMeasureRange.operator()().Alloc(); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
551 |
User::Leave(KErrArgument); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
552 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
553 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
554 |
else |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
555 |
{ |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
556 |
iErrorString = KErrInvalidPowValue.operator()().Alloc(); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
557 |
User::Leave(KErrArgument); |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
558 |
} |
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
559 |
|
5d0ec8b709be
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
560 |
}//end of GetScaleFactor |
19 | 561 |
else |
562 |
{ |
|
563 |
iErrorString = KErrSensorInvalidCmd.operator()().Alloc(); |
|
564 |
User::Leave( KErrNotSupported ); |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
/* |
|
569 |
----------------------------------------------------------------------------- |
|
570 |
CSensorInterface* CSensorInterface::NewL() |
|
571 |
Description : Two-phased constructor. |
|
572 |
Return values : CSensorInterface object pointer |
|
573 |
||
574 |
----------------------------------------------------------------------------- |
|
575 |
*/ |
|
576 |
CSensorInterface* CSensorInterface::NewL() |
|
577 |
{ |
|
578 |
CSensorInterface* self = new ( ELeave ) CSensorInterface(); |
|
579 |
CleanupStack::PushL( self ); |
|
580 |
self->ConstructL(); |
|
581 |
CleanupStack::Pop( self ); |
|
582 |
return self; |
|
583 |
} |
|
584 |
/* |
|
585 |
----------------------------------------------------------------------------- |
|
586 |
CSensorInterface::~CSensorInterface() |
|
587 |
Description : Destructor, free allocated resources |
|
588 |
Return values : N/A |
|
589 |
----------------------------------------------------------------------------- |
|
590 |
*/ |
|
591 |
CSensorInterface::~CSensorInterface() |
|
592 |
{ |
|
593 |
||
594 |
TInt count = iAsyncInfo.Count(); |
|
595 |
CStoreAsyncInfo* info = NULL; |
|
596 |
||
597 |
TAsyncType asyncType = EInvalid; |
|
598 |
TInt stopErr; |
|
599 |
TUint chnlId = 0; |
|
600 |
||
601 |
//Cleanup async info store |
|
602 |
for( TInt i = 0; i< count; i++) |
|
603 |
{ |
|
604 |
info = iAsyncInfo[i]; |
|
605 |
if( info ) |
|
606 |
{ |
|
607 |
asyncType = info->iAsyncType; |
|
608 |
chnlId = info->ichnlId; |
|
609 |
} |
|
610 |
||
611 |
switch( asyncType ) |
|
612 |
{ |
|
613 |
case EData: // To stop data notification |
|
614 |
{ |
|
615 |
if( iSensorService ) |
|
616 |
{ |
|
617 |
TRAP( stopErr, |
|
618 |
iSensorService->StopNotificationL( EStopData, |
|
619 |
chnlId ) ); |
|
620 |
} |
|
621 |
break; |
|
622 |
} |
|
623 |
} |
|
624 |
||
625 |
if( info->iCallback ) |
|
626 |
{ |
|
627 |
delete info->iCallback; |
|
628 |
info->iCallback = NULL; |
|
629 |
} |
|
630 |
||
631 |
||
632 |
if( info ) |
|
633 |
{ |
|
634 |
delete info; |
|
635 |
info = NULL; |
|
636 |
} |
|
637 |
} |
|
638 |
||
639 |
iAsyncInfo.Reset(); |
|
640 |
||
641 |
if( iSensorService ) |
|
642 |
delete iSensorService; |
|
643 |
||
644 |
if( iErrorString ) |
|
645 |
delete iErrorString; |
|
646 |
||
647 |
} |
|
648 |
||
649 |
/* |
|
650 |
----------------------------------------------------------------------------- |
|
651 |
CSensorInterface::GetSapiErrorCode() |
|
652 |
Description : Returns the Sapi Error Code. |
|
653 |
Return values : SapiErrors |
|
654 |
----------------------------------------------------------------------------- |
|
655 |
*/ |
|
656 |
SapiErrors CSensorInterface:: GetSapiErrorCode( TInt aError ) |
|
657 |
{ |
|
658 |
SapiErrors sapiErr = SErrNone; |
|
659 |
switch ( aError ) |
|
660 |
{ |
|
661 |
case KErrArgument: |
|
662 |
{ |
|
663 |
sapiErr = SErrBadArgumentType; |
|
664 |
break; |
|
665 |
} |
|
666 |
case KErrNotSupported: |
|
667 |
{ |
|
668 |
sapiErr = SErrServiceNotSupported; |
|
669 |
break; |
|
670 |
} |
|
671 |
case KErrNone: |
|
672 |
{ |
|
673 |
sapiErr= SErrNone; |
|
674 |
break; |
|
675 |
} |
|
676 |
case KErrNotFound: |
|
677 |
{ |
|
678 |
sapiErr= SErrNotFound; |
|
679 |
break; |
|
680 |
} |
|
681 |
case SErrMissingArgument: |
|
682 |
{ |
|
683 |
sapiErr = SErrMissingArgument; |
|
684 |
break; |
|
685 |
} |
|
686 |
case SErrInvalidServiceArgument: |
|
687 |
{ |
|
688 |
sapiErr = SErrInvalidServiceArgument; |
|
689 |
break; |
|
690 |
} |
|
691 |
case KErrInUse: |
|
692 |
{ |
|
693 |
sapiErr = SErrServiceInUse; |
|
694 |
break; |
|
695 |
} |
|
696 |
} |
|
697 |
return sapiErr; |
|
698 |
} |
|
699 |
||
700 |
/* |
|
701 |
----------------------------------------------------------------------------- |
|
702 |
CSensorInterface::ExecuteCmdL() |
|
703 |
Description : This is called by the consumer with command to execute. |
|
704 |
Return values : N/A |
|
705 |
----------------------------------------------------------------------------- |
|
706 |
*/ |
|
707 |
void CSensorInterface::ExecuteCmdL( const TDesC8& aCmdName, |
|
708 |
const CLiwGenericParamList& aInParamList, |
|
709 |
CLiwGenericParamList& aOutParamList, |
|
710 |
TUint aCmdOptions, |
|
711 |
MLiwNotifyCallback* aCallback ) |
|
712 |
{ |
|
713 |
TRAPD( err, ExecuteServiceCommandL( aCmdName, |
|
714 |
aInParamList, |
|
715 |
aOutParamList, |
|
716 |
aCmdOptions, |
|
717 |
aCallback ) ); |
|
718 |
if( err != KErrNone ) |
|
719 |
{ |
|
720 |
||
721 |
if( iErrorString ) |
|
722 |
{ |
|
723 |
TBuf<KErrMessageLen> errorMessage; |
|
724 |
errorMessage.Append( KMsgErr.operator()() ); |
|
725 |
TBuf<KCmdLen> commandName; |
|
726 |
commandName.Copy( aCmdName ); |
|
727 |
errorMessage.Append( commandName ); |
|
728 |
errorMessage.Append( KColon.operator()()); |
|
729 |
errorMessage.Append( iErrorString->Des() ); |
|
730 |
||
731 |
aOutParamList.AppendL(TLiwGenericParam( KErrorMessage, |
|
732 |
TLiwVariant( errorMessage ))); |
|
733 |
} |
|
734 |
} |
|
735 |
||
736 |
TInt32 returnCode = CSensorInterface::GetSapiErrorCode( err ); |
|
737 |
aOutParamList.AppendL( TLiwGenericParam( KErrorCode, |
|
738 |
TLiwVariant( ( TInt32 ) returnCode ) ) ); |
|
739 |
||
740 |
} |
|
741 |
||
742 |
/* |
|
743 |
----------------------------------------------------------------------------- |
|
744 |
CSensorInterface::Close() |
|
745 |
Description : This is called by the consumer to delete the handle. |
|
746 |
Return values : N/A |
|
747 |
----------------------------------------------------------------------------- |
|
748 |
*/ |
|
749 |
void CSensorInterface::Close() |
|
750 |
{ |
|
751 |
delete this; |
|
752 |
} |
|
753 |
||
754 |
/* |
|
755 |
----------------------------------------------------------------------------- |
|
756 |
CSensorInterface::AppendChannelInfoL() |
|
757 |
Description : Internal function used to append result of found sensor |
|
758 |
channel to the outputlist |
|
759 |
Return values : N/A |
|
760 |
----------------------------------------------------------------------------- |
|
761 |
*/ |
|
762 |
void CSensorInterface::AppendChannelInfoL |
|
763 |
( const RSensrvChannelInfoList& aChannelInfoList, |
|
764 |
CLiwDefaultList* aList) |
|
765 |
{ |
|
766 |
// Obtain channel count |
|
767 |
TInt channelCount = aChannelInfoList.Count(); |
|
768 |
||
769 |
for(TInt i = 0; i < channelCount; i++) |
|
770 |
{ |
|
771 |
||
772 |
TInt32 chnlType = (TInt32)aChannelInfoList[i].iChannelType; |
|
773 |
||
774 |
switch(chnlType) |
|
775 |
{ |
|
776 |
case EFindAccelerometerXYZAxisData: |
|
777 |
case EFindAccelerometerDoubleTappingData: |
|
778 |
case EFindOrientationData: |
|
779 |
case EFindRotationData: |
|
780 |
{ |
|
781 |
// Map to be appended to the list |
|
782 |
CLiwDefaultMap* chnlMap = CLiwDefaultMap::NewL() ; |
|
783 |
CleanupStack::PushL( chnlMap ); |
|
784 |
||
785 |
//Retreive channel information |
|
786 |
TInt32 chnlId = (TInt32)aChannelInfoList[i].iChannelId; |
|
787 |
TInt32 contextType = aChannelInfoList[i].iContextType; |
|
788 |
TInt32 quantity = aChannelInfoList[i].iQuantity; |
|
789 |
TBuf8<KSensrvLocationLength> location( aChannelInfoList[i].iLocation ); |
|
790 |
TBuf8<KSensrvVendorIdLength> vendorId( aChannelInfoList[i].iVendorId ); |
|
791 |
TInt32 dataItemSize = aChannelInfoList[i].iDataItemSize; |
|
792 |
TInt32 chnlDataTypeId = (TInt32)aChannelInfoList[i].iChannelDataTypeId; |
|
793 |
||
794 |
_LIT( KDummyLoc, "Unknown" ); |
|
795 |
TBufC<KSensrvLocationLength> dummyLoc( KDummyLoc ); |
|
796 |
TPtr location16 = dummyLoc.Des(); |
|
797 |
CnvUtfConverter::ConvertToUnicodeFromUtf8( location16, location ); |
|
798 |
||
799 |
_LIT( KDummyVen, "Unknown" ); |
|
800 |
TBufC<KSensrvVendorIdLength> dummyVen( KDummyVen ); |
|
801 |
TPtr vendor16 = dummyVen.Des(); |
|
802 |
CnvUtfConverter::ConvertToUnicodeFromUtf8( vendor16, vendorId ); |
|
803 |
||
804 |
// Insert channel info to the map |
|
805 |
chnlMap->InsertL( KChnlId ,TLiwVariant( (TInt32)chnlId ) ); |
|
806 |
chnlMap->InsertL( KContextType ,TLiwVariant( (TInt32)contextType ) ); |
|
807 |
chnlMap->InsertL( KQuantity ,TLiwVariant( (TInt32)quantity ) ); |
|
808 |
chnlMap->InsertL( KChannelType ,TLiwVariant( (TInt32)chnlType ) ); |
|
809 |
chnlMap->InsertL( KLocation , TLiwVariant( location16 ) ); |
|
810 |
chnlMap->InsertL( KVendorId , TLiwVariant( vendor16 ) ); |
|
811 |
chnlMap->InsertL( KDataItemSize ,TLiwVariant( (TInt32)dataItemSize ) ); |
|
812 |
chnlMap->InsertL( KChnlDataTypeId ,TLiwVariant( (TInt32)chnlDataTypeId ) ); |
|
813 |
||
814 |
//Append it to the list |
|
815 |
aList->AppendL( TLiwVariant( chnlMap ) ); |
|
816 |
CleanupStack::Pop( chnlMap ); |
|
817 |
||
818 |
//done with the map |
|
819 |
chnlMap->DecRef(); |
|
820 |
break; |
|
821 |
} |
|
822 |
default: |
|
823 |
break; |
|
824 |
||
825 |
} |
|
826 |
} |
|
827 |
} |
|
828 |
||
829 |
/* |
|
830 |
----------------------------------------------------------------------------- |
|
831 |
CSensorInterface::AppendPropertyToMapL() |
|
832 |
Description : Internal function used to append result of get property |
|
833 |
to the output map |
|
834 |
Return values : N/A |
|
835 |
----------------------------------------------------------------------------- |
|
836 |
*/ |
|
837 |
void CSensorInterface::AppendPropertyToMapL |
|
838 |
( const RSensrvPropertyList& aPropertyList, |
|
839 |
CLiwDefaultMap* aMap, |
|
840 |
const TUint aPropertyId) |
|
841 |
{ |
|
842 |
// Obtain property count |
|
843 |
TInt propCount = aPropertyList.Count(); |
|
844 |
||
845 |
// If no properties listed then leave with error - Not found |
|
846 |
if( propCount == 0 ) |
|
847 |
{ |
|
848 |
User::Leave( KErrNotFound ); |
|
849 |
} |
|
850 |
||
851 |
TInt i = 0; // Loop variable |
|
852 |
TSensrvProperty tempProperty; // Property for copy from property list |
|
853 |
TSensrvProperty tempProperty1;// Property for obtaining value in array |
|
854 |
||
855 |
TBool found = FALSE; |
|
856 |
||
857 |
TInt propType = 0; |
|
858 |
TInt intVal; |
|
859 |
TReal rValue; |
|
860 |
TBuf8<KBufSize> bufValue; |
|
861 |
TInt32 itemIndex; |
|
862 |
||
863 |
// Search within property list and fill output map |
|
864 |
for ( i = 0; i < propCount; i++ ) |
|
865 |
{ |
|
866 |
tempProperty = aPropertyList[i]; |
|
867 |
||
868 |
if( aPropertyId == ( tempProperty.GetPropertyId() ) ) |
|
869 |
{ |
|
870 |
// Property has been found |
|
871 |
found = TRUE; |
|
872 |
TPtrC propertyStr = PropertyStrL( aPropertyId ); |
|
873 |
aMap->InsertL( KPropId ,TLiwVariant( propertyStr ) ); |
|
874 |
||
875 |
// Obtain item index,property type and read only |
|
876 |
itemIndex = tempProperty.PropertyItemIndex(); |
|
877 |
propType = tempProperty.PropertyType(); |
|
878 |
||
879 |
// Insert item index,property type and read only into output map |
|
880 |
aMap->InsertL( KPropertyDataType ,TLiwVariant( (TInt32) ( propType - 1 ) ) ); |
|
881 |
aMap->InsertL( KItemIndex ,TLiwVariant( (TInt32) itemIndex ) ); |
|
882 |
aMap->InsertL( KReadOnly ,TLiwVariant(1) ); |
|
883 |
||
884 |
// For single property,just fill the actual values |
|
885 |
if( ESensrvSingleProperty == ( tempProperty.GetArrayIndex() ) ) |
|
886 |
{ |
|
887 |
||
888 |
// Obtain values for integer property |
|
889 |
if( propType == ESensrvIntProperty ) |
|
890 |
{ |
|
891 |
tempProperty.GetValue( intVal ); |
|
892 |
aMap->InsertL( KPropertyValue ,TLiwVariant( (TInt32) intVal ) ); |
|
893 |
} |
|
894 |
// Obtain values for real property |
|
895 |
else if( propType == ESensrvRealProperty ) |
|
896 |
{ |
|
897 |
tempProperty.GetValue( rValue ); |
|
898 |
aMap->InsertL( KPropertyValue ,TLiwVariant( rValue ) ); |
|
899 |
} |
|
900 |
// Obtain values for string property |
|
901 |
else if( propType == ESensrvBufferProperty ) |
|
902 |
{ |
|
903 |
tempProperty.GetValue( bufValue ); |
|
904 |
_LIT( KDummyDesc, "Unknown" ); |
|
905 |
TBufC<KSensrvLocationLength> dummyDesc( KDummyDesc ); |
|
906 |
TPtr description16 = dummyDesc.Des(); |
|
907 |
CnvUtfConverter::ConvertToUnicodeFromUtf8( description16, bufValue ); |
|
908 |
||
909 |
aMap->InsertL( KPropertyValue ,TLiwVariant( description16 ) ); |
|
910 |
} |
|
911 |
break; |
|
912 |
} |
|
913 |
// If array property then get values from the actual listed props |
|
914 |
else if( ESensrvArrayPropertyInfo == ( tempProperty.GetArrayIndex() ) ) |
|
915 |
{ |
|
916 |
// For integer property |
|
917 |
if( propType == ESensrvIntProperty ) |
|
918 |
{ |
|
919 |
TInt indexVal; |
|
920 |
tempProperty.GetValue( indexVal ); |
|
921 |
tempProperty1 = aPropertyList[ i + indexVal ]; |
|
922 |
tempProperty1.GetValue( intVal ); |
|
923 |
aMap->InsertL( KPropertyValue ,TLiwVariant( (TInt32) intVal ) ); |
|
924 |
} |
|
925 |
// For real property |
|
926 |
else if( propType == ESensrvRealProperty ) |
|
927 |
{ |
|
928 |
TReal indexVal; |
|
929 |
tempProperty.GetValue( indexVal ); |
|
930 |
tempProperty1 = aPropertyList[ i + indexVal ]; |
|
931 |
tempProperty1.GetValue( rValue ); |
|
932 |
aMap->InsertL( KPropertyValue ,TLiwVariant( rValue ) ); |
|
933 |
} |
|
934 |
break; |
|
935 |
} |
|
936 |
||
937 |
} |
|
938 |
else |
|
939 |
continue; |
|
940 |
} |
|
941 |
||
942 |
// If property not found then leave with error - not found |
|
943 |
if( found == FALSE ) |
|
944 |
{ |
|
945 |
User::Leave( KErrNotFound ); |
|
946 |
} |
|
947 |
||
948 |
} |
|
949 |
||
950 |
||
951 |
/* |
|
952 |
----------------------------------------------------------------------------- |
|
953 |
CSensorInterface::GetChannelInfoL() |
|
954 |
Description : Internal function used to extract channel info from the |
|
955 |
: Input |
|
956 |
Return values : N/A |
|
957 |
----------------------------------------------------------------------------- |
|
958 |
*/ |
|
959 |
void CSensorInterface::GetChannelInfoL( TSensrvChannelInfo& aChannelInfo, |
|
960 |
const CLiwMap* aChnlInfoMap ) |
|
961 |
{ |
|
962 |
TLiwVariant infoVariant; |
|
963 |
||
964 |
if( aChnlInfoMap->FindL( KChnlId , infoVariant ) ) |
|
965 |
{ |
|
966 |
CheckInputTypeL( &infoVariant, |
|
967 |
LIW::EVariantTypeTInt32, |
|
968 |
KChnlId.operator&() ); |
|
969 |
||
970 |
aChannelInfo.iChannelId = infoVariant.AsTInt32(); |
|
971 |
} |
|
972 |
else |
|
973 |
{ |
|
974 |
infoVariant.Reset(); |
|
975 |
MissingValueL( KChnlId.operator&() ); |
|
976 |
} |
|
977 |
||
978 |
if( aChnlInfoMap->FindL( KContextType , infoVariant ) ) |
|
979 |
{ |
|
980 |
CheckInputTypeL( &infoVariant, |
|
981 |
LIW::EVariantTypeTInt32, |
|
982 |
KContextType.operator&() ); |
|
983 |
||
984 |
aChannelInfo.iContextType = infoVariant.AsTInt32(); |
|
985 |
} |
|
986 |
else |
|
987 |
{ |
|
988 |
infoVariant.Reset(); |
|
989 |
MissingValueL( KContextType.operator&() ); |
|
990 |
} |
|
991 |
||
992 |
if( aChnlInfoMap->FindL( KQuantity , infoVariant ) ) |
|
993 |
{ |
|
994 |
CheckInputTypeL( &infoVariant, |
|
995 |
LIW::EVariantTypeTInt32, |
|
996 |
KQuantity.operator&() ); |
|
997 |
||
998 |
aChannelInfo.iQuantity = infoVariant.AsTInt32(); |
|
999 |
} |
|
1000 |
else |
|
1001 |
{ |
|
1002 |
infoVariant.Reset(); |
|
1003 |
MissingValueL( KQuantity.operator&() ); |
|
1004 |
} |
|
1005 |
||
1006 |
if( aChnlInfoMap->FindL( KChannelType , infoVariant ) ) |
|
1007 |
{ |
|
1008 |
CheckInputTypeL( &infoVariant, |
|
1009 |
LIW::EVariantTypeTInt32, |
|
1010 |
KChannelType.operator&() ); |
|
1011 |
||
1012 |
aChannelInfo.iChannelType = infoVariant.AsTInt32(); |
|
1013 |
} |
|
1014 |
else |
|
1015 |
{ |
|
1016 |
infoVariant.Reset(); |
|
1017 |
MissingValueL( KChannelType.operator&() ); |
|
1018 |
} |
|
1019 |
||
1020 |
if( aChnlInfoMap->FindL( KLocation , infoVariant ) ) |
|
1021 |
{ |
|
1022 |
CheckInputTypeL( &infoVariant, |
|
1023 |
LIW::EVariantTypeDesC, |
|
1024 |
KLocation.operator&() ); |
|
1025 |
||
1026 |
TPtrC location16 = infoVariant.AsDes(); |
|
1027 |
TBuf8<KSensrvLocationLength> location8; |
|
1028 |
CnvUtfConverter::ConvertFromUnicodeToUtf8( location8, location16 ); |
|
1029 |
||
1030 |
aChannelInfo.iLocation = location8; |
|
1031 |
} |
|
1032 |
else |
|
1033 |
{ |
|
1034 |
infoVariant.Reset(); |
|
1035 |
MissingValueL( KLocation.operator&() ); |
|
1036 |
} |
|
1037 |
||
1038 |
if( aChnlInfoMap->FindL( KVendorId , infoVariant ) ) |
|
1039 |
{ |
|
1040 |
CheckInputTypeL( &infoVariant, |
|
1041 |
LIW::EVariantTypeDesC, |
|
1042 |
KVendorId.operator&() ); |
|
1043 |
||
1044 |
TPtrC vendorId16 = infoVariant.AsDes(); |
|
1045 |
TBuf8<KSensrvVendorIdLength> vendorId8; |
|
1046 |
CnvUtfConverter::ConvertFromUnicodeToUtf8( vendorId8, vendorId16 ); |
|
1047 |
||
1048 |
aChannelInfo.iVendorId = vendorId8; |
|
1049 |
} |
|
1050 |
else |
|
1051 |
{ |
|
1052 |
infoVariant.Reset(); |
|
1053 |
MissingValueL( KVendorId.operator&() ); |
|
1054 |
} |
|
1055 |
||
1056 |
if( aChnlInfoMap->FindL( KDataItemSize , infoVariant ) ) |
|
1057 |
{ |
|
1058 |
CheckInputTypeL( &infoVariant, |
|
1059 |
LIW::EVariantTypeTInt32, |
|
1060 |
KDataItemSize.operator&() ); |
|
1061 |
||
1062 |
aChannelInfo.iDataItemSize = infoVariant.AsTInt32(); |
|
1063 |
} |
|
1064 |
else |
|
1065 |
{ |
|
1066 |
infoVariant.Reset(); |
|
1067 |
MissingValueL( KDataItemSize.operator&() ); |
|
1068 |
} |
|
1069 |
||
1070 |
if( aChnlInfoMap->FindL( KChnlDataTypeId , infoVariant ) ) |
|
1071 |
{ |
|
1072 |
CheckInputTypeL( &infoVariant, |
|
1073 |
LIW::EVariantTypeTInt32, |
|
1074 |
KChnlDataTypeId.operator&() ); |
|
1075 |
||
1076 |
aChannelInfo.iChannelDataTypeId = infoVariant.AsTInt32(); |
|
1077 |
} |
|
1078 |
else |
|
1079 |
{ |
|
1080 |
infoVariant.Reset(); |
|
1081 |
MissingValueL( KChnlDataTypeId.operator&() ); |
|
1082 |
} |
|
1083 |
infoVariant.Reset(); |
|
1084 |
} |
|
1085 |
||
1086 |
/* |
|
1087 |
----------------------------------------------------------------------------- |
|
1088 |
CSensorInterface::PropertyStr() |
|
1089 |
Description : Internal function used to extract property string from |
|
1090 |
: the input property id |
|
1091 |
Return values : N/A |
|
1092 |
----------------------------------------------------------------------------- |
|
1093 |
*/ |
|
1094 |
TPtrC CSensorInterface::PropertyStrL( TSensrvPropertyId aPropertyId ) |
|
1095 |
{ |
|
1096 |
||
1097 |
TPtrC ptr; |
|
1098 |
||
1099 |
switch( aPropertyId ) |
|
1100 |
{ |
|
1101 |
case KSensrvPropIdDataRate: |
|
1102 |
ptr.Set( KDataRate ); |
|
1103 |
break; |
|
1104 |
||
1105 |
case KSensrvPropIdAvailability: |
|
1106 |
ptr.Set( KAvailability ); |
|
1107 |
break; |
|
1108 |
||
1109 |
case KSensrvPropIdMeasureRange: |
|
1110 |
ptr.Set( KMeasureRange ); |
|
1111 |
break; |
|
1112 |
||
1113 |
case KSensrvPropIdChannelDataFormat: |
|
1114 |
ptr.Set( KChannelDataFormat ); |
|
1115 |
break; |
|
1116 |
||
1117 |
case KSensrvPropIdChannelAccuracy: |
|
1118 |
ptr.Set( KChannelAccuracy ); |
|
1119 |
break; |
|
1120 |
||
1121 |
case KSensrvPropIdChannelScale: |
|
1122 |
ptr.Set( KChannelScale ); |
|
1123 |
break; |
|
1124 |
||
1125 |
case KSensrvPropIdScaledRange: |
|
1126 |
ptr.Set( KScaledRange ); |
|
1127 |
break; |
|
1128 |
||
1129 |
case KSensrvPropIdChannelUnit: |
|
1130 |
ptr.Set( KChannelUnit ); |
|
1131 |
break; |
|
1132 |
||
1133 |
case KSensrvSensorModel: |
|
1134 |
ptr.Set( KSensorModel ); |
|
1135 |
break; |
|
1136 |
||
1137 |
case KSensrvSensorConnectionType: |
|
1138 |
ptr.Set( KConnectionType ); |
|
1139 |
break; |
|
1140 |
||
1141 |
case KSensrvSensorDescription: |
|
1142 |
ptr.Set( KSensorDescription ); |
|
1143 |
break; |
|
1144 |
||
1145 |
default: |
|
1146 |
User::Leave( KErrNotSupported ); |
|
1147 |
} |
|
1148 |
return ptr; |
|
1149 |
} |
|
1150 |
||
1151 |
/* |
|
1152 |
----------------------------------------------------------------------------- |
|
1153 |
CSensorInterface::PropertyIdInfoL() |
|
1154 |
Description : Internal function used to extract property id info from |
|
1155 |
: the Input |
|
1156 |
Return values : N/A |
|
1157 |
----------------------------------------------------------------------------- |
|
1158 |
*/ |
|
1159 |
TSensrvPropertyId CSensorInterface::PropertyIdInfoL( const TDesC& aPropertyIdStr ) |
|
1160 |
{ |
|
1161 |
TSensrvPropertyId propId = 0; |
|
1162 |
||
1163 |
if( aPropertyIdStr == KDataRate ) |
|
1164 |
propId = KSensrvPropIdDataRate; |
|
1165 |
else if( aPropertyIdStr == KAvailability ) |
|
1166 |
propId = KSensrvPropIdAvailability; |
|
1167 |
else if( aPropertyIdStr == KMeasureRange ) |
|
1168 |
propId = KSensrvPropIdMeasureRange; |
|
1169 |
else if( aPropertyIdStr == KChannelDataFormat ) |
|
1170 |
propId = KSensrvPropIdChannelDataFormat; |
|
1171 |
else if( aPropertyIdStr == KChannelAccuracy ) |
|
1172 |
propId = KSensrvPropIdChannelAccuracy; |
|
1173 |
else if( aPropertyIdStr == KChannelScale ) |
|
1174 |
propId = KSensrvPropIdChannelScale; |
|
1175 |
else if( aPropertyIdStr == KScaledRange ) |
|
1176 |
propId = KSensrvPropIdScaledRange; |
|
1177 |
else if( aPropertyIdStr == KChannelUnit ) |
|
1178 |
propId = KSensrvPropIdChannelUnit; |
|
1179 |
else if( aPropertyIdStr == KSensorModel ) |
|
1180 |
propId = KSensrvSensorModel; |
|
1181 |
else if( aPropertyIdStr == KConnectionType ) |
|
1182 |
propId = KSensrvSensorConnectionType; |
|
1183 |
else if( aPropertyIdStr == KSensorDescription ) |
|
1184 |
propId = KSensrvSensorDescription; |
|
1185 |
else |
|
1186 |
{ |
|
1187 |
iErrorString = KErrPropInvalidPropId.operator()().Alloc(); |
|
1188 |
User::Leave( SErrInvalidServiceArgument ); |
|
1189 |
} |
|
1190 |
return propId; |
|
1191 |
} |