radioapp/radioenginewrapper/src/radioenginewrapper_p.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 32 189d20c34778
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    21 #include "radioenginewrapper_p.h"
    21 #include "radioenginewrapper_p.h"
    22 #include "radiosettings.h"
    22 #include "radiosettings.h"
    23 #include "radiosettings_p.h"
    23 #include "radiosettings_p.h"
    24 #include "radiologger.h"
    24 #include "radiologger.h"
    25 #include "radio_global.h"
    25 #include "radio_global.h"
    26 #include "cradioenginehandler.h"
    26 #include "radioenginehandler.h"
    27 #include "radiostationhandlerif.h"
    27 #include "radiostationhandlerif.h"
    28 #include "cradiopubsub.h"
       
    29 #include "radiocontroleventlistener.h"
    28 #include "radiocontroleventlistener.h"
    30 #include "radiordslistener.h"
    29 #include "radiordslistener.h"
    31 #include "cradiorepositorymanager.h"
       
    32 #include "radioenginewrapperobserver.h"
    30 #include "radioenginewrapperobserver.h"
    33 
    31 
    34 // Constants
    32 // Constants
    35 
    33 
    36 /*!
    34 /*!
    38  */
    36  */
    39 RadioEngineWrapperPrivate::RadioEngineWrapperPrivate( RadioEngineWrapper* wrapper,
    37 RadioEngineWrapperPrivate::RadioEngineWrapperPrivate( RadioEngineWrapper* wrapper,
    40                                                       RadioStationHandlerIf& stationHandler ) :
    38                                                       RadioStationHandlerIf& stationHandler ) :
    41     q_ptr( wrapper ),
    39     q_ptr( wrapper ),
    42     mStationHandler( stationHandler ),
    40     mStationHandler( stationHandler ),
    43     mEngineHandler( new CRadioEngineHandler( *this ) ),
    41     mEngineHandler( new RadioEngineHandler( *this ) ),
    44     mControlEventListener( new RadioControlEventListener( *this ) ),
    42     mControlEventListener( new RadioControlEventListener( *this ) ),
    45     mRdsListener ( new RadioRdsListener( mStationHandler, *this ) ),
    43     mRdsListener ( new RadioRdsListener( mStationHandler, *this ) ),
    46     mTuneReason( 0 ),
    44     mTuneReason( TuneReason::Unspecified ),
    47     mUseLoudspeaker( false )
    45     mUseLoudspeaker( false )
    48 {
    46 {
    49 }
    47 }
    50 
    48 
    51 /*!
    49 /*!
    59 }
    57 }
    60 
    58 
    61 /*!
    59 /*!
    62  * Initializes the private implementation
    60  * Initializes the private implementation
    63  */
    61  */
    64 void RadioEngineWrapperPrivate::init()
    62 bool RadioEngineWrapperPrivate::init()
    65 {
    63 {
    66     TRAPD( err, mEngineHandler->ConstructL() );
    64     if ( !mEngineHandler->constructEngine() ) {
    67     if ( err != KErrNone ) {
    65         LOG( "RadioEngineWrapperPrivate::init, EngineHandler construct failed" );
    68         LOG_FORMAT( "RadioEngineWrapperPrivate::init, EngineHandler construct failed: %d", err );
       
    69         mEngineHandler.reset();
    66         mEngineHandler.reset();
    70         return;
    67         return false;
    71         //TODO: Error handling?
    68     }
    72     }
    69 
    73 
    70     mEngineHandler->setRdsObserver( mRdsListener.data() );
    74     mEngineHandler->SetRdsObserver( mRdsListener.data() );
       
    75     mEngineHandler->PubSub().SetControlEventObserver( mControlEventListener.data() );
       
    76     mControlEventListener->init();
    71     mControlEventListener->init();
    77 
    72 
    78     // Start observing profile changes
    73     mUseLoudspeaker = mEngineHandler->isAudioRoutedToLoudspeaker();
    79     mEngineHandler->Repository().AddEntityL( KCRUidProfileEngine,
       
    80                                              KProEngActiveProfile,
       
    81                                              CRadioRepositoryManager::ERadioEntityInt );
       
    82 
       
    83     mUseLoudspeaker = mEngineHandler->IsAudioRoutedToLoudspeaker();
       
    84     if ( !mUseLoudspeaker ) {
    74     if ( !mUseLoudspeaker ) {
    85         RUN_NOTIFY_LOOP( mObservers, audioRouteChanged( false ) );
    75         RUN_NOTIFY_LOOP( mObservers, audioRouteChanged( false ) );
    86     }
    76     }
    87 }
    77 
    88 
    78     return true;
    89 /*!
       
    90  * Starts up the radio engine
       
    91  */
       
    92 bool RadioEngineWrapperPrivate::isEngineConstructed()
       
    93 {
       
    94     return mEngineHandler != 0;
       
    95 }
    79 }
    96 
    80 
    97 /*!
    81 /*!
    98  * Returns the settings handler owned by the engine
    82  * Returns the settings handler owned by the engine
    99  */
    83  */
   100 RadioSettingsIf& RadioEngineWrapperPrivate::settings()
    84 RadioSettingsIf& RadioEngineWrapperPrivate::settings()
   101 {
    85 {
   102     if ( !mSettings ) {
    86     if ( !mSettings ) {
   103         mSettings.reset( new RadioSettings() );
    87         mSettings.reset( new RadioSettings() );
   104         mSettings->d_func()->init( &mEngineHandler->ApplicationSettings() );
    88         mSettings->d_func()->init( &mEngineHandler->applicationSettings() );
   105     }
    89     }
   106     return *mSettings;
    90     return *mSettings;
   107 }
    91 }
   108 
    92 
   109 /*!
    93 /*!
   110  * Returns the enginehandler owned by the engine
    94  * Returns the enginehandler owned by the engine
   111  */
    95  */
   112 CRadioEngineHandler& RadioEngineWrapperPrivate::RadioEnginehandler()
    96 RadioEngineHandler& RadioEngineWrapperPrivate::radioEnginehandler()
   113 {
    97 {
   114     return *mEngineHandler;
    98     return *mEngineHandler;
   115 }
    99 }
   116 
   100 
   117 /*!
   101 /*!
   118  * Tunes to the given frequency
   102  * Tunes to the given frequency
   119  */
   103  */
   120 void RadioEngineWrapperPrivate::tuneFrequency( uint frequency, const int reason )
   104 void RadioEngineWrapperPrivate::setFrequency( uint frequency, const int reason )
   121 {
   105 {
   122     if ( mEngineHandler->TunedFrequency() != frequency ) {
   106     if ( mEngineHandler->currentFrequency() != frequency ) {
   123         mTuneReason = reason;
   107         mTuneReason = reason;
   124         mEngineHandler->Tune( frequency );
   108         mEngineHandler->setFrequency( frequency );
   125     }
       
   126 }
       
   127 
       
   128 /*!
       
   129  * Tunes to the given frequency after a delay
       
   130  */
       
   131 void RadioEngineWrapperPrivate::tuneWithDelay( uint frequency, const int reason )
       
   132 {
       
   133     if ( mEngineHandler->TunedFrequency() != frequency ) {
       
   134         mTuneReason = reason;
       
   135         mEngineHandler->TuneWithDelay( frequency );
       
   136     }
   109     }
   137 }
   110 }
   138 
   111 
   139 /*!
   112 /*!
   140  *
   113  *
   145 }
   118 }
   146 
   119 
   147 /*!
   120 /*!
   148  *
   121  *
   149  */
   122  */
   150 void RadioEngineWrapperPrivate::startSeeking( Seeking::Direction direction, const int reason )
   123 void RadioEngineWrapperPrivate::startSeeking( Seek::Direction direction, const int reason )
   151 {
   124 {
   152     mTuneReason = reason;
   125     mTuneReason = reason;
   153     mEngineHandler->Seek( direction );
   126     mEngineHandler->seek( direction );
   154 }
   127 }
   155 
   128 
   156 /*!
   129 /*!
   157  * \reimp
   130  * \reimp
   158  */
   131  */
   168 void RadioEngineWrapperPrivate::FrequencyEventL( TUint32 aFrequency,
   141 void RadioEngineWrapperPrivate::FrequencyEventL( TUint32 aFrequency,
   169                                                  RadioEngine::TRadioFrequencyEventReason aReason,
   142                                                  RadioEngine::TRadioFrequencyEventReason aReason,
   170                                                  TInt aError )
   143                                                  TInt aError )
   171 {
   144 {
   172     Q_UNUSED( aReason );
   145     Q_UNUSED( aReason );
   173     LOG_FORMAT( "RadioEngineWrapperPrivate::FrequencyEventL - Frequency: %d, Reason: %d, Error: %d", aFrequency, aReason, aError );
   146     LOG_FORMAT( "RadioEngineWrapperPrivate::FrequencyEventL - Freq: %d, TuneReason: %d, Err: %d", aFrequency, mTuneReason, aError );
   174 
   147 
   175     if ( !aError ) {
   148     if ( !aError ) {
   176         const uint frequency = static_cast<uint>( aFrequency );
   149         const uint frequency = static_cast<uint>( aFrequency );
   177         RUN_NOTIFY_LOOP( mObservers, tunedToFrequency( frequency, mTuneReason ) );
   150         RUN_NOTIFY_LOOP( mObservers, tunedToFrequency( frequency, mTuneReason ) );
       
   151     } else {
       
   152         RUN_NOTIFY_LOOP( mObservers, tunedToFrequency( mEngineHandler->minFrequency(), TuneReason::StationScanNoStationsFound ) ); // no frequencies found
   178     }
   153     }
   179 }
   154 }
   180 
   155 
   181 /*!
   156 /*!
   182  * \reimp
   157  * \reimp
   223 }
   198 }
   224 
   199 
   225 /*!
   200 /*!
   226  * \reimp
   201  * \reimp
   227  */
   202  */
   228 void RadioEngineWrapperPrivate::SeekingEventL( TInt aSeekingState, TInt aError )
   203 void RadioEngineWrapperPrivate::SeekingEventL( TInt DEBUGVAR( aSeekingState ), TInt DEBUGVAR( aError ) )
   229 {
   204 {
   230     Q_UNUSED( aSeekingState );
   205     LOG_FORMAT( "RadioEngineWrapperPrivate::SeekingEventL, aSeekingState: %d, Error: %d", aSeekingState, aError );
   231     Q_UNUSED( aError );
       
   232 }
   206 }
   233 
   207 
   234 /*!
   208 /*!
   235  * \reimp
   209  * \reimp
   236  */
   210  */
   266 //    ERadioAudioRoutingHeadset,      ///< Audio routed through headset
   240 //    ERadioAudioRoutingHeadset,      ///< Audio routed through headset
   267 //    ERadioAudioRoutingSpeaker,      ///< Audio routed through speaker ( IHF )
   241 //    ERadioAudioRoutingSpeaker,      ///< Audio routed through speaker ( IHF )
   268 //    ERadioAudioResourcesAvailable,  ///< Audio resources have become available
   242 //    ERadioAudioResourcesAvailable,  ///< Audio resources have become available
   269 //    ERadioAudioAutoResumeForbidden  ///< Audio auto resuming is forbidden
   243 //    ERadioAudioAutoResumeForbidden  ///< Audio auto resuming is forbidden
   270 }
   244 }
   271 
       
   272 /*!
       
   273  * \reimp
       
   274  */
       
   275 void RadioEngineWrapperPrivate::HandleRepositoryValueChangeL( const TUid& aUid, TUint32 aKey, TInt aValue, TInt aError )
       
   276 {
       
   277     if ( aUid == KCRUidProfileEngine && aKey == KProEngActiveProfile && !aError && aValue == KOfflineProfileId ) {
       
   278         LOG( "RadioEngineWrapperPrivate::HandleRepositoryValueChangeL: Offline profile activated" );
       
   279     }
       
   280 }