diff -r f3d95d9c00ab -r 46974bebc798 radioengine/engine/inc/cradioengineimp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/radioengine/engine/inc/cradioengineimp.h Fri Mar 19 09:29:04 2010 +0200 @@ -0,0 +1,425 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#ifndef CRADIOENGINEIMP_H +#define CRADIOENGINEIMP_H + +#include +#include +#include + +#include "cradioengine.h" +#include "mradiosettingsobserver.h" +#include "mradiordsdataobserver.h" +#include "mradiosystemeventobserver.h" +#include "radioenginedef.h" + +class CRadioPubSub; +class CRadioRdsReceiverBase; +class CRadioNetworkInfoListener; +class MRadioEngineSettings; +class MRadioSettingsSetter; +class MRadioEngineObserver; +class MRadioScanObserver; + +/** + * Radio class takes care of the FM-radio side. + */ +NONSHARABLE_CLASS( CRadioEngineImp ) : public CRadioEngine + , public MRadioSystemEventObserver + , public MRadioFmTunerObserver + , public MRadioPlayerObserver + , public MRadioSettingsObserver + , public MRadioRdsDataObserver + { + friend class CRadioEngine; + +public: + + ~CRadioEngineImp(); + + void SetSystemEventCollector( CRadioSystemEventCollector* aCollector ); + void SetRadioSettings( CRadioSettings* aSettings ); + void SetRadioPubSub( CRadioPubSub* aPubSub ); + +private: + + CRadioEngineImp( CRadioAudioRouter* aAudioRouter ); + +// from base class CRadioEngine + + CRadioAudioRouter& AudioRouter() const; + CRadioSystemEventCollector& SystemEventCollector() const; + CRadioSettings& Settings() const; + CRadioPubSub* PubSub() const; + TRadioRegion DetermineRegion(); + void InitRadioL( TInt aRegionId, CRadioPubSub* aPubSub = 0 ); + TBool RadioInitialized() const; + void EnableAudio( TBool aEnable, TBool aDelay = ETrue ); + TBool RadioAudioEnabled() const; + void SetAudioOverride( TBool aOverride ); + void AddObserverL( MRadioEngineObserver* aObserver ); + void RemoveObserver( MRadioEngineObserver* aObserver ); + void SetAudioMode( TInt aAudioMode ); + TBool IsFrequencyValid( TUint32 aFrequency = 0 ) const; + void SetFrequency( TUint32 aFrequency, + RadioEngine::TRadioFrequencyEventReason aReason = RadioEngine::ERadioFrequencyEventReasonUnknown ); + void SetFrequencyFast( TUint32 aFrequency, + RadioEngine::TRadioFrequencyEventReason aReason = RadioEngine::ERadioFrequencyEventReasonUnknown ); + void StepToFrequency( RadioEngine::TRadioTuneDirection aDirection ); + void Seek( RadioEngine::TRadioTuneDirection aDirection ); + void CancelSeek(); + RadioEngine::TRadioSeeking Seeking() const; + void StartScan( MRadioScanObserver& aObserver ); + void StopScan( TInt aError = KErrCancel ); + void AdjustVolume( RadioEngine::TRadioVolumeSetDirection aDirection ); + void SetVolume( TInt aVolume ); + void SetVolumeMuted( TBool aMute ); + TBool IsAntennaAttached(); + TBool IsFmTransmitterActive() const; + void SetAntennaAttached( TBool aAntennaAttached ); + TInt MaxVolumeLevel() const; + TBool FrequencySetByRdsAf() const; + MRadioRdsReceiver& RdsReceiver(); + TBool IsAudioRoutingPossible() const; + TBool OkToPlay( TUint32 aFrequency ) const; + +private: + + /** Radio event notifications */ + enum TRadioEventNotification + { + ERadioEventPower = 1, + ERadioEventFrequency, + ERadioEventVolume, + ERadioEventMute, + ERadioEventAudioMode, + ERadioEventAntenna, + ERadioEventAudioRouting, + ERadioEventSeeking, + ERadioEventRegion, + ERadioEventFmTransmitter + }; + + /** + * Possible radio scan events. + */ + enum TRadioScanEvent + { + /** + * Scanning found a valid frequency. + */ + ERadioEventFrequencyScanned, + + /** + * Scanning is completed. + */ + ERadioEventScanCompleted + + }; + + enum TRadioInitialisationState + { + ERadioNotInitialized, + ERadioUtilitiesConstructed, + ERadioTunerControlGranted + }; + + void ConstructL(); + + /** + * Switches power on/off after a delay + * + * @param aPowerOn ETrue if power is to be switched on, + * EFalse if power is to be switched off + */ + void SwitchPower( TBool aPowerOn ); + + /** + * Callback for switching the radio power on + * + * @param aSelfPtr A pointer to CRadioEngineImp instance + * @return KErrNone + */ + static TInt StaticPowerOnCallback( TAny* aSelfPtr ); + + /** + * Callback for switching the radio power off + * + * @param aSelfPtr A pointer to CRadioEngineImp instance + * @return KErrNone + */ + static TInt StaticPowerOffCallback( TAny* aSelfPtr ); + + /** + * Switches radio power ON. + */ + void PowerOn(); + + /** + * Switches radio power OFF. + */ + void PowerOff(); + + /** + * Converts region code used internally by Visual Radio + * in to a frequency range by tuner ( TFmRadioFrequencyRange ) + * + * @param aRegionId VR region ID + * @return Frequency range + */ + TFmRadioFrequencyRange TunerFrequencyRangeForRegionId( TInt aRegionId ) const; + + /** + * Non-leaving version of DoNotifyRadioEventL. + * @param aRadioEvent event notification ( identification ) + * @param aErrorCode error code related to state change + */ + void NotifyRadioEvent( TInt aRadioEvent, TInt aErrorCode = KErrNone ); + + /** + * Leaving version of DoNotifyRadioEvent. + * @param aRadioEvent event notification ( identification ) + * @param aErrorCode error code related to state change + */ + void DoNotifyRadioEventL( TInt aRadioEvent, TInt aErrorCode = KErrNone ); + + /** + * Notifies the observer of a radio scan event. + * + * @param aEvent Event to notify. + * @param aObserver Scan observer. + * @param aError Error code the event completed with. + */ + void NotifyRadioScanEvent( TRadioScanEvent aEvent, MRadioScanObserver& aObserver, + TInt aError = KErrNone ); + + /** + * Notifies the observer of a radio scan event. + * + * @param aEvent Event to notify. + * @param aObserver Scan observer. + * @param aError Error code the event completed with. + */ + void DoNotifyRadioScanEventL( TRadioScanEvent aEvent, MRadioScanObserver& aObserver, + TInt aError ); + + /** + * Handles the change in audio routing + * + * @param aDestination The new routing destination + */ + void HandleAudioRoutingEvent( RadioEngine::TRadioAudioRoute aDestination ); + + /** + * Handles the change in power state + * + * @param aPowerOn The power state + * @param aErrorCode Error code related to state change + */ + void HandlePowerEvent( TBool aPowerOn, TInt aErrorCode = KErrNone ); + + /** + * Handles the change in power state + * + * @param aFrequency The current frequency + * @param aErrorCode Error code related to state change + */ + void HandleFrequencyEvent( TUint32 aFrequency, TInt aErrorCode = KErrNone ); + + /** + * Converts the volume used by Visual Radio to volume used by Radio Utility + * + * @param aUiVolume The Volume used by Visual Radio + * @return The volume used by Radio Utility + */ + TInt TunerVolumeForUiVolume( TInt aUiVolume ); + +// from base class MRadioSystemEventObserver + + void HandleSystemEventL( TRadioSystemEventType aEventType ); + +// from base class MRadioFmTunerObserver + + void MrftoRequestTunerControlComplete( TInt aError ); + void MrftoSetFrequencyRangeComplete( TInt aError ); + void MrftoSetFrequencyComplete( TInt aError ); + void MrftoStationSeekComplete( TInt aError, TInt aFrequency ); + void MrftoFmTransmitterStatusChange( TBool aActive ); + void MrftoAntennaStatusChange( TBool aAttached ); + void MrftoOfflineModeStatusChange( TBool aOfflineMode ); + void MrftoFrequencyRangeChange( TFmRadioFrequencyRange aBand ); + void MrftoFrequencyChange( TInt aNewFrequency ); + void MrftoForcedMonoChange( TBool aForcedMono ); + void MrftoSquelchChange( TBool aSquelch ); + +// from base class MRadioPlayerObserver + + void MrpoStateChange( TPlayerState aState, TInt aError ); + void MrpoVolumeChange( TInt aVolume ); + void MrpoMuteChange( TBool aMute ); + void MrpoBalanceChange( TInt aLeftPercentage, TInt aRightPercentage ); + +// from base class MRadioSettingsObserver + + void RdsAfSearchSettingChangedL( TBool aEnabled ); + void RegionSettingChangedL( TInt aRegion ); + +// from base class MRadioRdsDataObserver + + void RdsAvailable( TUint32 /*aFrequency*/, TBool /*aAvailable*/ ) {} + void RdsAfSearchBegin(); + void RdsAfSearchEnd( TUint32 aFrequency, TInt aError ); + void RdsAfSearchStateChange( TBool /*aEnabled*/ ) {} + void RdsDataProgrammeService( TUint32 /*aFrequency*/, const TDesC& /*aProgramService*/ ) {} + void RdsDataRadioText( TUint32 /*aFrequency*/, const TDesC& /*aRadioText*/ ) {} + void RdsDataRadioTextPlus( TUint32 /*aFrequency*/, const TInt /*aRadioTextPlusClass*/, const TDesC& /*aRadioText*/ ) {} + void RdsDataGenre( TUint32 /*aFrequency*/, const TInt /*aGenre*/ ) {} + void RdsDataPiCode( TUint32 /*aFrequency*/, const TInt /*aPiCode*/ ) {} + +// New functions + + /** + * Tries to figure the region out based on current mobile network id + */ + TRadioRegion RegionFromMobileNetwork() const; + + /** + * Tries to figure the region out based on timezone selection + */ + TRadioRegion RegionFromTimezone() const; + + /** + * Performs the timezone-based check + */ + TRadioRegion DoRegionFromTimezoneL() const; + +private: // data + + /** + * Array of state change observers. + */ + RPointerArray iObservers; + + /** + * A pointer to system event collector + * Own. + */ + CRadioSystemEventCollector* iSystemEventCollector; + + /** + * Radio settings + * Own. + */ + CRadioSettings* iSettings; + + /** + * Network info listener + * Own. + */ + CRadioNetworkInfoListener* iNetworkInfoListener; + + /** + * Controls the radio hardware + */ + CRadioUtility* iRadioUtility; + + /** + * Controls FM radio tuner. Not owned. + */ + CRadioFmTunerUtility* iTunerUtility; + + /** + * Controls the radio player. Not owned. + */ + CRadioPlayerUtility* iPlayerUtility; + + /** + * Receives and notifies of the RDS data + */ + CRadioRdsReceiverBase* iRdsReceiver; + + /** + * State for radio initialization + */ + TRadioInitialisationState iRadioInitializationState; + + /** + * Radio on/off timer. + */ + CPeriodic* iRadioTimer; + + /** + * If this is true, audio resource availability is ignored on next radio power on + */ + TBool iOverrideAudioResources; + + /** + * Direction of the previous seek request, needed for canceling + */ + RadioEngine::TRadioSeeking iSeekingState; + + /** + * Antenna state. + */ + TBool iAntennaAttached; + + /** + * Radio enabling state + */ + TBool iRadioEnabled; + + /** + * ETrue if frequency was set by RDS AF + */ + TBool iFrequencySetByRdsAf; + + /** + * The state of the fm transmitter + */ + TBool iFmTransmitterActive; + + /** + * Cause for the ongoing frequency change operation. + */ + RadioEngine::TRadioFrequencyEventReason iFreqEventReason; + + /** + * Publish&Subscribe object. Can be NULL. + * Owned if set + */ + CRadioPubSub* iPubSub; + + /** + * Radio scan observer. NULL when scanning is not ongoing + * Not owned. + */ + MRadioScanObserver* iScanObserver; + + /** + * The previously scanned frequency, or KErrNotFound if none. + */ + TUint32 iPreviousScannedFrequency; + + /** + * The state of mute before scan has been started. + */ + TBool iPreviousMuteState; + + }; + +#endif // CRADIOENGINEIMP_H +