radioapp/radioenginewrapper/src/cradioenginehandler.cpp
changeset 32 189d20c34778
parent 28 075425b8d9a4
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
     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 "cradioenginehandler.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 // ======== MEMBER FUNCTIONS ========
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CRadioEngineHandler::CRadioEngineHandler( MRadioEngineHandlerObserver& aObserver )
       
    88     : iObserver( aObserver )
       
    89     {
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CRadioEngineHandler::~CRadioEngineHandler()
       
    97     {
       
    98     delete iEngine;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CRadioEngineHandler::ConstructL()
       
   106     {
       
   107     LOG_METHOD;
       
   108 
       
   109     iEngine = CRadioEngine::NewL( *this );
       
   110 
       
   111     iEngine->SystemEventCollector().AddObserverL( &iObserver );
       
   112     iEngine->AddObserverL( &iObserver );
       
   113 
       
   114     iRegion = MAP_TO_UI_REGION( iEngine->Settings().EngineSettings().RegionId() );
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // Sets the rds data observer
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CRadioEngineHandler::SetRdsObserver( MRadioRdsDataObserver* aObserver )
       
   122     {
       
   123     TRAP_IGNORE( iEngine->RdsReceiver().AddObserverL( aObserver ) );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Starts or stops receiving RDS data
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CRadioEngineHandler::SetRdsEnabled( TBool aRdsEnabled )
       
   131     {
       
   132     if ( aRdsEnabled )
       
   133         {
       
   134         iEngine->RdsReceiver().StartReceiver();
       
   135         }
       
   136     else
       
   137         {
       
   138         iEngine->RdsReceiver().StopReceiver();
       
   139         }
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // Returns the radio status.
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 TBool CRadioEngineHandler::IsRadioOn()
       
   147     {
       
   148     return iEngine->Settings().EngineSettings().IsPowerOn();
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // Sets the manual seek status
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CRadioEngineHandler::SetManualSeekMode( TBool aManualSeek )
       
   156     {
       
   157     iEngine->SetManualSeekMode( aManualSeek );
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // Returns the manual seek status
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 TBool CRadioEngineHandler::IsInManualSeekMode() const
       
   165     {
       
   166     return iEngine->IsInManualSeekMode();
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // Tune to the specified frequency
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CRadioEngineHandler::SetFrequency( TUint aFrequency )
       
   174     {
       
   175     iEngine->SetFrequency( aFrequency );
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // Sets the audio mute state
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CRadioEngineHandler::SetMuted( const TBool aMuted, const TBool aUpdateSettings )
       
   183     {
       
   184     iEngine->SetVolumeMuted( aMuted, aUpdateSettings );
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // Gets the audio mute state
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 TBool CRadioEngineHandler::IsMuted() const
       
   192     {
       
   193     return iEngine->Settings().EngineSettings().IsVolMuted();
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // Sets the volume level of the FM radio
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CRadioEngineHandler::SetVolume( TInt aVolume )
       
   201     {
       
   202     if ( Volume() != aVolume )
       
   203         {
       
   204         if ( aVolume > 0 )
       
   205             {
       
   206             iEngine->SetVolumeMuted( EFalse );
       
   207             }
       
   208 
       
   209         iEngine->SetVolume( aVolume );
       
   210         }
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // Gets the volumelevel.
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 TInt CRadioEngineHandler::Volume() const
       
   218     {
       
   219     return iEngine->Settings().EngineSettings().Volume();
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Gets the max volumelevel.
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 TInt CRadioEngineHandler::MaxVolume() const
       
   227     {
       
   228     return iEngine->MaxVolumeLevel();
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // Increases the volume by one increment
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CRadioEngineHandler::IncreaseVolume()
       
   236     {
       
   237     iEngine->AdjustVolume( RadioEngine::ERadioIncVolume );
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // Decreases the volume by one increment
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CRadioEngineHandler::DecreaseVolume()
       
   245     {
       
   246     iEngine->AdjustVolume( RadioEngine::ERadioDecVolume );
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // Checks if the antenna is attached
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 TBool CRadioEngineHandler::IsAntennaAttached() const
       
   254     {
       
   255     return iEngine->IsAntennaAttached();
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // Retrieves the current frequency.
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 TUint CRadioEngineHandler::CurrentFrequency() const
       
   263     {
       
   264     return iEngine->Settings().EngineSettings().TunedFrequency();
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // Returns the minimum allowed frequency in the current region
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 TUint CRadioEngineHandler::MinFrequency() const
       
   272     {
       
   273     return iEngine->Settings().EngineSettings().MinFrequency();
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // Returns the maximum allowed frequency in the current region
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 TUint CRadioEngineHandler::MaxFrequency() const
       
   281     {
       
   282     return iEngine->Settings().EngineSettings().MaxFrequency();
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // Checks if the given frequency is valid in the current region
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 TBool CRadioEngineHandler::IsFrequencyValid( TUint aFrequency ) const
       
   290     {
       
   291     return iEngine->IsFrequencyValid( aFrequency );
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // Scan up to the next available frequency
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CRadioEngineHandler::Seek( Seek::Direction direction )
       
   299     {
       
   300     LOG_TIMESTAMP( "Seek" );
       
   301     iEngine->Seek( MAP_FROM_UI_DIRECTION( direction ) );
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // Cancel previously requested scan, and return to the
       
   306 // already tuned frequency
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 void CRadioEngineHandler::CancelSeek()
       
   310     {
       
   311     iEngine->CancelSeek();
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // Returns the engine seeking state
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 Seek::State CRadioEngineHandler::SeekingState() const
       
   319     {
       
   320     return MAP_TO_UI_SEEKING_STATE( iEngine->Seeking() );
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // return step size for tuning.
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 TUint32 CRadioEngineHandler::FrequencyStepSize() const
       
   328     {
       
   329     return iEngine->Settings().EngineSettings().FrequencyStepSize();
       
   330     }
       
   331 
       
   332 // ----------------------------------------------------------------------------------------------------
       
   333 // Returns the selected radio region
       
   334 // ----------------------------------------------------------------------------------------------------
       
   335 //
       
   336 RadioRegion::Region CRadioEngineHandler::Region() const
       
   337     {
       
   338     return iRegion;
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------------------------
       
   342 // Sets whether or not audio should be routed to loudspeaker
       
   343 // ---------------------------------------------------------------------------
       
   344 //
       
   345 void CRadioEngineHandler::SetAudioRouteToLoudspeaker( TBool aLoudspeaker )
       
   346     {
       
   347     TRAPD( err, iEngine->AudioRouter().SetAudioRouteL( aLoudspeaker ? RadioEngine::ERadioSpeaker
       
   348                                                          : RadioEngine::ERadioHeadset ) );
       
   349     if ( err )
       
   350         {
       
   351         LOG_FORMAT( "Failed to set audioroute: UseLoudspeadker: %d", aLoudspeaker );
       
   352         }
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // Checks if audio is routed to loudspeaker
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 TBool CRadioEngineHandler::IsAudioRoutedToLoudspeaker() const
       
   360     {
       
   361     return iEngine->Settings().EngineSettings().AudioRoute() == RadioEngine::ERadioSpeaker;
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 // Returns the repository manager.
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 MRadioApplicationSettings& CRadioEngineHandler::ApplicationSettings() const
       
   369     {
       
   370     return iEngine->Settings().ApplicationSettings();
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // From MRadioEngineInitializer
       
   375 //
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 CRadioAudioRouter* CRadioEngineHandler::InitAudioRouterL()
       
   379     {
       
   380     return CRadioAudioRouter::NewL( iObserver );
       
   381     }
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // From MRadioEngineInitializer
       
   385 //
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 CRadioSystemEventCollector* CRadioEngineHandler::InitSystemEventCollectorL()
       
   389     {
       
   390     return CRadioSystemEventCollector::NewL();
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // From MRadioEngineInitializer
       
   395 //
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 CRadioSettings* CRadioEngineHandler::InitSettingsL()
       
   399     {
       
   400     return CRadioSettings::NewL();
       
   401     }