|
1 /* |
|
2 * Copyright (c) 2007,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: Channel class of Orientation SSY |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ssycallback.h> |
|
20 #include <sensrvorientationsensor.h> |
|
21 #include "SsyChannel.h" |
|
22 #include "SsyOrientation.h" |
|
23 #include "SsyProperty.h" |
|
24 #include "SsyConfiguration.h" |
|
25 #include "SsyTrace.h" |
|
26 |
|
27 |
|
28 #ifdef _DEBUG |
|
29 |
|
30 // ---------------------------------------------------------------------------------- |
|
31 // ConvertChannelStateIntoString() |
|
32 // Helper function for printing this channel into a "string" |
|
33 // ---------------------------------------------------------------------------------- |
|
34 // |
|
35 const TDesC* ConvertChannelStateIntoString( TChannelState aChannelState ) |
|
36 { |
|
37 _LIT(KChannelIdle, "EChannelIdle"); |
|
38 _LIT(KChannelOpening, "EChannelOpening"); |
|
39 _LIT(KChannelOpen, "EChannelOpen"); |
|
40 _LIT(KChannelClosing, "EChannelClosing"); |
|
41 _LIT(KChannelListening, "EChannelListening"); |
|
42 _LIT(KChannelDataReceived, "EChannelDataReceived"); |
|
43 _LIT(KChannelStopListening, "EChannelStopListening"); |
|
44 _LIT(KChannelForceBufferFilled, "EChannelForceBufferFilled"); |
|
45 _LIT(KChannelBufferFilled, "EChannelBufferFilled"); |
|
46 _LIT(KDefault, "EDefault"); |
|
47 |
|
48 switch ( aChannelState ) |
|
49 { |
|
50 case EChannelIdle: |
|
51 return &KChannelIdle; |
|
52 case EChannelOpening: |
|
53 return &KChannelOpening; |
|
54 case EChannelOpen: |
|
55 return &KChannelOpen; |
|
56 case EChannelClosing: |
|
57 return &KChannelClosing; |
|
58 case EChannelListening: |
|
59 return &KChannelListening; |
|
60 case EChannelDataReceived: |
|
61 return &KChannelDataReceived; |
|
62 case EChannelStopListening: |
|
63 return &KChannelStopListening; |
|
64 case EChannelForceBufferFilled: |
|
65 return &KChannelForceBufferFilled; |
|
66 case EChannelBufferFilled: |
|
67 return &KChannelBufferFilled; |
|
68 default: |
|
69 return &KDefault; |
|
70 } |
|
71 } |
|
72 |
|
73 #endif |
|
74 |
|
75 // ---------------------------------------------------------------------------------- |
|
76 // CSSYChannel::CSSYChannel() |
|
77 // ---------------------------------------------------------------------------------- |
|
78 // |
|
79 CSSYChannel::CSSYChannel( CSSYProperty* aProperty, |
|
80 MSsyCallback* const aCallBack, |
|
81 const TSensrvChannelInfo& aChannelInfo ) : |
|
82 CActive( EPriorityStandard ), |
|
83 iOrientationHandler( NULL ), |
|
84 iChannelProperties( NULL ), |
|
85 iSensorProperties( aProperty ), |
|
86 iCallback( aCallBack ), |
|
87 iChannelState( EChannelIdle ), |
|
88 iChannelInfo( aChannelInfo ), |
|
89 iBuffer( NULL ), |
|
90 iCount( 0 ), |
|
91 iCountReceived( 0 ), |
|
92 iWritePointer( NULL ) |
|
93 { |
|
94 SSY_TRACE_IN(); |
|
95 |
|
96 //ASSERT_DEBUG_SSY( aCallBack ); |
|
97 |
|
98 // Add our active object to the process active scheduler |
|
99 CActiveScheduler::Add( this ); |
|
100 |
|
101 SSY_TRACE_OUT(); |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------------------------------------- |
|
105 // CSSYChannel::NewL() |
|
106 // ---------------------------------------------------------------------------------- |
|
107 // |
|
108 CSSYChannel* CSSYChannel::NewL( CSSYProperty* aProperty, |
|
109 MSsyCallback* const aCallBack, |
|
110 const TSensrvChannelInfo& aChannelInfo ) |
|
111 { |
|
112 SSY_TRACE_IN(); |
|
113 |
|
114 ASSERT_DEBUG_SSY( aCallBack ); |
|
115 |
|
116 if ( !aCallBack ) |
|
117 { |
|
118 User::Leave( KErrArgument ); |
|
119 } |
|
120 |
|
121 CSSYChannel* self = new( ELeave ) CSSYChannel( aProperty, aCallBack, aChannelInfo ); |
|
122 CleanupStack::PushL( self ); |
|
123 self->ConstructL(); |
|
124 CleanupStack::Pop( self ); |
|
125 |
|
126 SSY_TRACE_OUT(); |
|
127 |
|
128 return self; |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------------------------------------- |
|
132 // CSSYChannel::ConstructL() |
|
133 // ---------------------------------------------------------------------------------- |
|
134 // |
|
135 void CSSYChannel::ConstructL() |
|
136 { |
|
137 SSY_TRACE_IN(); |
|
138 |
|
139 _LIT( KThreadName, "OrientationThread" ); |
|
140 RThread thread; |
|
141 thread.RenameMe( KThreadName ); |
|
142 |
|
143 // Create channel properties |
|
144 if ( iChannelInfo.iChannelType == KSensrvChannelTypeIdOrientationData ) |
|
145 { |
|
146 iChannelProperties = new (ELeave) CSSYProperty( |
|
147 0, |
|
148 KSSyChannelOrientationProperties, |
|
149 ARRAY_LENGTH( |
|
150 KSSyChannelOrientationProperties) ); |
|
151 } |
|
152 else if ( iChannelInfo.iChannelType == KSensrvChannelTypeIdRotationData ) |
|
153 { |
|
154 iChannelProperties = new (ELeave) CSSYProperty( |
|
155 0, |
|
156 KSSyChannelRotationProperties, |
|
157 ARRAY_LENGTH( |
|
158 KSSyChannelRotationProperties) ); |
|
159 } |
|
160 |
|
161 // Create orientation handler |
|
162 iOrientationHandler = new (ELeave) CSSYOrientation( iChannelInfo.iChannelType ); |
|
163 iOrientationHandler->ConstructL(); |
|
164 |
|
165 SSY_TRACE_OUT(); |
|
166 } |
|
167 |
|
168 // ---------------------------------------------------------------------------------- |
|
169 // CSSYChannel::~CSSYChannel() |
|
170 // ---------------------------------------------------------------------------------- |
|
171 // |
|
172 CSSYChannel::~CSSYChannel() |
|
173 { |
|
174 SSY_TRACE_IN(); |
|
175 |
|
176 Cancel(); |
|
177 |
|
178 delete iChannelProperties; |
|
179 iChannelProperties = NULL; |
|
180 |
|
181 delete iOrientationHandler; |
|
182 iOrientationHandler = NULL; |
|
183 |
|
184 // These pointers are not owned |
|
185 iSensorProperties = NULL; // Pointer assigned in cosntructor |
|
186 iCallback = NULL; // Pointer assigned in cosntructor |
|
187 iBuffer = NULL; // Assigned in StartChannelData |
|
188 iWritePointer = NULL; // Assigned in AppendData |
|
189 |
|
190 SSY_TRACE_OUT(); |
|
191 } |
|
192 |
|
193 // ---------------------------------------------------------------------------------- |
|
194 // CSSYChannel::DoCancel() |
|
195 // ---------------------------------------------------------------------------------- |
|
196 // |
|
197 void CSSYChannel::DoCancel() |
|
198 { |
|
199 SSY_TRACE_IN(); |
|
200 |
|
201 // Try to stop the channel, ignore errors |
|
202 TRAP_IGNORE( StopChannelDataL( iChannelInfo.iChannelId ) ); |
|
203 |
|
204 SSY_TRACE_OUT(); |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------------------------------------- |
|
208 // CSSYChannel::RunError() |
|
209 // ---------------------------------------------------------------------------------- |
|
210 // |
|
211 TInt CSSYChannel::RunError( TInt aError ) |
|
212 { |
|
213 SSY_TRACE( EMust, "ORIENTATIONSSY:RunError %d", aError ); |
|
214 |
|
215 return KErrNone; |
|
216 } |
|
217 |
|
218 |
|
219 // ---------------------------------------------------------------------------------- |
|
220 // CSSYChannel::SetChannelState() |
|
221 // ---------------------------------------------------------------------------------- |
|
222 // |
|
223 void CSSYChannel::SetChannelState( const TChannelState aChannelState ) |
|
224 { |
|
225 #ifdef _DEBUG |
|
226 SSY_TRACE( EMust, "ORIENTATIONSSY:State change from %S to %S with channelId %d", |
|
227 ConvertChannelStateIntoString(iChannelState), |
|
228 ConvertChannelStateIntoString(aChannelState), |
|
229 iChannelInfo.iChannelId ); |
|
230 #endif |
|
231 |
|
232 iChannelState = aChannelState; |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------------------------------------- |
|
236 // CSSYChannel::AppendData() |
|
237 // ---------------------------------------------------------------------------------- |
|
238 // |
|
239 TBool CSSYChannel::AppendData( |
|
240 const TSensrvOrientationData& aOrientationData, |
|
241 const TSensrvRotationData& aRotationData ) |
|
242 { |
|
243 TBool ret( ETrue ); |
|
244 |
|
245 if ( iChannelState == EChannelDataReceived ) |
|
246 { |
|
247 if( iCountReceived == 0 ) |
|
248 { |
|
249 SSY_TRACE( EExtended, "ORIENTATIONSSY:First data append to buffer" ); |
|
250 iWritePointer = iBuffer; |
|
251 } |
|
252 |
|
253 ASSERT_DEBUG_SSY( iWritePointer ); |
|
254 |
|
255 if ( !iWritePointer ) |
|
256 { |
|
257 return EFalse; |
|
258 } |
|
259 |
|
260 if ( iChannelInfo.iChannelType == KSensrvChannelTypeIdOrientationData ) |
|
261 { |
|
262 TSensrvOrientationData* p = reinterpret_cast<TSensrvOrientationData*>(iWritePointer); |
|
263 p->iTimeStamp = aOrientationData.iTimeStamp; |
|
264 p->iDeviceOrientation = aOrientationData.iDeviceOrientation; |
|
265 iWritePointer += sizeof( TSensrvOrientationData ); |
|
266 } |
|
267 else if ( iChannelInfo.iChannelType == KSensrvChannelTypeIdRotationData ) |
|
268 { |
|
269 TSensrvRotationData* p = reinterpret_cast<TSensrvRotationData*>(iWritePointer); |
|
270 p->iDeviceRotationAboutZAxis = aRotationData.iDeviceRotationAboutZAxis; |
|
271 p->iDeviceRotationAboutXAxis = aRotationData.iDeviceRotationAboutXAxis; |
|
272 p->iDeviceRotationAboutYAxis = aRotationData.iDeviceRotationAboutYAxis; |
|
273 p->iTimeStamp = aRotationData.iTimeStamp; |
|
274 iWritePointer += sizeof( TSensrvRotationData ); |
|
275 } |
|
276 else |
|
277 { |
|
278 ret = EFalse; |
|
279 } |
|
280 } |
|
281 else |
|
282 { |
|
283 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Trying to append while not listening ", ChannelId() ); |
|
284 ret = EFalse; |
|
285 } |
|
286 |
|
287 return ret; |
|
288 } |
|
289 |
|
290 // ---------------------------------------------------------------------------------- |
|
291 // CSSYChannel::RunL() |
|
292 // ---------------------------------------------------------------------------------- |
|
293 // |
|
294 void CSSYChannel::RunL() |
|
295 { |
|
296 SSY_TRACE_IN(); |
|
297 |
|
298 SSY_TRACE( EMust, "ORIENTATIONSSY:RunL in state %S", ConvertChannelStateIntoString(iChannelState) ); |
|
299 |
|
300 switch ( iChannelState ) |
|
301 { |
|
302 case EChannelIdle: |
|
303 break; |
|
304 case EChannelOpening: |
|
305 { |
|
306 // Before completing channel opening, get max data rate from actual SSY |
|
307 if ( !iSensorProperties->DataRateUpdated() ) |
|
308 { |
|
309 TSensrvProperty maxdatarate; |
|
310 RSensrvChannelList affectedChannels; |
|
311 // Get max data rate |
|
312 iOrientationHandler->GetMaxDataRateL( maxdatarate ); |
|
313 // Set property |
|
314 iSensorProperties->SetProperty( maxdatarate, affectedChannels ); |
|
315 } |
|
316 |
|
317 SetChannelState( EChannelOpen ); |
|
318 iCallback->ChannelOpened( iChannelInfo.iChannelId, iStatus.Int(), this, this ); |
|
319 break; |
|
320 } |
|
321 case EChannelOpen: |
|
322 break; |
|
323 case EChannelClosing: |
|
324 SetChannelState( EChannelIdle ); |
|
325 iCallback->ChannelClosed( iChannelInfo.iChannelId ); |
|
326 break; |
|
327 case EChannelListening: |
|
328 SetChannelState( EChannelDataReceived ); |
|
329 iOrientationHandler->GetDataFromHardware( this ); |
|
330 break; |
|
331 case EChannelDataReceived: |
|
332 |
|
333 // Channel excepted data, increase the receive counter |
|
334 iCountReceived++; |
|
335 |
|
336 if( iCountReceived == iCount ) |
|
337 { |
|
338 SetChannelState( EChannelBufferFilled ); |
|
339 } |
|
340 else |
|
341 { |
|
342 SetChannelState( EChannelListening ); |
|
343 } |
|
344 |
|
345 IssueRequest(); |
|
346 break; |
|
347 case EChannelStopListening: |
|
348 SetChannelState( EChannelOpen ); |
|
349 iBuffer = NULL; |
|
350 iCount = 0; |
|
351 iCountReceived = 0; |
|
352 break; |
|
353 case EChannelForceBufferFilled: |
|
354 // Intentional flowthrough |
|
355 case EChannelBufferFilled: |
|
356 |
|
357 iBuffer = NULL; |
|
358 iCount = 0; |
|
359 |
|
360 iCallback->BufferFilled( iChannelInfo.iChannelId, iCountReceived, iBuffer, iCount ); |
|
361 |
|
362 // Check that client did not change the state in the callback function |
|
363 if ( iChannelState == EChannelForceBufferFilled || |
|
364 iChannelState == EChannelBufferFilled ) |
|
365 { |
|
366 iCountReceived = 0; |
|
367 |
|
368 if ( iBuffer && iCount ) |
|
369 { |
|
370 SetChannelState( EChannelListening ); |
|
371 } |
|
372 else |
|
373 { |
|
374 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR:New buffer and/or count values are wrong!" ); |
|
375 iOrientationHandler->StopListeningL(); |
|
376 SetChannelState( EChannelStopListening ); |
|
377 } |
|
378 |
|
379 IssueRequest(); |
|
380 } |
|
381 break; |
|
382 default: |
|
383 ASSERT_DEBUG_SSY( 0 ); |
|
384 break; |
|
385 } |
|
386 |
|
387 SSY_TRACE_OUT(); |
|
388 } |
|
389 |
|
390 // ---------------------------------------------------------------------------------- |
|
391 // CSSYChannel::IssueRequest() |
|
392 // ---------------------------------------------------------------------------------- |
|
393 // |
|
394 void CSSYChannel::IssueRequest( TInt aError ) |
|
395 { |
|
396 SSY_TRACE_IN(); |
|
397 |
|
398 if ( !IsActive() ) |
|
399 { |
|
400 iStatus = KRequestPending; |
|
401 TRequestStatus *status = &iStatus; |
|
402 User::RequestComplete( status, aError ); |
|
403 SSY_TRACE( EExtended, "ORIENTATIONSSY:Setactive for channelId %d", iChannelInfo.iChannelId ); |
|
404 SetActive(); |
|
405 } |
|
406 |
|
407 SSY_TRACE_OUT(); |
|
408 } |
|
409 |
|
410 // ---------------------------------------------------------------------------------- |
|
411 // CSSYChannel::StartChannelDataL() |
|
412 // ---------------------------------------------------------------------------------- |
|
413 // |
|
414 void CSSYChannel::StartChannelDataL( const TSensrvChannelId aChannelId, |
|
415 TUint8* aBuffer, |
|
416 TInt aCount ) |
|
417 { |
|
418 SSY_TRACE_IN(); |
|
419 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
420 |
|
421 if ( ChannelId() != aChannelId ) |
|
422 { |
|
423 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: StartChannelDataL wrong channelId!" ); |
|
424 User::Leave( KErrArgument ); |
|
425 } |
|
426 |
|
427 ASSERT_DEBUG_SSY( aBuffer ); |
|
428 ASSERT_DEBUG_SSY( aCount ); |
|
429 |
|
430 if ( !aBuffer || !aCount ) |
|
431 { |
|
432 User::Leave( KErrArgument ); |
|
433 } |
|
434 |
|
435 iBuffer = aBuffer; |
|
436 iCount = aCount; |
|
437 |
|
438 SSY_TRACE( EExtended, "ORIENTATIONSSY:New data buffer: 0x%x", iBuffer ); |
|
439 SSY_TRACE( EExtended, "ORIENTATIONSSY:New data count : %d", iCount ); |
|
440 |
|
441 if ( iChannelState & KChannelCanBeListened ) |
|
442 { |
|
443 iOrientationHandler->StartListeningL(); |
|
444 SetChannelState( EChannelListening ); |
|
445 IssueRequest(); |
|
446 } |
|
447 else |
|
448 { |
|
449 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Trying to listen a channel that is not open! channelId: %d, state: %S", |
|
450 aChannelId, |
|
451 ConvertChannelStateIntoString( iChannelState ) ); |
|
452 |
|
453 User::Leave( KErrGeneral ); |
|
454 } |
|
455 |
|
456 SSY_TRACE_OUT(); |
|
457 } |
|
458 |
|
459 // ---------------------------------------------------------------------------------- |
|
460 // CSSYChannel::StopChannelDataL() |
|
461 // ---------------------------------------------------------------------------------- |
|
462 // |
|
463 void CSSYChannel::StopChannelDataL( const TSensrvChannelId aChannelId ) |
|
464 { |
|
465 SSY_TRACE_IN(); |
|
466 SSY_TRACE( EExtended, "ORIENTATIONSSY::ChannelId %d", iChannelInfo.iChannelId ); |
|
467 |
|
468 if ( ChannelId() != aChannelId ) |
|
469 { |
|
470 SSY_TRACE( EError, "ORIENTATIONSSY::ERROR: StartChannelDataL wrong channelId!" ); |
|
471 User::Leave( KErrArgument ); |
|
472 } |
|
473 |
|
474 if ( iChannelState & KChannelCanBeStopped ) |
|
475 { |
|
476 iOrientationHandler->StopListeningL(); |
|
477 SetChannelState( EChannelStopListening ); |
|
478 IssueRequest(); |
|
479 } |
|
480 else |
|
481 { |
|
482 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Trying to stop listening a channel that is not listened! channelId: %d, state: %S", |
|
483 aChannelId, |
|
484 ConvertChannelStateIntoString( iChannelState ) ); |
|
485 |
|
486 User::Leave( KErrGeneral ); |
|
487 } |
|
488 |
|
489 SSY_TRACE_OUT(); |
|
490 } |
|
491 |
|
492 // ---------------------------------------------------------------------------------- |
|
493 // CSSYChannel::ForceBufferFilledL() |
|
494 // ---------------------------------------------------------------------------------- |
|
495 // |
|
496 void CSSYChannel::ForceBufferFilledL( const TSensrvChannelId aChannelId ) |
|
497 { |
|
498 SSY_TRACE_IN(); |
|
499 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
500 |
|
501 if ( ChannelId() != aChannelId ) |
|
502 { |
|
503 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: StartChannelDataL wrong channelId!" ); |
|
504 User::Leave( KErrArgument ); |
|
505 } |
|
506 |
|
507 if( iChannelState & KChannelCanBeFilled ) |
|
508 { |
|
509 SetChannelState( EChannelForceBufferFilled ); |
|
510 IssueRequest(); |
|
511 } |
|
512 else |
|
513 { |
|
514 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: ForceBufferFilledL called in incorrected state! channelId: %d, state: %S", |
|
515 aChannelId, |
|
516 ConvertChannelStateIntoString( iChannelState ) ); |
|
517 |
|
518 User::Leave( KErrGeneral ); |
|
519 } |
|
520 |
|
521 SSY_TRACE_OUT(); |
|
522 } |
|
523 |
|
524 // ---------------------------------------------------------------------------------- |
|
525 // CSSYChannel::ChannelId() |
|
526 // ---------------------------------------------------------------------------------- |
|
527 // |
|
528 TSensrvChannelId CSSYChannel::ChannelId() |
|
529 { |
|
530 SSY_TRACE_IN(); |
|
531 SSY_TRACE_OUT(); |
|
532 return iChannelInfo.iChannelId; |
|
533 } |
|
534 |
|
535 // ---------------------------------------------------------------------------------- |
|
536 // CSSYChannel::SetChannelId() |
|
537 // ---------------------------------------------------------------------------------- |
|
538 // |
|
539 void CSSYChannel::SetChannelId( const TSensrvChannelId aChannelId ) |
|
540 { |
|
541 SSY_TRACE_IN(); |
|
542 // Set the channelId |
|
543 iChannelInfo.iChannelId = aChannelId; |
|
544 |
|
545 // Add us as an affected party to the sensor properties, ignore errors |
|
546 iSensorProperties->RegisterChannel( iChannelInfo.iChannelId ); |
|
547 |
|
548 // Add us as an affected party to the channel properties, ignore errors |
|
549 iChannelProperties->RegisterChannel( iChannelInfo.iChannelId ); |
|
550 |
|
551 SSY_TRACE_OUT(); |
|
552 } |
|
553 |
|
554 // ---------------------------------------------------------------------------------- |
|
555 // CSSYChannel::ChannelInfo() |
|
556 // ---------------------------------------------------------------------------------- |
|
557 // |
|
558 TSensrvChannelInfo& CSSYChannel::ChannelInfo() |
|
559 { |
|
560 SSY_TRACE_IN(); |
|
561 SSY_TRACE_OUT(); |
|
562 return iChannelInfo; |
|
563 } |
|
564 |
|
565 // ---------------------------------------------------------------------------------- |
|
566 // CSSYChannel::OpenChannel() |
|
567 // ---------------------------------------------------------------------------------- |
|
568 // |
|
569 TInt CSSYChannel::OpenChannel() |
|
570 { |
|
571 SSY_TRACE_IN(); |
|
572 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
573 |
|
574 TInt err( KErrNone ); |
|
575 |
|
576 if ( iChannelState & KChannelCanBeOpened ) |
|
577 { |
|
578 TRAP( err, iOrientationHandler->OpenChannelL() ); |
|
579 if ( err == KErrNone ) |
|
580 { |
|
581 SetChannelState( EChannelOpening ); |
|
582 IssueRequest(); |
|
583 } |
|
584 } |
|
585 else |
|
586 { |
|
587 SSY_TRACE( EExtended, "ORIENTATIONSSY:ERROR: Trying to open a channel in a wrong state! channelId: %d, state: %S", |
|
588 iChannelInfo.iChannelId, |
|
589 ConvertChannelStateIntoString( iChannelState ) ); |
|
590 |
|
591 err = KErrGeneral; |
|
592 } |
|
593 |
|
594 SSY_TRACE_OUT(); |
|
595 return err; |
|
596 } |
|
597 |
|
598 // ---------------------------------------------------------------------------------- |
|
599 // CSSYChannel::CloseChannel() |
|
600 // ---------------------------------------------------------------------------------- |
|
601 // |
|
602 TInt CSSYChannel::CloseChannel() |
|
603 { |
|
604 SSY_TRACE_IN(); |
|
605 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
606 |
|
607 TInt err( KErrNone ); |
|
608 |
|
609 if( iChannelState & KChannelCanBeClosed ) |
|
610 { |
|
611 TRAP( err, iOrientationHandler->CloseChannelL() ); |
|
612 if ( err == KErrNone ) |
|
613 { |
|
614 iBuffer = NULL; // Reassigned in data listening |
|
615 iCount = 0; |
|
616 iCountReceived = 0; |
|
617 SetChannelState( EChannelClosing ); |
|
618 IssueRequest(); |
|
619 } |
|
620 else |
|
621 { |
|
622 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Trying to close a channel! err: %d, channelId: %d, state: %S", |
|
623 err, |
|
624 iChannelInfo.iChannelId, |
|
625 ConvertChannelStateIntoString( iChannelState ) ); |
|
626 } |
|
627 } |
|
628 else |
|
629 { |
|
630 SSY_TRACE( EExtended, "ORIENTATIONSSY:ERROR: Trying to close a channel in a wrong state! channelId: %d, state: %S", |
|
631 iChannelInfo.iChannelId, |
|
632 ConvertChannelStateIntoString( iChannelState ) ); |
|
633 |
|
634 err = KErrGeneral; |
|
635 } |
|
636 |
|
637 SSY_TRACE_OUT(); |
|
638 return err; |
|
639 } |
|
640 |
|
641 // ---------------------------------------------------------------------------------- |
|
642 // CSSYChannel::CheckPropertyDependenciesL() |
|
643 // ---------------------------------------------------------------------------------- |
|
644 // |
|
645 void CSSYChannel::CheckPropertyDependenciesL( const TSensrvChannelId aChannelId, |
|
646 const TSensrvProperty& aProperty, |
|
647 RSensrvChannelList& aAffectedChannels ) |
|
648 { |
|
649 SSY_TRACE_IN(); |
|
650 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
651 |
|
652 if ( ChannelId() != aChannelId ) |
|
653 { |
|
654 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: CheckPropertyDependenciesL wrong channelId!" ); |
|
655 User::Leave( KErrArgument ); |
|
656 } |
|
657 |
|
658 CSSYProperty* propertyPtr = iSensorProperties; |
|
659 TSensrvProperty property = aProperty; |
|
660 |
|
661 // try first common sensor properties |
|
662 TInt ret = iSensorProperties->GetProperty( property ); |
|
663 |
|
664 if ( ret != KErrNone ) |
|
665 { |
|
666 propertyPtr = iChannelProperties; |
|
667 |
|
668 // then try the channel properties |
|
669 ret = iChannelProperties->GetProperty( property ); |
|
670 } |
|
671 |
|
672 if ( ret != KErrNone ) |
|
673 { |
|
674 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Property is not supported: 0x%x ", aProperty.GetPropertyId() ); |
|
675 User::Leave( KErrNotFound ); |
|
676 } |
|
677 |
|
678 propertyPtr->GetAffectedChannels( aAffectedChannels ); |
|
679 |
|
680 SSY_TRACE_OUT(); |
|
681 } |
|
682 |
|
683 // ---------------------------------------------------------------------------------- |
|
684 // CSSYChannel::SetPropertyL() |
|
685 // ---------------------------------------------------------------------------------- |
|
686 // |
|
687 void CSSYChannel::SetPropertyL( const TSensrvChannelId aChannelId, |
|
688 const TSensrvProperty& aProperty ) |
|
689 { |
|
690 SSY_TRACE_IN(); |
|
691 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
692 |
|
693 if ( ChannelId() != aChannelId ) |
|
694 { |
|
695 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: SetPropertyL wrong channelId!" ); |
|
696 User::Leave( KErrArgument ); |
|
697 } |
|
698 |
|
699 TBool valueChanged( ETrue ); |
|
700 RSensrvChannelList affectedChannels; |
|
701 TInt valueInt( 0 ); |
|
702 |
|
703 // try first common sensor properties |
|
704 TInt ret = iSensorProperties->SetProperty( aProperty, affectedChannels ); |
|
705 |
|
706 if ( ret == KErrNotFound ) |
|
707 { |
|
708 // then try the channel properties |
|
709 ret = iChannelProperties->SetProperty( aProperty, affectedChannels ); |
|
710 } |
|
711 |
|
712 if ( ret != KErrNone && ret != KErrAlreadyExists ) |
|
713 { |
|
714 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Property is not supported or it's readonly: 0x%x ", aProperty.GetPropertyId() ); |
|
715 User::Leave( KErrNotSupported ); |
|
716 } |
|
717 |
|
718 if ( ret == KErrAlreadyExists ) |
|
719 { |
|
720 // client tried to set the same value that the property already has, lets just return without doing anything |
|
721 // but informing the "change" via the callback |
|
722 valueChanged = EFalse; |
|
723 } |
|
724 |
|
725 // do something if the value was really changed |
|
726 if ( valueChanged ) |
|
727 { |
|
728 aProperty.GetValue( valueInt ); |
|
729 |
|
730 // These are ReadOnly values, cannot change these |
|
731 if ( ( aProperty.GetPropertyId() == KSensrvPropIdDataRate ) || |
|
732 ( aProperty.GetPropertyId() == KSensrvPropIdAvailability ) || |
|
733 ( aProperty.GetPropertyId() == KSensrvPropIdMeasureRange ) || |
|
734 ( aProperty.GetPropertyId() == KSensrvPropIdChannelDataFormat ) || |
|
735 ( aProperty.GetPropertyId() == KSensrvPropIdChannelAccuracy ) ) |
|
736 { |
|
737 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Setting the property is not supported: 0x%x ", aProperty.GetPropertyId() ); |
|
738 User::Leave( KErrNotSupported ); |
|
739 } |
|
740 } |
|
741 |
|
742 // we call the callback function to inform that property was changed, even if it was not actually changed |
|
743 iCallback->PropertyChanged( iChannelInfo.iChannelId, affectedChannels, aProperty ); |
|
744 |
|
745 affectedChannels.Reset(); |
|
746 |
|
747 SSY_TRACE_OUT(); |
|
748 } |
|
749 |
|
750 // ---------------------------------------------------------------------------------- |
|
751 // CSSYChannel::GetPropertyL() |
|
752 // ---------------------------------------------------------------------------------- |
|
753 // |
|
754 void CSSYChannel::GetPropertyL( const TSensrvChannelId aChannelId, |
|
755 TSensrvProperty& aProperty ) |
|
756 { |
|
757 SSY_TRACE_IN(); |
|
758 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
759 |
|
760 if ( ChannelId() != aChannelId ) |
|
761 { |
|
762 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: GetPropertyL wrong channelId!" ); |
|
763 User::Leave( KErrArgument ); |
|
764 } |
|
765 |
|
766 // try first common sensor properties |
|
767 TInt ret = iSensorProperties->GetProperty( aProperty ); |
|
768 |
|
769 if ( ret != KErrNone ) |
|
770 { |
|
771 // then try the channel properties |
|
772 ret = iChannelProperties->GetProperty( aProperty ); |
|
773 } |
|
774 |
|
775 if ( ret != KErrNone ) |
|
776 { |
|
777 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Property is not supported: 0x%x ", aProperty.GetPropertyId() ); |
|
778 User::Leave( KErrNotSupported ); |
|
779 } |
|
780 |
|
781 SSY_TRACE_OUT(); |
|
782 } |
|
783 |
|
784 // ---------------------------------------------------------------------------------- |
|
785 // CSSYChannel::GetAllPropertiesL() |
|
786 // ---------------------------------------------------------------------------------- |
|
787 // |
|
788 void CSSYChannel::GetAllPropertiesL( const TSensrvChannelId aChannelId, |
|
789 RSensrvPropertyList& aChannelPropertyList ) |
|
790 { |
|
791 SSY_TRACE_IN(); |
|
792 SSY_TRACE( EExtended, "ORIENTATIONSSY:ChannelId %d", iChannelInfo.iChannelId ); |
|
793 |
|
794 if ( ChannelId() != aChannelId ) |
|
795 { |
|
796 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: GetAllPropertiesL wrong channelId!" ); |
|
797 User::Leave( KErrArgument ); |
|
798 } |
|
799 |
|
800 aChannelPropertyList.Reset(); |
|
801 |
|
802 RSensrvPropertyList channelProperties; |
|
803 |
|
804 iSensorProperties->GetAllProperties( aChannelPropertyList ); |
|
805 iChannelProperties->GetAllProperties( channelProperties ); |
|
806 |
|
807 for ( TInt index = 0; index < channelProperties.Count(); index++ ) |
|
808 { |
|
809 aChannelPropertyList.Append( channelProperties[index] ); |
|
810 } |
|
811 |
|
812 SSY_TRACE_OUT(); |
|
813 } |
|
814 |
|
815 // ---------------------------------------------------------------------------------- |
|
816 // CSSYChannel::GetPropertyProviderInterfaceL() |
|
817 // ---------------------------------------------------------------------------------- |
|
818 // |
|
819 void CSSYChannel::GetPropertyProviderInterfaceL( |
|
820 TUid aInterfaceUid, |
|
821 TAny*& aInterface ) |
|
822 { |
|
823 aInterface = NULL; |
|
824 |
|
825 if ( aInterfaceUid.iUid == KSsyPropertyProviderInterface1.iUid ) |
|
826 { |
|
827 aInterface = reinterpret_cast<TAny*>( |
|
828 static_cast<MSsyPropertyProvider*>( this ) ); |
|
829 } |
|
830 } |
|
831 |
|
832 // ---------------------------------------------------------------------------------- |
|
833 // CSSYChannel::GetChannelDataProviderInterfaceL() |
|
834 // ---------------------------------------------------------------------------------- |
|
835 // |
|
836 void CSSYChannel::GetChannelDataProviderInterfaceL( |
|
837 TUid aInterfaceUid, |
|
838 TAny*& aInterface ) |
|
839 { |
|
840 aInterface = NULL; |
|
841 |
|
842 if ( aInterfaceUid.iUid == KSsyChannelDataProviderInterface1.iUid ) |
|
843 { |
|
844 aInterface = reinterpret_cast<TAny*>( |
|
845 static_cast<MSsyChannelDataProvider*>( this ) ); |
|
846 } |
|
847 } |
|
848 |
|
849 // End of File |