|
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 "cradiorepositorymanager.h" |
|
25 #include "mradiordsreceiver.h" |
|
26 #include "radioenginehandler.h" |
|
27 #include "mradioenginehandlerobserver.h" |
|
28 #include "radio_global.h" |
|
29 #include "radiologger.h" |
|
30 #include "radioenummapper.h" |
|
31 |
|
32 /*! |
|
33 * Map to translate seek direction enum from its definition in the engine to |
|
34 * its definition in the ui and vice versa |
|
35 */ |
|
36 BEGIN_ENUM_MAP( KSeekDirectionMap ) |
|
37 ENUM_MAP_ITEM( Seek::Down, RadioEngine::ERadioDown ), |
|
38 ENUM_MAP_ITEM( Seek::Up, RadioEngine::ERadioUp ) |
|
39 END_ENUM_MAP( KSeekDirectionMap ) |
|
40 |
|
41 /*! |
|
42 * Convenience macro to do the mapping of seek directions |
|
43 */ |
|
44 #define MAP_FROM_UI_DIRECTION(ui_enum) MAP_FROM_UI_ENUM( RadioEngine::TRadioTuneDirection, ui_enum, KSeekDirectionMap ) |
|
45 |
|
46 /*! |
|
47 * Map to translate radio region enum from its definition in the engine to |
|
48 * its definition in the ui and vice versa |
|
49 */ |
|
50 BEGIN_ENUM_MAP( KRegionMap ) |
|
51 ENUM_MAP_ITEM( RadioRegion::None, ERadioRegionNone ), |
|
52 ENUM_MAP_ITEM( RadioRegion::Default, ERadioRegionDefault ), |
|
53 ENUM_MAP_ITEM( RadioRegion::Japan, ERadioRegionJapan ), |
|
54 ENUM_MAP_ITEM( RadioRegion::America, ERadioRegionAmerica ), |
|
55 ENUM_MAP_ITEM( RadioRegion::Poland, ERadioRegionPoland ), |
|
56 END_ENUM_MAP( KRegionMap ) |
|
57 |
|
58 /*! |
|
59 * Convenience macros to do the mapping of radio regions |
|
60 */ |
|
61 #define MAP_FROM_UI_REGION(ui_enum) MAP_FROM_UI_ENUM( TRadioRegion, ui_enum, KRegionMap ) |
|
62 #define MAP_TO_UI_REGION(engine_enum) MAP_TO_UI_ENUM( RadioRegion::Region, engine_enum, KRegionMap ) |
|
63 |
|
64 /*! |
|
65 * Map to translate seeking state enum from its definition in the engine to |
|
66 * its definition in the ui and vice versa |
|
67 */ |
|
68 BEGIN_ENUM_MAP( KSeekingStateMap ) |
|
69 ENUM_MAP_ITEM( Seek::NotSeeking, RadioEngine::ERadioNotSeeking ), |
|
70 ENUM_MAP_ITEM( Seek::SeekingUp, RadioEngine::ERadioSeekingUp ), |
|
71 ENUM_MAP_ITEM( Seek::SeekingDown, RadioEngine::ERadioSeekingDown ) |
|
72 END_ENUM_MAP( KSeekingStateMap ) |
|
73 |
|
74 /*! |
|
75 * Convenience macro to do the mapping of seeking states |
|
76 */ |
|
77 #define MAP_TO_UI_SEEKING_STATE(ui_enum) MAP_TO_UI_ENUM( Seek::State, ui_enum, KSeekingStateMap ) |
|
78 |
|
79 /*! |
|
80 * |
|
81 */ |
|
82 RadioEngineHandler::RadioEngineHandler( MRadioEngineHandlerObserver& observer ) |
|
83 : mObserver( observer ) |
|
84 { |
|
85 } |
|
86 |
|
87 /*! |
|
88 * |
|
89 */ |
|
90 RadioEngineHandler::~RadioEngineHandler() |
|
91 { |
|
92 } |
|
93 |
|
94 /*! |
|
95 * Attempts to construct the radio engine |
|
96 */ |
|
97 bool RadioEngineHandler::constructEngine() |
|
98 { |
|
99 LOG_METHOD; |
|
100 |
|
101 CRadioEngine* engine = NULL; |
|
102 TRAPD( err, engine = CRadioEngine::NewL( *this ) ); |
|
103 if ( err ) { |
|
104 return false; |
|
105 } |
|
106 |
|
107 mEngine.reset( engine ); |
|
108 TRAP( err, |
|
109 mEngine->SystemEventCollector().AddObserverL( &mObserver ); |
|
110 mEngine->AddObserverL( &mObserver ); |
|
111 ); |
|
112 if ( err ) { |
|
113 return false; |
|
114 } |
|
115 |
|
116 mRegion = MAP_TO_UI_REGION( mEngine->Settings().EngineSettings().RegionId() ); |
|
117 return true; |
|
118 } |
|
119 |
|
120 /*! |
|
121 * Sets the rds data observer |
|
122 */ |
|
123 void RadioEngineHandler::setRdsObserver( MRadioRdsDataObserver* observer ) |
|
124 { |
|
125 TRAP_IGNORE( mEngine->RdsReceiver().AddObserverL( observer ) ); |
|
126 } |
|
127 |
|
128 /*! |
|
129 * Starts or stops receiving RDS data |
|
130 */ |
|
131 void RadioEngineHandler::setRdsEnabled( bool rdsEnabled ) |
|
132 { |
|
133 if ( rdsEnabled ) { |
|
134 mEngine->RdsReceiver().StartReceiver(); |
|
135 } else { |
|
136 mEngine->RdsReceiver().StopReceiver(); |
|
137 } |
|
138 } |
|
139 |
|
140 /*! |
|
141 * Returns the radio status. |
|
142 */ |
|
143 bool RadioEngineHandler::isRadioOn() |
|
144 { |
|
145 return mEngine->Settings().EngineSettings().IsPowerOn(); |
|
146 } |
|
147 |
|
148 /*! |
|
149 * Sets the manual seek status |
|
150 */ |
|
151 void RadioEngineHandler::setManualSeekMode( bool manualSeek ) |
|
152 { |
|
153 mEngine->SetManualSeekMode( manualSeek ); |
|
154 } |
|
155 |
|
156 /*! |
|
157 * Returns the manual seek status |
|
158 */ |
|
159 bool RadioEngineHandler::isInManualSeekMode() const |
|
160 { |
|
161 return mEngine->IsInManualSeekMode(); |
|
162 } |
|
163 |
|
164 /*! |
|
165 * Tune to the specified frequency |
|
166 */ |
|
167 void RadioEngineHandler::setFrequency( uint frequency ) |
|
168 { |
|
169 mEngine->SetFrequency( frequency ); |
|
170 } |
|
171 |
|
172 /*! |
|
173 * Sets the audio mute state |
|
174 */ |
|
175 void RadioEngineHandler::setMute( const bool muted, const bool updateSettings ) |
|
176 { |
|
177 mEngine->SetVolumeMuted( muted, updateSettings ); |
|
178 } |
|
179 |
|
180 /*! |
|
181 * Gets the audio mute state |
|
182 */ |
|
183 bool RadioEngineHandler::isMuted() const |
|
184 { |
|
185 return mEngine->Settings().EngineSettings().IsVolMuted(); |
|
186 } |
|
187 |
|
188 /*! |
|
189 * Sets the volume level of the FM radio |
|
190 */ |
|
191 void RadioEngineHandler::setVolume( int newVolume ) |
|
192 { |
|
193 if ( volume() != newVolume ) { |
|
194 if ( newVolume > 0 ) { |
|
195 mEngine->SetVolumeMuted( EFalse ); |
|
196 } |
|
197 |
|
198 mEngine->SetVolume( newVolume ); |
|
199 } |
|
200 } |
|
201 |
|
202 /*! |
|
203 * Gets the volumelevel. |
|
204 */ |
|
205 int RadioEngineHandler::volume() const |
|
206 { |
|
207 return mEngine->Settings().EngineSettings().Volume(); |
|
208 } |
|
209 |
|
210 /*! |
|
211 * Gets the max volumelevel. |
|
212 */ |
|
213 int RadioEngineHandler::maxVolume() const |
|
214 { |
|
215 return mEngine->MaxVolumeLevel(); |
|
216 } |
|
217 |
|
218 /*! |
|
219 * Increases the volume by one increment |
|
220 */ |
|
221 void RadioEngineHandler::increaseVolume() |
|
222 { |
|
223 mEngine->AdjustVolume( RadioEngine::ERadioIncVolume ); |
|
224 } |
|
225 |
|
226 /*! |
|
227 * Decreases the volume by one increment |
|
228 */ |
|
229 void RadioEngineHandler::decreaseVolume() |
|
230 { |
|
231 mEngine->AdjustVolume( RadioEngine::ERadioDecVolume ); |
|
232 } |
|
233 |
|
234 |
|
235 /*! |
|
236 * Checks if the antenna is attached |
|
237 */ |
|
238 bool RadioEngineHandler::isAntennaAttached() const |
|
239 { |
|
240 return mEngine->IsAntennaAttached(); |
|
241 } |
|
242 |
|
243 /*! |
|
244 * Retrieves the current frequency. |
|
245 */ |
|
246 uint RadioEngineHandler::currentFrequency() const |
|
247 { |
|
248 return mEngine->Settings().EngineSettings().TunedFrequency(); |
|
249 } |
|
250 |
|
251 /*! |
|
252 * Returns the minimum allowed frequency in the current region |
|
253 */ |
|
254 uint RadioEngineHandler::minFrequency() const |
|
255 { |
|
256 return mEngine->Settings().EngineSettings().MinFrequency(); |
|
257 } |
|
258 |
|
259 /*! |
|
260 * Returns the maximum allowed frequency in the current region |
|
261 */ |
|
262 uint RadioEngineHandler::maxFrequency() const |
|
263 { |
|
264 return mEngine->Settings().EngineSettings().MaxFrequency(); |
|
265 } |
|
266 |
|
267 /*! |
|
268 * Checks if the given frequency is valid in the current region |
|
269 */ |
|
270 bool RadioEngineHandler::isFrequencyValid( uint frequency ) const |
|
271 { |
|
272 return mEngine->IsFrequencyValid( frequency ); |
|
273 } |
|
274 |
|
275 /*! |
|
276 * Scan up to the next available frequency |
|
277 */ |
|
278 void RadioEngineHandler::seek( Seek::Direction direction ) |
|
279 { |
|
280 LOG_TIMESTAMP( "Seek" ); |
|
281 mEngine->Seek( MAP_FROM_UI_DIRECTION( direction ) ); |
|
282 } |
|
283 |
|
284 /*! |
|
285 * Cancel previously requested scan, and return to the already tuned frequency |
|
286 */ |
|
287 void RadioEngineHandler::cancelSeek() |
|
288 { |
|
289 mEngine->CancelSeek(); |
|
290 } |
|
291 |
|
292 /*! |
|
293 * Returns the engine seeking state |
|
294 */ |
|
295 Seek::State RadioEngineHandler::seekingState() const |
|
296 { |
|
297 return MAP_TO_UI_SEEKING_STATE( mEngine->Seeking() ); |
|
298 } |
|
299 |
|
300 /*! |
|
301 * return step size for tuning. |
|
302 */ |
|
303 uint RadioEngineHandler::frequencyStepSize() const |
|
304 { |
|
305 return mEngine->Settings().EngineSettings().FrequencyStepSize(); |
|
306 } |
|
307 |
|
308 /*! |
|
309 * Returns the selected radio region |
|
310 */ |
|
311 RadioRegion::Region RadioEngineHandler::region() const |
|
312 { |
|
313 return mRegion; |
|
314 } |
|
315 |
|
316 /*! |
|
317 * Sets whether or not audio should be routed to loudspeaker |
|
318 */ |
|
319 void RadioEngineHandler::setAudioRouteToLoudspeaker( bool loudspeaker ) |
|
320 { |
|
321 TRAPD( err, mEngine->AudioRouter().SetAudioRouteL( loudspeaker ? RadioEngine::ERadioSpeaker |
|
322 : RadioEngine::ERadioHeadset ) ); |
|
323 if ( err ) { |
|
324 LOG_FORMAT( "Failed to set audioroute: UseLoudspeadker: %d", loudspeaker ); |
|
325 } |
|
326 } |
|
327 |
|
328 /*! |
|
329 * Checks if audio is routed to loudspeaker |
|
330 */ |
|
331 bool RadioEngineHandler::isAudioRoutedToLoudspeaker() const |
|
332 { |
|
333 return mEngine->Settings().EngineSettings().AudioRoute() == RadioEngine::ERadioSpeaker; |
|
334 } |
|
335 |
|
336 /*! |
|
337 * Returns the repository manager. |
|
338 */ |
|
339 MRadioApplicationSettings& RadioEngineHandler::applicationSettings() const |
|
340 { |
|
341 return mEngine->Settings().ApplicationSettings(); |
|
342 } |
|
343 |
|
344 /*! |
|
345 * \reimp |
|
346 */ |
|
347 CRadioAudioRouter* RadioEngineHandler::InitAudioRouterL() |
|
348 { |
|
349 return CRadioAudioRouter::NewL( mObserver ); |
|
350 } |
|
351 |
|
352 /*! |
|
353 * \reimp |
|
354 */ |
|
355 CRadioSystemEventCollector* RadioEngineHandler::InitSystemEventCollectorL() |
|
356 { |
|
357 return CRadioSystemEventCollector::NewL(); |
|
358 } |
|
359 |
|
360 /*! |
|
361 * \reimp |
|
362 */ |
|
363 CRadioSettings* RadioEngineHandler::InitSettingsL() |
|
364 { |
|
365 return CRadioSettings::NewL(); |
|
366 } |