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