|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifdef USE_STUBBED_RADIOENGINE |
|
20 # include "t_cradioengine.h" |
|
21 # include "t_mrdshandler.h" |
|
22 #else |
|
23 # include "cradioengine.h" |
|
24 # include "cradioaudiorouter.h" |
|
25 # include "cradiosystemeventcollector.h" |
|
26 # include "cradiosettings.h" |
|
27 # include "mradioenginesettings.h" |
|
28 # include "cradiopubsub.h" |
|
29 # include "cradiorepositorymanager.h" |
|
30 # include "mradiordsreceiver.h" |
|
31 #endif |
|
32 |
|
33 #include "cradioenginehandler.h" |
|
34 #include "mradioenginehandlerobserver.h" |
|
35 #include "radio_global.h" |
|
36 #include "radiologger.h" |
|
37 #include "radioenummapper.h" |
|
38 |
|
39 /** |
|
40 * Delayed tuning delay |
|
41 */ |
|
42 const TInt KTuneDelay = 100000; |
|
43 |
|
44 /*! |
|
45 * Map to translate seek direction enum from its definition in the engine to |
|
46 * its definition in the ui and vice versa |
|
47 */ |
|
48 BEGIN_ENUM_MAP( KSeekDirectionMap ) |
|
49 ENUM_MAP_ITEM( Seeking::Down, RadioEngine::ERadioDown ), |
|
50 ENUM_MAP_ITEM( Seeking::Up, RadioEngine::ERadioUp ) |
|
51 END_ENUM_MAP( KSeekDirectionMap ) |
|
52 |
|
53 /*! |
|
54 * Convenience macro to do the mapping of seek directions |
|
55 */ |
|
56 #define MAP_FROM_UI_DIRECTION(ui_enum) MAP_FROM_UI_ENUM( RadioEngine::TRadioTuneDirection, ui_enum, KSeekDirectionMap ) |
|
57 |
|
58 /*! |
|
59 * Map to translate radio region enum from its definition in the engine to |
|
60 * its definition in the ui and vice versa |
|
61 */ |
|
62 BEGIN_ENUM_MAP( KRegionMap ) |
|
63 ENUM_MAP_ITEM( RadioRegion::None, ERadioRegionNone ), |
|
64 ENUM_MAP_ITEM( RadioRegion::Default, ERadioRegionDefault ), |
|
65 ENUM_MAP_ITEM( RadioRegion::Japan, ERadioRegionJapan ), |
|
66 ENUM_MAP_ITEM( RadioRegion::America, ERadioRegionAmerica ), |
|
67 ENUM_MAP_ITEM( RadioRegion::Poland, ERadioRegionPoland ), |
|
68 END_ENUM_MAP( KRegionMap ) |
|
69 |
|
70 /*! |
|
71 * Convenience macros to do the mapping of radio regions |
|
72 */ |
|
73 #define MAP_FROM_UI_REGION(ui_enum) MAP_FROM_UI_ENUM( TRadioRegion, ui_enum, KRegionMap ) |
|
74 #define MAP_TO_UI_REGION(engine_enum) MAP_TO_UI_ENUM( RadioRegion::Region, engine_enum, KRegionMap ) |
|
75 |
|
76 /*! |
|
77 * Map to translate seeking state enum from its definition in the engine to |
|
78 * its definition in the ui and vice versa |
|
79 */ |
|
80 BEGIN_ENUM_MAP( KSeekingStateMap ) |
|
81 ENUM_MAP_ITEM( Seeking::NotSeeking, RadioEngine::ERadioNotSeeking ), |
|
82 ENUM_MAP_ITEM( Seeking::SeekingUp, RadioEngine::ERadioSeekingUp ), |
|
83 ENUM_MAP_ITEM( Seeking::SeekingDown, RadioEngine::ERadioSeekingDown ) |
|
84 END_ENUM_MAP( KSeekingStateMap ) |
|
85 |
|
86 /*! |
|
87 * Convenience macro to do the mapping of seeking states |
|
88 */ |
|
89 #define MAP_TO_UI_SEEKING_STATE(ui_enum) MAP_TO_UI_ENUM( Seeking::State, ui_enum, KSeekingStateMap ) |
|
90 |
|
91 |
|
92 // ======== MEMBER FUNCTIONS ======== |
|
93 |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CRadioEngineHandler::CRadioEngineHandler( MRadioEngineHandlerObserver& aObserver ) |
|
100 : iObserver( aObserver ) |
|
101 { |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 CRadioEngineHandler::~CRadioEngineHandler() |
|
109 { |
|
110 if ( iEngine ) { |
|
111 iEngine->Settings().Repository().RemoveObserver( &iObserver ); |
|
112 } |
|
113 |
|
114 delete iEngine; |
|
115 delete iDelayTimer; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CRadioEngineHandler::ConstructL() |
|
123 { |
|
124 LOG_METHOD; |
|
125 |
|
126 iDelayTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
127 |
|
128 iEngine = CRadioEngine::NewL( *this ); |
|
129 |
|
130 iEngine->SystemEventCollector().AddObserverL( &iObserver ); |
|
131 iEngine->Settings().Repository().AddObserverL( &iObserver ); |
|
132 iEngine->AudioRouter().SetAudioRouteL( RadioEngine::ERadioHeadset ); |
|
133 iEngine->AddObserverL( &iObserver ); |
|
134 |
|
135 iRegion = MAP_TO_UI_REGION( iEngine->Settings().EngineSettings().RegionId() ); |
|
136 |
|
137 // iEngineHolder->PubSub().SetControlEventObserver( &iObserver ); |
|
138 |
|
139 // iRadioEngine->SetVolumeMuted( EFalse ); |
|
140 // iRadioEngine->SetVolume( MaxVolume() ); |
|
141 |
|
142 // CVRRepositoryManager::GetRepositoryValueL( KVRCRUid, KVRCRLaunchCount, usageCount ); |
|
143 // CVRRepositoryManager::SetRepositoryValueL( KVRCRUid, KVRCRLaunchCount, ++usageCount ); |
|
144 // iControlEventObserver = CVRControlEventObserverImpl::NewL( *this ); |
|
145 // doc->PubSubL().SetControlEventObserver( iControlEventObserver ); |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // Sets the rds data observer |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void CRadioEngineHandler::SetRdsObserver( MRadioRdsDataObserver* aObserver ) |
|
153 { |
|
154 TRAP_IGNORE( iEngine->RdsReceiver().AddObserverL( aObserver ) ); |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Returns the radio status. |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 TBool CRadioEngineHandler::IsRadioOn() |
|
162 { |
|
163 return iEngine->Settings().EngineSettings().IsPowerOn(); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // Tune to the specified frequency |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CRadioEngineHandler::Tune( TUint aFrequency ) |
|
171 { |
|
172 iEngine->SetFrequency( aFrequency ); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // Tune to the specified frequency after a delay |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 void CRadioEngineHandler::TuneWithDelay( TUint aFrequency ) |
|
180 { |
|
181 iFrequency = aFrequency; |
|
182 iDelayTimer->Cancel(); |
|
183 iDelayTimer->Start( KTuneDelay, KTuneDelay, TCallBack( TuneDelayCallback, this ) ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // Sets the audio mute state |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 void CRadioEngineHandler::SetMuted( const TBool aMuted ) |
|
191 { |
|
192 iEngine->SetVolumeMuted( aMuted ); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // Gets the audio mute state |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 TBool CRadioEngineHandler::IsMuted() const |
|
200 { |
|
201 return iEngine->Settings().EngineSettings().IsVolMuted(); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // Sets the volume level of the FM radio |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CRadioEngineHandler::SetVolume( TInt aVolume ) |
|
209 { |
|
210 if ( Volume() != aVolume ) |
|
211 { |
|
212 if ( aVolume > 0 ) |
|
213 { |
|
214 iEngine->SetVolumeMuted( EFalse ); |
|
215 } |
|
216 |
|
217 iEngine->SetVolume( aVolume ); |
|
218 } |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // Gets the volumelevel. |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 TInt CRadioEngineHandler::Volume() const |
|
226 { |
|
227 return iEngine->Settings().EngineSettings().Volume(); |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // Gets the max volumelevel. |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 TInt CRadioEngineHandler::MaxVolume() const |
|
235 { |
|
236 return iEngine->MaxVolumeLevel(); |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // Increases the volume by one increment |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void CRadioEngineHandler::IncreaseVolume() |
|
244 { |
|
245 iEngine->AdjustVolume( RadioEngine::ERadioIncVolume ); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // Decreases the volume by one increment |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CRadioEngineHandler::DecreaseVolume() |
|
253 { |
|
254 iEngine->AdjustVolume( RadioEngine::ERadioDecVolume ); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Checks if the antenna is attached |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 TBool CRadioEngineHandler::IsAntennaAttached() const |
|
262 { |
|
263 return iEngine->IsAntennaAttached(); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // Retrieves the current frequency. |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 TUint CRadioEngineHandler::TunedFrequency() const |
|
271 { |
|
272 return iEngine->Settings().EngineSettings().TunedFrequency(); |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // Returns the minimum allowed frequency in the current region |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 TUint CRadioEngineHandler::MinFrequency() const |
|
280 { |
|
281 return iEngine->Settings().EngineSettings().MinFrequency(); |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // Returns the maximum allowed frequency in the current region |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 TUint CRadioEngineHandler::MaxFrequency() const |
|
289 { |
|
290 return iEngine->Settings().EngineSettings().MaxFrequency(); |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // Checks if the given frequency is valid in the current region |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 TBool CRadioEngineHandler::IsFrequencyValid( TUint aFrequency ) const |
|
298 { |
|
299 return iEngine->IsFrequencyValid( aFrequency ); |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // Scan up to the next available frequency |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CRadioEngineHandler::Seek( Seeking::Direction direction ) |
|
307 { |
|
308 LOG_TIMESTAMP( "Seek" ); |
|
309 iEngine->Seek( MAP_FROM_UI_DIRECTION( direction ) ); |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // Cancel previously requested scan, and return to the |
|
314 // already tuned frequency |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CRadioEngineHandler::CancelSeek() |
|
318 { |
|
319 iEngine->CancelSeek(); |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // Returns the engine seeking state |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 Seeking::State CRadioEngineHandler::SeekingState() const |
|
327 { |
|
328 return MAP_TO_UI_SEEKING_STATE( iEngine->Seeking() ); |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 void CRadioEngineHandler::StartScan( MRadioScanObserver& aObserver ) |
|
336 { |
|
337 iEngine->StartScan( aObserver ); |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 void CRadioEngineHandler::StopScan( TInt aError ) |
|
345 { |
|
346 iEngine->StopScan( aError ); |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // return step size for tuning. |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 TUint32 CRadioEngineHandler::FrequencyStepSize() const |
|
354 { |
|
355 return iEngine->Settings().EngineSettings().FrequencyStepSize(); |
|
356 } |
|
357 |
|
358 // ---------------------------------------------------------------------------------------------------- |
|
359 // Returns the selected radio region |
|
360 // ---------------------------------------------------------------------------------------------------- |
|
361 // |
|
362 RadioRegion::Region CRadioEngineHandler::Region() const |
|
363 { |
|
364 return iRegion; |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------------------------- |
|
368 // Sets whether or not audio should be routed to loudspeaker |
|
369 // --------------------------------------------------------------------------- |
|
370 // |
|
371 void CRadioEngineHandler::SetAudioRouteToLoudspeaker( TBool aLoudspeaker ) |
|
372 { |
|
373 TRAPD( err, iEngine->AudioRouter().SetAudioRouteL( aLoudspeaker ? RadioEngine::ERadioSpeaker |
|
374 : RadioEngine::ERadioHeadset ) ); |
|
375 if ( err ) |
|
376 { |
|
377 LOG_FORMAT( "Failed to set audioroute: UseLoudspeadker: %d", aLoudspeaker ); |
|
378 } |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // Checks if audio is routed to loudspeaker |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 TBool CRadioEngineHandler::IsAudioRoutedToLoudspeaker() const |
|
386 { |
|
387 return iEngine->Settings().EngineSettings().AudioRoute() == RadioEngine::ERadioSpeaker; |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // Returns ar reference to the publish & subscribe handler |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 CRadioPubSub& CRadioEngineHandler::PubSub() |
|
395 { |
|
396 return *iEngine->PubSub(); |
|
397 } |
|
398 |
|
399 // --------------------------------------------------------------------------- |
|
400 // Returns the repository manager. |
|
401 // --------------------------------------------------------------------------- |
|
402 // |
|
403 CRadioRepositoryManager& CRadioEngineHandler::Repository() const |
|
404 { |
|
405 return iEngine->Settings().Repository(); |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // Returns the repository manager. |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 MRadioApplicationSettings& CRadioEngineHandler::ApplicationSettings() const |
|
413 { |
|
414 return iEngine->Settings().ApplicationSettings(); |
|
415 } |
|
416 |
|
417 // --------------------------------------------------------------------------- |
|
418 // From MRadioEngineInitializer |
|
419 // |
|
420 // --------------------------------------------------------------------------- |
|
421 // |
|
422 CRadioAudioRouter* CRadioEngineHandler::InitAudioRouterL() |
|
423 { |
|
424 return CRadioAudioRouter::NewL( iObserver ); |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // From MRadioEngineInitializer |
|
429 // |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 CRadioSystemEventCollector* CRadioEngineHandler::InitSystemEventCollectorL() |
|
433 { |
|
434 return CRadioSystemEventCollector::NewL(); |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // From MRadioEngineInitializer |
|
439 // |
|
440 // --------------------------------------------------------------------------- |
|
441 // |
|
442 CRadioSettings* CRadioEngineHandler::InitSettingsL() |
|
443 { |
|
444 return CRadioSettings::NewL(); |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------------------------- |
|
448 // From MRadioEngineInitializer |
|
449 // |
|
450 // --------------------------------------------------------------------------- |
|
451 // |
|
452 CRadioPubSub* CRadioEngineHandler::InitPubSubL() |
|
453 { |
|
454 return CRadioPubSub::NewL(); |
|
455 } |
|
456 |
|
457 // -------------------------------------------------------------------------------- |
|
458 // Static callback function to be used by the tune delay timer |
|
459 // -------------------------------------------------------------------------------- |
|
460 // |
|
461 TInt CRadioEngineHandler::TuneDelayCallback( TAny* aSelf ) |
|
462 { |
|
463 CRadioEngineHandler* self = static_cast<CRadioEngineHandler*>( aSelf ); |
|
464 self->iDelayTimer->Cancel(); |
|
465 self->Tune( self->iFrequency ); |
|
466 return 0; // Not used by CPeriodic |
|
467 } |