|
1 /* |
|
2 * Copyright (c) 2009 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: FMRadio active idle engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 |
|
21 #include "fmradioactiveidleengine.h" |
|
22 #include "fmradioactiveidleenginenotifyhandler.h" |
|
23 |
|
24 |
|
25 /** |
|
26 * Listing of the subscribed P&S values. |
|
27 * Changing the order of this enumeration requires changes to CFMRadioActiveIdleEngine::ConstructL as well. |
|
28 */ |
|
29 |
|
30 enum TFMRadioActiveIdleStatusObserverArray |
|
31 { |
|
32 //EFMRadioActiveIdleRadioVolumeObserver, /**< Index of the radio volume observer. */ |
|
33 EFMRadioActiveIdleTuningStateObserver, /**< Index of the tuning state observer. */ |
|
34 EFMRadioActiveIdleFrequencyObserver, /**< Index of the current frequency observer. */ |
|
35 EFMRadioActiveIdleChannelChangeObserver, /**< Index of the current channel observer. */ |
|
36 EFMRadioActiveIdleChannelModifyObserver, /**< Index of the channel modified observer. */ |
|
37 EFMRadioActiveIdleMuteStateObserver, /**< Index of the muting state observer. */ |
|
38 EFMRadioActiveIdleApplicationObserver, /**< Index of the FM Radio application observer used to observer whether the application is running or not. */ |
|
39 EFMRadioActiveIdleHeadsetStatusObserver, /**< Index of the antenna status observer. */ |
|
40 EFMRadioActiveIdleDecimalCountObserver, /**< Index of the frequency decimal count observer. */ |
|
41 EFMRadioActiveIdlePowerStateObserver, /**< Index of the power state observer. */ |
|
42 EFMRadioActiveIdleRDSProgramServiceObserver, /**< Index of the RDS Program Service observer. */ |
|
43 EFMRadioPSDataRDSRadioText, |
|
44 EFMRadioPSDataChannelName, |
|
45 EFMRadioActiveIdlePresetListCountObserver, /**< Index of the active preset list count observer */ |
|
46 EFMRadioActiveIdlePresetListFocusObserver /**< Index of the active preset list focus observer */ |
|
47 }; |
|
48 |
|
49 // ==================== LOCAL FUNCTIONS ==================== |
|
50 |
|
51 // ================= MEMBER FUNCTIONS ======================= |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Constructor. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CFMRadioActiveIdleEngine::CFMRadioActiveIdleEngine( MFMRadioActiveIdleEngineNotifyHandler& aObserver ) |
|
58 : iObserver( aObserver ) |
|
59 { |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Second-phase constructor. |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void CFMRadioActiveIdleEngine::ConstructL() |
|
67 { |
|
68 //User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioEnginePSUid, KFMRadioPSDataVolume, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
69 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataTuningState, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
70 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataFrequency, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
71 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataChannel, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
72 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataChannelDataChanged, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
73 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataRadioMuteState, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
74 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataApplicationRunning, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
75 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataHeadsetStatus, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
76 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataFrequencyDecimalCount, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
77 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataRadioPowerState, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
78 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataRDSProgramService, CFMRadioPropertyObserver::EFMRadioPropertyText ) ) ); |
|
79 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataRDSRadioText, CFMRadioPropertyObserver::EFMRadioPropertyText ) ) ); |
|
80 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioPSDataChannelName, CFMRadioPropertyObserver::EFMRadioPropertyText ) ) ); |
|
81 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioActiveIdlePresetListCount, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
82 User::LeaveIfError( iPropertyObserverArray.Append( CFMRadioPropertyObserver::NewL( *this, KFMRadioPSUid, KFMRadioActiveIdlePresetListFocus, CFMRadioPropertyObserver::EFMRadioPropertyInt ) ) ); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Makes all pubsub objects to subscribe. |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C void CFMRadioActiveIdleEngine::ActivateL() |
|
90 { |
|
91 for ( TInt i = 0; i < iPropertyObserverArray.Count(); i++ ) |
|
92 { |
|
93 iPropertyObserverArray[i]->ActivateL(); |
|
94 } |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Cancels all pubsub objects. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 EXPORT_C void CFMRadioActiveIdleEngine::Cancel() |
|
102 { |
|
103 for ( TInt i = 0; i < iPropertyObserverArray.Count(); i++ ) |
|
104 { |
|
105 iPropertyObserverArray[i]->Cancel(); |
|
106 } |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // Static constructor. |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C CFMRadioActiveIdleEngine* CFMRadioActiveIdleEngine::NewL( MFMRadioActiveIdleEngineNotifyHandler& aObserver ) |
|
114 { |
|
115 CFMRadioActiveIdleEngine* self = new ( ELeave ) CFMRadioActiveIdleEngine( aObserver ); |
|
116 CleanupStack::PushL( self ); |
|
117 self->ConstructL(); |
|
118 CleanupStack::Pop( self ); |
|
119 return self; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // Destructor. |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C CFMRadioActiveIdleEngine::~CFMRadioActiveIdleEngine() |
|
127 { |
|
128 iPropertyObserverArray.ResetAndDestroy(); |
|
129 iPropertyObserverArray.Close(); |
|
130 /* |
|
131 if ( iServ ) |
|
132 { |
|
133 iServ->Close(); |
|
134 } |
|
135 delete iServ; |
|
136 */ |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // Invoked when a listened integer P&S key is changed. |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CFMRadioActiveIdleEngine::HandlePropertyChangeL( const TUid& aCategory, TUint aKey, TInt aValue ) |
|
144 { |
|
145 if ( aCategory == KFMRadioPSUid ) |
|
146 { |
|
147 switch ( aKey ) |
|
148 {/* |
|
149 case KFMRadioPSDataVolume: |
|
150 iObserver.HandleRadioVolumeChangeL( aValue ); |
|
151 break;*/ |
|
152 |
|
153 case KFMRadioPSDataTuningState: |
|
154 iObserver.HandleTuningStateChangeL( static_cast<TFMRadioPSTuningState>( aValue ) ); |
|
155 break; |
|
156 |
|
157 case KFMRadioPSDataFrequency: |
|
158 iObserver.HandleFrequencyChangeL( aValue ); |
|
159 break; |
|
160 |
|
161 case KFMRadioPSDataChannel: |
|
162 // Sync the cache values for channel name and index |
|
163 iPropertyObserverArray[EFMRadioPSDataChannelName]->ValueDes( ETrue ); |
|
164 iObserver.HandleChannelChangeL( aValue ); |
|
165 break; |
|
166 |
|
167 case KFMRadioPSDataChannelDataChanged: |
|
168 iPropertyObserverArray[EFMRadioPSDataChannelName]->ValueDes( ETrue ); |
|
169 iObserver.HandleChannelModifyL( aValue ); |
|
170 break; |
|
171 |
|
172 case KFMRadioPSDataRadioMuteState: |
|
173 iObserver.HandleMuteStateChangeL( static_cast<TFMRadioPSRadioMuteState>( aValue ) ); |
|
174 break; |
|
175 |
|
176 case KFMRadioPSDataApplicationRunning: |
|
177 iObserver.HandleApplicationRunningStateChangeL( static_cast<TFMRadioPSApplicationRunningState>( aValue ) ); |
|
178 break; |
|
179 |
|
180 case KFMRadioPSDataHeadsetStatus: |
|
181 iObserver.HandleAntennaStatusChangeL( static_cast<TFMRadioPSHeadsetStatus>( aValue ) ); |
|
182 break; |
|
183 |
|
184 case KFMRadioPSDataFrequencyDecimalCount: |
|
185 iObserver.HandleFrequencyDecimalCountChangeL( static_cast<TFMRadioPSFrequencyDecimalCount>( aValue ) ); |
|
186 break; |
|
187 |
|
188 case KFMRadioPSDataRadioPowerState: |
|
189 iObserver.HandlePowerStateChangeL( static_cast<TFMRadioPSRadioPowerState>( aValue ) ); |
|
190 break; |
|
191 |
|
192 case KFMRadioActiveIdlePresetListCount: |
|
193 iObserver.HandlePresetListCountChangeL( aValue ); |
|
194 break; |
|
195 |
|
196 case KFMRadioActiveIdlePresetListFocus: |
|
197 //iObserver.HandlePresetListFocusChangeL( aValue ); |
|
198 break; |
|
199 |
|
200 default: |
|
201 break; |
|
202 } |
|
203 } |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // Invoked when a listened byte array P&S key is changed. |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 //void CFMRadioActiveIdleEngine::HandlePropertyChangeL( const TUid& /*aCategory*/, TUint /*aKey*/, const TDesC8& /*aValue*/ ) |
|
211 // { |
|
212 // } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // Invoked when a listened text P&S key is changed. |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 |
|
219 void CFMRadioActiveIdleEngine::HandlePropertyChangeL( const TUid& aCategory, TUint aKey, const TDesC& aValue ) |
|
220 { |
|
221 if ( aCategory == KFMRadioPSUid ) |
|
222 { |
|
223 switch ( aKey ) |
|
224 { |
|
225 case KFMRadioPSDataRDSProgramService: |
|
226 iObserver.HandleRDSProgramServiceChangeL( aValue ); |
|
227 break; |
|
228 case KFMRadioPSDataRDSRadioText: |
|
229 iObserver.HandleRDSRadioTextChangeL( aValue ); |
|
230 break; |
|
231 case KFMRadioPSDataChannelName: |
|
232 // Sync the cache valuse for channel name and index |
|
233 iPropertyObserverArray[EFMRadioActiveIdleChannelChangeObserver]->ValueInt( ETrue ); |
|
234 iObserver.HandleChannelNameChangeL( aValue ); |
|
235 break; |
|
236 default: |
|
237 break; |
|
238 } |
|
239 } |
|
240 |
|
241 } |
|
242 // --------------------------------------------------------------------------- |
|
243 // Invoked when a listened text P&S key is changed. |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CFMRadioActiveIdleEngine::HandlePropertyChangeL( const TUid&, TUint, const TDesC8&) |
|
247 { |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // Invoked when an error has occured while fetching the new value of any listened P&S key. |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void CFMRadioActiveIdleEngine::HandlePropertyChangeErrorL( const TUid& /*aCategory*/, TUint /*aKey*/, TInt aError ) |
|
255 { |
|
256 if (aError < 0) |
|
257 { |
|
258 // If any error should pass to this method, handle it like 'application shutdown'. |
|
259 // This situation will realize whenever the application is killed, by accident/by system/by an app crash |
|
260 // or due to change to offline mode. |
|
261 HandlePropertyChangeL(KFMRadioPSUid, KFMRadioPSDataApplicationRunning, EFMRadioPSApplicationClosing); |
|
262 } |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // Returns the current radio volume. |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 EXPORT_C TInt CFMRadioActiveIdleEngine::RadioVolume() const |
|
270 { |
|
271 //return iPropertyObserverArray[EFMRadioActiveIdleRadioVolumeObserver]->ValueInt(); |
|
272 return 0; |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // Sets the radio volume. |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 EXPORT_C void CFMRadioActiveIdleEngine::AdjustRadioVolume( TFMRadioPSAdjustVolume aVolume ) const |
|
280 { |
|
281 RProperty::Set( KFMRadioPSUid, KFMRadioPSControlAdjustVolume, aVolume ); |
|
282 } |
|
283 |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // Returns the current tuning state. |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 EXPORT_C TFMRadioPSTuningState CFMRadioActiveIdleEngine::TuningState() const |
|
290 { |
|
291 return static_cast<TFMRadioPSTuningState>( iPropertyObserverArray[EFMRadioActiveIdleTuningStateObserver]->ValueInt() ); |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // Returns the current frequency. |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 EXPORT_C TInt CFMRadioActiveIdleEngine::Frequency() const |
|
299 { |
|
300 return iPropertyObserverArray[EFMRadioActiveIdleFrequencyObserver]->ValueInt(); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // Returns the currently active channel ID. |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C TInt CFMRadioActiveIdleEngine::Channel() const |
|
308 { |
|
309 return iPropertyObserverArray[EFMRadioActiveIdleChannelChangeObserver]->ValueInt(); |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // Returns the currently active channel name. |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 EXPORT_C const TDesC& CFMRadioActiveIdleEngine::ChannelName() const |
|
317 { |
|
318 return iPropertyObserverArray[EFMRadioPSDataChannelName]->ValueDes(); |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // Returns the current mute state. |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 EXPORT_C TFMRadioPSRadioMuteState CFMRadioActiveIdleEngine::MuteState() const |
|
326 { |
|
327 return static_cast<TFMRadioPSRadioMuteState>( iPropertyObserverArray[EFMRadioActiveIdleMuteStateObserver]->ValueInt() ); |
|
328 } |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // Sets the mute state. |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 EXPORT_C void CFMRadioActiveIdleEngine::SetMuteState( TFMRadioPSRadioMuteState aMuteState ) const |
|
335 { |
|
336 RProperty::Set( KFMRadioPSUid, KFMRadioPSControlSetRadioMuteState, aMuteState ); |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // Returns the current antenna connectivity status. |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 EXPORT_C TFMRadioPSHeadsetStatus CFMRadioActiveIdleEngine::AntennaStatus() const |
|
344 { |
|
345 return static_cast<TFMRadioPSHeadsetStatus>( iPropertyObserverArray[EFMRadioActiveIdleHeadsetStatusObserver]->ValueInt() ); |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // Returns the current frequency decimal count. |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 EXPORT_C TFMRadioPSFrequencyDecimalCount CFMRadioActiveIdleEngine::FrequencyDecimalCount() const |
|
353 { |
|
354 return static_cast<TFMRadioPSFrequencyDecimalCount>( iPropertyObserverArray[EFMRadioActiveIdleDecimalCountObserver]->ValueInt() ); |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------------------------- |
|
358 // Returns FM Radio application's running state. |
|
359 // --------------------------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C TFMRadioPSApplicationRunningState CFMRadioActiveIdleEngine::ApplicationRunningState() const |
|
362 { |
|
363 return static_cast<TFMRadioPSApplicationRunningState>( iPropertyObserverArray[EFMRadioActiveIdleApplicationObserver]->ValueInt() ); |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // Returns the radio's power state. |
|
368 // --------------------------------------------------------------------------- |
|
369 // |
|
370 EXPORT_C TFMRadioPSRadioPowerState CFMRadioActiveIdleEngine::PowerState() const |
|
371 { |
|
372 return static_cast<TFMRadioPSRadioPowerState>( iPropertyObserverArray[EFMRadioActiveIdlePowerStateObserver]->ValueInt() ); |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // Returns RDS Program Service information. |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 |
|
380 EXPORT_C const TDesC& CFMRadioActiveIdleEngine::RDSProgramService() const |
|
381 { |
|
382 return iPropertyObserverArray[EFMRadioActiveIdleRDSProgramServiceObserver]->ValueDes(); |
|
383 } |
|
384 |
|
385 // ================= OTHER EXPORTED FUNCTIONS ============== |
|
386 |