|
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: Contaions implementaion for sensor callback class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "sensorcallback.h" |
|
19 #include "sensorservice.hrh" |
|
20 |
|
21 |
|
22 |
|
23 /* |
|
24 ----------------------------------------------------------------------------- |
|
25 CSensorCallback* CSensorCallback::NewL() |
|
26 Description : Two-phased constructor. |
|
27 Return values : CSensorCallback object pointer |
|
28 |
|
29 ----------------------------------------------------------------------------- |
|
30 */ |
|
31 CSensorCallback* CSensorCallback::NewL( MLiwNotifyCallback* aCallBack, |
|
32 TInt32 aTransactionid) |
|
33 |
|
34 { |
|
35 CSensorCallback* self = new ( ELeave ) CSensorCallback( aCallBack, |
|
36 aTransactionid ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 |
|
42 } |
|
43 |
|
44 /* |
|
45 ----------------------------------------------------------------------------- |
|
46 void CSensorCallback::DataNotificationL() |
|
47 Description : Called by sensor framework when sensor |
|
48 channel data is received to send received |
|
49 data to the client |
|
50 Return values : N/A |
|
51 |
|
52 ----------------------------------------------------------------------------- |
|
53 */ |
|
54 void CSensorCallback::DataNotificationL( CSensrvChannel& aChannel ) |
|
55 { |
|
56 |
|
57 //Array for orientation data |
|
58 const TPtrC gOrientationArr[] = |
|
59 { |
|
60 KUndefined(), |
|
61 KDisplayUp(), |
|
62 KDisplayDown(), |
|
63 KDisplayLeftUp(), |
|
64 KDisplayRightUp(), |
|
65 KDisplayUpwards(), |
|
66 KDisplayDownwards() |
|
67 }; |
|
68 |
|
69 //Conversion from Localtime returned by Sensor FW to UTC time |
|
70 TTime utcNow; |
|
71 utcNow.UniversalTime(); |
|
72 TTime localNow; |
|
73 localNow.HomeTime(); |
|
74 // convert UTC time to local time |
|
75 TTimeIntervalMicroSeconds diff = localNow.MicroSecondsFrom( utcNow ); |
|
76 |
|
77 CleanupStack :: PushL( this ); |
|
78 CLiwGenericParamList* outParamList = CLiwGenericParamList :: NewL(); |
|
79 CleanupStack :: PushL( outParamList ); |
|
80 CLiwGenericParamList* inputParamList = CLiwGenericParamList :: NewL(); |
|
81 CleanupStack :: PushL( inputParamList ); |
|
82 TSensrvChannelInfo info = aChannel.GetChannelInfo(); |
|
83 |
|
84 TLiwGenericParam errorparam(KErrorCode , TLiwVariant(( TInt32 )KErrNone)) ; |
|
85 outParamList->AppendL(errorparam); |
|
86 |
|
87 CLiwDefaultMap* chnlDataMap = CLiwDefaultMap::NewL() ; |
|
88 CleanupStack::PushL( chnlDataMap ); |
|
89 |
|
90 switch( info.iChannelType ) |
|
91 { |
|
92 case EFindAccelerometerXYZAxisData: |
|
93 { |
|
94 TSensrvAccelerometerAxisData accData; |
|
95 TPckg<TSensrvAccelerometerAxisData> accPackage( accData ); |
|
96 aChannel.GetData( accPackage ); |
|
97 |
|
98 chnlDataMap->InsertL( KDataType , |
|
99 TLiwVariant( KAcclmtrAxisData ) ); |
|
100 chnlDataMap->InsertL( KTimeStamp , |
|
101 TLiwVariant((TTime)( accData.iTimeStamp - diff ) ) ); |
|
102 chnlDataMap->InsertL( KXAxisData , |
|
103 TLiwVariant((TInt32)( accData.iAxisX ) ) ); |
|
104 chnlDataMap->InsertL( KYAxisData , |
|
105 TLiwVariant((TInt32)( accData.iAxisY ) ) ); |
|
106 chnlDataMap->InsertL( KZAxisData , |
|
107 TLiwVariant((TInt32)( accData.iAxisZ ) ) ); |
|
108 |
|
109 break; |
|
110 } |
|
111 case EFindAccelerometerDoubleTappingData: |
|
112 { |
|
113 TSensrvTappingData accData; |
|
114 TPckg<TSensrvTappingData> accPackage( accData ); |
|
115 aChannel.GetData( accPackage ); |
|
116 |
|
117 chnlDataMap->InsertL( KDataType , |
|
118 TLiwVariant( KAcclmtrDoubleTappingData ) ); |
|
119 chnlDataMap->InsertL( KTimeStamp , |
|
120 TLiwVariant((TTime)( accData.iTimeStamp - diff ) ) ); |
|
121 chnlDataMap->InsertL( KDirection , |
|
122 TLiwVariant( (TInt32)(accData.iDirection) ) ); |
|
123 |
|
124 break; |
|
125 } |
|
126 |
|
127 case EFindOrientationData: |
|
128 { |
|
129 TSensrvOrientationData accData; |
|
130 TPckg<TSensrvOrientationData> accPackage( accData ); |
|
131 aChannel.GetData( accPackage ); |
|
132 |
|
133 chnlDataMap->InsertL( KDataType , |
|
134 TLiwVariant( KOrientationData ) ); |
|
135 chnlDataMap->InsertL( KTimeStamp , |
|
136 TLiwVariant((TTime)( accData.iTimeStamp - diff ) ) ); |
|
137 |
|
138 TInt orientation = accData.iDeviceOrientation; |
|
139 chnlDataMap->InsertL( KDeviceOrientation, |
|
140 TLiwVariant( gOrientationArr[orientation] ) ); |
|
141 break; |
|
142 } |
|
143 |
|
144 case EFindRotationData: |
|
145 { |
|
146 TSensrvRotationData accData; |
|
147 TPckg<TSensrvRotationData> accPackage( accData ); |
|
148 aChannel.GetData( accPackage ); |
|
149 |
|
150 chnlDataMap->InsertL( KDataType , TLiwVariant( KRotationData ) ); |
|
151 chnlDataMap->InsertL( KTimeStamp , |
|
152 TLiwVariant( (TTime) ( accData.iTimeStamp - diff ) ) ); |
|
153 chnlDataMap->InsertL ( KAbtXAxis , |
|
154 TLiwVariant((TInt32)( accData.iDeviceRotationAboutXAxis ) ) ); |
|
155 chnlDataMap->InsertL( KAbtYAxis , |
|
156 TLiwVariant((TInt32)( accData.iDeviceRotationAboutYAxis ) ) ); |
|
157 chnlDataMap->InsertL( KAbtZAxis , |
|
158 TLiwVariant((TInt32)( accData.iDeviceRotationAboutZAxis ) ) ); |
|
159 |
|
160 |
|
161 break; |
|
162 } |
|
163 |
|
164 } |
|
165 |
|
166 TLiwGenericParam outParm( KReturnValue , TLiwVariant( chnlDataMap ) ) ; |
|
167 |
|
168 outParamList->AppendL( outParm ) ; |
|
169 CleanupStack::Pop( chnlDataMap ); |
|
170 chnlDataMap->DecRef(); |
|
171 |
|
172 //Notify user with the data received from a particular sensor channel |
|
173 iCallBack->HandleNotifyL( iTransactionId , KLiwEventInProgress , *outParamList , *inputParamList ) ; |
|
174 |
|
175 CleanupStack::PopAndDestroy( inputParamList ); |
|
176 CleanupStack::PopAndDestroy( outParamList ); |
|
177 CleanupStack::Pop( this ); |
|
178 } |
|
179 |
|
180 |
|
181 /* |
|
182 ----------------------------------------------------------------------------- |
|
183 void CSensorCallback::DataReceived() |
|
184 Description : Called by sensor framework when sensor |
|
185 channel data is received |
|
186 Return values : N/A |
|
187 |
|
188 ----------------------------------------------------------------------------- |
|
189 */ |
|
190 void CSensorCallback::DataReceived( CSensrvChannel& aChannel, |
|
191 TInt /*aCount*/, |
|
192 TInt /*aDataLost*/ ) |
|
193 |
|
194 { |
|
195 TInt err = 0; |
|
196 TRAP( err , DataNotificationL( aChannel ) ); |
|
197 } |
|
198 |
|
199 /* |
|
200 ----------------------------------------------------------------------------- |
|
201 void CSensorCallback::DataError() |
|
202 Description : Called by sensor framework when an |
|
203 error occurs |
|
204 Return values : N/A |
|
205 |
|
206 ----------------------------------------------------------------------------- |
|
207 */ |
|
208 void CSensorCallback::DataError( CSensrvChannel& /*aChannel*/, |
|
209 TSensrvErrorSeverity /*aError*/ ) |
|
210 { |
|
211 } |
|
212 |
|
213 |
|
214 /* |
|
215 ----------------------------------------------------------------------------- |
|
216 void CSensorCallback::GetDataListenerInterfaceL() |
|
217 Description : Returns a pointer to a specified interface - to allow |
|
218 future extension of this class without breaking binary |
|
219 compatibility |
|
220 Return values : N/A |
|
221 |
|
222 ----------------------------------------------------------------------------- |
|
223 */ |
|
224 void CSensorCallback::GetDataListenerInterfaceL( TUid /*aInterfaceUid*/, |
|
225 TAny*& aInterface ) |
|
226 { |
|
227 aInterface = NULL; // Extension interfaces are not supported |
|
228 } |
|
229 |
|
230 |
|
231 /* |
|
232 ----------------------------------------------------------------------------- |
|
233 CSensorCallback::CSensorCallback() |
|
234 Description : Constructor |
|
235 Return values : N/A |
|
236 ----------------------------------------------------------------------------- |
|
237 */ |
|
238 CSensorCallback::CSensorCallback( MLiwNotifyCallback* aCallBack, |
|
239 TInt32 aTransactionid ) |
|
240 :iCallBack( aCallBack ), |
|
241 iTransactionId( aTransactionid ) |
|
242 { |
|
243 } |
|
244 |
|
245 /* |
|
246 ----------------------------------------------------------------------------- |
|
247 void CSensorCallback::ConstructL() |
|
248 Description : Symbian 2nd phase constructor can leave. |
|
249 Return values : N/A |
|
250 ----------------------------------------------------------------------------- |
|
251 */ |
|
252 void CSensorCallback::ConstructL() |
|
253 { |
|
254 } |
|
255 |
|
256 /* |
|
257 ----------------------------------------------------------------------------- |
|
258 CSensorCallback::~CSensorCallback() |
|
259 Description : Destructor, free allocated resources |
|
260 Return values : N/A |
|
261 ----------------------------------------------------------------------------- |
|
262 */ |
|
263 CSensorCallback::~CSensorCallback() |
|
264 { |
|
265 } |
|
266 |
|
267 |