|
1 /* |
|
2 * Copyright (c) 2006 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 |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ssycallback.h> // MSsyCallback |
|
20 #include "ssyreferencechannel.h" |
|
21 #include "ssyreferencecontrol.h" // SSY Control |
|
22 #include "ssyreferencepropertyprovider.h" // iChannelPropertyProvider |
|
23 #include "ssyreferencechanneldataprovider.h" // iChannelDataProvider |
|
24 #include "ssyreferencetrace.h" |
|
25 #include "ssyreferencecmdhandler.h" |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CSsyReferenceChannel C++ constructor |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CSsyReferenceChannel::CSsyReferenceChannel( CSsyReferenceControl& aSsyControl, TSensrvChannelInfo aChannelInfo ) : |
|
35 iSsyControl( aSsyControl ), |
|
36 iChannelInfo( aChannelInfo ), |
|
37 iState( ESsyReferenceChannelIdle ) |
|
38 { |
|
39 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::CSsyReferenceChannel()" ) ) ); |
|
40 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::CSsyReferenceChannel() - return" ) ) ); |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Symbian 2nd phase constructor |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 void CSsyReferenceChannel::ConstructL() |
|
49 { |
|
50 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ConstructL()" ) ) ); |
|
51 |
|
52 // Create command handler |
|
53 iCmdHandler = CSsyReferenceCmdHandler::NewL( *this ); |
|
54 |
|
55 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ConstructL() - return" ) ) ); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CSsyReferenceChannel::NewL |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CSsyReferenceChannel* CSsyReferenceChannel::NewL( CSsyReferenceControl& aSsyControl, TSensrvChannelInfo aChannelInfo ) |
|
63 { |
|
64 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::NewL()" ) ) ); |
|
65 CSsyReferenceChannel* self = new ( ELeave ) CSsyReferenceChannel( aSsyControl, aChannelInfo ); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop( self ); |
|
69 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::NewL() - return" ) ) ); |
|
70 return self; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Destructor |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CSsyReferenceChannel::~CSsyReferenceChannel() |
|
78 { |
|
79 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::~CSsyReferenceChannel()" ) ) ); |
|
80 |
|
81 // In case channel is not closed before destruction, providers are not deleted |
|
82 if ( iChannelDataProvider ) |
|
83 { |
|
84 delete iChannelDataProvider; |
|
85 iChannelDataProvider = NULL; |
|
86 } |
|
87 |
|
88 if ( iChannelPropertyProvider ) |
|
89 { |
|
90 delete iChannelPropertyProvider; |
|
91 iChannelPropertyProvider = NULL; |
|
92 } |
|
93 |
|
94 if ( iCmdHandler ) |
|
95 { |
|
96 delete iCmdHandler; |
|
97 iCmdHandler = NULL; |
|
98 } |
|
99 |
|
100 iProperties.Reset(); |
|
101 |
|
102 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::~CSsyReferenceChannel() - return" ) ) ); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CSsyReferenceChannel::ChannelId |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 TInt CSsyReferenceChannel::ChannelId() |
|
110 { |
|
111 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ChannelId() - %i" ), iChannelInfo.iChannelId ) ); |
|
112 return iChannelInfo.iChannelId; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CSsyReferenceChannel::SsyControl |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 CSsyReferenceControl& CSsyReferenceChannel::SsyControl() const |
|
120 { |
|
121 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::SsyControl()" ) ) ); |
|
122 return iSsyControl; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CSsyReferenceControl::SsyCmdHandler |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 CSsyReferenceCmdHandler& CSsyReferenceChannel::CommandHandler() const |
|
130 { |
|
131 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::SsyCmdHandler()" ) ) ); |
|
132 return *iCmdHandler; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CSsyReferenceChannel::FindPropertyL |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TSensrvProperty& CSsyReferenceChannel::FindPropertyL( |
|
140 const TSensrvPropertyId aPropertyId, |
|
141 TInt aItemIndex, |
|
142 TInt aArrayIndex ) |
|
143 { |
|
144 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::FindPropertyL()" ) ) ); |
|
145 TSensrvProperty* property = NULL; |
|
146 TBool propertyFound( EFalse ); |
|
147 |
|
148 // Search property |
|
149 for ( TInt i = 0; i < iProperties.Count() && !propertyFound; i++ ) |
|
150 { |
|
151 property = static_cast<TSensrvProperty*>( &iProperties[i] ); |
|
152 |
|
153 // Compare property IDs and array index |
|
154 if ( property->GetPropertyId() == aPropertyId ) |
|
155 { |
|
156 // Compare item index if it is given |
|
157 if ( ( KErrNotFound == aItemIndex ) || ( property->PropertyItemIndex() == aItemIndex ) ) |
|
158 { |
|
159 // Correct property ID is found, now check is it array type of property. |
|
160 // Either array indexes must match or propertys array index has to be array info |
|
161 if ( ( property->GetArrayIndex() == aArrayIndex ) || |
|
162 ( ( property->GetArrayIndex() == ESensrvArrayPropertyInfo ) && |
|
163 ( ESensrvSingleProperty == aArrayIndex ) ) ) |
|
164 { |
|
165 // Correct array index found |
|
166 propertyFound = ETrue; |
|
167 } |
|
168 } |
|
169 } |
|
170 } |
|
171 |
|
172 // Leave if not found |
|
173 if ( !propertyFound ) |
|
174 { |
|
175 iSsyControl.FindPropertyL( aPropertyId, aArrayIndex, *property ); |
|
176 } |
|
177 |
|
178 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::FindPropertyL() - return" ) ) ); |
|
179 return *property; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CSsyReferenceChannel::FindAndUpdatePropertyL |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CSsyReferenceChannel::FindAndUpdatePropertyL( const TSensrvProperty& aProperty ) |
|
187 { |
|
188 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::FindAndUpdatePropertyL()" ) ) ); |
|
189 TBool propertyFound( EFalse ); |
|
190 |
|
191 // Search property |
|
192 for ( TInt i = 0; i < iProperties.Count() && !propertyFound; i++ ) |
|
193 { |
|
194 // Compare property IDs |
|
195 if ( iProperties[i].GetPropertyId() == aProperty.GetPropertyId() ) |
|
196 { |
|
197 // Compare item index if it is given |
|
198 if ( ( KErrNotFound != aProperty.PropertyItemIndex() ) && |
|
199 ( iProperties[i].PropertyItemIndex() == aProperty.PropertyItemIndex() ) ) |
|
200 { |
|
201 // Property found -> update if possible |
|
202 if ( iProperties[i].ReadOnly() ) |
|
203 { |
|
204 User::Leave( KErrAccessDenied ); |
|
205 } |
|
206 // If modifiable, get type and update value |
|
207 switch ( iProperties[i].PropertyType() ) |
|
208 { |
|
209 case ESensrvIntProperty: |
|
210 { |
|
211 TInt value( 0 ); |
|
212 aProperty.GetValue( value ); |
|
213 iProperties[i].SetValue( value ); |
|
214 break; |
|
215 } |
|
216 case ESensrvRealProperty: |
|
217 { |
|
218 TReal value( 0 ); |
|
219 aProperty.GetValue( value ); |
|
220 iProperties[i].SetValue( (TReal) value ); |
|
221 break; |
|
222 } |
|
223 case ESensrvBufferProperty: |
|
224 { |
|
225 TBuf8<20> propValue; |
|
226 aProperty.GetValue( propValue ); |
|
227 iProperties[i].SetValue( propValue ); |
|
228 break; |
|
229 } |
|
230 default: |
|
231 { |
|
232 break; |
|
233 } |
|
234 } |
|
235 propertyFound = ETrue; |
|
236 } |
|
237 } |
|
238 } |
|
239 |
|
240 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::FindPropertyL() - return" ) ) ); |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // CSsyReferenceChannel::GetProperties |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 void CSsyReferenceChannel::GetProperties( RSensrvPropertyList& aPropertyList ) |
|
248 { |
|
249 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::GetProperties()" ) ) ); |
|
250 // Copy properties one by one to param aPropertyList |
|
251 TInt propCount( iProperties.Count() ); |
|
252 RSensrvPropertyList propList( propCount ); |
|
253 |
|
254 for ( TInt i = 0; i < propCount; i++ ) |
|
255 { |
|
256 propList.Append( iProperties[i] ); |
|
257 } |
|
258 |
|
259 aPropertyList = propList; |
|
260 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::GetProperties() - return" ) ) ); |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CSsyReferenceChannel::UpdateState |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CSsyReferenceChannel::UpdateState( const TSsyReferenceChannelState aNewState ) |
|
268 { |
|
269 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::UpdateState() - %i" ), aNewState ) ); |
|
270 iState = aNewState; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CSsyReferenceChannel::ProcessResponse |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CSsyReferenceChannel::ProcessResponse( TSsyReferenceMsg* aMessage ) |
|
278 { |
|
279 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ProcessResponse()" ) ) ); |
|
280 |
|
281 if ( aMessage ) |
|
282 { |
|
283 switch ( aMessage->Function() ) |
|
284 { |
|
285 case ESsyReferenceOpenChannelResp: |
|
286 { |
|
287 // Open channel specific handling here |
|
288 TRAPD( err, HandleOpenChannelRespL( aMessage->Error() ) ); |
|
289 if ( KErrNone != err ) |
|
290 { |
|
291 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ProcessResponse() - Error opening channel: %i" ), err ) ); |
|
292 } |
|
293 break; |
|
294 } |
|
295 case ESsyReferenceDataItemReceived: |
|
296 { |
|
297 // Send data item to data provider |
|
298 TRAPD( err, iChannelDataProvider->ChannelDataReceivedL( aMessage ) ); |
|
299 if ( KErrNone != err ) |
|
300 { |
|
301 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ProcessResponse() - Error receiving data: %i" ), err ) ); |
|
302 } |
|
303 break; |
|
304 } |
|
305 case ESsyReferenceCloseChannelResp: |
|
306 { |
|
307 // Close channel specific handling here |
|
308 HandleCloseChannelResp(); |
|
309 break; |
|
310 } |
|
311 default: |
|
312 { |
|
313 // This command was not intended to process here, try Control class |
|
314 iSsyControl.ProcessResponse( aMessage ); |
|
315 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ProcessResponse() - Unknown function" ) ) ); |
|
316 } |
|
317 } |
|
318 } |
|
319 |
|
320 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::ProcessResponse() - return" ) ) ); |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CSsyReferenceChannel::OpenChannel |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 TInt CSsyReferenceChannel::OpenChannel() |
|
328 { |
|
329 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::OpenChannel()" ) ) ); |
|
330 |
|
331 TInt err( KErrAlreadyExists ); |
|
332 |
|
333 // Check that this channel is not already open |
|
334 if ( ESsyReferenceChannelIdle == iState ) |
|
335 { |
|
336 // Update state and issue request. Will continue in HandleOpenChannelResp |
|
337 UpdateState( ESsyReferenceChannelOpening ); |
|
338 |
|
339 // Create message with function spesific information |
|
340 // and pass it to command handler |
|
341 err = iCmdHandler->ProcessCommand( TSsyReferenceMsg( ChannelId(), ESsyReferenceOpenChannel ) ); |
|
342 } |
|
343 |
|
344 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::OpenChannel() - return" ) ) ); |
|
345 return err; |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // CSsyReferenceChannel::HandleOpenChannelResp |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 void CSsyReferenceChannel::HandleOpenChannelRespL( const TInt aError ) |
|
353 { |
|
354 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::HandleOpenChannelResp()" ) ) ); |
|
355 |
|
356 // Open channel asynhronously and complete request with MSsyCallback::ChannelOpened() when |
|
357 // channel is opened. |
|
358 |
|
359 // Create instance of the data provider of this channel |
|
360 iChannelDataProvider = CSsyReferenceChannelDataProvider::NewL( *this ); |
|
361 // Create instance of the property provider of this channel |
|
362 iChannelPropertyProvider = CSsyReferencePropertyProvider::NewL( *this ); |
|
363 |
|
364 TInt error( aError ); |
|
365 |
|
366 // If channel opening succeeds, update state to Open |
|
367 if ( KErrNone == aError ) |
|
368 { |
|
369 // Update state to Open |
|
370 UpdateState( ESsyReferenceChannelOpen ); |
|
371 // Get channel properties |
|
372 TRAP( error, iSsyControl.SsyConfig().GetChannelPropertiesL( ChannelId(), iProperties ) ); |
|
373 } |
|
374 else |
|
375 { |
|
376 // Channel opening failed, back to idle |
|
377 UpdateState( ESsyReferenceChannelIdle ); |
|
378 } |
|
379 |
|
380 // Complete transaction |
|
381 iSsyControl.SsyCallback().ChannelOpened( ChannelId(), |
|
382 error, |
|
383 iChannelDataProvider, |
|
384 iChannelPropertyProvider ); |
|
385 |
|
386 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::HandleOpenChannelResp() - return" ) ) ); |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // CSsyReferenceChannel::CloseChannel |
|
391 // --------------------------------------------------------------------------- |
|
392 // |
|
393 TInt CSsyReferenceChannel::CloseChannel() |
|
394 { |
|
395 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::CloseChannel()" ) ) ); |
|
396 |
|
397 TInt err( KErrNotFound ); |
|
398 |
|
399 // Check that this channel is open |
|
400 if ( ESsyReferenceChannelOpen == iState ) |
|
401 { |
|
402 // Update state and issue request. Will continue in HandleCloseChannelResp |
|
403 UpdateState( ESsyReferenceChannelClosing ); |
|
404 // Create message with function spesific information |
|
405 // and pass it to command handler |
|
406 err = iCmdHandler->ProcessCommand( TSsyReferenceMsg( ChannelId(), ESsyReferenceCloseChannel ) ); |
|
407 } |
|
408 |
|
409 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::CloseChannel() - return" ) ) ); |
|
410 return err; |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // CSsyReferenceChannel::HandleCloseChannelResp |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 void CSsyReferenceChannel::HandleCloseChannelResp() |
|
418 { |
|
419 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::HandleCloseChannelResp()" ) ) ); |
|
420 |
|
421 // Close channel and complete request with MSsyCallback::ChannelClosed() when |
|
422 // channel is closed. |
|
423 |
|
424 // Delete providers |
|
425 delete iChannelDataProvider; |
|
426 iChannelDataProvider = NULL; |
|
427 |
|
428 delete iChannelPropertyProvider; |
|
429 iChannelPropertyProvider = NULL; |
|
430 |
|
431 // Update state to idle |
|
432 UpdateState( ESsyReferenceChannelIdle ); |
|
433 |
|
434 // Reset properties |
|
435 iProperties.Reset(); |
|
436 |
|
437 // Complete transaction |
|
438 iSsyControl.SsyCallback().ChannelClosed( ChannelId() ); |
|
439 |
|
440 COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceChannel::HandleCloseChannelResp() - return" ) ) ); |
|
441 } |
|
442 |
|
443 // End of file |