radioengine/engine/inc/cradioengineimp.h
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 #ifndef CRADIOENGINEIMP_H
       
    18 #define CRADIOENGINEIMP_H
       
    19 
       
    20 // System includes
       
    21 #include <RadioFmTunerUtility.h>
       
    22 #include <RadioPlayerUtility.h>
       
    23 #include <RadioUtility.h>
       
    24 
       
    25 // User includes
       
    26 #include "cradioengine.h"
       
    27 #include "mradiosettingsobserver.h"
       
    28 #include "mradiordsdataobserver.h"
       
    29 #include "mradiosystemeventobserver.h"
       
    30 #include "radioenginedef.h"
       
    31 
       
    32 // Forward declarations
       
    33 class CRadioRdsReceiverBase;
       
    34 class CRadioNetworkInfoListener;
       
    35 class MRadioEngineSettings;
       
    36 class MRadioSettingsSetter;
       
    37 class MRadioEngineObserver;
       
    38 
       
    39 /**
       
    40  * Radio class takes care of the FM-radio side.
       
    41  */
       
    42 NONSHARABLE_CLASS( CRadioEngineImp ) : public CRadioEngine
       
    43                                      , public MRadioSystemEventObserver
       
    44                                      , public MRadioFmTunerObserver
       
    45                                      , public MRadioPlayerObserver
       
    46                                      , public MRadioSettingsObserver
       
    47                                      , public MRadioRdsDataObserver
       
    48     {
       
    49     friend class CRadioEngine;
       
    50 
       
    51 public:
       
    52 
       
    53     ~CRadioEngineImp();
       
    54 
       
    55     void SetSystemEventCollector( CRadioSystemEventCollector* aCollector );
       
    56     void SetRadioSettings( CRadioSettings* aSettings );
       
    57 
       
    58 private:
       
    59 
       
    60     CRadioEngineImp( CRadioAudioRouter* aAudioRouter );
       
    61 
       
    62 // from base class CRadioEngine
       
    63 
       
    64     CRadioAudioRouter& AudioRouter() const;
       
    65     CRadioSystemEventCollector& SystemEventCollector() const;
       
    66     CRadioSettings& Settings() const;
       
    67     TRadioRegion DetermineRegion();
       
    68     void InitRadioL( TInt aRegionId );
       
    69     TBool RadioInitialized() const;
       
    70     void EnableAudio( TBool aEnable, TBool aDelay = ETrue );
       
    71     TBool RadioAudioEnabled() const;
       
    72     void SetAudioOverride( TBool aOverride );
       
    73     void AddObserverL( MRadioEngineObserver* aObserver );
       
    74     void RemoveObserver( MRadioEngineObserver* aObserver );
       
    75     void SetAudioMode( TInt aAudioMode );
       
    76     TBool IsFrequencyValid( TUint32 aFrequency = 0 ) const;
       
    77     void SetManualSeekMode( TBool aManualSeekActive );
       
    78     TBool IsInManualSeekMode() const;
       
    79     void SetFrequency( TUint32 aFrequency,
       
    80             RadioEngine::TRadioFrequencyEventReason aReason = RadioEngine::ERadioFrequencyEventReasonUnknown );
       
    81     void Seek( RadioEngine::TRadioTuneDirection aDirection );
       
    82     void CancelSeek();
       
    83     RadioEngine::TRadioSeeking Seeking() const;
       
    84     void AdjustVolume( RadioEngine::TRadioVolumeSetDirection aDirection );
       
    85     void SetVolume( TInt aVolume );
       
    86     void SetVolumeMuted( TBool aMute, TBool aUpdateSettings = ETrue );
       
    87     TBool IsAntennaAttached();
       
    88     TBool IsFmTransmitterActive() const;
       
    89     void SetAntennaAttached( TBool aAntennaAttached );
       
    90     TInt MaxVolumeLevel() const;
       
    91     TBool FrequencySetByRdsAf() const;
       
    92     MRadioRdsReceiver& RdsReceiver();
       
    93     TBool IsAudioRoutingPossible() const;
       
    94     TBool OkToPlay( TUint32 aFrequency ) const;
       
    95 
       
    96 private:
       
    97 
       
    98     /** Radio event notifications */
       
    99     enum TRadioEventNotification
       
   100         {
       
   101         ERadioEventPower = 1,
       
   102         ERadioEventFrequency,
       
   103         ERadioEventVolume,
       
   104         ERadioEventMute,
       
   105         ERadioEventAudioMode,
       
   106         ERadioEventAntenna,
       
   107         ERadioEventAudioRouting,
       
   108         ERadioEventSeeking,
       
   109         ERadioEventRegion,
       
   110         ERadioEventFmTransmitter
       
   111         };
       
   112 
       
   113     enum TRadioInitialisationState
       
   114         {
       
   115         ERadioNotInitialized,
       
   116         ERadioUtilitiesConstructed,
       
   117         ERadioTunerControlRequested,
       
   118         ERadioTunerControlGranted
       
   119         };
       
   120 
       
   121     void ConstructL();
       
   122 
       
   123     /**
       
   124      * Switches power on/off after a delay
       
   125      *
       
   126      * @param aPowerOn ETrue if power is to be switched on,
       
   127      *                 EFalse if power is to be switched off
       
   128      */
       
   129     void SwitchPower( TBool aPowerOn );
       
   130 
       
   131     /**
       
   132      * Callback for switching the radio power on
       
   133      *
       
   134      * @param aSelfPtr A pointer to CRadioEngineImp instance
       
   135      * @return KErrNone
       
   136      */
       
   137     static TInt StaticPowerOnCallback( TAny* aSelfPtr );
       
   138 
       
   139     /**
       
   140      * Callback for switching the radio power off
       
   141      *
       
   142      * @param aSelfPtr A pointer to CRadioEngineImp instance
       
   143      * @return KErrNone
       
   144      */
       
   145     static TInt StaticPowerOffCallback( TAny* aSelfPtr );
       
   146 
       
   147     /**
       
   148      * Switches radio power ON.
       
   149      */
       
   150     void PowerOn();
       
   151 
       
   152     /**
       
   153      * Switches radio power OFF.
       
   154      */
       
   155     void PowerOff();
       
   156 
       
   157     /**
       
   158      * Requests tuner control from tuner utility
       
   159      */
       
   160     void RequestTunerControl();
       
   161 
       
   162     /**
       
   163      * Converts region code used internally by Visual Radio
       
   164      * in to a frequency range by tuner ( TFmRadioFrequencyRange )
       
   165      *
       
   166      * @param aRegionId VR region ID
       
   167      * @return Frequency range
       
   168      */
       
   169     TFmRadioFrequencyRange TunerFrequencyRangeForRegionId( TInt aRegionId ) const;
       
   170 
       
   171     /**
       
   172      * Non-leaving version of DoNotifyRadioEventL.
       
   173      * @param aRadioEvent event notification ( identification )
       
   174      * @param aErrorCode error code related to state change
       
   175      */
       
   176     void NotifyRadioEvent( TInt aRadioEvent, TInt aErrorCode = KErrNone );
       
   177 
       
   178     /**
       
   179      * Leaving version of DoNotifyRadioEvent.
       
   180      * @param aRadioEvent event notification ( identification )
       
   181      * @param aErrorCode error code related to state change
       
   182      */
       
   183     void DoNotifyRadioEventL( TInt aRadioEvent, TInt aErrorCode = KErrNone );
       
   184 
       
   185     /**
       
   186      * Handles the change in audio routing
       
   187      *
       
   188      * @param aDestination The new routing destination
       
   189      */
       
   190     void HandleAudioRoutingEvent( RadioEngine::TRadioAudioRoute aDestination );
       
   191 
       
   192     /**
       
   193      * Handles the change in power state
       
   194      *
       
   195      * @param aPowerOn The power state
       
   196      * @param aErrorCode Error code related to state change
       
   197      */
       
   198     void HandlePowerEvent( TBool aPowerOn, TInt aErrorCode = KErrNone );
       
   199 
       
   200     /**
       
   201      * Handles the change in power state
       
   202      *
       
   203      * @param aFrequency The current frequency
       
   204      * @param aErrorCode Error code related to state change
       
   205      */
       
   206     void HandleFrequencyEvent( TUint32 aFrequency, TInt aErrorCode = KErrNone );
       
   207 
       
   208     /**
       
   209      * Converts the volume used by Visual Radio to volume used by Radio Utility
       
   210      *
       
   211      * @param aUiVolume The Volume used by Visual Radio
       
   212      * @return The volume used by Radio Utility
       
   213      */
       
   214     TInt TunerVolumeForUiVolume( TInt aUiVolume );
       
   215 
       
   216 // from base class MRadioSystemEventObserver
       
   217 
       
   218     void HandleSystemEventL( TRadioSystemEventType aEventType );
       
   219 
       
   220 // from base class MRadioFmTunerObserver
       
   221 
       
   222     void MrftoRequestTunerControlComplete( TInt aError );
       
   223     void MrftoSetFrequencyRangeComplete( TInt aError );
       
   224     void MrftoSetFrequencyComplete( TInt aError );
       
   225     void MrftoStationSeekComplete( TInt aError, TInt aFrequency );
       
   226     void MrftoFmTransmitterStatusChange( TBool aActive );
       
   227     void MrftoAntennaStatusChange( TBool aAttached );
       
   228     void MrftoOfflineModeStatusChange( TBool aOfflineMode );
       
   229     void MrftoFrequencyRangeChange( TFmRadioFrequencyRange aBand );
       
   230     void MrftoFrequencyChange( TInt aNewFrequency );
       
   231     void MrftoForcedMonoChange( TBool aForcedMono );
       
   232     void MrftoSquelchChange( TBool aSquelch );
       
   233 
       
   234 // from base class MRadioPlayerObserver
       
   235 
       
   236     void MrpoStateChange( TPlayerState aState, TInt aError );
       
   237     void MrpoVolumeChange( TInt aVolume );
       
   238     void MrpoMuteChange( TBool aMute );
       
   239     void MrpoBalanceChange( TInt aLeftPercentage, TInt aRightPercentage );
       
   240 
       
   241 // from base class MRadioSettingsObserver
       
   242 
       
   243     void RdsAfSearchSettingChangedL( TBool aEnabled );
       
   244     void RegionSettingChangedL( TInt aRegion );
       
   245 
       
   246 // from base class MRadioRdsDataObserver
       
   247 
       
   248     void RdsAvailable( TUint32 /*aFrequency*/, TBool /*aAvailable*/ ) {}
       
   249     void RdsAfSearchBegin();
       
   250     void RdsAfSearchEnd( TUint32 aFrequency, TInt aError );
       
   251     void RdsAfSearchStateChange( TBool /*aEnabled*/ ) {}
       
   252     void RdsDataProgrammeService( TUint32 /*aFrequency*/, const TDesC& /*aProgramService*/ ) {}
       
   253     void RdsDataRadioText( TUint32 /*aFrequency*/, const TDesC& /*aRadioText*/ ) {}
       
   254     void RdsDataRadioTextPlus( TUint32 /*aFrequency*/, const TInt /*aRadioTextPlusClass*/, const TDesC& /*aRadioText*/ ) {}
       
   255     void RdsDataGenre( TUint32 /*aFrequency*/, const TInt /*aGenre*/ ) {}
       
   256     void RdsDataPiCode( TUint32 /*aFrequency*/, const TInt /*aPiCode*/ ) {}
       
   257 
       
   258 // New functions
       
   259 
       
   260     /**
       
   261      * Tries to figure the region out based on current mobile network id
       
   262      */
       
   263     TRadioRegion RegionFromMobileNetwork() const;
       
   264 
       
   265     /**
       
   266      * Tries to figure the region out based on timezone selection
       
   267      */
       
   268     TRadioRegion RegionFromTimezone() const;
       
   269 
       
   270     /**
       
   271      * Performs the timezone-based check
       
   272      */
       
   273     TRadioRegion DoRegionFromTimezoneL() const;
       
   274 
       
   275 private: // data
       
   276 
       
   277     /**
       
   278      * Array of state change observers.
       
   279      */
       
   280     RPointerArray<MRadioEngineObserver>         iObservers;
       
   281 
       
   282     /**
       
   283      * A pointer to system event collector
       
   284      * Own.
       
   285      */
       
   286     CRadioSystemEventCollector*                 iSystemEventCollector;
       
   287 
       
   288     /**
       
   289      * Radio settings
       
   290      * Own.
       
   291      */
       
   292     CRadioSettings*                             iSettings;
       
   293 
       
   294     /**
       
   295      * Network info listener
       
   296      * Own.
       
   297      */
       
   298     CRadioNetworkInfoListener*                  iNetworkInfoListener;
       
   299 
       
   300     /**
       
   301      * Controls the radio hardware
       
   302      */
       
   303     CRadioUtility*                              iRadioUtility;
       
   304 
       
   305     /**
       
   306      * Controls FM radio tuner. Not owned.
       
   307      */
       
   308     CRadioFmTunerUtility*                       iTunerUtility;
       
   309 
       
   310     /**
       
   311      * Controls the radio player. Not owned.
       
   312      */
       
   313     CRadioPlayerUtility*                        iPlayerUtility;
       
   314 
       
   315     /**
       
   316      * Receives and notifies of the RDS data
       
   317      */
       
   318     CRadioRdsReceiverBase*                      iRdsReceiver;
       
   319 
       
   320     /**
       
   321      * State for radio initialization
       
   322      */
       
   323     TRadioInitialisationState                   iRadioInitializationState;
       
   324 
       
   325     /**
       
   326      * Radio on/off timer.
       
   327      */
       
   328     CPeriodic*                                  iRadioTimer;
       
   329 
       
   330     /**
       
   331     * If this is true, audio resource availability is ignored on next radio power on
       
   332     */
       
   333     TBool                                       iOverrideAudioResources;
       
   334 
       
   335     /**
       
   336      * Direction of the previous seek request, needed for canceling
       
   337      */
       
   338     RadioEngine::TRadioSeeking                  iSeekingState;
       
   339 
       
   340     /**
       
   341      * Antenna state.
       
   342      */
       
   343     TBool                                       iAntennaAttached;
       
   344 
       
   345     /**
       
   346      * Radio enabling state
       
   347      */
       
   348     TBool                                       iRadioEnabled;
       
   349 
       
   350     /**
       
   351      * ETrue if frequency was set by RDS AF
       
   352      */
       
   353     TBool                                       iFrequencySetByRdsAf;
       
   354 
       
   355     /**
       
   356      * The state of the fm transmitter
       
   357      */
       
   358     TBool                                       iFmTransmitterActive;
       
   359 
       
   360     /**
       
   361      * Cause for the ongoing frequency change operation.
       
   362      */
       
   363     RadioEngine::TRadioFrequencyEventReason     iFreqEventReason;
       
   364 
       
   365     /**
       
   366      * The previously scanned frequency, or <code>KErrNotFound</code> if none.
       
   367      */
       
   368     TUint32                                     iPreviousScannedFrequency;
       
   369 
       
   370     /**
       
   371      * The state of mute before scan has been started.
       
   372      */
       
   373     TBool                                       iPreviousMuteState;
       
   374 
       
   375     /**
       
   376      * Manual seek mode flag
       
   377      */
       
   378     TBool                                       iManualSeekMode;
       
   379 
       
   380     };
       
   381 
       
   382 #endif  // CRADIOENGINEIMP_H
       
   383