|
1 /* |
|
2 * Copyright (c) 2006-2008 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 "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: Reference implementation of SSY Channel Data Provider interface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ssyreferencechanneldataprovider.h" |
|
20 #include "ssyreferencetrace.h" |
|
21 #include "ssyreferencechannel.h" |
|
22 #include "ssyreferencecontrol.h" |
|
23 #include "ssyreferencecmdhandler.h" |
|
24 #include "ssycallback.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CSsyReferenceChannelDataProvider C++ constructor |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CSsyReferenceChannelDataProvider::CSsyReferenceChannelDataProvider( CSsyReferenceChannel& aChannel ) : |
|
33 iChannel( aChannel ) |
|
34 { |
|
35 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::CSsyReferenceChannelDataProvider()" ) ) ); |
|
36 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::CSsyReferenceChannelDataProvider() - return" ) ) ); |
|
37 } |
|
38 |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Symbian 2nd phase constructor |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void CSsyReferenceChannelDataProvider::ConstructL() |
|
45 { |
|
46 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::ConstructL()" ) ) ); |
|
47 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::ConstructL() - return" ) ) ); |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CSsyReferenceChannelDataProvider::NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CSsyReferenceChannelDataProvider* CSsyReferenceChannelDataProvider::NewL( CSsyReferenceChannel& aChannel ) |
|
56 { |
|
57 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::NewL()" ) ) ); |
|
58 CSsyReferenceChannelDataProvider* self = new ( ELeave ) CSsyReferenceChannelDataProvider( aChannel ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop( self ); |
|
62 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::NewL() - return" ) ) ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Destructor |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CSsyReferenceChannelDataProvider::~CSsyReferenceChannelDataProvider() |
|
71 { |
|
72 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::~CSsyReferenceChannelDataProvider()" ) ) ); |
|
73 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::~CSsyReferenceChannelDataProvider() - return" ) ) ); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CSsyReferenceChannelDataProvider::StartChannelDataL |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CSsyReferenceChannelDataProvider::StartChannelDataL( |
|
81 const TSensrvChannelId aChannelId, |
|
82 TUint8* aBuffer, |
|
83 TInt aCount ) |
|
84 { |
|
85 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::StartChannelDataL()" ) ) ); |
|
86 |
|
87 if ( iChannel.ChannelId() != aChannelId ) |
|
88 { |
|
89 User::Leave( KErrNotFound ); |
|
90 } |
|
91 |
|
92 // Store buffer pointer |
|
93 iDataBuffer = aBuffer; |
|
94 iMaxCount = aCount; |
|
95 iDataCount = 0; |
|
96 |
|
97 // Udpate channel state |
|
98 iChannel.UpdateState( CSsyReferenceChannel::ESsyReferenceChannelReceiving ); |
|
99 |
|
100 // Start receiving |
|
101 iChannel.CommandHandler().ProcessCommand( TSsyReferenceMsg( aChannelId, ESsyReferenceStartChannelData ) ); |
|
102 |
|
103 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::StartChannelDataL() - return" ) ) ); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CSsyReferenceChannelDataProvider::StopChannelDataL |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void CSsyReferenceChannelDataProvider::StopChannelDataL( const TSensrvChannelId aChannelId ) |
|
111 { |
|
112 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::StopChannelDataL()" ) ) ); |
|
113 |
|
114 // Leave if wrong channel |
|
115 if ( iChannel.ChannelId() != aChannelId ) |
|
116 { |
|
117 User::Leave( KErrNotFound ); |
|
118 } |
|
119 |
|
120 // Udpate channel state |
|
121 iChannel.UpdateState( CSsyReferenceChannel::ESsyReferenceChannelOpen ); |
|
122 |
|
123 // Stop receiving |
|
124 iChannel.CommandHandler().ProcessCommand( TSsyReferenceMsg( aChannelId, ESsyReferenceStopChannelData ) ); |
|
125 |
|
126 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::StopChannelDataL() - return" ) ) ); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CSsyReferenceChannelDataProvider::ForceBufferFilledL |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CSsyReferenceChannelDataProvider::ForceBufferFilledL( const TSensrvChannelId aChannelId ) |
|
134 { |
|
135 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::ForceBufferFilledL()" ) ) ); |
|
136 |
|
137 // Leave if wrong channel |
|
138 if ( iChannel.ChannelId() != aChannelId ) |
|
139 { |
|
140 User::Leave( KErrNotFound ); |
|
141 } |
|
142 |
|
143 // Send current buffer. Channel keeps receiveing |
|
144 SendBufferFilled(); |
|
145 |
|
146 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::ForceBufferFilledL() - return" ) ) ); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CSensrvTestCases::GetChannelDataProviderInterfaceL |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CSsyReferenceChannelDataProvider::GetChannelDataProviderInterfaceL( TUid aInterfaceUid, |
|
154 TAny*& aInterface ) |
|
155 { |
|
156 aInterface = NULL; |
|
157 |
|
158 if ( aInterfaceUid.iUid == KSsyChannelDataProviderInterface1.iUid ) |
|
159 { |
|
160 aInterface = reinterpret_cast<TAny*>( |
|
161 static_cast<MSsyChannelDataProvider*>( this ) ); |
|
162 } |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CSsyReferenceChannelDataProvider::ChannelDataReceived |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void CSsyReferenceChannelDataProvider::ChannelDataReceivedL( TSsyReferenceMsg* aMessage ) |
|
170 { |
|
171 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::ChannelDataReceived()" ) ) ); |
|
172 |
|
173 // Get base class from message |
|
174 TSsyRefChannelDataBase* dataItemBase = aMessage->DataItem(); |
|
175 |
|
176 if ( !dataItemBase ) |
|
177 { |
|
178 User::Leave( KErrArgument ); |
|
179 } |
|
180 |
|
181 // get size of the object |
|
182 TInt size( dataItemBase->Size() ); |
|
183 |
|
184 // First, resolve data item type |
|
185 switch ( dataItemBase->ChannelDataType() ) |
|
186 { |
|
187 case TSsyRefChannelDataBase::ESsyRefChannelTypeTapping: |
|
188 { |
|
189 // Cast data item base to tapping data item |
|
190 TSsyRefChannelDataTapping* tappingData = static_cast<TSsyRefChannelDataTapping*>( dataItemBase ); |
|
191 TSensrvTappingData senSrvTapping; |
|
192 senSrvTapping.iTimeStamp = tappingData->Timestamp(); |
|
193 senSrvTapping.iDirection = tappingData->Direction(); |
|
194 |
|
195 // Add mapped data item into buffer |
|
196 AddDataToBuffer( reinterpret_cast<TUint8*>( &senSrvTapping ), size ); |
|
197 break; |
|
198 } |
|
199 case TSsyRefChannelDataBase::ESsyRefChannelTypeAxis: |
|
200 { |
|
201 // Cast data item base to Axis data item |
|
202 TSsyRefChannelDataAxis* axisData = static_cast<TSsyRefChannelDataAxis*>( dataItemBase ); |
|
203 TSensrvAccelerometerAxisData senSrvAxis; |
|
204 senSrvAxis.iTimeStamp = axisData->Timestamp(); |
|
205 senSrvAxis.iAxisX = axisData->XAxis(); |
|
206 senSrvAxis.iAxisY = axisData->YAxis(); |
|
207 senSrvAxis.iAxisZ = axisData->ZAxis(); |
|
208 |
|
209 // Add data to buffer |
|
210 AddDataToBuffer( reinterpret_cast<TUint8*>( &senSrvAxis ), size ); |
|
211 break; |
|
212 } |
|
213 case TSsyRefChannelDataBase::ESsyRefChannelTypeProximity: |
|
214 { |
|
215 // Cast data item base to tapping data item |
|
216 TSsyRefChannelDataProximity* proximityData = static_cast<TSsyRefChannelDataProximity*>( dataItemBase ); |
|
217 TSensrvProximityData senSrvProximity; |
|
218 senSrvProximity.iProximityState = ( TSensrvProximityData::TProximityState ) proximityData->ProximityState(); |
|
219 |
|
220 // Add mapped data item into buffer |
|
221 AddDataToBuffer( reinterpret_cast<TUint8*>( &senSrvProximity ), size ); |
|
222 break; |
|
223 } |
|
224 case TSsyRefChannelDataBase::ESsyRefChannelTypeAmbientLight: |
|
225 { |
|
226 // Cast data item base to tapping data item |
|
227 TSsyRefChannelDataAmbientLight* ambientLightData = static_cast<TSsyRefChannelDataAmbientLight*>( dataItemBase ); |
|
228 TSensrvAmbientLightData senSrvAmbientLight; |
|
229 senSrvAmbientLight.iAmbientLight = ambientLightData->AmbientLightState(); |
|
230 |
|
231 // Add mapped data item into buffer |
|
232 AddDataToBuffer( reinterpret_cast<TUint8*>( &senSrvAmbientLight ), size ); |
|
233 break; |
|
234 } |
|
235 case TSsyRefChannelDataBase::ESsyRefChannelTypeMagneticAxis: |
|
236 { |
|
237 // Cast data item base to Axis data item |
|
238 TSsyRefChannelDataMagneticAxis* axisData = static_cast<TSsyRefChannelDataMagneticAxis*>( dataItemBase ); |
|
239 TSensrvMagnetometerAxisData senSrvAxis; |
|
240 senSrvAxis.iTimeStamp = axisData->Timestamp(); |
|
241 senSrvAxis.iAxisXRaw = axisData->XAxis(); |
|
242 senSrvAxis.iAxisYRaw = axisData->YAxis(); |
|
243 senSrvAxis.iAxisZRaw = axisData->ZAxis(); |
|
244 senSrvAxis.iAxisXCalibrated = axisData->XAxisCalib(); |
|
245 senSrvAxis.iAxisYCalibrated = axisData->YAxisCalib(); |
|
246 senSrvAxis.iAxisZCalibrated = axisData->ZAxisCalib(); |
|
247 |
|
248 // Add data to buffer |
|
249 AddDataToBuffer( reinterpret_cast<TUint8*>( &senSrvAxis ), size ); |
|
250 break; |
|
251 } |
|
252 default: |
|
253 { |
|
254 // Unknown data item -> Leave |
|
255 User::Leave( KErrUnknown ); |
|
256 } |
|
257 } |
|
258 |
|
259 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::ChannelDataReceived() - return" ) ) ); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CSsyReferenceChannelDataProvider::AddDataToBuffer |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CSsyReferenceChannelDataProvider::AddDataToBuffer( TUint8* aData, const TInt aSize ) |
|
267 { |
|
268 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::AddDataToBuffer()" ) ) ); |
|
269 // Write data to buffer. If buffer is full, send notification to SensorServer |
|
270 |
|
271 // Write data bytes one by one to buffer pointer. The actual buffer is in Sensor Server |
|
272 for ( TInt i = 0; i < aSize; i++ ) |
|
273 { |
|
274 *iDataBuffer++ = *aData++; |
|
275 } |
|
276 |
|
277 // Increase number of items count |
|
278 iDataCount++; |
|
279 |
|
280 // Check is maximum data count received |
|
281 if ( iDataCount == iMaxCount ) |
|
282 { |
|
283 // Send BufferFilled notification to Sensor server |
|
284 SendBufferFilled(); |
|
285 } |
|
286 |
|
287 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::AddDataToBuffer() - return" ) ) ); |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // CSsyReferenceChannelDataProvider::SendBufferFilled |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 void CSsyReferenceChannelDataProvider::SendBufferFilled() |
|
295 { |
|
296 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::SendBufferFilled()" ) ) ); |
|
297 // Send BufferFilled notification to Sensor server |
|
298 iChannel.SsyControl().SsyCallback().BufferFilled( iChannel.ChannelId(), iDataCount, iDataBuffer, iMaxCount ); |
|
299 iDataCount = 0; |
|
300 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannelDataProvider::SendBufferFilled() - return" ) ) ); |
|
301 } |
|
302 |
|
303 // End of file |