|
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: CSensrvChannelImpl implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "sensrvpropertylistener.h" |
|
20 #include "sensrvchannelimpl.h" |
|
21 #include "sensrvdatahandler.h" |
|
22 #include "sensrvpropertyhandler.h" |
|
23 #include "sensrvtrace.h" |
|
24 #include "sensrvtypes.h" |
|
25 #include "sensrvdatalistener.h" |
|
26 #include "sensrvchannelconditionlistener.h" |
|
27 #include "sensrvconditionhandler.h" |
|
28 #include "sensrvchannelconditionimpl.h" |
|
29 #include "sensrvchannelconditionsetimpl.h" |
|
30 |
|
31 const TInt KDefaultPropertyCount = 40; |
|
32 |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // C++ constructor |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CSensrvChannelImpl::CSensrvChannelImpl( const TSensrvChannelInfo& aChannelInfo ) |
|
42 : iChannelInfo( aChannelInfo ), |
|
43 iConditionSetList(_FOFF(CSensrvChannelConditionSetImpl,iLink)), |
|
44 iConditionSetIter(iConditionSetList) |
|
45 { |
|
46 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::CSensrvChannelImpl()" ) ) ); |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // 2nd phase of construction |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CSensrvChannelImpl::ConstructL() |
|
55 { |
|
56 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ConstructL() - Start" ) ) ); |
|
57 |
|
58 // Nothing to do |
|
59 |
|
60 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ConstructL() - Return" ) ) ); |
|
61 } |
|
62 |
|
63 |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // Destructor |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CSensrvChannelImpl::~CSensrvChannelImpl() |
|
70 { |
|
71 delete iDataHandler; |
|
72 delete iChannelPropertyHandler; |
|
73 delete iConditionHandler; |
|
74 iSensrvClient.Close(); |
|
75 iConditionSetList.Reset(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CSensrvChannelImpl::OpenChannelL |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CSensrvChannelImpl::OpenChannelL() |
|
83 { |
|
84 // Open Channel and reset listeners |
|
85 DoOpenChannelL( ETrue ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CSensrvChannelImpl::DoOpenChannelL |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CSensrvChannelImpl::DoOpenChannelL( TBool aResetListeners ) |
|
93 { |
|
94 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DoOpenChannelL()" ) ) ); |
|
95 |
|
96 if( iChannelOpen ) |
|
97 { |
|
98 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DoOpenChannelL() - ERROR: Channel is already open" ) ) ); |
|
99 User::Leave( KErrAlreadyExists ); |
|
100 } |
|
101 |
|
102 User::LeaveIfError( iSensrvClient.Connect() ); |
|
103 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DoOpenChannelL() - Client connected" ) ) ); |
|
104 |
|
105 TInt maxBufferCount(0); |
|
106 TSensrvTIntPckgBuf intBuf( maxBufferCount ); |
|
107 TInt dataItemSize(0); |
|
108 TSensrvTIntPckgBuf intBuf2( dataItemSize ); |
|
109 |
|
110 User::LeaveIfError( iSensrvClient.SendReceiveSync( ESensrvSrvReqOpenChannel, |
|
111 TIpcArgs( iChannelInfo.iChannelId, &intBuf, &intBuf2 ) ) ); |
|
112 |
|
113 iMaxBufferCount = intBuf(); |
|
114 iChannelInfo.iDataItemSize = intBuf2(); // Store the actual data item size, known after SSY channel registration |
|
115 |
|
116 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DoOpenChannelL - iMaxBufferSize: %d" ), iMaxBufferCount ) ); |
|
117 |
|
118 iChannelOpen = ETrue; |
|
119 |
|
120 if( aResetListeners ) |
|
121 { |
|
122 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DoOpenChannelL() - Reset listeners" ) ) ); |
|
123 iDataListener = NULL; |
|
124 iChannelPropertyListener = NULL; |
|
125 iConditionListener = NULL; |
|
126 |
|
127 // Also reset conditions |
|
128 iConditionSetList.Reset(); |
|
129 } |
|
130 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DoOpenChannelL() - Return" ) ) ); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CSensrvChannelImpl::CloseChannel |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CSensrvChannelImpl::CloseChannel() |
|
138 { |
|
139 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::CloseChannel() - Start" ) ) ); |
|
140 if( iChannelOpen ) |
|
141 { |
|
142 // Cancel handlers handler |
|
143 if ( iDataHandler ) |
|
144 { |
|
145 iDataHandler->Cancel(); |
|
146 } |
|
147 |
|
148 if ( iChannelPropertyHandler ) |
|
149 { |
|
150 iChannelPropertyHandler->Cancel(); |
|
151 } |
|
152 |
|
153 if ( iConditionHandler ) |
|
154 { |
|
155 iConditionHandler->Cancel(); |
|
156 } |
|
157 |
|
158 iSensrvClient.SendReceiveSync( ESensrvSrvReqCloseChannel, TIpcArgs( iChannelInfo.iChannelId ) ); |
|
159 iChannelOpen = EFalse; |
|
160 |
|
161 iSensrvClient.Close(); |
|
162 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::CloseChannel() - Client closed" ) ) ); |
|
163 } |
|
164 |
|
165 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::CloseChannel() - Return" ) ) ); |
|
166 |
|
167 return KErrNone; |
|
168 } |
|
169 |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // CSensrvChannelImpl::GetChannelInfo |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 const TSensrvChannelInfo& CSensrvChannelImpl::GetChannelInfo() const |
|
176 { |
|
177 return iChannelInfo; |
|
178 } |
|
179 |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CSensrvChannelImpl::StartDataListeningL |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CSensrvChannelImpl::StartDataListeningL( MSensrvDataListener* aDataListener, |
|
186 const TInt aDesiredCount, |
|
187 const TInt aMaximumCount, |
|
188 const TInt aBufferingPeriod ) |
|
189 { |
|
190 COMPONENT_TRACE( ( |
|
191 _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - Start: aDataListener=%x, aDesiredCount=%d, aMaximumCount =%d, aBufferingPeriod=%d" ), |
|
192 aDataListener, aDesiredCount, aMaximumCount, aBufferingPeriod ) ); |
|
193 |
|
194 if( aDesiredCount < 0 || aMaximumCount < 0 || aBufferingPeriod < 0 ) |
|
195 { |
|
196 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - ERROR: Negative argument: leaving KErrArgument" ) ) ); |
|
197 User::Leave( KErrArgument ); |
|
198 } |
|
199 |
|
200 if ( !aDataListener ) |
|
201 { |
|
202 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - ERROR: NULL listener: leaving KErrArgument" ) ) ); |
|
203 User::Leave( KErrArgument ); |
|
204 } |
|
205 |
|
206 if( !iChannelOpen ) |
|
207 { |
|
208 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - ERROR: Channel is not open: leaving KErrNotFound" ) ) ); |
|
209 User::Leave( KErrNotFound ); |
|
210 } |
|
211 |
|
212 TSensrvStartListeningParameters listeningParams; |
|
213 |
|
214 listeningParams.iDesiredBufferingCount = aDesiredCount; |
|
215 listeningParams.iMaximumBufferingCount = aMaximumCount; |
|
216 listeningParams.iBufferingPeriod = aBufferingPeriod; |
|
217 |
|
218 // Data and condition listening use same parameters for desired count and buffering period, |
|
219 // so use lowest value specified, if both are active at the same time |
|
220 if ( iConditionListener ) |
|
221 { |
|
222 if (iDataListeningParameters.iDesiredBufferingCount < aDesiredCount) |
|
223 { |
|
224 listeningParams.iDesiredBufferingCount = iDataListeningParameters.iDesiredBufferingCount; |
|
225 } |
|
226 |
|
227 if ( iDataListeningParameters.iBufferingPeriod < aBufferingPeriod ) |
|
228 { |
|
229 listeningParams.iBufferingPeriod = iDataListeningParameters.iBufferingPeriod; |
|
230 } |
|
231 } |
|
232 |
|
233 TSensrvStartListeningParametersPckgBuf startListeningPckg( listeningParams ); |
|
234 |
|
235 TInt startErr = iSensrvClient.SendReceiveSync( ESensrvSrvReqStartListening, |
|
236 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ); |
|
237 |
|
238 if ( startErr == KErrAlreadyExists ) |
|
239 { |
|
240 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - ERROR: Already listening: return KErrAlreadyExists" ) ) ); |
|
241 User::Leave( startErr ); |
|
242 } |
|
243 |
|
244 if ( startErr ) |
|
245 { |
|
246 // Try start |
|
247 startErr = iSensrvClient.SendReceiveSync( ESensrvSrvReqStartListening, |
|
248 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ); |
|
249 if ( startErr ) |
|
250 { |
|
251 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - ERROR: restart failed %d" ), startErr ) ); |
|
252 |
|
253 // Open channel |
|
254 TRAPD( err, ReopenChannelForListeningL(EStartDataListening) ); |
|
255 |
|
256 if ( !err ) |
|
257 { |
|
258 // try startListening again |
|
259 startErr = iSensrvClient.SendReceiveSync( ESensrvSrvReqStartListening, |
|
260 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ); |
|
261 } |
|
262 else |
|
263 { |
|
264 // Note: Channel can be left closed if reopen fails, depending at which |
|
265 // point it fails. |
|
266 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - ERROR: Reopening channel failed %d" ), err ) ); |
|
267 } |
|
268 } |
|
269 } |
|
270 |
|
271 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - error code: %d" ), startErr ) ); |
|
272 |
|
273 User::LeaveIfError( startErr ); |
|
274 |
|
275 // If first time, create datahandler |
|
276 if (!iDataHandler) |
|
277 { |
|
278 TRAP( startErr, iDataHandler = CSensrvDataHandler::NewL( iSensrvClient, iChannelInfo ) ); |
|
279 } |
|
280 |
|
281 if ( startErr == KErrNone ) |
|
282 { |
|
283 TRAP( startErr, iDataHandler->StartListeningL( this, listeningParams, iMaxBufferCount ) ); |
|
284 } |
|
285 |
|
286 if ( startErr ) |
|
287 { |
|
288 // Stop listening |
|
289 iSensrvClient.SendReceiveSync( ESensrvSrvReqStopListening, TIpcArgs( iChannelInfo.iChannelId ) ); |
|
290 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - ERROR: Starting listening failed, leave: %d" ), startErr ) ); |
|
291 User::Leave( startErr ); |
|
292 } |
|
293 |
|
294 // Now that we have successfully started, store parameters |
|
295 iDataListener = aDataListener; |
|
296 |
|
297 iDataListeningParameters.iDesiredBufferingCount = listeningParams.iDesiredBufferingCount; |
|
298 iDataListeningParameters.iMaximumBufferingCount = listeningParams.iMaximumBufferingCount; |
|
299 iDataListeningParameters.iBufferingPeriod = listeningParams.iBufferingPeriod; |
|
300 |
|
301 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartDataListening() - Return" ) ) ); |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // CSensrvChannelImpl::StopDataListening |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 TInt CSensrvChannelImpl::StopDataListening() |
|
309 { |
|
310 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StopDataListening() - Start" ) ) ); |
|
311 |
|
312 TInt err( KErrNone ); |
|
313 if ( iChannelOpen ) |
|
314 { |
|
315 if ( iDataHandler && iDataHandler->IsActive() ) |
|
316 { |
|
317 iDataHandler->Cancel(); |
|
318 } |
|
319 else |
|
320 { |
|
321 err = iSensrvClient.SendReceiveSync( ESensrvSrvReqStopListening, TIpcArgs( iChannelInfo.iChannelId ) ); |
|
322 } |
|
323 } |
|
324 |
|
325 iDataListener = NULL; |
|
326 |
|
327 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StopDataListening() - Return" ) ) ); |
|
328 |
|
329 return err; |
|
330 } |
|
331 |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // CSensrvChannelImpl::GetData |
|
335 // --------------------------------------------------------------------------- |
|
336 // |
|
337 TInt CSensrvChannelImpl::GetData( TDes8& aDataPtr ) |
|
338 { |
|
339 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetData() - Start" ) ) ); |
|
340 TInt err( KErrNone ); |
|
341 if ( !iChannelOpen ) |
|
342 { |
|
343 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetData() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
344 err = KErrNotFound; |
|
345 } |
|
346 else |
|
347 { |
|
348 if ( iDataHandler ) |
|
349 { |
|
350 err = iDataHandler->GetData( aDataPtr ); |
|
351 } |
|
352 else |
|
353 { |
|
354 err = KErrNotFound; |
|
355 } |
|
356 } |
|
357 |
|
358 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetData() - Return %d" ), err ) ); |
|
359 return err; |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // CSensrvChannelImpl::SetProperty |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 TInt CSensrvChannelImpl::SetProperty( const TSensrvProperty& aProperty ) |
|
367 { |
|
368 #ifdef COMPONENT_TRACE_DEBUG |
|
369 if ( ESensrvIntProperty == aProperty.PropertyType() ) |
|
370 { |
|
371 TInt value( 0 ); |
|
372 aProperty.GetValue( value ); |
|
373 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetProperty(PropertyId:0x%x value:%d)" ), aProperty.GetPropertyId(), value ) ); |
|
374 } |
|
375 else if ( ESensrvRealProperty == aProperty.PropertyType() ) |
|
376 { |
|
377 TReal value( 0 ); |
|
378 aProperty.GetValue( value ); |
|
379 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetProperty(PropertyId:0x%x value:%f)" ), aProperty.GetPropertyId(), value ) ); |
|
380 } |
|
381 else if ( ESensrvBufferProperty == aProperty.PropertyType() ) |
|
382 { |
|
383 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetProperty(PropertyId:0x%x value:%S)" ) , aProperty.GetPropertyId(), &const_cast<TSensrvProperty*>(&aProperty)->GetValueRef() ) ); |
|
384 } |
|
385 else |
|
386 { |
|
387 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetProperty(PropertyId:0x%x)" ), aProperty.GetPropertyId() ) ); |
|
388 } |
|
389 #endif//COMPONENT_TRACE_DEBUG |
|
390 |
|
391 TInt err( KErrNone ); |
|
392 if ( !iChannelOpen ) |
|
393 { |
|
394 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetProperty() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
395 err = KErrNotFound; |
|
396 } |
|
397 else |
|
398 { |
|
399 TPropertyPckg propertyPckg( aProperty ); |
|
400 |
|
401 err = iSensrvClient.SendReceiveSync( ESensrvSrvReqSetProperty, TIpcArgs( iChannelInfo.iChannelId, &propertyPckg ) ); |
|
402 } |
|
403 |
|
404 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetProperty - return %d" ), err ) ); |
|
405 return err; |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // CSensrvChannelImpl::GetPropertyL |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 void CSensrvChannelImpl::GetPropertyL( const TSensrvPropertyId aPropertyId, |
|
413 const TInt aItemIndex, |
|
414 TSensrvProperty& aProperty ) |
|
415 { |
|
416 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL(PropertyId:0x%x ItemIndex:%d)" ),aPropertyId, aItemIndex ) ); |
|
417 |
|
418 if (aItemIndex < 0 && aItemIndex != KSensrvItemIndexNone) |
|
419 { |
|
420 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL() - ERROR: Negative argument: leaving KErrArgument" ) ) ); |
|
421 User::Leave( KErrArgument ); |
|
422 } |
|
423 |
|
424 if ( !iChannelOpen ) |
|
425 { |
|
426 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
427 User::Leave( KErrNotFound ); |
|
428 } |
|
429 |
|
430 TPropertyPckg propertyPckg( aProperty ); |
|
431 |
|
432 //Set aPropertyId and aItemIndex to aProperty for server use |
|
433 aProperty.SetPropertyId(aPropertyId); |
|
434 aProperty.SetItemIndex(aItemIndex); |
|
435 |
|
436 User::LeaveIfError( iSensrvClient.SendReceiveSync( |
|
437 ESensrvSrvReqGetProperty, TIpcArgs( iChannelInfo.iChannelId, &propertyPckg ) ) ); |
|
438 |
|
439 #ifdef COMPONENT_TRACE_DEBUG |
|
440 if ( ESensrvIntProperty == aProperty.PropertyType() ) |
|
441 { |
|
442 TInt value( 0 ); |
|
443 aProperty.GetValue( value ); |
|
444 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL() - Return property value=%d" ), value ) ); |
|
445 } |
|
446 else if ( ESensrvRealProperty == aProperty.PropertyType() ) |
|
447 { |
|
448 TReal value( 0 ); |
|
449 aProperty.GetValue( value ); |
|
450 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL() - Return property value=%f" ), value ) ); |
|
451 } |
|
452 else if ( ESensrvBufferProperty == aProperty.PropertyType() ) |
|
453 { |
|
454 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL() - Return property value=%S" ), &aProperty.GetValueRef() ) ); |
|
455 } |
|
456 else |
|
457 { |
|
458 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL() - Return" ) ) ); |
|
459 } |
|
460 #endif//COMPONENT_TRACE_DEBUG |
|
461 } |
|
462 |
|
463 // --------------------------------------------------------------------------- |
|
464 // CSensrvChannelImpl::GetAllPropertiesL |
|
465 // --------------------------------------------------------------------------- |
|
466 // |
|
467 void CSensrvChannelImpl::GetAllPropertiesL( RSensrvPropertyList& aChannelPropertyList ) |
|
468 { |
|
469 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL()" ) ) ); |
|
470 |
|
471 if ( !iChannelOpen ) |
|
472 { |
|
473 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
474 User::Leave( KErrNotFound ); |
|
475 } |
|
476 TSensrvTIntPckgBuf countPckgBuf; |
|
477 TInt err( KErrNone ); |
|
478 RSensrvPropertyList channelPropertyList( KDefaultPropertyCount ); |
|
479 |
|
480 CleanupClosePushL( channelPropertyList ); |
|
481 |
|
482 for( TInt i=0; i<KDefaultPropertyCount; i++ ) |
|
483 { |
|
484 channelPropertyList.AppendL( TSensrvProperty() ); |
|
485 } |
|
486 |
|
487 TInt arraySize( ( sizeof( TSensrvProperty ) ) * KDefaultPropertyCount ); |
|
488 TPtr8 arrayPtr( (TUint8*)&channelPropertyList[0], arraySize, arraySize ); |
|
489 |
|
490 err = iSensrvClient.SendReceiveSync( ESensrvSrvReqGetAllProperties, |
|
491 TIpcArgs( iChannelInfo.iChannelId, |
|
492 &arrayPtr, |
|
493 &countPckgBuf ) ); |
|
494 |
|
495 if ( err == KErrOverflow ) // buffer overflow. Allocate new buffer |
|
496 { |
|
497 for( TInt i=KDefaultPropertyCount; i<countPckgBuf(); i++ ) |
|
498 { |
|
499 channelPropertyList.AppendL( TSensrvProperty() ); |
|
500 } |
|
501 TInt arraySize( ( sizeof( TSensrvProperty ) ) * countPckgBuf() ); |
|
502 TPtr8 arrayPtr( (TUint8*)&channelPropertyList[0], arraySize, arraySize ); |
|
503 err = iSensrvClient.SendReceiveSync( ESensrvSrvReqGetAllProperties, |
|
504 TIpcArgs( iChannelInfo.iChannelId, |
|
505 &arrayPtr, |
|
506 &countPckgBuf ) ); |
|
507 } |
|
508 |
|
509 if ( err == KErrNone ) |
|
510 { |
|
511 for( TInt i = 0; i < countPckgBuf(); ++i ) |
|
512 { |
|
513 aChannelPropertyList.AppendL( channelPropertyList[i] ); |
|
514 } |
|
515 } |
|
516 else |
|
517 { |
|
518 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL() - ERROR: Failed to get properties" ) ) ); |
|
519 User::Leave( err ); |
|
520 } |
|
521 |
|
522 // Close the array and free all memory allocated to the array. |
|
523 CleanupStack::PopAndDestroy( &channelPropertyList ); |
|
524 |
|
525 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL return void" ) ) ); |
|
526 } |
|
527 |
|
528 // --------------------------------------------------------------------------- |
|
529 // CSensrvChannelImpl::GetPropertyL |
|
530 // --------------------------------------------------------------------------- |
|
531 // |
|
532 void CSensrvChannelImpl::GetPropertyL( const TSensrvPropertyId aPropertyId, |
|
533 const TInt aItemIndex, |
|
534 const TInt aArrayIndex, |
|
535 TSensrvProperty& aProperty ) |
|
536 { |
|
537 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL(item:%d array:%d)"), aItemIndex, aArrayIndex ) ); |
|
538 |
|
539 if ((aItemIndex < 0 && aItemIndex != KSensrvItemIndexNone) || |
|
540 (aArrayIndex < 0 && aArrayIndex != ESensrvSingleProperty && aArrayIndex != ESensrvArrayPropertyInfo)) |
|
541 { |
|
542 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetPropertyL() - ERROR: Negative argument: leaving KErrArgument" ) ) ); |
|
543 User::Leave( KErrArgument ); |
|
544 } |
|
545 |
|
546 aProperty.SetArrayIndex( aArrayIndex ); |
|
547 GetPropertyL( aPropertyId, aItemIndex, aProperty ); |
|
548 |
|
549 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL -index- return void" ) ) ); |
|
550 } |
|
551 |
|
552 // --------------------------------------------------------------------------- |
|
553 // CSensrvChannelImpl::GetAllPropertiesL |
|
554 // --------------------------------------------------------------------------- |
|
555 // |
|
556 void CSensrvChannelImpl::GetAllPropertiesL( const TSensrvPropertyId aPropertyId, |
|
557 RSensrvPropertyList& aChannelPropertyList ) |
|
558 { |
|
559 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL(id:%d)"),aPropertyId ) ); |
|
560 RSensrvPropertyList propertyList; |
|
561 CleanupClosePushL( propertyList ); |
|
562 TBool found( EFalse ); |
|
563 |
|
564 GetAllPropertiesL( propertyList ); |
|
565 |
|
566 for( TInt i = 0; i < propertyList.Count(); ++i ) |
|
567 { |
|
568 if ( aPropertyId == propertyList[i].GetPropertyId() ) |
|
569 { |
|
570 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL - match found" ) ) ); |
|
571 aChannelPropertyList.AppendL( propertyList[i] ); |
|
572 found = ETrue; |
|
573 } |
|
574 } |
|
575 |
|
576 // Close the array and free all memory allocated to the array. |
|
577 CleanupStack::PopAndDestroy( &propertyList ); |
|
578 |
|
579 if ( !found ) |
|
580 { |
|
581 User::Leave( KErrNotFound );//According to the specification |
|
582 } |
|
583 |
|
584 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::GetAllPropertiesL -id- return void" ) ) ); |
|
585 } |
|
586 |
|
587 // --------------------------------------------------------------------------- |
|
588 // CSensrvChannelImpl::SetPropertyListenerL |
|
589 // --------------------------------------------------------------------------- |
|
590 // |
|
591 void CSensrvChannelImpl::SetPropertyListenerL( MSensrvPropertyListener* aChannelPropertyListener ) |
|
592 { |
|
593 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetPropertyListenerL()" ) ) ); |
|
594 |
|
595 if ( !iChannelOpen ) |
|
596 { |
|
597 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetPropertyListenerL() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
598 User::Leave( KErrNotFound ); |
|
599 } |
|
600 |
|
601 if ( iChannelPropertyListener && aChannelPropertyListener ) |
|
602 { |
|
603 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetPropertyListenerL() - ERROR: Already listening: return KErrAlreadyExists" ) ) ); |
|
604 User::Leave( KErrAlreadyExists ); |
|
605 } |
|
606 |
|
607 iChannelPropertyListener = aChannelPropertyListener; |
|
608 |
|
609 if ( iChannelPropertyListener ) |
|
610 { |
|
611 if ( !iChannelPropertyHandler ) |
|
612 { |
|
613 iChannelPropertyHandler = CSensrvPropertyHandler::NewL( iSensrvClient, iChannelInfo ); |
|
614 } |
|
615 |
|
616 iChannelPropertyHandler->StartListening( this ); |
|
617 } |
|
618 else |
|
619 { |
|
620 if ( iChannelPropertyHandler && iChannelPropertyHandler->IsActive() ) |
|
621 { |
|
622 iChannelPropertyHandler->Cancel(); |
|
623 } |
|
624 else |
|
625 { |
|
626 TInt ignore = iSensrvClient.SendReceiveSync( ESensrvSrvReqStopPropertyListening, |
|
627 TIpcArgs( iChannelInfo.iChannelId ) ); |
|
628 } |
|
629 } |
|
630 |
|
631 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetPropertyListenerL() - Return" ) ) ); |
|
632 } |
|
633 |
|
634 // --------------------------------------------------------------------------- |
|
635 // CSensrvChannelImpl::AddConditionL |
|
636 // --------------------------------------------------------------------------- |
|
637 // |
|
638 void CSensrvChannelImpl::AddConditionL( CSensrvChannelConditionSet& aChannelConditionSet ) |
|
639 { |
|
640 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::AddConditionL() - Start" ) ) ); |
|
641 |
|
642 // Check that channel is open |
|
643 if ( !iChannelOpen ) |
|
644 { |
|
645 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::AddConditionL() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
646 User::Leave( KErrNotFound ); |
|
647 } |
|
648 |
|
649 CSensrvChannelConditionSetImpl* setImpl = |
|
650 static_cast<CSensrvChannelConditionSetImpl*>(&aChannelConditionSet); |
|
651 |
|
652 // Check that condition set is complete (i.e. no unpaired range conditions) |
|
653 if ( !setImpl->IsComplete() ) |
|
654 { |
|
655 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::AddConditionL() - ERROR: Condition set is incomplete" ) ) ); |
|
656 User::Leave( KErrArgument ); |
|
657 } |
|
658 |
|
659 TBool duplicateId(ETrue); |
|
660 |
|
661 // Set the set id after checking for conflicts |
|
662 while ( duplicateId ) |
|
663 { |
|
664 duplicateId = EFalse; |
|
665 iConditionSetIdCounter++; |
|
666 |
|
667 // Find set from local list |
|
668 CSensrvChannelConditionSetImpl* ptr = NULL; |
|
669 iConditionSetIter.SetToFirst(); |
|
670 while ( (ptr = iConditionSetIter++) != NULL ) |
|
671 { |
|
672 if ( ptr == setImpl ) |
|
673 { |
|
674 // Do not allow same set to be added twice |
|
675 User::Leave( KErrAlreadyExists ); |
|
676 } |
|
677 |
|
678 if ( ptr->ConditionSetId() == iConditionSetIdCounter ) |
|
679 { |
|
680 duplicateId = ETrue; |
|
681 } |
|
682 }; |
|
683 } |
|
684 |
|
685 setImpl->SetConditionSetId(iConditionSetIdCounter); |
|
686 |
|
687 // Extract data from set |
|
688 HBufC8* serializedSet = setImpl->SerializeLC(); |
|
689 |
|
690 // Add set to local list |
|
691 iConditionSetList.AddLast(*setImpl); |
|
692 |
|
693 // Add set to server |
|
694 TInt err(iSensrvClient.SendReceiveSync( ESensrvSrvReqAddConditionSet, |
|
695 TIpcArgs( iChannelInfo.iChannelId, |
|
696 serializedSet ) ) ); |
|
697 |
|
698 // If set adding to server failed, remove set from local list also |
|
699 if (err != KErrNone) |
|
700 { |
|
701 iConditionSetList.Remove( *setImpl ); |
|
702 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::AddConditionL() - ERROR: Adding set to server failed" ) ) ); |
|
703 User::Leave(err); |
|
704 } |
|
705 |
|
706 CleanupStack::PopAndDestroy(serializedSet); |
|
707 |
|
708 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::AddConditionL() - Return" ) ) ); |
|
709 } |
|
710 |
|
711 // --------------------------------------------------------------------------- |
|
712 // CSensrvChannelImpl::RemoveConditionL |
|
713 // --------------------------------------------------------------------------- |
|
714 // |
|
715 void CSensrvChannelImpl::RemoveConditionL( CSensrvChannelConditionSet& aChannelConditionSet ) |
|
716 { |
|
717 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::RemoveConditionL() - Start" ) ) ); |
|
718 |
|
719 // Check that channel is open |
|
720 if ( !iChannelOpen ) |
|
721 { |
|
722 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::RemoveConditionL() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
723 User::Leave( KErrNotFound ); |
|
724 } |
|
725 |
|
726 CSensrvChannelConditionSetImpl* setImpl = static_cast<CSensrvChannelConditionSetImpl*>(&aChannelConditionSet); |
|
727 |
|
728 // Remove set from server |
|
729 User::LeaveIfError(iSensrvClient.SendReceiveSync( ESensrvSrvReqRemoveConditionSet, |
|
730 TIpcArgs( iChannelInfo.iChannelId, |
|
731 setImpl->ConditionSetId()))); |
|
732 // Remove set from local list if it is there |
|
733 iConditionSetIter.SetToFirst(); |
|
734 TBool found(EFalse); |
|
735 CSensrvChannelConditionSetImpl* ptr = NULL; |
|
736 while (!found && (ptr = iConditionSetIter++) != NULL) |
|
737 { |
|
738 if (ptr == setImpl) |
|
739 { |
|
740 found = ETrue; |
|
741 iConditionSetList.Remove( *setImpl ); |
|
742 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::RemoveConditionL() - Removed set from client side list" ) ) ); |
|
743 } |
|
744 }; |
|
745 |
|
746 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::RemoveConditionL() - Return" ) ) ); |
|
747 } |
|
748 |
|
749 // --------------------------------------------------------------------------- |
|
750 // CSensrvChannelImpl::StartConditionListeningL |
|
751 // --------------------------------------------------------------------------- |
|
752 // |
|
753 void CSensrvChannelImpl::StartConditionListeningL( |
|
754 MSensrvChannelConditionListener* aChannelConditionListener, |
|
755 const TInt aObjectCount, |
|
756 const TInt aBufferingPeriod ) |
|
757 { |
|
758 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL(aChannelConditionListener: 0x%x, aObjectCount: %d, aBufferingPeriod: %d) " ), |
|
759 aChannelConditionListener, aObjectCount, aBufferingPeriod ) ); |
|
760 |
|
761 if (aObjectCount < 0 || aBufferingPeriod < 0) |
|
762 { |
|
763 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - ERROR: Negative argument: leaving KErrArgument" ) ) ); |
|
764 User::Leave( KErrArgument ); |
|
765 } |
|
766 |
|
767 if (!aChannelConditionListener) |
|
768 { |
|
769 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - ERROR: NULL listener: leaving KErrArgument" ) ) ); |
|
770 User::Leave( KErrArgument ); |
|
771 } |
|
772 |
|
773 if ( !iChannelOpen ) |
|
774 { |
|
775 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - ERROR: Channel is not open: return KErrNotFound" ) ) ); |
|
776 User::Leave( KErrNotFound ); |
|
777 } |
|
778 |
|
779 TSensrvStartListeningParameters listeningParams; |
|
780 |
|
781 listeningParams.iDesiredBufferingCount = aObjectCount; |
|
782 listeningParams.iMaximumBufferingCount = iDataListeningParameters.iMaximumBufferingCount; |
|
783 listeningParams.iBufferingPeriod = aBufferingPeriod; |
|
784 |
|
785 // Data and condition listening use same parameters for desired count and buffering period, |
|
786 // so use lowest value specified, if both are active at the same time. |
|
787 if (iDataListener) |
|
788 { |
|
789 if (iDataListeningParameters.iDesiredBufferingCount < aObjectCount) |
|
790 { |
|
791 listeningParams.iDesiredBufferingCount = iDataListeningParameters.iDesiredBufferingCount; |
|
792 } |
|
793 |
|
794 if (iDataListeningParameters.iBufferingPeriod < aBufferingPeriod) |
|
795 { |
|
796 listeningParams.iBufferingPeriod = iDataListeningParameters.iBufferingPeriod; |
|
797 } |
|
798 } |
|
799 |
|
800 TSensrvStartListeningParametersPckgBuf startListeningPckg( listeningParams ); |
|
801 |
|
802 TInt startErr = iSensrvClient.SendReceiveSync( ESensrvSrvReqStartConditionListening, |
|
803 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ); |
|
804 |
|
805 if ( startErr == KErrAlreadyExists ) |
|
806 { |
|
807 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - ERROR: Already listening: return KErrAlreadyExists" ) ) ); |
|
808 User::Leave( startErr ); |
|
809 } |
|
810 |
|
811 if ( startErr ) |
|
812 { |
|
813 // Try start again |
|
814 startErr = iSensrvClient.SendReceiveSync( ESensrvSrvReqStartConditionListening, |
|
815 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ); |
|
816 if ( startErr ) |
|
817 { |
|
818 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - ERROR: restart failed %d" ), startErr ) ); |
|
819 |
|
820 // Open channel |
|
821 TRAPD( err, ReopenChannelForListeningL(EStartConditionListening) ); |
|
822 |
|
823 if ( !err ) |
|
824 { |
|
825 // try startListening again |
|
826 startErr = iSensrvClient.SendReceiveSync( ESensrvSrvReqStartConditionListening, |
|
827 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ); |
|
828 } |
|
829 else |
|
830 { |
|
831 // Note: Channel can be left closed if reopen fails, depending at which |
|
832 // point it fails. |
|
833 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - ERROR: Reopening channel failed %d" ), startErr ) ); |
|
834 } |
|
835 } |
|
836 } |
|
837 |
|
838 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - error code: %d" ), startErr ) ); |
|
839 |
|
840 User::LeaveIfError( startErr ); |
|
841 |
|
842 if ( !iConditionHandler ) |
|
843 { |
|
844 TRAP( startErr, iConditionHandler = CSensrvConditionHandler::NewL( iSensrvClient, iChannelInfo )); |
|
845 } |
|
846 |
|
847 if ( startErr == KErrNone ) |
|
848 { |
|
849 TRAP( startErr, iConditionHandler->StartListening( this, listeningParams ) ); |
|
850 } |
|
851 |
|
852 if ( startErr ) |
|
853 { |
|
854 // Stop listening |
|
855 iSensrvClient.SendReceiveSync( ESensrvSrvReqStopConditionListening, TIpcArgs( iChannelInfo.iChannelId ) ); |
|
856 ERROR_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - ERROR: Starting listening failed, leave: %d" ), startErr ) ); |
|
857 User::Leave( startErr ); |
|
858 } |
|
859 |
|
860 // Now that we have successfully started, store parameters |
|
861 iConditionListener = aChannelConditionListener; |
|
862 |
|
863 iDataListeningParameters.iDesiredBufferingCount = listeningParams.iDesiredBufferingCount; |
|
864 iDataListeningParameters.iBufferingPeriod = listeningParams.iBufferingPeriod; |
|
865 |
|
866 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StartConditionListeningL() - Return" ) ) ); |
|
867 } |
|
868 |
|
869 // --------------------------------------------------------------------------- |
|
870 // CSensrvChannelImpl::StopConditionListening |
|
871 // --------------------------------------------------------------------------- |
|
872 // |
|
873 TInt CSensrvChannelImpl::StopConditionListening() |
|
874 { |
|
875 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StopConditionListening() - Start" ) ) ); |
|
876 |
|
877 TInt err( KErrNone ); |
|
878 |
|
879 // Check that channel is open |
|
880 if ( iChannelOpen ) |
|
881 { |
|
882 if ( iConditionHandler && iConditionHandler->IsActive() ) |
|
883 { |
|
884 iConditionHandler->Cancel(); |
|
885 } |
|
886 else |
|
887 { |
|
888 // Block further async condition messages, |
|
889 // in case stop is called from ConditionMet, when handler is not active. |
|
890 if ( iConditionHandler ) |
|
891 { |
|
892 iConditionHandler->BlockAsyncMessage(); |
|
893 } |
|
894 |
|
895 err = iSensrvClient.SendReceiveSync( ESensrvSrvReqStopConditionListening, TIpcArgs( iChannelInfo.iChannelId ) ); |
|
896 } |
|
897 } |
|
898 |
|
899 iConditionListener = NULL; |
|
900 |
|
901 // Remove all added conditions |
|
902 iConditionSetList.Reset(); |
|
903 |
|
904 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::StopConditionListening() - Return " ) ) ); |
|
905 |
|
906 return err; |
|
907 } |
|
908 |
|
909 // --------------------------------------------------------------------------- |
|
910 // CSensrvChannelImpl::DataReceived |
|
911 // --------------------------------------------------------------------------- |
|
912 // |
|
913 void CSensrvChannelImpl::DataReceived( TInt aCount, TInt aDataLost ) |
|
914 { |
|
915 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DataReceived()" ) ) ); |
|
916 if ( iDataListener ) |
|
917 { |
|
918 iDataListener->DataReceived( *this, aCount, aDataLost ); |
|
919 } |
|
920 } |
|
921 |
|
922 // --------------------------------------------------------------------------- |
|
923 // CSensrvChannelImpl::DataError |
|
924 // --------------------------------------------------------------------------- |
|
925 // |
|
926 void CSensrvChannelImpl::DataError( TSensrvErrorSeverity aError ) |
|
927 { |
|
928 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::DataError( %d )" ), aError ) ); |
|
929 |
|
930 if ( aError == ESensrvErrorSeverityFatal ) |
|
931 { |
|
932 CloseChannel(); |
|
933 } |
|
934 |
|
935 if ( iDataListener ) |
|
936 { |
|
937 iDataListener->DataError( *this, aError ); |
|
938 } |
|
939 } |
|
940 |
|
941 // --------------------------------------------------------------------------- |
|
942 // CSensrvChannelImpl::ReopenChannelForDataListeningL |
|
943 // --------------------------------------------------------------------------- |
|
944 // |
|
945 void CSensrvChannelImpl::ReopenChannelForDataListeningL( TInt& aMaxBufferCount ) |
|
946 { |
|
947 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ReopenChannelForDataListeningL" ) ) ); |
|
948 |
|
949 ReopenChannelForListeningL(EDataHandler); |
|
950 |
|
951 aMaxBufferCount = iMaxBufferCount; |
|
952 } |
|
953 |
|
954 // --------------------------------------------------------------------------- |
|
955 // CSensrvChannelImpl::PropertyChanged |
|
956 // --------------------------------------------------------------------------- |
|
957 // |
|
958 void CSensrvChannelImpl::PropertyChanged( const TSensrvProperty& aChangedProperty ) |
|
959 { |
|
960 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::PropertyChanged()" ) ) ); |
|
961 |
|
962 if ( iChannelPropertyListener ) |
|
963 { |
|
964 iChannelPropertyListener->PropertyChanged( *this, aChangedProperty ); |
|
965 } |
|
966 |
|
967 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::PropertyChanged - return" ) ) ); |
|
968 } |
|
969 |
|
970 // --------------------------------------------------------------------------- |
|
971 // CSensrvChannelImpl::PropertyError |
|
972 // --------------------------------------------------------------------------- |
|
973 // |
|
974 void CSensrvChannelImpl::PropertyError( TSensrvErrorSeverity aError ) |
|
975 { |
|
976 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::PropertyError()" ) ) ); |
|
977 |
|
978 if ( aError == ESensrvErrorSeverityFatal ) |
|
979 { |
|
980 CloseChannel(); |
|
981 } |
|
982 |
|
983 if ( iChannelPropertyListener ) |
|
984 { |
|
985 iChannelPropertyListener->PropertyError( *this, aError ); |
|
986 } |
|
987 |
|
988 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::PropertyError - return" ) ) ); |
|
989 } |
|
990 |
|
991 |
|
992 // --------------------------------------------------------------------------- |
|
993 // CSensrvChannelImpl::ReopenChannelForPropertyListeningL |
|
994 // --------------------------------------------------------------------------- |
|
995 // |
|
996 void CSensrvChannelImpl::ReopenChannelForPropertyListeningL() |
|
997 { |
|
998 ReopenChannelForListeningL(EPropertyHandler); |
|
999 } |
|
1000 |
|
1001 // --------------------------------------------------------------------------- |
|
1002 // CSensrvChannelImpl::SetPropertySuccessIndicationChanged |
|
1003 // --------------------------------------------------------------------------- |
|
1004 // |
|
1005 void CSensrvChannelImpl::SetPropertySuccessIndicationChanged( TSetPropertySuccessIndicator aIndication ) |
|
1006 { |
|
1007 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetPropertySuccessIndicationChanged()" ) ) ); |
|
1008 |
|
1009 if ( iChannelPropertyListener ) |
|
1010 { |
|
1011 iChannelPropertyListener->SetPropertySuccessIndicationChanged( aIndication ); |
|
1012 } |
|
1013 |
|
1014 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::SetPropertySuccessIndicationChanged - return" ) ) ); |
|
1015 } |
|
1016 |
|
1017 // --------------------------------------------------------------------------- |
|
1018 // CSensrvChannelImpl::ConditionMet |
|
1019 // --------------------------------------------------------------------------- |
|
1020 // |
|
1021 void CSensrvChannelImpl::ConditionMet( TInt aSetId, |
|
1022 TDesC8& aValue ) |
|
1023 { |
|
1024 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ConditionMet()" ) ) ); |
|
1025 |
|
1026 // Find set from local list |
|
1027 TBool found(EFalse); |
|
1028 CSensrvChannelConditionSetImpl* ptr = NULL; |
|
1029 iConditionSetIter.SetToFirst(); |
|
1030 while (!found && (ptr = iConditionSetIter++) != NULL) |
|
1031 { |
|
1032 if (ptr->ConditionSetId() == aSetId) |
|
1033 { |
|
1034 found = ETrue; |
|
1035 } |
|
1036 }; |
|
1037 |
|
1038 // Remove met set from list as it is no longer an added set |
|
1039 iConditionSetList.Remove(*ptr); |
|
1040 |
|
1041 // Notify listener |
|
1042 if ( iConditionListener ) |
|
1043 { |
|
1044 iConditionListener->ConditionMet( *this, |
|
1045 *(static_cast<CSensrvChannelConditionSet*>(ptr)), |
|
1046 aValue ); |
|
1047 } |
|
1048 |
|
1049 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ConditionMet - return void" ) ) ); |
|
1050 } |
|
1051 |
|
1052 // --------------------------------------------------------------------------- |
|
1053 // CSensrvChannelImpl::ConditionError |
|
1054 // --------------------------------------------------------------------------- |
|
1055 // |
|
1056 void CSensrvChannelImpl::ConditionError( TSensrvErrorSeverity aError ) |
|
1057 { |
|
1058 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ConditionError( %d )" ), aError ) ); |
|
1059 |
|
1060 if ( aError == ESensrvErrorSeverityFatal ) |
|
1061 { |
|
1062 CloseChannel(); |
|
1063 } |
|
1064 |
|
1065 if ( iConditionListener ) |
|
1066 { |
|
1067 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ConditionError - Notifying listener" ) ) ); |
|
1068 iConditionListener->ConditionError( *this, aError ); |
|
1069 } |
|
1070 } |
|
1071 |
|
1072 // --------------------------------------------------------------------------- |
|
1073 // CSensrvChannelImpl::ReopenChannelForConditionListeningL |
|
1074 // --------------------------------------------------------------------------- |
|
1075 // |
|
1076 void CSensrvChannelImpl::ReopenChannelForConditionListeningL() |
|
1077 { |
|
1078 ReopenChannelForListeningL(EConditionHandler); |
|
1079 } |
|
1080 |
|
1081 // --------------------------------------------------------------------------- |
|
1082 // Reopens channel and restarts listenings, except for the initiator. |
|
1083 // |
|
1084 // Note: Initiator is excluded for (at least) the following reasons: |
|
1085 // - In start listening initiated cases, the member variables required cannot |
|
1086 // be updated yet when this method is potentially needed. |
|
1087 // - In data handler case also the maximum buffering count |
|
1088 // can theoretically change (if it is ever based on something else than |
|
1089 // maximum data rate, which should never change). |
|
1090 // - In property and condition handling it might be possible to just always |
|
1091 // do same thing regardless of the initator, but for consistency we do |
|
1092 // it the same way for every initiator. |
|
1093 // |
|
1094 // With some redesign, it would probably be possible |
|
1095 // to make reopening without almost duplicate code in handlers |
|
1096 // and starting listening. |
|
1097 // --------------------------------------------------------------------------- |
|
1098 // |
|
1099 void CSensrvChannelImpl::ReopenChannelForListeningL( THandlerId aInitiator ) |
|
1100 { |
|
1101 COMPONENT_TRACE( ( _L( "Sensrv Client - CSensrvChannelImpl::ReopenChannelForListeningL(aInitiator: %d)" ), aInitiator ) ); |
|
1102 |
|
1103 // Close channel without resetting listeners or clearing conditions |
|
1104 CloseChannel(); |
|
1105 |
|
1106 // open channel without resetting listeners or clearing conditions |
|
1107 DoOpenChannelL( EFalse ); |
|
1108 |
|
1109 // Re-add conditions |
|
1110 CSensrvChannelConditionSetImpl* ptr = NULL; |
|
1111 iConditionSetIter.SetToFirst(); |
|
1112 while ((ptr = iConditionSetIter++) != NULL) |
|
1113 { |
|
1114 // Extract data from set |
|
1115 HBufC8* serializedSet = ptr->SerializeLC(); |
|
1116 |
|
1117 // Add set to server |
|
1118 User::LeaveIfError(iSensrvClient.SendReceiveSync( |
|
1119 ESensrvSrvReqAddConditionSet, |
|
1120 TIpcArgs( iChannelInfo.iChannelId, |
|
1121 serializedSet ) ) ); |
|
1122 |
|
1123 CleanupStack::PopAndDestroy(serializedSet); |
|
1124 }; |
|
1125 |
|
1126 // Start data listening |
|
1127 if ( aInitiator != EDataHandler |
|
1128 && aInitiator != EStartDataListening |
|
1129 && iDataListener |
|
1130 && iDataHandler ) |
|
1131 { |
|
1132 TSensrvStartListeningParametersPckgBuf startListeningPckg( iDataListeningParameters ); |
|
1133 |
|
1134 User::LeaveIfError( iSensrvClient.SendReceiveSync( |
|
1135 ESensrvSrvReqStartListening, |
|
1136 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ) ); |
|
1137 |
|
1138 iDataHandler->StartListeningL( this, iDataListeningParameters, iMaxBufferCount ); |
|
1139 } |
|
1140 |
|
1141 // Start property listening |
|
1142 if ( aInitiator != EPropertyHandler |
|
1143 && iChannelPropertyListener |
|
1144 && iChannelPropertyHandler ) |
|
1145 { |
|
1146 iChannelPropertyHandler->StartListening( this ); |
|
1147 } |
|
1148 |
|
1149 // Start condition listening |
|
1150 if ( aInitiator != EConditionHandler |
|
1151 && aInitiator != EStartConditionListening |
|
1152 && iConditionListener |
|
1153 && iConditionHandler ) |
|
1154 { |
|
1155 TSensrvStartListeningParametersPckgBuf startListeningPckg( iDataListeningParameters ); |
|
1156 |
|
1157 User::LeaveIfError( iSensrvClient.SendReceiveSync( |
|
1158 ESensrvSrvReqStartConditionListening, |
|
1159 TIpcArgs( iChannelInfo.iChannelId, &startListeningPckg ) ) ); |
|
1160 |
|
1161 iConditionHandler->StartListening( this, iDataListeningParameters); |
|
1162 } |
|
1163 } |