radioapp/radioenginewrapper/src/radioenginewrapper_p.cpp
branchRCL_3
changeset 19 cce62ebc198e
equal deleted inserted replaced
18:1a6714c53019 19:cce62ebc198e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 // User includes
       
    21 #include "radioenginewrapper_p.h"
       
    22 #include "radiosettings.h"
       
    23 #include "radiosettings_p.h"
       
    24 #include "radiologger.h"
       
    25 #include "radio_global.h"
       
    26 #include "radioenginehandler.h"
       
    27 #include "radiostationhandlerif.h"
       
    28 #include "radiocontroleventlistener.h"
       
    29 #include "radiordslistener.h"
       
    30 #include "radioenginewrapperobserver.h"
       
    31 
       
    32 // Constants
       
    33 
       
    34 /*!
       
    35  *
       
    36  */
       
    37 RadioEngineWrapperPrivate::RadioEngineWrapperPrivate( RadioEngineWrapper* wrapper,
       
    38                                                       RadioStationHandlerIf& stationHandler ) :
       
    39     q_ptr( wrapper ),
       
    40     mStationHandler( stationHandler ),
       
    41     mEngineHandler( new RadioEngineHandler( *this ) ),
       
    42     mControlEventListener( new RadioControlEventListener( *this ) ),
       
    43     mRdsListener ( new RadioRdsListener( mStationHandler, *this ) ),
       
    44     mTuneReason( TuneReason::Unspecified ),
       
    45     mUseLoudspeaker( false )
       
    46 {
       
    47 }
       
    48 
       
    49 /*!
       
    50  *
       
    51  */
       
    52 RadioEngineWrapperPrivate::~RadioEngineWrapperPrivate()
       
    53 {
       
    54     // Destructor needs to be defined because some member variables that are forward declared
       
    55     // in the header are managed by QT's smart pointers and they require that the owning class
       
    56     // has a non-inlined destructor. Compiler generates an inlined destructor if it isn't defined.
       
    57 }
       
    58 
       
    59 /*!
       
    60  * Initializes the private implementation
       
    61  */
       
    62 bool RadioEngineWrapperPrivate::init()
       
    63 {
       
    64     if ( !mEngineHandler->constructEngine() ) {
       
    65         LOG( "RadioEngineWrapperPrivate::init, EngineHandler construct failed" );
       
    66         mEngineHandler.reset();
       
    67         return false;
       
    68     }
       
    69 
       
    70     mEngineHandler->setRdsObserver( mRdsListener.data() );
       
    71     mControlEventListener->init();
       
    72 
       
    73     mUseLoudspeaker = mEngineHandler->isAudioRoutedToLoudspeaker();
       
    74     if ( !mUseLoudspeaker ) {
       
    75         RUN_NOTIFY_LOOP( mObservers, audioRouteChanged( false ) );
       
    76     }
       
    77 
       
    78     return true;
       
    79 }
       
    80 
       
    81 /*!
       
    82  * Returns the settings handler owned by the engine
       
    83  */
       
    84 RadioSettingsIf& RadioEngineWrapperPrivate::settings()
       
    85 {
       
    86     if ( !mSettings ) {
       
    87         mSettings.reset( new RadioSettings() );
       
    88         mSettings->d_func()->init( &mEngineHandler->applicationSettings() );
       
    89     }
       
    90     return *mSettings;
       
    91 }
       
    92 
       
    93 /*!
       
    94  * Returns the enginehandler owned by the engine
       
    95  */
       
    96 RadioEngineHandler& RadioEngineWrapperPrivate::radioEnginehandler()
       
    97 {
       
    98     return *mEngineHandler;
       
    99 }
       
   100 
       
   101 /*!
       
   102  * Tunes to the given frequency
       
   103  */
       
   104 void RadioEngineWrapperPrivate::setFrequency( uint frequency, const int reason )
       
   105 {
       
   106     if ( mEngineHandler->currentFrequency() != frequency ) {
       
   107         mTuneReason = reason;
       
   108         mEngineHandler->setFrequency( frequency );
       
   109     }
       
   110 }
       
   111 
       
   112 /*!
       
   113  *
       
   114  */
       
   115 ObserverList& RadioEngineWrapperPrivate::observers()
       
   116 {
       
   117     return mObservers;
       
   118 }
       
   119 
       
   120 /*!
       
   121  *
       
   122  */
       
   123 void RadioEngineWrapperPrivate::startSeeking( Seek::Direction direction, const int reason )
       
   124 {
       
   125     mTuneReason = reason;
       
   126     mEngineHandler->seek( direction );
       
   127 }
       
   128 
       
   129 /*!
       
   130  * \reimp
       
   131  */
       
   132 void RadioEngineWrapperPrivate::PowerEventL( TBool aPowerState, TInt DEBUGVAR( aError ) )
       
   133 {
       
   134     LOG_FORMAT( "RadioEngineWrapperPrivate::PowerEventL, PowerState: %d, Error: %d", aPowerState, aError );
       
   135     RUN_NOTIFY_LOOP( mObservers, radioStatusChanged( aPowerState ) );
       
   136 }
       
   137 
       
   138 /*!
       
   139  * \reimp
       
   140  */
       
   141 void RadioEngineWrapperPrivate::FrequencyEventL( TUint32 aFrequency,
       
   142                                                  RadioEngine::TRadioFrequencyEventReason aReason,
       
   143                                                  TInt aError )
       
   144 {
       
   145     Q_UNUSED( aReason );
       
   146     LOG_FORMAT( "RadioEngineWrapperPrivate::FrequencyEventL - Freq: %d, TuneReason: %d, Err: %d", aFrequency, mTuneReason, aError );
       
   147 
       
   148     if ( !aError ) {
       
   149         const uint frequency = static_cast<uint>( aFrequency );
       
   150         RUN_NOTIFY_LOOP( mObservers, tunedToFrequency( frequency, mTuneReason ) );
       
   151     } else {
       
   152         RUN_NOTIFY_LOOP( mObservers, tunedToFrequency( mEngineHandler->minFrequency(), TuneReason::StationScanNoStationsFound ) ); // no frequencies found
       
   153     }
       
   154 }
       
   155 
       
   156 /*!
       
   157  * \reimp
       
   158  */
       
   159 void RadioEngineWrapperPrivate::VolumeEventL( TInt aVolume, TInt aError )
       
   160 {
       
   161     Q_UNUSED( aError );
       
   162     RUN_NOTIFY_LOOP( mObservers, volumeChanged( aVolume ) );
       
   163 }
       
   164 
       
   165 /*!
       
   166  * \reimp
       
   167  */
       
   168 void RadioEngineWrapperPrivate::MuteEventL( TBool aMuteState, TInt aError )
       
   169 {
       
   170     Q_UNUSED( aError );
       
   171     RUN_NOTIFY_LOOP( mObservers, muteChanged( aMuteState ) );
       
   172 }
       
   173 
       
   174 /*!
       
   175  * \reimp
       
   176  */
       
   177 void RadioEngineWrapperPrivate::AudioModeEventL( TInt DEBUGVAR( aAudioMode ), TInt DEBUGVAR( aError ) )
       
   178 {
       
   179     LOG_FORMAT( "RadioEngineWrapperPrivate::AudioModeEventL, AudioMode: %d, Error: %d", aAudioMode, aError );
       
   180 }
       
   181 
       
   182 /*!
       
   183  * \reimp
       
   184  */
       
   185 void RadioEngineWrapperPrivate::AntennaEventL( TBool aAntennaAttached, TInt aError )
       
   186 {
       
   187     Q_UNUSED( aError );
       
   188     RUN_NOTIFY_LOOP( mObservers, antennaStatusChanged( aAntennaAttached ) );
       
   189 }
       
   190 
       
   191 /*!
       
   192  * \reimp
       
   193  */
       
   194 void RadioEngineWrapperPrivate::AudioRoutingEventL( TInt aAudioDestination, TInt aError )
       
   195 {
       
   196     Q_UNUSED( aAudioDestination )
       
   197     Q_UNUSED( aError )
       
   198 }
       
   199 
       
   200 /*!
       
   201  * \reimp
       
   202  */
       
   203 void RadioEngineWrapperPrivate::SeekingEventL( TInt DEBUGVAR( aSeekingState ), TInt DEBUGVAR( aError ) )
       
   204 {
       
   205     LOG_FORMAT( "RadioEngineWrapperPrivate::SeekingEventL, aSeekingState: %d, Error: %d", aSeekingState, aError );
       
   206 }
       
   207 
       
   208 /*!
       
   209  * \reimp
       
   210  */
       
   211 void RadioEngineWrapperPrivate::RegionEventL( TInt DEBUGVAR( aRegion ), TInt DEBUGVAR( aError ) )
       
   212 {
       
   213     LOG_FORMAT( "RadioEngineWrapperPrivate::RegionEventL, aRegion: %d, Error: %d", aRegion, aError );
       
   214 }
       
   215 
       
   216 /*!
       
   217  * \reimp
       
   218  */
       
   219 void RadioEngineWrapperPrivate::AudioRouteChangedL( RadioEngine::TRadioAudioRoute aRoute )
       
   220 {
       
   221     mUseLoudspeaker = aRoute == RadioEngine::ERadioSpeaker;
       
   222     RUN_NOTIFY_LOOP( mObservers, audioRouteChanged( mUseLoudspeaker ) );
       
   223 }
       
   224 
       
   225 /*!
       
   226  * \reimp
       
   227  */
       
   228 void RadioEngineWrapperPrivate::HandleSystemEventL( TRadioSystemEventType DEBUGVAR( aEventType ) )
       
   229 {
       
   230     LOG_FORMAT( "RadioEngineWrapperPrivate::HandleSystemEventL, Event: %d", aEventType );
       
   231 //    ERadioHeadsetConnected,         ///< Headset was connected
       
   232 //    ERadioHeadsetDisconnected,      ///< Headset was disconnected
       
   233 //    ERadioNetworkCoverageUp,        ///< Network coverage detected
       
   234 //    ERadioNetworkCoverageDown,      ///< Network coverage lost
       
   235 //    ERadioCallActivated,            ///< Call activated or ringing
       
   236 //    ERadioCallDeactivated,          ///< Call disconnected
       
   237 //    ERadioEmergencyCallActivated,   ///< Call activated or ringing
       
   238 //    ERadioEmergencyCallDeactivated, ///< Call disconnected
       
   239 //    ERadioLowDiskSpace,             ///< Low disk space
       
   240 //    ERadioAudioRoutingHeadset,      ///< Audio routed through headset
       
   241 //    ERadioAudioRoutingSpeaker,      ///< Audio routed through speaker ( IHF )
       
   242 //    ERadioAudioResourcesAvailable,  ///< Audio resources have become available
       
   243 //    ERadioAudioAutoResumeForbidden  ///< Audio auto resuming is forbidden
       
   244 }