radioengine/engine/src/cradioengineimp.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 14 63aabac4416d
parent 32 189d20c34778
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    22 #include <badesca.h>
    22 #include <badesca.h>
    23 #include <tzlocalizer.h>
    23 #include <tzlocalizer.h>
    24 
    24 
    25 // User includes
    25 // User includes
    26 #include "cradioenginelogger.h"
    26 #include "cradioenginelogger.h"
    27 #include "radiointernalpskeys.h"
       
    28 #include "radiointernalcrkeys.h"
    27 #include "radiointernalcrkeys.h"
    29 #include "cradioaudiorouter.h"
    28 #include "cradioaudiorouter.h"
    30 #include "cradiopubsub.h"
       
    31 #include "cradioengineimp.h"
    29 #include "cradioengineimp.h"
    32 #include "mradioengineobserver.h"
    30 #include "mradioengineobserver.h"
    33 #include "mradioscanobserver.h"
       
    34 #include "cradioregion.h"
    31 #include "cradioregion.h"
    35 #include "cradiosettings.h"
    32 #include "cradiosettings.h"
    36 #include "mradioenginesettings.h"
    33 #include "mradioenginesettings.h"
    37 #include "mradiosettingssetter.h"
    34 #include "mradiosettingssetter.h"
    38 #include "cradiorepositorymanager.h"
       
    39 #include "cradiordsreceiver.h"
    35 #include "cradiordsreceiver.h"
    40 #include "cradiosystemeventcollector.h"
    36 #include "cradiosystemeventcollector.h"
    41 #include "cradionetworkinfolistener.h"
    37 #include "cradionetworkinfolistener.h"
    42 #include "radioengine.hrh"
    38 #include "radioengine.hrh"
    43 
    39 #include "cradioenginelogger.h"
    44 #include "../../group/buildflags.hrh"
    40 
    45 #ifdef __FEATURE_RDS_SIMULATOR
    41 // This has to be the last include.
    46 #   include "t_cradiordsreceiversimulator.h"
    42 #ifdef STUB_CONSTELLATION
    47 #endif
    43 #   include <RadioStubManager.h>
       
    44 #endif //STUB_CONSTELLATION
    48 
    45 
    49 // Constants
    46 // Constants
    50 
    47 
    51 /** The limit of volume steps that must not be divided */
    48 /** The limit of volume steps that must not be divided */
    52 const TInt KRadioVolumeStepsDividinglimit = 20;
    49 const TInt KRadioVolumeStepsDividinglimit = 20;
    86 CRadioEngineImp::CRadioEngineImp( CRadioAudioRouter* aAudioRouter )
    83 CRadioEngineImp::CRadioEngineImp( CRadioAudioRouter* aAudioRouter )
    87     : CRadioEngine( aAudioRouter )
    84     : CRadioEngine( aAudioRouter )
    88     , iAntennaAttached( ETrue )
    85     , iAntennaAttached( ETrue )
    89     , iFreqEventReason( RadioEngine::ERadioFrequencyEventReasonUnknown )
    86     , iFreqEventReason( RadioEngine::ERadioFrequencyEventReasonUnknown )
    90     {
    87     {
       
    88     LEVEL3( LOG_METHOD_AUTO );
    91     }
    89     }
    92 
    90 
    93 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
    94 //
    92 //
    95 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
   113     // to headset
   111     // to headset
   114     RadioEngine::TRadioAudioRoute route = iSystemEventCollector->IsHeadsetConnectedL() ?
   112     RadioEngine::TRadioAudioRoute route = iSystemEventCollector->IsHeadsetConnectedL() ?
   115                                 RadioEngine::ERadioHeadset : RadioEngine::ERadioSpeaker;
   113                                 RadioEngine::ERadioHeadset : RadioEngine::ERadioSpeaker;
   116     User::LeaveIfError( iSettings->RadioSetter().SetAudioRoute( route ) );
   114     User::LeaveIfError( iSettings->RadioSetter().SetAudioRoute( route ) );
   117 
   115 
   118 #ifdef __FEATURE_RDS_SIMULATOR
       
   119     iRdsReceiver = CRadioRdsReceiverSimulator::NewL( iSettings->EngineSettings() );
       
   120 #else
       
   121     iRdsReceiver = CRadioRdsReceiver::NewL( iSettings->EngineSettings() );
   116     iRdsReceiver = CRadioRdsReceiver::NewL( iSettings->EngineSettings() );
   122 #endif
       
   123 
       
   124     iNetworkInfoListener = CRadioNetworkInfoListener::NewL( iSettings->RadioSetter(), NULL );
   117     iNetworkInfoListener = CRadioNetworkInfoListener::NewL( iSettings->RadioSetter(), NULL );
   125 
   118 
   126     iRdsReceiver->AddObserverL( this );
   119     iRdsReceiver->AddObserverL( this );
   127 
   120 
   128     // Create timer that is used when polling for radio restart.
   121     // Create timer that is used when polling for radio restart.
   133 //
   126 //
   134 // ---------------------------------------------------------------------------
   127 // ---------------------------------------------------------------------------
   135 //
   128 //
   136 CRadioEngineImp::~CRadioEngineImp()
   129 CRadioEngineImp::~CRadioEngineImp()
   137     {
   130     {
   138     LOG( "CRadioEngineImp::~CRadioEngineImp -- Start" );
   131     LEVEL3( LOG_METHOD_AUTO );
   139 
   132 
   140     delete iNetworkInfoListener;
   133     delete iNetworkInfoListener;
   141 
   134 
   142     PowerOff();
   135     PowerOff();
   143 
   136 
   169         {
   162         {
   170         iSystemEventCollector->RemoveObserver( this );
   163         iSystemEventCollector->RemoveObserver( this );
   171         }
   164         }
   172     delete iSystemEventCollector;
   165     delete iSystemEventCollector;
   173 
   166 
   174     delete iPubSub;
       
   175 
       
   176     if ( iSettings )
   167     if ( iSettings )
   177         {
   168         {
   178         iSettings->RadioSetter().SetObserver( NULL );
   169         iSettings->RadioSetter().SetObserver( NULL );
   179         }
   170         }
   180     delete iSettings;
   171     delete iSettings;
   181 
   172 
   182     LOG( "CRadioEngineImp::~CRadioEngineImp -- End" );
       
   183     }
   173     }
   184 
   174 
   185 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   186 //
   176 //
   187 // ---------------------------------------------------------------------------
   177 // ---------------------------------------------------------------------------
   188 //
   178 //
   189 void CRadioEngineImp::SetSystemEventCollector( CRadioSystemEventCollector* aCollector )
   179 void CRadioEngineImp::SetSystemEventCollector( CRadioSystemEventCollector* aCollector )
   190     {
   180     {
       
   181     LEVEL3( LOG_METHOD_AUTO );
   191     iSystemEventCollector = aCollector;
   182     iSystemEventCollector = aCollector;
   192     }
   183     }
   193 
   184 
   194 // ---------------------------------------------------------------------------
   185 // ---------------------------------------------------------------------------
   195 //
   186 //
   196 // ---------------------------------------------------------------------------
   187 // ---------------------------------------------------------------------------
   197 //
   188 //
   198 void CRadioEngineImp::SetRadioSettings( CRadioSettings* aSettings )
   189 void CRadioEngineImp::SetRadioSettings( CRadioSettings* aSettings )
   199     {
   190     {
       
   191     LEVEL3( LOG_METHOD_AUTO );
   200     iSettings = aSettings;
   192     iSettings = aSettings;
   201     iSettings->RadioSetter().SetObserver( this );
   193     iSettings->RadioSetter().SetObserver( this );
   202     }
   194     }
   203 
   195 
   204 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
   205 //
   197 //
   206 // ---------------------------------------------------------------------------
   198 // ---------------------------------------------------------------------------
   207 //
   199 //
   208 void CRadioEngineImp::SetRadioPubSub( CRadioPubSub* aPubSub )
       
   209     {
       
   210     iPubSub = aPubSub;
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 CRadioAudioRouter& CRadioEngineImp::AudioRouter() const
   200 CRadioAudioRouter& CRadioEngineImp::AudioRouter() const
   218     {
   201     {
       
   202     LEVEL3( LOG_METHOD_AUTO );
   219     return *iAudioRouter;
   203     return *iAudioRouter;
   220     }
   204     }
   221 
   205 
   222 // ---------------------------------------------------------------------------
   206 // ---------------------------------------------------------------------------
   223 //
   207 //
   224 // ---------------------------------------------------------------------------
   208 // ---------------------------------------------------------------------------
   225 //
   209 //
   226 CRadioSystemEventCollector& CRadioEngineImp::SystemEventCollector() const
   210 CRadioSystemEventCollector& CRadioEngineImp::SystemEventCollector() const
   227     {
   211     {
       
   212     LEVEL3( LOG_METHOD_AUTO );
   228     return *iSystemEventCollector;
   213     return *iSystemEventCollector;
   229     }
   214     }
   230 
   215 
   231 // ---------------------------------------------------------------------------
   216 // ---------------------------------------------------------------------------
   232 //
   217 //
   233 // ---------------------------------------------------------------------------
   218 // ---------------------------------------------------------------------------
   234 //
   219 //
   235 CRadioSettings& CRadioEngineImp::Settings() const
   220 CRadioSettings& CRadioEngineImp::Settings() const
   236     {
   221     {
       
   222     LEVEL3( LOG_METHOD_AUTO );
   237     return *iSettings;
   223     return *iSettings;
   238     }
   224     }
   239 
   225 
   240 // ---------------------------------------------------------------------------
   226 // ---------------------------------------------------------------------------
   241 //
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 CRadioPubSub* CRadioEngineImp::PubSub() const
       
   245     {
       
   246     return iPubSub;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // Determines radio region
   227 // Determines radio region
   251 // ---------------------------------------------------------------------------
   228 // ---------------------------------------------------------------------------
   252 //
   229 //
   253 TRadioRegion CRadioEngineImp::DetermineRegion()
   230 TRadioRegion CRadioEngineImp::DetermineRegion()
   254     {
   231     {
       
   232     LEVEL3( LOG_METHOD_AUTO );
   255     TRadioRegion region = ERadioRegionNone;
   233     TRadioRegion region = ERadioRegionNone;
   256 
   234 
   257     MRadioEngineSettings& engineSettings = iSettings->EngineSettings();
   235     MRadioEngineSettings& engineSettings = iSettings->EngineSettings();
   258     if ( iSystemEventCollector->IsMobileNetworkCoverage() )
   236     if ( iSystemEventCollector->IsMobileNetworkCoverage() )
   259         {
   237         {
   287 // ---------------------------------------------------------------------------
   265 // ---------------------------------------------------------------------------
   288 // Initializes / reinitializes the radio. If this is not called
   266 // Initializes / reinitializes the radio. If this is not called
   289 // the radio is not functional
   267 // the radio is not functional
   290 // ---------------------------------------------------------------------------
   268 // ---------------------------------------------------------------------------
   291 //
   269 //
   292 void CRadioEngineImp::InitRadioL( TInt aRegionId, CRadioPubSub* aPubSub )
   270 void CRadioEngineImp::InitRadioL( TInt aRegionId )
   293     {
   271     {
   294     LOG_METHOD_AUTO;
   272     LOG_METHOD_AUTO;
   295     LOG_FORMAT( "CRadioEngineImp::InitRadioL: Region: %d", aRegionId );
   273     LOG_FORMAT( "Region: %d", aRegionId );
   296 
   274 
   297     iRadioInitializationState = ERadioNotInitialized;
   275     iRadioInitializationState = ERadioNotInitialized;
   298 
       
   299     iPubSub = aPubSub;
       
   300 
   276 
   301     iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonUnknown;
   277     iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonUnknown;
   302     if ( iSettings->EngineSettings().RegionId() != aRegionId )
   278     if ( iSettings->EngineSettings().RegionId() != aRegionId )
   303         {
   279         {
   304         // Change only when necessary as it changes also the default tuned frequency
   280         // Change only when necessary as it changes also the default tuned frequency
   333 //
   309 //
   334 // ---------------------------------------------------------------------------
   310 // ---------------------------------------------------------------------------
   335 //
   311 //
   336 TBool CRadioEngineImp::RadioInitialized() const
   312 TBool CRadioEngineImp::RadioInitialized() const
   337     {
   313     {
       
   314     LEVEL3( LOG_METHOD_AUTO );
   338     return iRadioInitializationState == ERadioTunerControlGranted;
   315     return iRadioInitializationState == ERadioTunerControlGranted;
   339     }
   316     }
   340 
   317 
   341 // ---------------------------------------------------------------------------
   318 // ---------------------------------------------------------------------------
   342 // Sets the state for radio audio
   319 // Sets the state for radio audio
   343 // ---------------------------------------------------------------------------
   320 // ---------------------------------------------------------------------------
   344 //
   321 //
   345 void CRadioEngineImp::EnableAudio( TBool aEnable, TBool aDelay )
   322 void CRadioEngineImp::EnableAudio( TBool aEnable, TBool aDelay )
   346     {
   323     {
   347     LOG_FORMAT( "CRadioEngineImp::EnableAudio( %d )", aEnable );
   324     LOG_METHOD_AUTO;
       
   325     LOG_FORMAT( "aEnable %d ", aEnable );
   348     iRadioEnabled = aEnable;
   326     iRadioEnabled = aEnable;
   349     if ( aDelay )
   327     if ( aDelay )
   350         {
   328         {
   351         SwitchPower( iRadioEnabled );
   329         SwitchPower( iRadioEnabled );
   352         }
   330         }
   374 // Gets the state for radio audio.
   352 // Gets the state for radio audio.
   375 // ---------------------------------------------------------------------------
   353 // ---------------------------------------------------------------------------
   376 //
   354 //
   377 TBool CRadioEngineImp::RadioAudioEnabled() const
   355 TBool CRadioEngineImp::RadioAudioEnabled() const
   378     {
   356     {
       
   357     LEVEL3( LOG_METHOD_AUTO );
   379     return iRadioEnabled;
   358     return iRadioEnabled;
   380     }
   359     }
   381 
   360 
   382 // ---------------------------------------------------------------------------
   361 // ---------------------------------------------------------------------------
   383 // Sets the state for audio overriding
   362 // Sets the state for audio overriding
   384 // ---------------------------------------------------------------------------
   363 // ---------------------------------------------------------------------------
   385 //
   364 //
   386 void CRadioEngineImp::SetAudioOverride( TBool aOverride )
   365 void CRadioEngineImp::SetAudioOverride( TBool aOverride )
   387     {
   366     {
   388     LOG_FORMAT( "CRadioEngineImp::SetAudioOverride( %d )", aOverride );
   367     LEVEL3( LOG_METHOD_AUTO );
       
   368     LEVEL3( LOG_FORMAT( "aOverride %d ", aOverride ) );
   389     iOverrideAudioResources = aOverride;
   369     iOverrideAudioResources = aOverride;
   390     }
   370     }
   391 
   371 
   392 // ---------------------------------------------------------------------------
   372 // ---------------------------------------------------------------------------
   393 // Adds an observer for the radio state changes notifications.
   373 // Adds an observer for the radio state changes notifications.
   394 // ---------------------------------------------------------------------------
   374 // ---------------------------------------------------------------------------
   395 //
   375 //
   396 void CRadioEngineImp::AddObserverL( MRadioEngineObserver* aObserver )
   376 void CRadioEngineImp::AddObserverL( MRadioEngineObserver* aObserver )
   397     {
   377     {
   398     LOG( "CRadioEngineImp::AddObserver" );
   378     LEVEL3( LOG_METHOD_AUTO );
   399     TInt index = iObservers.FindInAddressOrder( aObserver );
   379     TInt index = iObservers.FindInAddressOrder( aObserver );
   400     if ( index == KErrNotFound )
   380     if ( index == KErrNotFound )
   401         {
   381         {
   402         iObservers.InsertInAddressOrderL( aObserver );
   382         iObservers.InsertInAddressOrderL( aObserver );
   403         }
   383         }
   407 // Removes an observer from the list of obsevers
   387 // Removes an observer from the list of obsevers
   408 // ---------------------------------------------------------------------------
   388 // ---------------------------------------------------------------------------
   409 //
   389 //
   410 void CRadioEngineImp::RemoveObserver( MRadioEngineObserver* aObserver )
   390 void CRadioEngineImp::RemoveObserver( MRadioEngineObserver* aObserver )
   411     {
   391     {
   412     LOG( "CRadioEngineImp::RemoveObserver" );
   392     LEVEL3( LOG_METHOD_AUTO );
   413     TInt index = iObservers.FindInAddressOrder( aObserver );
   393     TInt index = iObservers.FindInAddressOrder( aObserver );
   414 
   394 
   415     if ( index >= 0 )
   395     if ( index >= 0 )
   416         {
   396         {
   417         iObservers.Remove( index );
   397         iObservers.Remove( index );
   422 //
   402 //
   423 // ---------------------------------------------------------------------------
   403 // ---------------------------------------------------------------------------
   424 //
   404 //
   425 TFmRadioFrequencyRange CRadioEngineImp::TunerFrequencyRangeForRegionId( TInt aRegionId ) const
   405 TFmRadioFrequencyRange CRadioEngineImp::TunerFrequencyRangeForRegionId( TInt aRegionId ) const
   426     {
   406     {
       
   407     LEVEL3( LOG_METHOD_AUTO );
   427     TFmRadioFrequencyRange result = EFmRangeEuroAmerica;
   408     TFmRadioFrequencyRange result = EFmRangeEuroAmerica;
   428     switch ( aRegionId )
   409     switch ( aRegionId )
   429         {
   410         {
   430         case ERadioRegionDefault:
   411         case ERadioRegionDefault:
   431             {
   412             {
   452 // Sets radio mode ERadioStereo or ERadioMono
   433 // Sets radio mode ERadioStereo or ERadioMono
   453 // ---------------------------------------------------------------------------
   434 // ---------------------------------------------------------------------------
   454 
   435 
   455 void CRadioEngineImp::SetAudioMode( TInt aAudioMode )
   436 void CRadioEngineImp::SetAudioMode( TInt aAudioMode )
   456     {
   437     {
   457     LOG_FORMAT( "CRadioEngineImp::SetAudioMode: aAudioMode: %d", aAudioMode );
   438     LEVEL3( LOG_METHOD_AUTO );
       
   439     LOG_FORMAT( "aAudioMode: %d", aAudioMode );
   458     TInt err = KErrNone;
   440     TInt err = KErrNone;
   459     if ( !RadioInitialized() )
   441     if ( !RadioInitialized() )
   460         {
   442         {
   461         TInt err = iSettings->RadioSetter().SetOutputMode( aAudioMode );
   443         TInt err = iSettings->RadioSetter().SetOutputMode( aAudioMode );
   462         NotifyRadioEvent( ERadioEventAudioMode, err );
   444         NotifyRadioEvent( ERadioEventAudioMode, err );
   476 // Switches power on/off after a delay
   458 // Switches power on/off after a delay
   477 // ---------------------------------------------------------------------------
   459 // ---------------------------------------------------------------------------
   478 //
   460 //
   479 void CRadioEngineImp::SwitchPower( TBool aPowerOn )
   461 void CRadioEngineImp::SwitchPower( TBool aPowerOn )
   480     {
   462     {
   481     LOG_FORMAT( "CRadioEngineImp::SwitchPower( %d )", aPowerOn );
   463     LEVEL3( LOG_METHOD_AUTO );
       
   464     LOG_FORMAT( "aPowerOn %d", aPowerOn );
   482     if ( RadioInitialized() )
   465     if ( RadioInitialized() )
   483         {
   466         {
   484         if ( !aPowerOn || OkToPlay( iSettings->EngineSettings().TunedFrequency() ) )
   467         if ( !aPowerOn || OkToPlay( iSettings->EngineSettings().TunedFrequency() ) )
   485             {
   468             {
   486             iRadioTimer->Cancel();
   469             iRadioTimer->Cancel();
   517 // Executes the power switch
   500 // Executes the power switch
   518 // ---------------------------------------------------------------------------
   501 // ---------------------------------------------------------------------------
   519 //
   502 //
   520 TInt CRadioEngineImp::StaticPowerOnCallback( TAny* aSelfPtr )
   503 TInt CRadioEngineImp::StaticPowerOnCallback( TAny* aSelfPtr )
   521     {
   504     {
   522     LOG( "CRadioEngineImp::StaticPowerOnCallback" );
   505     LEVEL3( LOG_METHOD_AUTO );
   523     CRadioEngineImp* self = reinterpret_cast<CRadioEngineImp*>( aSelfPtr );
   506     CRadioEngineImp* self = reinterpret_cast<CRadioEngineImp*>( aSelfPtr );
   524 
   507 
   525     if ( self )
   508     if ( self )
   526         {
   509         {
   527         self->iRadioTimer->Cancel(); // prevents the further calls.
   510         self->iRadioTimer->Cancel(); // prevents the further calls.
   539 // Executes the power switch
   522 // Executes the power switch
   540 // ---------------------------------------------------------------------------
   523 // ---------------------------------------------------------------------------
   541 //
   524 //
   542 TInt CRadioEngineImp::StaticPowerOffCallback( TAny* aSelfPtr )
   525 TInt CRadioEngineImp::StaticPowerOffCallback( TAny* aSelfPtr )
   543     {
   526     {
   544     LOG( "CRadioEngineImp::StaticPowerOffCallback" );
   527     LEVEL3( LOG_METHOD_AUTO );
   545     CRadioEngineImp* self = reinterpret_cast<CRadioEngineImp*>( aSelfPtr );
   528     CRadioEngineImp* self = reinterpret_cast<CRadioEngineImp*>( aSelfPtr );
   546 
   529 
   547     if ( self )
   530     if ( self )
   548         {
   531         {
   549         self->iRadioTimer->Cancel(); // prevents the further calls.
   532         self->iRadioTimer->Cancel(); // prevents the further calls.
   571         {
   554         {
   572         SetAudioMode( iSettings->EngineSettings().OutputMode() );
   555         SetAudioMode( iSettings->EngineSettings().OutputMode() );
   573         iPlayerUtility->SetVolumeRamp( TTimeIntervalMicroSeconds( MAKE_TINT64( 0, KRadioMillion ) ) );
   556         iPlayerUtility->SetVolumeRamp( TTimeIntervalMicroSeconds( MAKE_TINT64( 0, KRadioMillion ) ) );
   574         iPlayerUtility->SetVolume( TunerVolumeForUiVolume( iSettings->EngineSettings().Volume() ) );
   557         iPlayerUtility->SetVolume( TunerVolumeForUiVolume( iSettings->EngineSettings().Volume() ) );
   575 
   558 
   576         // If we are about to start scanning, mute the radio and set minimum frequency
   559         iPlayerUtility->Mute( iSettings->EngineSettings().IsVolMuted() );
   577         if ( iScanObserver )
   560         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
   578             {
       
   579             iPlayerUtility->Mute( ETrue );
       
   580             iTunerUtility->SetFrequency( iSettings->EngineSettings().MinFrequency() );
       
   581             }
       
   582         else
       
   583             {
       
   584             iPlayerUtility->Mute( iSettings->EngineSettings().IsVolMuted() );
       
   585             iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
       
   586             }
       
   587         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
   561         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
   588 
   562 
   589         TRAP_IGNORE( iAudioRouter->SetAudioRouteL(
   563         TRAP_IGNORE( iAudioRouter->SetAudioRouteL(
   590                 RadioEngine::TRadioAudioRoute( iSettings->EngineSettings().AudioRoute() ) ) )
   564                 RadioEngine::TRadioAudioRoute( iSettings->EngineSettings().AudioRoute() ) ) )
   591 
   565 
   601 // Radio power off
   575 // Radio power off
   602 // ---------------------------------------------------------------------------
   576 // ---------------------------------------------------------------------------
   603 //
   577 //
   604 void CRadioEngineImp::PowerOff()
   578 void CRadioEngineImp::PowerOff()
   605     {
   579     {
   606     LOG( "CRadioEngineImp::PowerOff" );
   580     LOG_METHOD_AUTO;
   607 
   581 
   608     if ( iSettings->EngineSettings().IsPowerOn() )
   582     if ( iSettings->EngineSettings().IsPowerOn() )
   609         {
   583         {
   610         if ( RadioInitialized() )
   584         if ( RadioInitialized() )
   611             {
   585             {
   622 //
   596 //
   623 // ---------------------------------------------------------------------------
   597 // ---------------------------------------------------------------------------
   624 //
   598 //
   625 TBool CRadioEngineImp::OkToPlay( TUint32 aFrequency ) const
   599 TBool CRadioEngineImp::OkToPlay( TUint32 aFrequency ) const
   626     {
   600     {
       
   601     LEVEL3( LOG_METHOD_AUTO );
   627     TBool audioResourcesAvailable = iSystemEventCollector->IsAudioResourcesAvailable();
   602     TBool audioResourcesAvailable = iSystemEventCollector->IsAudioResourcesAvailable();
   628     TBool okToPlay = iAntennaAttached &&
   603     TBool okToPlay = iAntennaAttached &&
   629                      !iFmTransmitterActive &&
   604                      !iFmTransmitterActive &&
   630                      ( audioResourcesAvailable || iOverrideAudioResources ) &&
   605                      ( audioResourcesAvailable || iOverrideAudioResources ) &&
   631 #ifdef COMPILE_IN_IVALO
   606 #ifdef COMPILE_IN_IVALO
   633                      && !iSystemEventCollector->IsCallActive();
   608                      && !iSystemEventCollector->IsCallActive();
   634 #else
   609 #else
   635                      IsFrequencyValid( aFrequency );
   610                      IsFrequencyValid( aFrequency );
   636 #endif //COMPILE_IN_IVALO
   611 #endif //COMPILE_IN_IVALO
   637 
   612 
   638     LOG_FORMAT( "CRadioEngineImp::OkToPlay, returning %d ", okToPlay );
   613     LEVEL2( LOG_FORMAT( "returning okToPlay %d ", okToPlay ) );
   639     return okToPlay;
   614     return okToPlay;
   640     }
   615     }
   641 
   616 
   642 // ---------------------------------------------------------------------------
   617 // ---------------------------------------------------------------------------
   643 //
   618 //
   644 // ---------------------------------------------------------------------------
   619 // ---------------------------------------------------------------------------
   645 //
   620 //
   646 TBool CRadioEngineImp::IsFrequencyValid( TUint32 aFrequency ) const
   621 TBool CRadioEngineImp::IsFrequencyValid( TUint32 aFrequency ) const
   647     {
   622     {
       
   623     LEVEL3( LOG_METHOD_AUTO );
   648     TBool ret( EFalse );
   624     TBool ret( EFalse );
   649     if ( !aFrequency )
   625     if ( !aFrequency )
   650         {
   626         {
   651         aFrequency = iSettings->EngineSettings().TunedFrequency();
   627         aFrequency = iSettings->EngineSettings().TunedFrequency();
   652         }
   628         }
   656         }
   632         }
   657     return ret;
   633     return ret;
   658     }
   634     }
   659 
   635 
   660 // ---------------------------------------------------------------------------
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 // ---------------------------------------------------------------------------
       
   639 //
       
   640 void CRadioEngineImp::SetManualSeekMode( TBool aManualSeekActive )
       
   641     {
       
   642     iManualSeekMode = aManualSeekActive;
       
   643     if ( iManualSeekMode )
       
   644         {
       
   645         CancelSeek();
       
   646         iRdsReceiver->StopReceiver();
       
   647         }
       
   648     else
       
   649         {
       
   650         iRdsReceiver->StartReceiver();
       
   651         TInt frequency = 0;
       
   652         iTunerUtility->GetFrequency( frequency );
       
   653         HandleFrequencyEvent( frequency );
       
   654         }
       
   655     }
       
   656 
       
   657 // ---------------------------------------------------------------------------
       
   658 //
       
   659 // ---------------------------------------------------------------------------
       
   660 //
       
   661 TBool CRadioEngineImp::IsInManualSeekMode() const
       
   662     {
       
   663     return iManualSeekMode;
       
   664     }
       
   665 
       
   666 // ---------------------------------------------------------------------------
   661 // Radio tuning
   667 // Radio tuning
   662 // ---------------------------------------------------------------------------
   668 // ---------------------------------------------------------------------------
   663 //
   669 //
   664 void CRadioEngineImp::SetFrequency( TUint32 aFrequency, RadioEngine::TRadioFrequencyEventReason aReason )
   670 void CRadioEngineImp::SetFrequency( TUint32 aFrequency, RadioEngine::TRadioFrequencyEventReason aReason )
   665     {
   671     {
   666     LOG_METHOD_AUTO;
   672     LEVEL3( LOG_METHOD_AUTO );
   667     LOG_FORMAT( "CRadioEngineImp::SetFrequency, freq: %u, Initialized: %d, Enabled: %d",
   673     LEVEL2( LOG_FORMAT( "freq: %u, Initialized: %d, Enabled: %d",
   668             aFrequency, RadioInitialized(), iRadioEnabled );
   674             aFrequency, RadioInitialized(), iRadioEnabled ) );
   669 
   675 
   670     iFrequencySetByRdsAf = EFalse;
       
   671     iFreqEventReason = aReason;
   676     iFreqEventReason = aReason;
   672 
   677     if ( iManualSeekMode )
   673     TInt frequency = 0;
   678         {
   674     if ( iTunerUtility )
   679         iTunerUtility->SetFrequency( aFrequency );
   675         {
       
   676         iTunerUtility->GetFrequency( frequency );
       
   677         }
       
   678     CancelSeek();
       
   679 
       
   680     if ( aFrequency == frequency ) //radio has already the frequency to be set.
       
   681         {
       
   682         LOG( "CRadioEngineImp::SetFrequency: Already at the requested frequency" );
       
   683         HandleFrequencyEvent( aFrequency );
       
   684         }
   680         }
   685     else
   681     else
   686         {
   682         {
   687         iRadioTimer->Cancel();
   683         iFrequencySetByRdsAf = EFalse;
   688         if ( RadioInitialized() && iRadioEnabled && OkToPlay( aFrequency ) )
   684 
   689             {
   685         TInt frequency = 0;
   690             LOG( "CRadioEngineImp::SetFrequency: Tuning to frequency" );
   686         if ( iTunerUtility )
   691             iTunerUtility->SetFrequency( aFrequency );
   687             {
       
   688             iTunerUtility->GetFrequency( frequency );
       
   689             }
       
   690         CancelSeek();
       
   691 
       
   692         if ( aFrequency == frequency ) //radio has already the frequency to be set.
       
   693             {
       
   694             LOG( "CRadioEngineImp::SetFrequency: Already at the requested frequency" );
       
   695             HandleFrequencyEvent( aFrequency );
   692             }
   696             }
   693         else
   697         else
   694             {
   698             {
   695             HandleFrequencyEvent( aFrequency );
   699             iRadioTimer->Cancel();
   696             }
   700             if ( RadioInitialized() && iRadioEnabled && OkToPlay( aFrequency ) )
   697         }
   701                 {
   698     }
   702                 LOG( "CRadioEngineImp::SetFrequency: Tuning to frequency" );
   699 
   703                 iTunerUtility->SetFrequency( aFrequency );
   700 // ---------------------------------------------------------------------------
   704                 }
   701 // Radio tuning
   705             else
   702 // ---------------------------------------------------------------------------
   706                 {
   703 //
   707                 HandleFrequencyEvent( aFrequency );
   704 void CRadioEngineImp::SetFrequencyFast( TUint32 aFrequency,
   708                 }
   705                                         RadioEngine::TRadioFrequencyEventReason /*aReason*/ )
   709             }
   706 {
   710         }
   707     if ( iSeekingState != RadioEngine::ERadioNotSeeking )
       
   708     {
       
   709         iSeekingState = RadioEngine::ERadioNotSeeking;
       
   710         iTunerUtility->CancelStationSeek();
       
   711     }
       
   712     iTunerUtility->SetFrequency( aFrequency );
       
   713     iSettings->RadioSetter().SetTunedFrequency( aFrequency );
       
   714 }
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // Frequency stepping
       
   718 // ---------------------------------------------------------------------------
       
   719 //
       
   720 void CRadioEngineImp::StepToFrequency( RadioEngine::TRadioTuneDirection aDirection )
       
   721     {
       
   722     LOG( "CRadioEngineImp::StepToFrequency" );
       
   723 
       
   724     TUint32 freq = iSettings->EngineSettings().TunedFrequency();
       
   725     RadioEngine::TRadioFrequencyEventReason reason( RadioEngine::ERadioFrequencyEventReasonUnknown );
       
   726     if ( aDirection == RadioEngine::ERadioUp )
       
   727         {
       
   728         freq = freq + iSettings->EngineSettings().FrequencyStepSize();
       
   729         reason = RadioEngine::ERadioFrequencyEventReasonUp;
       
   730         }
       
   731     else
       
   732         {
       
   733         freq = freq - iSettings->EngineSettings().FrequencyStepSize();
       
   734         reason = RadioEngine::ERadioFrequencyEventReasonDown;
       
   735         }
       
   736 
       
   737     // Check overflow or underflow
       
   738     if ( IsFrequencyValid( freq ) )
       
   739         {
       
   740         if ( aDirection == RadioEngine::ERadioUp )
       
   741             {
       
   742             freq = iSettings->EngineSettings().MinFrequency();
       
   743             }
       
   744         else
       
   745             {
       
   746             freq = iSettings->EngineSettings().MaxFrequency();
       
   747             }
       
   748         }
       
   749     SetFrequency( freq, reason );
       
   750     }
   711     }
   751 
   712 
   752 // ---------------------------------------------------------------------------
   713 // ---------------------------------------------------------------------------
   753 // Radio seek
   714 // Radio seek
   754 // ---------------------------------------------------------------------------
   715 // ---------------------------------------------------------------------------
   755 //
   716 //
   756 void CRadioEngineImp::Seek( RadioEngine::TRadioTuneDirection aDirection )
   717 void CRadioEngineImp::Seek( RadioEngine::TRadioTuneDirection aDirection )
   757     {
   718     {
   758     LOG_FORMAT( "CRadioEngineImp::Seek-- Start direction:%d",aDirection );
   719     LOG_METHOD_AUTO;
       
   720     LOG_FORMAT( "aDirection: %d",aDirection );
   759 
   721 
   760     iFrequencySetByRdsAf = EFalse;
   722     iFrequencySetByRdsAf = EFalse;
   761 
   723 
   762     // Check if audio playing parameters ( other than frequency ) are OK
   724     // Check if audio playing parameters ( other than frequency ) are OK
   763     if ( iRadioEnabled &&
   725     if ( iRadioEnabled &&
   796             }
   758             }
   797         }
   759         }
   798     else
   760     else
   799         {
   761         {
   800         NotifyRadioEvent( ERadioEventSeeking, KErrGeneral );
   762         NotifyRadioEvent( ERadioEventSeeking, KErrGeneral );
   801         StopScan( KErrGeneral );
       
   802         }
   763         }
   803     }
   764     }
   804 
   765 
   805 // ---------------------------------------------------------------------------
   766 // ---------------------------------------------------------------------------
   806 // Cancels seek up/down request
   767 // Cancels seek up/down request
   807 // ---------------------------------------------------------------------------
   768 // ---------------------------------------------------------------------------
   808 //
   769 //
   809 void CRadioEngineImp::CancelSeek()
   770 void CRadioEngineImp::CancelSeek()
   810     {
   771     {
   811     LOG_FORMAT( "CRadioEngineImp::CancelSeek -- seeking state was:%d", iSeekingState );
   772     LOG_METHOD_AUTO;
   812 
   773     LOG_FORMAT( "seeking state was:%d", iSeekingState );
   813     if ( !iScanObserver )
   774 
   814         {
   775     if ( iSeekingState != RadioEngine::ERadioNotSeeking )
   815         if ( iSeekingState != RadioEngine::ERadioNotSeeking )
   776         {
   816             {
   777         iSeekingState = RadioEngine::ERadioNotSeeking;
   817             iSeekingState = RadioEngine::ERadioNotSeeking;
   778         iTunerUtility->CancelStationSeek();
   818             iTunerUtility->CancelStationSeek();
   779         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
   819             iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
   780         NotifyRadioEvent( ERadioEventSeeking, KErrCancel );
   820             NotifyRadioEvent( ERadioEventSeeking, KErrCancel );
   781         NotifyRadioEvent( ERadioEventFrequency, KErrNone ); // Notify the observers even if the frequency remains the same.
   821             NotifyRadioEvent( ERadioEventFrequency, KErrNone ); // Notify the observers even if the frequency remains the same.
       
   822             }
       
   823         }
       
   824     else
       
   825         {
       
   826         StopScan( KErrCancel );
       
   827         }
   782         }
   828     }
   783     }
   829 
   784 
   830 // ---------------------------------------------------------------------------
   785 // ---------------------------------------------------------------------------
   831 //
   786 //
   832 // ---------------------------------------------------------------------------
   787 // ---------------------------------------------------------------------------
   833 //
   788 //
   834 RadioEngine::TRadioSeeking CRadioEngineImp::Seeking() const
   789 RadioEngine::TRadioSeeking CRadioEngineImp::Seeking() const
   835     {
   790     {
       
   791     LEVEL3( LOG_METHOD_AUTO );
   836     return iSeekingState;
   792     return iSeekingState;
   837     }
   793     }
   838 
   794 
   839 // ---------------------------------------------------------------------------
   795 // ---------------------------------------------------------------------------
   840 // Starts scanning all available stations from the minimum frequency
       
   841 // ---------------------------------------------------------------------------
       
   842 //
       
   843 void CRadioEngineImp::StartScan( MRadioScanObserver& aObserver )
       
   844     {
       
   845     LOG( "CRadioEngineImp::StartScan" );
       
   846 
       
   847     const TUint32 minFrequency = iSettings->EngineSettings().MinFrequency();
       
   848     if ( !iScanObserver && iRadioEnabled && RadioInitialized() && OkToPlay( minFrequency ) )
       
   849         {
       
   850         CancelSeek();
       
   851         iScanObserver = &aObserver;
       
   852         iPreviousMuteState = iSettings->EngineSettings().IsVolMuted();
       
   853         iPreviousScannedFrequency = 0;
       
   854         iPlayerUtility->Mute( ETrue );
       
   855         iTunerUtility->SetFrequency( minFrequency );
       
   856         Seek( RadioEngine::ERadioUp );
       
   857         }
       
   858     else
       
   859         {
       
   860         TInt error = iScanObserver ? KErrAlreadyExists : KErrNotReady;
       
   861         TRAP_IGNORE( aObserver.ScanCompletedEventL( error ) )
       
   862         }
       
   863     }
       
   864 
       
   865 // ---------------------------------------------------------------------------
       
   866 // Stops any scans currently in progress.
       
   867 // ---------------------------------------------------------------------------
       
   868 //
       
   869 void CRadioEngineImp::StopScan( TInt aError )
       
   870     {
       
   871     LOG_FORMAT( "CRadioEngineImp::StopScan, error: %d", aError );
       
   872     if ( iScanObserver )
       
   873         {
       
   874         if ( iSeekingState != RadioEngine::ERadioNotSeeking )
       
   875             {
       
   876             iSeekingState = RadioEngine::ERadioNotSeeking;
       
   877             if ( RadioInitialized() )
       
   878                 {
       
   879                 iTunerUtility->CancelStationSeek();
       
   880                 }
       
   881             }
       
   882 
       
   883         iPreviousScannedFrequency = 0;
       
   884         MRadioScanObserver& observer = *iScanObserver;
       
   885         iScanObserver = NULL;
       
   886         NotifyRadioScanEvent( ERadioEventScanCompleted, observer, aError );
       
   887 
       
   888         if ( !OkToPlay( iSettings->EngineSettings().MinFrequency() ) )
       
   889             {
       
   890             // Try to reset the frequency as sometimes extra frequency event occurs after seeking
       
   891             iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
       
   892             iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
       
   893             }
       
   894 
       
   895         if ( iPlayerUtility && OkToPlay( iSettings->EngineSettings().TunedFrequency() ) )
       
   896             {
       
   897             iPlayerUtility->Mute( iPreviousMuteState );
       
   898             }
       
   899         }
       
   900     }
       
   901 
       
   902 // ---------------------------------------------------------------------------
       
   903 // Sets volume level up/down one step.
   796 // Sets volume level up/down one step.
   904 // ---------------------------------------------------------------------------
   797 // ---------------------------------------------------------------------------
   905 //
   798 //
   906 void CRadioEngineImp::AdjustVolume( RadioEngine::TRadioVolumeSetDirection aDirection )
   799 void CRadioEngineImp::AdjustVolume( RadioEngine::TRadioVolumeSetDirection aDirection )
   907     {
   800     {
   908     LOG_FORMAT( "CRadioEngineImp::AdjustVolume( %d )", aDirection );
   801     LOG_METHOD_AUTO;
       
   802     LOG_FORMAT( "aDirection: %d ", aDirection );
   909 
   803 
   910     if ( iSettings->EngineSettings().IsPowerOn() )
   804     if ( iSettings->EngineSettings().IsPowerOn() )
   911         {
   805         {
   912         TInt volume = iSettings->EngineSettings().Volume();
   806         TInt volume = iSettings->EngineSettings().Volume();
   913         LOG_FORMAT( "CRadioEngineImp::AdjustVolume volume = ( %d )", volume );
   807         LOG_FORMAT( "volume = ( %d )", volume );
   914 
   808 
   915         if ( aDirection == RadioEngine::ERadioDecVolume )
   809         if ( aDirection == RadioEngine::ERadioDecVolume )
   916             {
   810             {
   917             TInt min = iSettings->EngineSettings().DefaultMinVolumeLevel();
   811             TInt min = iSettings->EngineSettings().DefaultMinVolumeLevel();
   918             if ( --volume < min )
   812             if ( --volume < min )
   929                 volume = max;
   823                 volume = max;
   930                 }
   824                 }
   931             }
   825             }
   932         else
   826         else
   933             {
   827             {
   934             LOG( "CRadioEngineImp::AdjustVolume - Unhandled case" );
   828             LOG( "Unhandled case" );
   935             }
   829             }
   936         SetVolume( volume );
   830         SetVolume( volume );
   937         }
   831         }
   938     }
   832     }
   939 
   833 
   941 // Sets audio volume level
   835 // Sets audio volume level
   942 // ---------------------------------------------------------------------------
   836 // ---------------------------------------------------------------------------
   943 //
   837 //
   944 void CRadioEngineImp::SetVolume( TInt aVolume )
   838 void CRadioEngineImp::SetVolume( TInt aVolume )
   945     {
   839     {
   946     LOG_FORMAT( "CRadioEngineImp::SetVolume vol: %d", aVolume );
   840     LOG_METHOD_AUTO;
       
   841     LOG_FORMAT( "aVolume: %d", aVolume );
   947 
   842 
   948     if ( iSettings->EngineSettings().IsPowerOn() && RadioInitialized() )
   843     if ( iSettings->EngineSettings().IsPowerOn() && RadioInitialized() )
   949         {
   844         {
   950         LOG( "CRadioEngineImp::SetVolume: Setting volume to player utility" );
   845         LOG( "Setting volume to player utility" );
   951 
   846 
   952         if ( aVolume == 0 )
   847         if ( aVolume == 0 )
   953             {
   848             {
   954             SetVolumeMuted( ETrue );
   849             SetVolumeMuted( ETrue );
   955             }
   850             }
   970 
   865 
   971 // ---------------------------------------------------------------------------
   866 // ---------------------------------------------------------------------------
   972 // Set radio audio muted/unmuted
   867 // Set radio audio muted/unmuted
   973 // ---------------------------------------------------------------------------
   868 // ---------------------------------------------------------------------------
   974 //
   869 //
   975 void CRadioEngineImp::SetVolumeMuted( TBool aMuteState )
   870 void CRadioEngineImp::SetVolumeMuted( TBool aMuteState, TBool aUpdateSettings )
   976     {
   871     {
   977     LOG_METHOD_AUTO;
   872     LOG_METHOD_AUTO;
   978     LOG_FORMAT( "MuteState = %d", aMuteState );
   873     LOG_FORMAT( "MuteState = %d", aMuteState );
   979 
   874 
   980     if ( iSettings->EngineSettings().IsPowerOn() )
   875     if ( iSettings->EngineSettings().IsPowerOn() )
   981         {
   876         {
   982         TInt err = KErrNone;
   877         TInt err = KErrNone;
   983         if ( RadioInitialized() )
   878         if ( RadioInitialized() )
   984             {
   879             {
   985             err = iPlayerUtility->Mute( aMuteState );
   880             err = iPlayerUtility->Mute( aMuteState );
   986             iSettings->RadioSetter().SetVolMuted( aMuteState );
   881             }
   987             NotifyRadioEvent( ERadioEventMute, err );
   882 
   988             }
   883         if ( aUpdateSettings )
   989         else
       
   990             {
   884             {
   991             err = iSettings->RadioSetter().SetVolMuted( aMuteState );
   885             err = iSettings->RadioSetter().SetVolMuted( aMuteState );
   992             NotifyRadioEvent( ERadioEventMute, err );
   886             }
   993             }
   887         NotifyRadioEvent( ERadioEventMute, err );
   994         }
   888         }
   995     }
   889     }
   996 
   890 
   997 // ---------------------------------------------------------------------------
   891 // ---------------------------------------------------------------------------
   998 //
   892 //
   999 // ---------------------------------------------------------------------------
   893 // ---------------------------------------------------------------------------
  1000 //
   894 //
  1001 TBool CRadioEngineImp::IsAntennaAttached()
   895 TBool CRadioEngineImp::IsAntennaAttached()
  1002     {
   896     {
  1003     LOG_FORMAT( "CRadioEngineImp::IsAntennaAttached, returning %d", iAntennaAttached );
   897     LEVEL3( LOG_METHOD_AUTO );
       
   898     LEVEL3( LOG_FORMAT( "returning iAntennaAttached: %d", iAntennaAttached ) );
  1004     return iAntennaAttached;
   899     return iAntennaAttached;
  1005     }
   900     }
  1006 
   901 
  1007 // ---------------------------------------------------------------------------
   902 // ---------------------------------------------------------------------------
  1008 //
   903 //
  1009 // ---------------------------------------------------------------------------
   904 // ---------------------------------------------------------------------------
  1010 //
   905 //
  1011 TBool CRadioEngineImp::IsFmTransmitterActive() const
   906 TBool CRadioEngineImp::IsFmTransmitterActive() const
  1012     {
   907     {
  1013     LOG_FORMAT( "CRadioEngineImp::IsFmTransmitterActive, returning %d", iFmTransmitterActive );
   908     LEVEL3( LOG_METHOD_AUTO );
       
   909     LEVEL3( LOG_FORMAT( "returning iFmTransmitterActive: %d", iFmTransmitterActive ) );
  1014     return iFmTransmitterActive;
   910     return iFmTransmitterActive;
  1015     }
   911     }
  1016 
   912 
  1017 // ---------------------------------------------------------------------------
   913 // ---------------------------------------------------------------------------
  1018 // This function is usable only in WINS emulator.
   914 // This function is usable only in WINS emulator.
  1019 // ---------------------------------------------------------------------------
   915 // ---------------------------------------------------------------------------
  1020 //
   916 //
  1021 void CRadioEngineImp::SetAntennaAttached( TBool aAntennaAttached )
   917 void CRadioEngineImp::SetAntennaAttached( TBool aAntennaAttached )
  1022     {
   918     {
       
   919     LOG_METHOD_AUTO;
  1023 #ifdef __WINS__
   920 #ifdef __WINS__
  1024     MrftoAntennaStatusChange( aAntennaAttached );
   921     MrftoAntennaStatusChange( aAntennaAttached );
  1025 #endif
   922 #endif
  1026     }
   923     }
  1027 
   924 
  1032 // is 20.
   929 // is 20.
  1033 // ---------------------------------------------------------------------------
   930 // ---------------------------------------------------------------------------
  1034 //
   931 //
  1035 TInt CRadioEngineImp::MaxVolumeLevel() const
   932 TInt CRadioEngineImp::MaxVolumeLevel() const
  1036     {
   933     {
       
   934     LEVEL3( LOG_METHOD_AUTO );
  1037     TInt maxLevel = 0;
   935     TInt maxLevel = 0;
  1038 
   936 
  1039 #if defined __WINS__
   937 #if defined __WINS__
  1040     maxLevel = KRadioVolumeStepsOld;
   938     maxLevel = KRadioVolumeStepsOld;
  1041 #else
   939 #else
  1057 //
   955 //
  1058 // ---------------------------------------------------------------------------
   956 // ---------------------------------------------------------------------------
  1059 //
   957 //
  1060 TBool CRadioEngineImp::FrequencySetByRdsAf() const
   958 TBool CRadioEngineImp::FrequencySetByRdsAf() const
  1061     {
   959     {
       
   960     LEVEL3( LOG_METHOD_AUTO );
  1062     return iFrequencySetByRdsAf;
   961     return iFrequencySetByRdsAf;
  1063     }
   962     }
  1064 
   963 
  1065 // ---------------------------------------------------------------------------
   964 // ---------------------------------------------------------------------------
  1066 //
   965 //
  1067 // ---------------------------------------------------------------------------
   966 // ---------------------------------------------------------------------------
  1068 //
   967 //
  1069 MRadioRdsReceiver& CRadioEngineImp::RdsReceiver()
   968 MRadioRdsReceiver& CRadioEngineImp::RdsReceiver()
  1070     {
   969     {
       
   970     LEVEL3( LOG_METHOD_AUTO );
  1071     return *iRdsReceiver;
   971     return *iRdsReceiver;
  1072     }
   972     }
  1073 
   973 
  1074 // ---------------------------------------------------------------------------
   974 // ---------------------------------------------------------------------------
  1075 //
   975 //
  1076 // ---------------------------------------------------------------------------
   976 // ---------------------------------------------------------------------------
  1077 //
   977 //
  1078 TInt CRadioEngineImp::TunerVolumeForUiVolume( TInt aUiVolume )
   978 TInt CRadioEngineImp::TunerVolumeForUiVolume( TInt aUiVolume )
  1079     {
   979     {
       
   980     LEVEL3( LOG_METHOD_AUTO );
  1080     TInt vol = aUiVolume * KRadioVolumeStepsDivider;
   981     TInt vol = aUiVolume * KRadioVolumeStepsDivider;
  1081 
   982 
  1082     return vol;
   983     return vol;
  1083     }
   984     }
  1084 
   985 
  1086 //
   987 //
  1087 // ---------------------------------------------------------------------------
   988 // ---------------------------------------------------------------------------
  1088 //
   989 //
  1089 void CRadioEngineImp::NotifyRadioEvent( TInt aRadioEvent, TInt aErrorCode )
   990 void CRadioEngineImp::NotifyRadioEvent( TInt aRadioEvent, TInt aErrorCode )
  1090     {
   991     {
       
   992     LEVEL3( LOG_METHOD_AUTO );
  1091     TRAP_IGNORE( DoNotifyRadioEventL( aRadioEvent, aErrorCode ) )
   993     TRAP_IGNORE( DoNotifyRadioEventL( aRadioEvent, aErrorCode ) )
  1092     }
   994     }
  1093 
   995 
  1094 // ---------------------------------------------------------------------------
   996 // ---------------------------------------------------------------------------
  1095 // Notifies all the registered observers of radio events
   997 // Notifies all the registered observers of radio events
  1096 // by sending notifications to observers.
   998 // by sending notifications to observers.
  1097 // ---------------------------------------------------------------------------
   999 // ---------------------------------------------------------------------------
  1098 //
  1000 //
  1099 void CRadioEngineImp::DoNotifyRadioEventL( TInt aRadioEvent, TInt aErrorCode )
  1001 void CRadioEngineImp::DoNotifyRadioEventL( TInt aRadioEvent, TInt aErrorCode )
  1100     {
  1002     {
       
  1003     LOG_METHOD_AUTO;
  1101     TInt count = iObservers.Count();
  1004     TInt count = iObservers.Count();
  1102 
  1005 
  1103     for ( TInt i = 0; i<count; i++)
  1006     for ( TInt i = 0; i<count; i++)
  1104         {
  1007         {
  1105         MRadioEngineObserver * observer = iObservers[i];
  1008         MRadioEngineObserver * observer = iObservers[i];
  1122                 observer->VolumeEventL( iSettings->EngineSettings().Volume(), aErrorCode );
  1025                 observer->VolumeEventL( iSettings->EngineSettings().Volume(), aErrorCode );
  1123                 break;
  1026                 break;
  1124                 }
  1027                 }
  1125             case ERadioEventMute:
  1028             case ERadioEventMute:
  1126                 {
  1029                 {
  1127                 if ( !iScanObserver )
  1030                 observer->MuteEventL( iSettings->EngineSettings().IsVolMuted(), aErrorCode );
  1128                     {
       
  1129                     observer->MuteEventL( iSettings->EngineSettings().IsVolMuted(), aErrorCode );
       
  1130                     }
       
  1131                 break;
  1031                 break;
  1132                 }
  1032                 }
  1133             case ERadioEventAudioMode:
  1033             case ERadioEventAudioMode:
  1134                 {
  1034                 {
  1135                 observer->AudioModeEventL( iSettings->EngineSettings().OutputMode(), aErrorCode );
  1035                 observer->AudioModeEventL( iSettings->EngineSettings().OutputMode(), aErrorCode );
  1167             }
  1067             }
  1168         }
  1068         }
  1169     }
  1069     }
  1170 
  1070 
  1171 // ---------------------------------------------------------------------------
  1071 // ---------------------------------------------------------------------------
  1172 // Notifies the observer of a radio scan event.
       
  1173 // ---------------------------------------------------------------------------
       
  1174 //
       
  1175 void CRadioEngineImp::NotifyRadioScanEvent( TRadioScanEvent aEvent,
       
  1176                                             MRadioScanObserver& aObserver,
       
  1177                                             TInt aError  )
       
  1178     {
       
  1179     TRAP_IGNORE( DoNotifyRadioScanEventL( aEvent, aObserver, aError ) )
       
  1180     }
       
  1181 
       
  1182 // ---------------------------------------------------------------------------
       
  1183 // Notifies the observer of a radio scan event.
       
  1184 // ---------------------------------------------------------------------------
       
  1185 //
       
  1186 void CRadioEngineImp::DoNotifyRadioScanEventL( TRadioScanEvent aEvent,
       
  1187                                                MRadioScanObserver& aObserver,
       
  1188                                                TInt aError )
       
  1189     {
       
  1190     LOG_FORMAT( "CRadioEngineImp::DoNotifyRadioScanEventL, aEvent: %d, aError: %d", aEvent, aError );
       
  1191 
       
  1192     if ( aEvent == ERadioEventFrequencyScanned )
       
  1193         {
       
  1194         if ( aError == KErrNone )
       
  1195             {
       
  1196             aObserver.ScanFrequencyEventL( iPreviousScannedFrequency );
       
  1197             }
       
  1198         }
       
  1199     else if ( aEvent == ERadioEventScanCompleted )
       
  1200         {
       
  1201         // KFmRadioErrTuning error means that no channels can be found anymore
       
  1202         if ( aError == KFmRadioErrTuning )
       
  1203             {
       
  1204             aError = KErrNotFound;
       
  1205             }
       
  1206 
       
  1207         aObserver.ScanCompletedEventL( aError );
       
  1208         }
       
  1209     }
       
  1210 
       
  1211 // ---------------------------------------------------------------------------
       
  1212 // Handles some system events
  1072 // Handles some system events
  1213 // ---------------------------------------------------------------------------
  1073 // ---------------------------------------------------------------------------
  1214 //
  1074 //
  1215 void CRadioEngineImp::HandleSystemEventL( TRadioSystemEventType aEventType )
  1075 void CRadioEngineImp::HandleSystemEventL( TRadioSystemEventType aEventType )
  1216     {
  1076     {
  1217     LOG_FORMAT( "CRadioEngineImp::HandleSystemEventL, aEventType = %d", aEventType );
  1077     LOG_METHOD_AUTO;
       
  1078     LOG_FORMAT( "aEventType = %d", aEventType );
  1218 
  1079 
  1219     switch ( aEventType )
  1080     switch ( aEventType )
  1220         {
  1081         {
  1221         case ERadioAudioResourcesAvailable:
  1082         case ERadioAudioResourcesAvailable:
  1222             {
  1083             {
  1243             }
  1104             }
  1244             break;
  1105             break;
  1245 
  1106 
  1246         case ERadioCallActivated:
  1107         case ERadioCallActivated:
  1247             {
  1108             {
  1248             StopScan( KErrGeneral );
       
  1249             CancelSeek();
  1109             CancelSeek();
  1250             }
  1110             }
  1251             break;
  1111             break;
  1252 
  1112 
  1253         case ERadioCallDeactivated:
  1113         case ERadioCallDeactivated:
  1258 
  1118 
  1259         case ERadioHeadsetConnected:
  1119         case ERadioHeadsetConnected:
  1260             {
  1120             {
  1261             // Explicitly set the audio routing to headset. Because system
  1121             // Explicitly set the audio routing to headset. Because system
  1262             // forces the routing to headset anyway, and without our knowledge.
  1122             // forces the routing to headset anyway, and without our knowledge.
       
  1123             MRadioSettingsSetter& setter = iSettings->RadioSetter();
       
  1124             setter.SetAudioRoute( RadioEngine::ERadioHeadset );
  1263             iAudioRouter->SetAudioRouteL( RadioEngine::ERadioHeadset );
  1125             iAudioRouter->SetAudioRouteL( RadioEngine::ERadioHeadset );
  1264             }
  1126             }
  1265             break;
  1127             break;
  1266 
  1128 
  1267         case ERadioHeadsetDisconnected:
  1129         case ERadioHeadsetDisconnected:
  1268             {
  1130             {
  1269             // Explicitly set the audio routing to speaker. Because system
  1131             // Explicitly set the audio routing to speaker. Because system
  1270             // forces the routing to speaker anyway, if radio stays on.
  1132             // forces the routing to speaker anyway, if radio stays on.
       
  1133             MRadioSettingsSetter& setter = iSettings->RadioSetter();
       
  1134             setter.SetAudioRoute( RadioEngine::ERadioSpeaker );
  1271             iAudioRouter->SetAudioRouteL( RadioEngine::ERadioSpeaker );
  1135             iAudioRouter->SetAudioRouteL( RadioEngine::ERadioSpeaker );
  1272             }
  1136             }
  1273             break;
  1137             break;
  1274         default:
  1138         default:
  1275             {
  1139             {
  1282 //
  1146 //
  1283 // ---------------------------------------------------------------------------
  1147 // ---------------------------------------------------------------------------
  1284 //
  1148 //
  1285 void CRadioEngineImp::MrftoRequestTunerControlComplete( TInt aError )
  1149 void CRadioEngineImp::MrftoRequestTunerControlComplete( TInt aError )
  1286     {
  1150     {
  1287     LOG_FORMAT( "CRadioEngineImp::MrftoRequestTunerControlComplete( %d )", aError );
  1151     LOG_METHOD_AUTO;
       
  1152     LOG_FORMAT( "aError: %d", aError );
  1288 
  1153 
  1289     if ( aError == KErrNone || aError == KErrAlreadyExists ) // Tuner activated now or was already active
  1154     if ( aError == KErrNone || aError == KErrAlreadyExists ) // Tuner activated now or was already active
  1290         {
  1155         {
  1291         iRadioInitializationState = ERadioTunerControlGranted;
  1156         iRadioInitializationState = ERadioTunerControlGranted;
  1292 
  1157 
  1317 
  1182 
  1318         TBool offlineAvailable( tunerCaps.iTunerFunctions &
  1183         TBool offlineAvailable( tunerCaps.iTunerFunctions &
  1319                                 TFmTunerCapabilities::ETunerAvailableInOfflineMode );
  1184                                 TFmTunerCapabilities::ETunerAvailableInOfflineMode );
  1320         iTunerUtility->EnableTunerInOfflineMode( offlineAvailable );
  1185         iTunerUtility->EnableTunerInOfflineMode( offlineAvailable );
  1321 
  1186 
  1322         TBool rdsSupported = EFalse;
  1187         if ( tunerCaps.iTunerFunctions & TFmTunerCapabilities::ETunerRdsSupport )
  1323         TRAP_IGNORE( CRadioRepositoryManager::GetRepositoryValueL( KRadioCRUid, KRadioCRRdsSupport,
  1188             {
  1324                                                                    rdsSupported ) )
  1189             TRAP_IGNORE( iRdsReceiver->InitL( *iRadioUtility ) )
  1325         if ( tunerCaps.iTunerFunctions & TFmTunerCapabilities::ETunerRdsSupport &&
       
  1326                 rdsSupported )
       
  1327             {
       
  1328             TRAP_IGNORE( iRdsReceiver->InitL( *iRadioUtility, iPubSub ) )
       
  1329             }
  1190             }
  1330 
  1191 
  1331         iTunerUtility->SetFrequencyRange( TunerFrequencyRangeForRegionId(
  1192         iTunerUtility->SetFrequencyRange( TunerFrequencyRangeForRegionId(
  1332                                           iSettings->EngineSettings().RegionId() ) );
  1193                                           iSettings->EngineSettings().RegionId() ) );
  1333         // To prevent false frequency changes
  1194         // To prevent false frequency changes
  1340 //
  1201 //
  1341 // ---------------------------------------------------------------------------
  1202 // ---------------------------------------------------------------------------
  1342 //
  1203 //
  1343 void CRadioEngineImp::MrftoSetFrequencyRangeComplete( TInt aError )
  1204 void CRadioEngineImp::MrftoSetFrequencyRangeComplete( TInt aError )
  1344     {
  1205     {
  1345     LOG_FORMAT( "CRadioEngineImp::MrftoSetFrequencyRangeComplete( %d )", aError );
  1206     LEVEL3( LOG_METHOD_AUTO );
       
  1207     LEVEL3( LOG_FORMAT( "aError: %d", aError ) );
  1346     if ( aError )
  1208     if ( aError )
  1347         {
  1209         {
  1348         NotifyRadioEvent( ERadioEventRegion, aError );
  1210         NotifyRadioEvent( ERadioEventRegion, aError );
  1349         }
  1211         }
  1350     }
  1212     }
  1353 //
  1215 //
  1354 // ---------------------------------------------------------------------------
  1216 // ---------------------------------------------------------------------------
  1355 //
  1217 //
  1356 void CRadioEngineImp::MrftoSetFrequencyComplete( TInt aError )
  1218 void CRadioEngineImp::MrftoSetFrequencyComplete( TInt aError )
  1357     {
  1219     {
  1358     LOG_FORMAT( "CRadioEngineImp::MrftoSetFrequencyComplete: Err: %d", aError );
  1220     LOG_METHOD_AUTO;
  1359 
  1221     LOG_FORMAT( "aError: %d", aError );
  1360     if ( aError )
  1222 
       
  1223     if ( aError && !iManualSeekMode )
  1361         {
  1224         {
  1362         if ( aError == KErrNotReady )
  1225         if ( aError == KErrNotReady )
  1363             {
  1226             {
  1364             iRadioInitializationState = ERadioUtilitiesConstructed;
  1227             iRadioInitializationState = ERadioUtilitiesConstructed;
  1365             }
  1228             }
  1371 //
  1234 //
  1372 // ---------------------------------------------------------------------------
  1235 // ---------------------------------------------------------------------------
  1373 //
  1236 //
  1374 void CRadioEngineImp::MrftoStationSeekComplete( TInt aError, TInt aFrequency )
  1237 void CRadioEngineImp::MrftoStationSeekComplete( TInt aError, TInt aFrequency )
  1375     {
  1238     {
  1376     LOG_FORMAT( "CRadioEngineImp::MrftoStationSeekComplete() -- aError = %d, aFrequency = %d", aError, aFrequency );
  1239     LOG_METHOD_AUTO;
       
  1240     LOG_FORMAT( "aError = %d, aFrequency = %d", aError, aFrequency );
  1377     // Seeking has ended, error code tells if it was successful
  1241     // Seeking has ended, error code tells if it was successful
  1378 
  1242 
  1379     if ( aError == KFmRadioErrAntennaNotConnected )
  1243     if ( aError == KFmRadioErrAntennaNotConnected )
  1380         {
  1244         {
  1381         iAntennaAttached = EFalse;
  1245         iAntennaAttached = EFalse;
  1385         iRadioInitializationState = ERadioUtilitiesConstructed;
  1249         iRadioInitializationState = ERadioUtilitiesConstructed;
  1386         }
  1250         }
  1387 
  1251 
  1388     iSeekingState = RadioEngine::ERadioNotSeeking;
  1252     iSeekingState = RadioEngine::ERadioNotSeeking;
  1389 
  1253 
  1390     NotifyRadioEvent( ERadioEventSeeking, aError );
  1254     if ( aFrequency == 0 ) {
       
  1255         NotifyRadioEvent( ERadioEventFrequency, aError );
       
  1256     }
  1391 
  1257 
  1392 //    if ( aError != KErrNone )
  1258 //    if ( aError != KErrNone )
  1393 //        {
  1259 //        {
  1394 //        iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
  1260 //        iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
  1395 //        NotifyRadioEvent( ERadioEventFrequency, KErrNone ); // Frequency change is not otherwise notified when seeking fails.
  1261 //        NotifyRadioEvent( ERadioEventFrequency, KErrNone ); // Frequency change is not otherwise notified when seeking fails.
  1400 //        if ( !iFrequencySetByRdsAf )
  1266 //        if ( !iFrequencySetByRdsAf )
  1401 //            {
  1267 //            {
  1402 //            NotifyRadioEvent( ERadioEventFrequency, KErrNone );
  1268 //            NotifyRadioEvent( ERadioEventFrequency, KErrNone );
  1403 //            }
  1269 //            }
  1404 //        }
  1270 //        }
  1405 
       
  1406     if ( iScanObserver )
       
  1407         {
       
  1408         if ( aError != KErrNone )
       
  1409             {
       
  1410             StopScan( aError );
       
  1411             }
       
  1412         else
       
  1413             {
       
  1414             if ( aFrequency > iSettings->EngineSettings().MinFrequency() && aFrequency > iPreviousScannedFrequency )
       
  1415                 {
       
  1416                 iPreviousScannedFrequency = aFrequency;
       
  1417                 NotifyRadioScanEvent( ERadioEventFrequencyScanned, *iScanObserver, KErrNone );
       
  1418                 Seek( RadioEngine::ERadioUp ); // Continue scanning.
       
  1419                 }
       
  1420             else
       
  1421                 {
       
  1422                 if ( aFrequency == iSettings->EngineSettings().MinFrequency() )
       
  1423                     {
       
  1424                     iPreviousScannedFrequency = aFrequency;
       
  1425                     NotifyRadioScanEvent( ERadioEventFrequencyScanned, *iScanObserver, KErrNone );
       
  1426                     }
       
  1427                 StopScan( aError );
       
  1428                 }
       
  1429             }
       
  1430         }
       
  1431     }
  1271     }
  1432 
  1272 
  1433 // ---------------------------------------------------------------------------
  1273 // ---------------------------------------------------------------------------
  1434 //
  1274 //
  1435 // ---------------------------------------------------------------------------
  1275 // ---------------------------------------------------------------------------
  1436 //
  1276 //
  1437 void CRadioEngineImp::MrftoFmTransmitterStatusChange( TBool aActive )
  1277 void CRadioEngineImp::MrftoFmTransmitterStatusChange( TBool aActive )
  1438     {
  1278     {
  1439     LOG_FORMAT( "CRadioEngineImp::MrftoFmTransmitterStatusChange( %d )", aActive );
  1279     LOG_METHOD_AUTO;
       
  1280     LOG_FORMAT( "aActive: %d", aActive );
  1440     iFmTransmitterActive = aActive;
  1281     iFmTransmitterActive = aActive;
  1441 
  1282 
  1442     if ( !iFmTransmitterActive )
  1283     if ( !iFmTransmitterActive )
  1443         {
  1284         {
  1444         SwitchPower( ETrue );
  1285         SwitchPower( ETrue );
  1451 //
  1292 //
  1452 // ---------------------------------------------------------------------------
  1293 // ---------------------------------------------------------------------------
  1453 //
  1294 //
  1454 void CRadioEngineImp::MrftoAntennaStatusChange( TBool aAttached )
  1295 void CRadioEngineImp::MrftoAntennaStatusChange( TBool aAttached )
  1455     {
  1296     {
  1456     LOG_FORMAT( "CRadioEngineImp::MrftoAntennaStatusChange( %d )", aAttached );
  1297     LOG_METHOD_AUTO;
       
  1298     LOG_FORMAT( "aAttached: %d", aAttached );
  1457     iAntennaAttached = aAttached;
  1299     iAntennaAttached = aAttached;
  1458     if ( iAntennaAttached )
  1300     if ( iAntennaAttached )
  1459         {
  1301         {
  1460         SwitchPower( ETrue );
  1302         SwitchPower( ETrue );
  1461         NotifyRadioEvent( ERadioEventAntenna );
  1303         NotifyRadioEvent( ERadioEventAntenna );
  1462         iPubSub->PublishAntennaState( ERadioPSRadioAntennaAttached );
       
  1463         }
  1304         }
  1464     else
  1305     else
  1465         {
  1306         {
  1466         NotifyRadioEvent( ERadioEventAntenna, KErrDisconnected );
  1307         NotifyRadioEvent( ERadioEventAntenna, KErrDisconnected );
  1467         iPubSub->PublishAntennaState( ERadioPSRadioAntennaDetached );
  1308         }
  1468         }
  1309     }
  1469     }
  1310 
  1470 
  1311 // ---------------------------------------------------------------------------
  1471 // ---------------------------------------------------------------------------
  1312 //
  1472 //
  1313 // ---------------------------------------------------------------------------
  1473 // ---------------------------------------------------------------------------
  1314 
  1474 
  1315 //
  1475 //
  1316 void CRadioEngineImp::MrftoOfflineModeStatusChange( TBool DEBUGVAR3( aOfflineMode ) )
  1476 void CRadioEngineImp::MrftoOfflineModeStatusChange( TBool DEBUGVAR( aOfflineMode ) )
  1317     {
  1477     {
  1318     LEVEL3( LOG_METHOD_AUTO );
  1478     LOG_FORMAT( "CRadioEngineImp::MrftoOfflineModeStatusChange( %d )", aOfflineMode );
  1319     LEVEL3( LOG_FORMAT( "aOfflineMode: %d", aOfflineMode ) );
  1479     }
  1320     }
  1480 
  1321 
  1481 // ---------------------------------------------------------------------------
  1322 // ---------------------------------------------------------------------------
  1482 //
  1323 //
  1483 // ---------------------------------------------------------------------------
  1324 // ---------------------------------------------------------------------------
  1484 //
  1325 //
  1485 void CRadioEngineImp::MrftoFrequencyRangeChange( TFmRadioFrequencyRange DEBUGVAR( aBand ) )
  1326 void CRadioEngineImp::MrftoFrequencyRangeChange( TFmRadioFrequencyRange DEBUGVAR3( aBand ) )
  1486     {
  1327     {
  1487     LOG_FORMAT( "CRadioEngineImp::MrftoFrequencyRangeChange( %d )", aBand );
  1328     LEVEL3( LOG_METHOD_AUTO );
       
  1329     LEVEL3( LOG_FORMAT( "aBand: %d", aBand ) );
  1488     if ( RadioInitialized() )
  1330     if ( RadioInitialized() )
  1489         {
  1331         {
  1490         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
  1332         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
  1491         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
  1333         iFreqEventReason = RadioEngine::ERadioFrequencyEventReasonImplicit;
  1492         }
  1334         }
  1497 //
  1339 //
  1498 // ---------------------------------------------------------------------------
  1340 // ---------------------------------------------------------------------------
  1499 //
  1341 //
  1500 void CRadioEngineImp::MrftoFrequencyChange( TInt aNewFrequency )
  1342 void CRadioEngineImp::MrftoFrequencyChange( TInt aNewFrequency )
  1501     {
  1343     {
  1502     LOG_FORMAT( "CRadioEngineImp::MrftoFrequencyChange aNewFrequency = %u", aNewFrequency );
  1344     LEVEL3( LOG_METHOD_AUTO );
       
  1345     LEVEL3( LOG_FORMAT( "aNewFrequency = %u", aNewFrequency ) );
  1503 
  1346 
  1504     // There may be frequency changed events when radio is not initialized ( because
  1347     // There may be frequency changed events when radio is not initialized ( because
  1505     // of SetFrequency or Seek returns with KErrNotReady ).
  1348     // of SetFrequency or Seek returns with KErrNotReady ).
  1506     if ( RadioInitialized() )
  1349     if ( !iManualSeekMode && RadioInitialized() )
  1507         {
  1350         {
  1508       
       
  1509         HandleFrequencyEvent( aNewFrequency );
  1351         HandleFrequencyEvent( aNewFrequency );
  1510         }
  1352         }
  1511     }
  1353     }
  1512 
  1354 
  1513 // ---------------------------------------------------------------------------
  1355 // ---------------------------------------------------------------------------
  1514 //
  1356 //
  1515 // ---------------------------------------------------------------------------
  1357 // ---------------------------------------------------------------------------
  1516 //
  1358 //
  1517 void CRadioEngineImp::MrftoForcedMonoChange( TBool aForcedMono )
  1359 void CRadioEngineImp::MrftoForcedMonoChange( TBool aForcedMono )
  1518     {
  1360     {
  1519     LOG_FORMAT( "CRadioEngineImp::MrftoForcedMonoChange -- aForcedMono = %d", aForcedMono );
  1361     LEVEL3( LOG_METHOD_AUTO );
       
  1362     LEVEL3( LOG_FORMAT( "aForcedMono = %d", aForcedMono ) );
  1520 
  1363 
  1521     iSettings->RadioSetter().SetOutputMode( aForcedMono ? RadioEngine::ERadioMono : RadioEngine::ERadioStereo );
  1364     iSettings->RadioSetter().SetOutputMode( aForcedMono ? RadioEngine::ERadioMono : RadioEngine::ERadioStereo );
  1522     NotifyRadioEvent( ERadioEventAudioMode );
  1365     NotifyRadioEvent( ERadioEventAudioMode );
  1523     }
  1366     }
  1524 
  1367 
  1526 //
  1369 //
  1527 // ---------------------------------------------------------------------------
  1370 // ---------------------------------------------------------------------------
  1528 //
  1371 //
  1529 void CRadioEngineImp::MrftoSquelchChange( TBool /*aSquelch*/ )
  1372 void CRadioEngineImp::MrftoSquelchChange( TBool /*aSquelch*/ )
  1530     {
  1373     {
       
  1374     LEVEL3( LOG_METHOD_AUTO );
  1531     }
  1375     }
  1532 
  1376 
  1533 // ---------------------------------------------------------------------------
  1377 // ---------------------------------------------------------------------------
  1534 //
  1378 //
  1535 // ---------------------------------------------------------------------------
  1379 // ---------------------------------------------------------------------------
  1536 //
  1380 //
  1537 void CRadioEngineImp::MrpoStateChange( TPlayerState aState, TInt aError )
  1381 void CRadioEngineImp::MrpoStateChange( TPlayerState aState, TInt aError )
  1538     {
  1382     {
  1539     LOG_FORMAT( "CRadioEngineImp::MrpoStateChange() -- aState = %d, aError = %d", aState, aError );
  1383     LEVEL3( LOG_METHOD_AUTO );
       
  1384     LEVEL3( LOG_FORMAT( "aState = %d, aError = %d", aState, aError ) );
  1540 
  1385 
  1541     if ( aError == KFmRadioErrAntennaNotConnected )
  1386     if ( aError == KFmRadioErrAntennaNotConnected )
  1542         {
  1387         {
  1543         iAntennaAttached = EFalse;
  1388         iAntennaAttached = EFalse;
  1544         }
  1389         }
  1549 //
  1394 //
  1550 // ---------------------------------------------------------------------------
  1395 // ---------------------------------------------------------------------------
  1551 //
  1396 //
  1552 void CRadioEngineImp::MrpoVolumeChange( TInt aVolume )
  1397 void CRadioEngineImp::MrpoVolumeChange( TInt aVolume )
  1553     {
  1398     {
  1554     aVolume = aVolume / KRadioVolumeStepsDivider;
  1399     LEVEL3( LOG_METHOD_AUTO );
  1555     LOG_FORMAT( "CRadioEngineImp::MrpoVolumeChange() --  volume = %d", aVolume );
  1400 	aVolume = aVolume / KRadioVolumeStepsDivider;
  1556     if ( aVolume != iSettings->EngineSettings().Volume() )
  1401     if ( aVolume != iSettings->EngineSettings().Volume() )
  1557         {
  1402         {
  1558         iSettings->RadioSetter().SetVolume( aVolume );
  1403         iSettings->RadioSetter().SetVolume( aVolume );
  1559         NotifyRadioEvent( ERadioEventVolume );
  1404         NotifyRadioEvent( ERadioEventVolume );
  1560         }
  1405         }
  1564 //
  1409 //
  1565 // ---------------------------------------------------------------------------
  1410 // ---------------------------------------------------------------------------
  1566 //
  1411 //
  1567 void CRadioEngineImp::MrpoMuteChange( TBool aMute )
  1412 void CRadioEngineImp::MrpoMuteChange( TBool aMute )
  1568     {
  1413     {
       
  1414     LEVEL3( LOG_METHOD_AUTO );
  1569     TBool muted = iSettings->EngineSettings().IsVolMuted();
  1415     TBool muted = iSettings->EngineSettings().IsVolMuted();
  1570     if ( !iScanObserver && !aMute != !muted )
  1416     if ( !aMute != !muted )
  1571         {
  1417         {
  1572         iSettings->RadioSetter().SetVolMuted( aMute );
  1418         iSettings->RadioSetter().SetVolMuted( aMute );
  1573         NotifyRadioEvent( ERadioEventMute );
  1419         NotifyRadioEvent( ERadioEventMute );
  1574         }
  1420         }
  1575     }
  1421     }
  1578 //
  1424 //
  1579 // ---------------------------------------------------------------------------
  1425 // ---------------------------------------------------------------------------
  1580 //
  1426 //
  1581 void CRadioEngineImp::MrpoBalanceChange( TInt /*aLeftPercentage*/, TInt /*aRightPercentage*/ )
  1427 void CRadioEngineImp::MrpoBalanceChange( TInt /*aLeftPercentage*/, TInt /*aRightPercentage*/ )
  1582     {
  1428     {
       
  1429     LEVEL3( LOG_METHOD_AUTO );
  1583     }
  1430     }
  1584 
  1431 
  1585 // ---------------------------------------------------------------------------
  1432 // ---------------------------------------------------------------------------
  1586 //
  1433 //
  1587 // ---------------------------------------------------------------------------
  1434 // ---------------------------------------------------------------------------
  1588 //
  1435 //
  1589 void CRadioEngineImp::RdsAfSearchSettingChangedL( TBool aEnabled )
  1436 void CRadioEngineImp::RdsAfSearchSettingChangedL( TBool aEnabled )
  1590     {
  1437     {
  1591     LOG_FORMAT( "CRadioEngineImp::RdsAfSearchSettingChangedL( %d )", aEnabled );
  1438     LEVEL3( LOG_METHOD_AUTO );
       
  1439     LEVEL3( LOG_FORMAT( "aEnabled: %d", aEnabled ) );
  1592     iRdsReceiver->SetAutomaticSwitchingL( aEnabled );
  1440     iRdsReceiver->SetAutomaticSwitchingL( aEnabled );
  1593     }
  1441     }
  1594 
  1442 
  1595 // ---------------------------------------------------------------------------
  1443 // ---------------------------------------------------------------------------
  1596 //
  1444 //
  1597 // ---------------------------------------------------------------------------
  1445 // ---------------------------------------------------------------------------
  1598 //
  1446 //
  1599 void CRadioEngineImp::RegionSettingChangedL( TInt DEBUGVAR( aRegion ) )
  1447 //TODO: Check if this can be removed. Radio doesn't currently support changing regions on the fly
  1600     {
  1448 void CRadioEngineImp::RegionSettingChangedL( TInt DEBUGVAR3( aRegion ) )
  1601     LOG_FORMAT( "CRadioEngineImp::RegionSettingChangedL( %d )", aRegion );
  1449     {
       
  1450     LEVEL3( LOG_METHOD_AUTO );
       
  1451     LEVEL3( LOG_FORMAT( "aRegion: %d", aRegion ) );
  1602 
  1452 
  1603     if ( RadioInitialized() )
  1453     if ( RadioInitialized() )
  1604         {
  1454         {
  1605         iTunerUtility->SetFrequencyRange( TunerFrequencyRangeForRegionId( iSettings->EngineSettings().RegionId() ) );
  1455         iTunerUtility->SetFrequencyRange( TunerFrequencyRangeForRegionId( iSettings->EngineSettings().RegionId() ) );
  1606         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
  1456         iTunerUtility->SetFrequency( iSettings->EngineSettings().TunedFrequency() );
  1612 //
  1462 //
  1613 // ---------------------------------------------------------------------------
  1463 // ---------------------------------------------------------------------------
  1614 //
  1464 //
  1615 void CRadioEngineImp::RdsAfSearchBegin()
  1465 void CRadioEngineImp::RdsAfSearchBegin()
  1616     {
  1466     {
  1617     LOG( "CRadioEngineImp::RdsAfSearchBegin()" );
  1467     LEVEL3( LOG_METHOD_AUTO );
  1618     iFrequencySetByRdsAf = ETrue;
  1468     iFrequencySetByRdsAf = ETrue;
  1619     }
  1469     }
  1620 
  1470 
  1621 // ---------------------------------------------------------------------------
  1471 // ---------------------------------------------------------------------------
  1622 //
  1472 //
  1623 // ---------------------------------------------------------------------------
  1473 // ---------------------------------------------------------------------------
  1624 //
  1474 //
  1625 void CRadioEngineImp::RdsAfSearchEnd( TUint32 DEBUGVAR( aFrequency ), TInt aError )
  1475 void CRadioEngineImp::RdsAfSearchEnd( TUint32 DEBUGVAR3( aFrequency ), TInt aError )
  1626     {
  1476     {
  1627     LOG_FORMAT( "CRadioEngineImp::RdsAfSearchEnd( %d, %d )", aFrequency, aError );
  1477     LEVEL3( LOG_METHOD_AUTO );
       
  1478     LEVEL3( LOG_FORMAT( "aFrequency: %d, aError: %d )", aFrequency, aError ) );
  1628     if ( aError != KErrNone )
  1479     if ( aError != KErrNone )
  1629         {
  1480         {
  1630         iFrequencySetByRdsAf = EFalse;
  1481         iFrequencySetByRdsAf = EFalse;
  1631         }
  1482         }
  1632     }
  1483     }
  1635 // Tries to figure the region out based on current mobile network id
  1486 // Tries to figure the region out based on current mobile network id
  1636 // ---------------------------------------------------------------------------
  1487 // ---------------------------------------------------------------------------
  1637 //
  1488 //
  1638 TRadioRegion CRadioEngineImp::RegionFromMobileNetwork() const
  1489 TRadioRegion CRadioEngineImp::RegionFromMobileNetwork() const
  1639     {
  1490     {
       
  1491     LEVEL3( LOG_METHOD_AUTO );
  1640     TRadioRegion region = ERadioRegionNone;
  1492     TRadioRegion region = ERadioRegionNone;
  1641 
  1493 
  1642     // Choose the frequency range according to country code
  1494     // Choose the frequency range according to country code
  1643     MRadioEngineSettings& engineSettings = iSettings->EngineSettings();
  1495     MRadioEngineSettings& engineSettings = iSettings->EngineSettings();
  1644     const TDesC& countryCode = engineSettings.CountryCode();
  1496     TPtrC countryCode = engineSettings.CountryCode();
  1645     const TInt regionCount = engineSettings.CountRegions();
  1497     const TInt regionCount = engineSettings.CountRegions();
  1646     TBool matchFound = EFalse;
  1498     TBool matchFound = EFalse;
  1647     for ( TInt i = 0; i < regionCount && !matchFound; ++i )
  1499     for ( TInt i = 0; i < regionCount && !matchFound; ++i )
  1648         {
  1500         {
  1649         const RRadioCountryCodeArray& regionCountryCodes =
  1501         const RRadioCountryCodeArray& regionCountryCodes =
  1668 // Tries to figure the region out based on timezone selection
  1520 // Tries to figure the region out based on timezone selection
  1669 // ---------------------------------------------------------------------------
  1521 // ---------------------------------------------------------------------------
  1670 //
  1522 //
  1671 TRadioRegion CRadioEngineImp::RegionFromTimezone() const
  1523 TRadioRegion CRadioEngineImp::RegionFromTimezone() const
  1672     {
  1524     {
       
  1525     LEVEL3( LOG_METHOD_AUTO );
  1673     TRadioRegion region = ERadioRegionNone;
  1526     TRadioRegion region = ERadioRegionNone;
  1674     TRAP_IGNORE( region = DoRegionFromTimezoneL() );
  1527     TRAP_IGNORE( region = DoRegionFromTimezoneL() );
  1675     return region;
  1528     return region;
  1676     }
  1529     }
  1677 
  1530 
  1692     // We get the ownership so we must delete
  1545     // We get the ownership so we must delete
  1693     CTzLocalizedCity* city = timezoneLocalizer->GetFrequentlyUsedZoneCityL( CTzLocalizedTimeZone::ECurrentZone );
  1546     CTzLocalizedCity* city = timezoneLocalizer->GetFrequentlyUsedZoneCityL( CTzLocalizedTimeZone::ECurrentZone );
  1694     const TUint8 cityId = city->GroupId();
  1547     const TUint8 cityId = city->GroupId();
  1695     delete city;
  1548     delete city;
  1696     city = NULL;
  1549     city = NULL;
  1697     LOG_FORMAT( "CRadioEngineHandler::CurrentTimeZoneToRegionL group id: %d", cityId );
  1550     LOG_FORMAT( "group id: %d", cityId );
  1698 
  1551 
  1699     TRadioRegion region = ERadioRegionNone;
  1552     TRadioRegion region = ERadioRegionNone;
  1700     const TInt cityGroupCount = cityGroups->Count();
  1553     const TInt cityGroupCount = cityGroups->Count();
  1701     TBool found = EFalse;
  1554     TBool found = EFalse;
  1702     for ( TInt i = 0; i < cityGroupCount && !found; ++i )
  1555     for ( TInt i = 0; i < cityGroupCount && !found; ++i )
  1709         }
  1562         }
  1710 
  1563 
  1711     CleanupStack::PopAndDestroy( cityGroups );
  1564     CleanupStack::PopAndDestroy( cityGroups );
  1712     CleanupStack::PopAndDestroy( timezoneLocalizer );
  1565     CleanupStack::PopAndDestroy( timezoneLocalizer );
  1713 
  1566 
  1714     LOG_ASSERT( found, LOG_FORMAT( "CRadioEngine::DoMapCurrentTimeZoneToRegionL. City not found: %d", cityId ) );
  1567     LOG_ASSERT( found, LOG_FORMAT( "City not found: %d", cityId ) );
  1715 
  1568 
  1716     return region;
  1569     return region;
  1717     }
  1570     }
  1718 
  1571 
  1719 // ---------------------------------------------------------------------------
  1572 // ---------------------------------------------------------------------------
  1720 //
  1573 //
  1721 // ---------------------------------------------------------------------------
  1574 // ---------------------------------------------------------------------------
  1722 //
  1575 //
  1723 void CRadioEngineImp::HandleAudioRoutingEvent( RadioEngine::TRadioAudioRoute aDestination )
  1576 void CRadioEngineImp::HandleAudioRoutingEvent( RadioEngine::TRadioAudioRoute aDestination )
  1724     {
  1577     {
  1725     LOG_FORMAT( "CRadioEngineImp::HandleAudioRoutingL( %d )", aDestination );
  1578     LOG_METHOD_AUTO;
       
  1579     LOG_FORMAT( "aDestination: %d", aDestination );
  1726 
  1580 
  1727     // Make modifications to volume ONLY if new audio source state
  1581     // Make modifications to volume ONLY if new audio source state
  1728     // differs from settings. If they don't differ, this state
  1582     // differs from settings. If they don't differ, this state
  1729     // change is a part of the radio initialization.
  1583     // change is a part of the radio initialization.
  1730     MRadioSettingsSetter& setter = iSettings->RadioSetter();
  1584     MRadioSettingsSetter& setter = iSettings->RadioSetter();
  1764 //
  1618 //
  1765 // ---------------------------------------------------------------------------
  1619 // ---------------------------------------------------------------------------
  1766 //
  1620 //
  1767 void CRadioEngineImp::HandlePowerEvent( TBool aPowerOn, TInt aErrorCode )
  1621 void CRadioEngineImp::HandlePowerEvent( TBool aPowerOn, TInt aErrorCode )
  1768     {
  1622     {
  1769     LOG_FORMAT( "CRadioEngineImp::HandlePowerEvent( %d, %d )", aPowerOn, aErrorCode );
  1623     LOG_METHOD_AUTO;
       
  1624     LOG_FORMAT( "aPowerOn: %d, aErrorCode: %d )", aPowerOn, aErrorCode );
  1770 
  1625 
  1771     const TBool powerState = iSettings->EngineSettings().IsPowerOn();
  1626     const TBool powerState = iSettings->EngineSettings().IsPowerOn();
  1772     if ( !powerState != !aPowerOn )
  1627     if ( !powerState != !aPowerOn )
  1773         {
  1628         {
  1774         iSettings->RadioSetter().SetPowerOn( aPowerOn );
  1629         iSettings->RadioSetter().SetPowerOn( aPowerOn );
  1783             }
  1638             }
  1784         }
  1639         }
  1785 
  1640 
  1786     if ( !iSettings->EngineSettings().IsPowerOn() )
  1641     if ( !iSettings->EngineSettings().IsPowerOn() )
  1787         {
  1642         {
  1788         StopScan( aErrorCode );
       
  1789         CancelSeek();
  1643         CancelSeek();
  1790         }
  1644         }
  1791 
  1645 
  1792     // If we are seeking, power event starts seeking
  1646     // If we are seeking, power event starts seeking
  1793     if ( iSeekingState != RadioEngine::ERadioNotSeeking && iSettings->EngineSettings().IsPowerOn() )
  1647     if ( iSeekingState != RadioEngine::ERadioNotSeeking && iSettings->EngineSettings().IsPowerOn() )
  1794         {
  1648         {
  1795         // Reset seeking state to enable seeking start
  1649         // Reset seeking state to enable seeking start
       
  1650         LOG( "PowerOn event in seekingstate. Restart seeking" );
  1796         RadioEngine::TRadioSeeking oldSeeking = iSeekingState;
  1651         RadioEngine::TRadioSeeking oldSeeking = iSeekingState;
  1797         iSeekingState = RadioEngine::ERadioNotSeeking;
  1652         iSeekingState = RadioEngine::ERadioNotSeeking;
  1798         Seek( oldSeeking == RadioEngine::ERadioSeekingUp ? RadioEngine::ERadioUp : RadioEngine::ERadioDown );
  1653         Seek( oldSeeking == RadioEngine::ERadioSeekingUp ? RadioEngine::ERadioUp : RadioEngine::ERadioDown );
  1799         }
  1654         }
  1800 
  1655 
  1801     if ( !powerState != !aPowerOn )
  1656     if ( !powerState != !aPowerOn || aErrorCode )
  1802         {
  1657         {
  1803         NotifyRadioEvent( ERadioEventPower, aErrorCode );
  1658         NotifyRadioEvent( ERadioEventPower, aErrorCode );
  1804         }
  1659         }
  1805     }
  1660     }
  1806 
  1661 
  1808 //
  1663 //
  1809 // ---------------------------------------------------------------------------
  1664 // ---------------------------------------------------------------------------
  1810 //
  1665 //
  1811 void CRadioEngineImp::HandleFrequencyEvent( TUint32 aFrequency, TInt aErrorCode )
  1666 void CRadioEngineImp::HandleFrequencyEvent( TUint32 aFrequency, TInt aErrorCode )
  1812     {
  1667     {
  1813     LOG_FORMAT( "CRadioEngineImp::HandleFrequencyEvent( %d, %d )", aFrequency, aErrorCode );
  1668     LOG_METHOD_AUTO;
       
  1669     LOG_FORMAT( "aFrequency:  %d, aErrorCode: %d )", aFrequency, aErrorCode );
  1814 
  1670 
  1815     if ( iSettings->EngineSettings().TunedFrequency() != aFrequency )
  1671     if ( iSettings->EngineSettings().TunedFrequency() != aFrequency )
  1816         {
  1672         {
  1817         if ( iSettings->EngineSettings().IsPowerOn() )
  1673         if ( iSettings->EngineSettings().IsPowerOn() )
  1818             {
  1674             {
  1855 // audio routing is not supported.
  1711 // audio routing is not supported.
  1856 // ---------------------------------------------------------------------------
  1712 // ---------------------------------------------------------------------------
  1857 //
  1713 //
  1858 TBool CRadioEngineImp::IsAudioRoutingPossible() const
  1714 TBool CRadioEngineImp::IsAudioRoutingPossible() const
  1859     {
  1715     {
       
  1716     LEVEL3( LOG_METHOD_AUTO );
  1860     TBool headsetConnected = EFalse;
  1717     TBool headsetConnected = EFalse;
  1861     TRAP_IGNORE( ( headsetConnected = iSystemEventCollector->IsHeadsetConnectedL() ) )
  1718     TRAP_IGNORE( ( headsetConnected = iSystemEventCollector->IsHeadsetConnectedL() ) )
  1862 
  1719 
  1863     TBool powerOn = iSettings->EngineSettings().IsPowerOn();
  1720     TBool powerOn = iSettings->EngineSettings().IsPowerOn();
  1864 
  1721