radioapp/radioenginewrapper/src/cradioenginehandler.cpp
changeset 28 075425b8d9a4
parent 24 6df133bd92e1
equal deleted inserted replaced
24:6df133bd92e1 28:075425b8d9a4
    19 #include "cradioengine.h"
    19 #include "cradioengine.h"
    20 #include "cradioaudiorouter.h"
    20 #include "cradioaudiorouter.h"
    21 #include "cradiosystemeventcollector.h"
    21 #include "cradiosystemeventcollector.h"
    22 #include "cradiosettings.h"
    22 #include "cradiosettings.h"
    23 #include "mradioenginesettings.h"
    23 #include "mradioenginesettings.h"
    24 #include "cradiopubsub.h"
       
    25 #include "cradiorepositorymanager.h"
    24 #include "cradiorepositorymanager.h"
    26 #include "mradiordsreceiver.h"
    25 #include "mradiordsreceiver.h"
    27 #include "cradioenginehandler.h"
    26 #include "cradioenginehandler.h"
    28 #include "mradioenginehandlerobserver.h"
    27 #include "mradioenginehandlerobserver.h"
    29 #include "radio_global.h"
    28 #include "radio_global.h"
    30 #include "radiologger.h"
    29 #include "radiologger.h"
    31 #include "radioenummapper.h"
    30 #include "radioenummapper.h"
    32 
    31 
    33 /**
       
    34  * Delayed tuning delay
       
    35  */
       
    36 const TInt KTuneDelay = 100000;
       
    37 
       
    38 /*!
    32 /*!
    39  * Map to translate seek direction enum from its definition in the engine to
    33  * Map to translate seek direction enum from its definition in the engine to
    40  * its definition in the ui and vice versa
    34  * its definition in the ui and vice versa
    41  */
    35  */
    42 BEGIN_ENUM_MAP( KSeekDirectionMap )
    36 BEGIN_ENUM_MAP( KSeekDirectionMap )
    43     ENUM_MAP_ITEM( Seeking::Down, RadioEngine::ERadioDown ),
    37     ENUM_MAP_ITEM( Seek::Down,              RadioEngine::ERadioDown ),
    44     ENUM_MAP_ITEM( Seeking::Up,   RadioEngine::ERadioUp )
    38     ENUM_MAP_ITEM( Seek::Up,                RadioEngine::ERadioUp )
    45 END_ENUM_MAP( KSeekDirectionMap )
    39 END_ENUM_MAP( KSeekDirectionMap )
    46 
    40 
    47 /*!
    41 /*!
    48  * Convenience macro to do the mapping of seek directions
    42  * Convenience macro to do the mapping of seek directions
    49  */
    43  */
    70 /*!
    64 /*!
    71  * Map to translate seeking state enum from its definition in the engine to
    65  * Map to translate seeking state enum from its definition in the engine to
    72  * its definition in the ui and vice versa
    66  * its definition in the ui and vice versa
    73  */
    67  */
    74 BEGIN_ENUM_MAP( KSeekingStateMap )
    68 BEGIN_ENUM_MAP( KSeekingStateMap )
    75     ENUM_MAP_ITEM( Seeking::NotSeeking,     RadioEngine::ERadioNotSeeking ),
    69     ENUM_MAP_ITEM( Seek::NotSeeking,        RadioEngine::ERadioNotSeeking ),
    76     ENUM_MAP_ITEM( Seeking::SeekingUp,      RadioEngine::ERadioSeekingUp ),
    70     ENUM_MAP_ITEM( Seek::SeekingUp,         RadioEngine::ERadioSeekingUp ),
    77     ENUM_MAP_ITEM( Seeking::SeekingDown,    RadioEngine::ERadioSeekingDown )
    71     ENUM_MAP_ITEM( Seek::SeekingDown,       RadioEngine::ERadioSeekingDown )
    78 END_ENUM_MAP( KSeekingStateMap )
    72 END_ENUM_MAP( KSeekingStateMap )
    79 
    73 
    80 /*!
    74 /*!
    81  * Convenience macro to do the mapping of seeking states
    75  * Convenience macro to do the mapping of seeking states
    82  */
    76  */
    83 #define MAP_TO_UI_SEEKING_STATE(ui_enum) MAP_TO_UI_ENUM( Seeking::State, ui_enum, KSeekingStateMap )
    77 #define MAP_TO_UI_SEEKING_STATE(ui_enum) MAP_TO_UI_ENUM( Seek::State, ui_enum, KSeekingStateMap )
    84 
    78 
    85 
    79 
    86 // ======== MEMBER FUNCTIONS ========
    80 // ======== MEMBER FUNCTIONS ========
    87 
    81 
    88 
    82 
    99 //
    93 //
   100 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
   101 //
    95 //
   102 CRadioEngineHandler::~CRadioEngineHandler()
    96 CRadioEngineHandler::~CRadioEngineHandler()
   103     {
    97     {
   104     if ( iEngine ) {
       
   105         iEngine->Settings().Repository().RemoveObserver( &iObserver );
       
   106     }
       
   107 
       
   108     delete iEngine;
    98     delete iEngine;
   109     delete iDelayTimer;
       
   110     }
    99     }
   111 
   100 
   112 // ---------------------------------------------------------------------------
   101 // ---------------------------------------------------------------------------
   113 //
   102 //
   114 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
   115 //
   104 //
   116 void CRadioEngineHandler::ConstructL()
   105 void CRadioEngineHandler::ConstructL()
   117     {
   106     {
   118     LOG_METHOD;
   107     LOG_METHOD;
   119 
   108 
   120     iDelayTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   121 
       
   122     iEngine = CRadioEngine::NewL( *this );
   109     iEngine = CRadioEngine::NewL( *this );
   123 
   110 
   124     iEngine->SystemEventCollector().AddObserverL( &iObserver );
   111     iEngine->SystemEventCollector().AddObserverL( &iObserver );
   125     iEngine->Settings().Repository().AddObserverL( &iObserver );
       
   126     iEngine->AudioRouter().SetAudioRouteL( RadioEngine::ERadioHeadset );
       
   127     iEngine->AddObserverL( &iObserver );
   112     iEngine->AddObserverL( &iObserver );
   128 
   113 
   129     iRegion = MAP_TO_UI_REGION( iEngine->Settings().EngineSettings().RegionId() );
   114     iRegion = MAP_TO_UI_REGION( iEngine->Settings().EngineSettings().RegionId() );
   130 
       
   131 //    iEngineHolder->PubSub().SetControlEventObserver( &iObserver );
       
   132 
       
   133 //    iRadioEngine->SetVolumeMuted( EFalse );
       
   134 //    iRadioEngine->SetVolume( MaxVolume() );
       
   135 
       
   136 //    CVRRepositoryManager::GetRepositoryValueL( KVRCRUid, KVRCRLaunchCount, usageCount );
       
   137 //    CVRRepositoryManager::SetRepositoryValueL( KVRCRUid, KVRCRLaunchCount, ++usageCount );
       
   138 //    iControlEventObserver = CVRControlEventObserverImpl::NewL( *this );
       
   139 //    doc->PubSubL().SetControlEventObserver( iControlEventObserver );
       
   140     }
   115     }
   141 
   116 
   142 // ---------------------------------------------------------------------------
   117 // ---------------------------------------------------------------------------
   143 // Sets the rds data observer
   118 // Sets the rds data observer
   144 // ---------------------------------------------------------------------------
   119 // ---------------------------------------------------------------------------
   147     {
   122     {
   148     TRAP_IGNORE( iEngine->RdsReceiver().AddObserverL( aObserver ) );
   123     TRAP_IGNORE( iEngine->RdsReceiver().AddObserverL( aObserver ) );
   149     }
   124     }
   150 
   125 
   151 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
       
   127 // Starts or stops receiving RDS data
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CRadioEngineHandler::SetRdsEnabled( TBool aRdsEnabled )
       
   131     {
       
   132     if ( aRdsEnabled )
       
   133         {
       
   134         iEngine->RdsReceiver().StartReceiver();
       
   135         }
       
   136     else
       
   137         {
       
   138         iEngine->RdsReceiver().StopReceiver();
       
   139         }
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
   152 // Returns the radio status.
   143 // Returns the radio status.
   153 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   154 //
   145 //
   155 TBool CRadioEngineHandler::IsRadioOn()
   146 TBool CRadioEngineHandler::IsRadioOn()
   156     {
   147     {
   157     return iEngine->Settings().EngineSettings().IsPowerOn();
   148     return iEngine->Settings().EngineSettings().IsPowerOn();
   158     }
   149     }
   159 
   150 
   160 // ---------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
       
   152 // Sets the manual seek status
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CRadioEngineHandler::SetManualSeekMode( TBool aManualSeek )
       
   156     {
       
   157     iEngine->SetManualSeekMode( aManualSeek );
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // Returns the manual seek status
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 TBool CRadioEngineHandler::IsInManualSeekMode() const
       
   165     {
       
   166     return iEngine->IsInManualSeekMode();
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
   161 // Tune to the specified frequency
   170 // Tune to the specified frequency
   162 // ---------------------------------------------------------------------------
   171 // ---------------------------------------------------------------------------
   163 //
   172 //
   164 void CRadioEngineHandler::Tune( TUint aFrequency )
   173 void CRadioEngineHandler::SetFrequency( TUint aFrequency )
   165     {
   174     {
   166     iEngine->SetFrequency( aFrequency );
   175     iEngine->SetFrequency( aFrequency );
   167     }
   176     }
   168 
   177 
   169 // ---------------------------------------------------------------------------
   178 // ---------------------------------------------------------------------------
   170 // Tune to the specified frequency after a delay
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CRadioEngineHandler::TuneWithDelay( TUint aFrequency )
       
   174     {
       
   175     iFrequency = aFrequency;
       
   176     iDelayTimer->Cancel();
       
   177     iDelayTimer->Start( KTuneDelay, KTuneDelay, TCallBack( TuneDelayCallback, this ) );
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // Sets the audio mute state
   179 // Sets the audio mute state
   182 // ---------------------------------------------------------------------------
   180 // ---------------------------------------------------------------------------
   183 //
   181 //
   184 void CRadioEngineHandler::SetMuted( const TBool aMuted )
   182 void CRadioEngineHandler::SetMuted( const TBool aMuted, const TBool aUpdateSettings )
   185     {
   183     {
   186     iEngine->SetVolumeMuted( aMuted );
   184     iEngine->SetVolumeMuted( aMuted, aUpdateSettings );
   187     }
   185     }
   188 
   186 
   189 // ---------------------------------------------------------------------------
   187 // ---------------------------------------------------------------------------
   190 // Gets the audio mute state
   188 // Gets the audio mute state
   191 // ---------------------------------------------------------------------------
   189 // ---------------------------------------------------------------------------
   259 
   257 
   260 // ---------------------------------------------------------------------------
   258 // ---------------------------------------------------------------------------
   261 // Retrieves the current frequency.
   259 // Retrieves the current frequency.
   262 // ---------------------------------------------------------------------------
   260 // ---------------------------------------------------------------------------
   263 //
   261 //
   264 TUint CRadioEngineHandler::TunedFrequency() const
   262 TUint CRadioEngineHandler::CurrentFrequency() const
   265     {
   263     {
   266     return iEngine->Settings().EngineSettings().TunedFrequency();
   264     return iEngine->Settings().EngineSettings().TunedFrequency();
   267     }
   265     }
   268 
   266 
   269 // ---------------------------------------------------------------------------
   267 // ---------------------------------------------------------------------------
   295 
   293 
   296 // ---------------------------------------------------------------------------
   294 // ---------------------------------------------------------------------------
   297 // Scan up to the next available frequency
   295 // Scan up to the next available frequency
   298 // ---------------------------------------------------------------------------
   296 // ---------------------------------------------------------------------------
   299 //
   297 //
   300 void CRadioEngineHandler::Seek( Seeking::Direction direction )
   298 void CRadioEngineHandler::Seek( Seek::Direction direction )
   301     {
   299     {
   302     LOG_TIMESTAMP( "Seek" );
   300     LOG_TIMESTAMP( "Seek" );
   303     iEngine->Seek( MAP_FROM_UI_DIRECTION( direction ) );
   301     iEngine->Seek( MAP_FROM_UI_DIRECTION( direction ) );
   304     }
   302     }
   305 
   303 
   315 
   313 
   316 // ---------------------------------------------------------------------------
   314 // ---------------------------------------------------------------------------
   317 // Returns the engine seeking state
   315 // Returns the engine seeking state
   318 // ---------------------------------------------------------------------------
   316 // ---------------------------------------------------------------------------
   319 //
   317 //
   320 Seeking::State CRadioEngineHandler::SeekingState() const
   318 Seek::State CRadioEngineHandler::SeekingState() const
   321     {
   319     {
   322     return MAP_TO_UI_SEEKING_STATE( iEngine->Seeking() );
   320     return MAP_TO_UI_SEEKING_STATE( iEngine->Seeking() );
   323     }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 void CRadioEngineHandler::StartScan( MRadioScanObserver& aObserver )
       
   330     {
       
   331     iEngine->StartScan( aObserver );
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CRadioEngineHandler::StopScan( TInt aError )
       
   339     {
       
   340     iEngine->StopScan( aError );
       
   341     }
   321     }
   342 
   322 
   343 // ---------------------------------------------------------------------------
   323 // ---------------------------------------------------------------------------
   344 // return step size for tuning.
   324 // return step size for tuning.
   345 // ---------------------------------------------------------------------------
   325 // ---------------------------------------------------------------------------
   380     {
   360     {
   381     return iEngine->Settings().EngineSettings().AudioRoute() == RadioEngine::ERadioSpeaker;
   361     return iEngine->Settings().EngineSettings().AudioRoute() == RadioEngine::ERadioSpeaker;
   382     }
   362     }
   383 
   363 
   384 // ---------------------------------------------------------------------------
   364 // ---------------------------------------------------------------------------
   385 // Returns ar reference to the publish & subscribe handler
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 CRadioPubSub& CRadioEngineHandler::PubSub()
       
   389     {
       
   390     return *iEngine->PubSub();
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // Returns the repository manager.
   365 // Returns the repository manager.
   395 // ---------------------------------------------------------------------------
   366 // ---------------------------------------------------------------------------
   396 //
   367 //
   397 CRadioRepositoryManager& CRadioEngineHandler::Repository() const
       
   398     {
       
   399     return iEngine->Settings().Repository();
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // Returns the repository manager.
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 MRadioApplicationSettings& CRadioEngineHandler::ApplicationSettings() const
   368 MRadioApplicationSettings& CRadioEngineHandler::ApplicationSettings() const
   407     {
   369     {
   408     return iEngine->Settings().ApplicationSettings();
   370     return iEngine->Settings().ApplicationSettings();
   409     }
   371     }
   410 
   372 
   435 //
   397 //
   436 CRadioSettings* CRadioEngineHandler::InitSettingsL()
   398 CRadioSettings* CRadioEngineHandler::InitSettingsL()
   437     {
   399     {
   438     return CRadioSettings::NewL();
   400     return CRadioSettings::NewL();
   439     }
   401     }
   440 
       
   441 // ---------------------------------------------------------------------------
       
   442 // From MRadioEngineInitializer
       
   443 //
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 CRadioPubSub* CRadioEngineHandler::InitPubSubL()
       
   447     {
       
   448     return CRadioPubSub::NewL();
       
   449     }
       
   450 
       
   451 // --------------------------------------------------------------------------------
       
   452 // Static callback function to be used by the tune delay timer
       
   453 // --------------------------------------------------------------------------------
       
   454 //
       
   455 TInt CRadioEngineHandler::TuneDelayCallback( TAny* aSelf )
       
   456     {
       
   457     CRadioEngineHandler* self = static_cast<CRadioEngineHandler*>( aSelf );
       
   458     self->iDelayTimer->Cancel();
       
   459     self->Tune( self->iFrequency );
       
   460     return 0; // Not used by CPeriodic
       
   461     }