fmradio/fmradioengine/src/fmradioengine.cpp
branchRCL_3
changeset 8 3cb097cb90f8
parent 7 108d9820af01
child 20 97dcae98e602
equal deleted inserted replaced
7:108d9820af01 8:3cb097cb90f8
   167     // Publish antenna status as connected, we'll be notified later if it's not.
   167     // Publish antenna status as connected, we'll be notified later if it's not.
   168     iPubSub->PublishAntennaStatusL( EFMRadioPSHeadsetConnected );
   168     iPubSub->PublishAntennaStatusL( EFMRadioPSHeadsetConnected );
   169     
   169     
   170     iPubSub->PublishFrequencyDecimalCountL( 
   170     iPubSub->PublishFrequencyDecimalCountL( 
   171             TFMRadioPSFrequencyDecimalCount( iRadioSettings->DecimalCount() ) );
   171             TFMRadioPSFrequencyDecimalCount( iRadioSettings->DecimalCount() ) );
   172     
   172 
   173     if ( iRadioSettings->StartupCount() == 0 )
       
   174         {
       
   175         ResetPresetsL();
       
   176         }
       
   177     
       
   178     FTRACE(FPrint(_L("CRadioEngine::ConstructL() End ")));
   173     FTRACE(FPrint(_L("CRadioEngine::ConstructL() End ")));
   179     }
   174     }
   180     
   175     
   181 // ----------------------------------------------------
   176 // ----------------------------------------------------
   182 // CRadioEngine::ConnectLineL
   177 // CRadioEngine::ConnectLineL
   807     FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() Output = %d"), aAudioOutput));
   802     FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() Output = %d"), aAudioOutput));
   808     TInt tempError = KErrNone;
   803     TInt tempError = KErrNone;
   809     // use mute here to avoid any audio peaks during output change
   804     // use mute here to avoid any audio peaks during output change
   810     SetMuteOn( ETrue );
   805     SetMuteOn( ETrue );
   811 
   806 
   812     TBool btAudioConnected = EFalse;
       
   813     TRAPD( err, btAudioConnected = IsBTAccessoryConnectedL(); )
       
   814     if ( err != KErrNone )
       
   815         {
       
   816         btAudioConnected = ETrue;
       
   817         }
       
   818     
       
   819 #ifndef __ACCESSORY_FW
   807 #ifndef __ACCESSORY_FW
   820 
   808 
   821     tempError = iDosServerObserver->SetAudioRouting(aAudioOutput);
   809     tempError = iDosServerObserver->SetAudioRouting(aAudioOutput);
   822     FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() tempError = %d"), tempError));
   810     FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() tempError = %d"), tempError));
   823 
   811 
   824 #else
   812 #else
   825 
   813 
   826     CAudioOutput::TAudioOutputPreference outputPreference = CAudioOutput::EPrivate;
   814     CAudioOutput::TAudioOutputPreference outputPreference = CAudioOutput::EPrivate;
   827 
   815 
   828     if( btAudioConnected && !iHeadsetObserver->IsHeadsetAccessoryConnected() )
   816     if ( EFMRadioOutputHeadset == aAudioOutput )
   829         {
       
   830         FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() EPublic don't route to BT")));
       
   831         outputPreference = CAudioOutput::EPublic;
       
   832         }
       
   833     else if ( EFMRadioOutputHeadset == aAudioOutput )
       
   834         {
   817         {
   835         FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() Headset is set to Output")));
   818         FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() Headset is set to Output")));
   836         outputPreference = CAudioOutput::EPrivate;
   819         outputPreference = CAudioOutput::EPrivate;
   837         }
   820         }
   838     else if ( EFMRadioOutputIHF == aAudioOutput )
   821     else if ( EFMRadioOutputIHF == aAudioOutput )
   839         {
   822         {
   840         FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() IHF is set to Output")));
   823         FTRACE(FPrint(_L("CRadioEngine::SetAudioOutput() IHF is set to Output")));
   841         
   824         
   842         if ( iHeadsetObserver->IsHeadsetAccessoryConnected() )
       
   843             { //user has chosen 'Activate IHF' in options menu
       
   844             iHFOptionActivated = ETrue;
       
   845             }
       
   846         outputPreference = CAudioOutput::EPublic;
   825         outputPreference = CAudioOutput::EPublic;
   847         }
   826         }
   848 
   827 
   849 #ifndef __WINS
   828 #ifndef __WINS
   850     if ( iAudioOutput )
   829     if ( iAudioOutput )
  1023 //
  1002 //
  1024 void CRadioEngine::HeadsetAccessoryConnectedCallbackL()
  1003 void CRadioEngine::HeadsetAccessoryConnectedCallbackL()
  1025     {
  1004     {
  1026     FTRACE(FPrint(_L("CRadioEngine::HeadsetAccessoryConnectedCallbackL")));
  1005     FTRACE(FPrint(_L("CRadioEngine::HeadsetAccessoryConnectedCallbackL")));
  1027     // forward volume changes to headset
  1006     // forward volume changes to headset
  1028     if ( iHFOptionActivated )
  1007     SetAudioOutput( EFMRadioOutputHeadset );
  1029     	{
       
  1030     	iHFOptionActivated = EFalse;
       
  1031     	}
       
  1032     else
       
  1033     	{
       
  1034         SetAudioOutput( EFMRadioOutputHeadset );
       
  1035     	}
       
  1036     }
  1008     }
  1037 
  1009 
  1038 // ----------------------------------------------------
  1010 // ----------------------------------------------------
  1039 // CRadioEngine::HeadsetAccessoryDisconnectedCallbackL
  1011 // CRadioEngine::HeadsetAccessoryDisconnectedCallbackL
  1040 // ----------------------------------------------------
  1012 // ----------------------------------------------------
  2009     iRadioSettings->SetFrequency( aFrequency );
  1981     iRadioSettings->SetFrequency( aFrequency );
  2010     TRAP_IGNORE( iPubSub->PublishFrequencyL( aFrequency ); )
  1982     TRAP_IGNORE( iPubSub->PublishFrequencyL( aFrequency ); )
  2011     }
  1983     }
  2012 
  1984 
  2013 // ---------------------------------------------------------------------------
  1985 // ---------------------------------------------------------------------------
  2014 // CRadioEngine::ResetPresetsL
  1986 // CRadioEngine::PresetUrlL
  2015 // initialize channel frequencies
       
  2016 // ---------------------------------------------------------------------------
  1987 // ---------------------------------------------------------------------------
  2017 //
  1988 //
  2018 void CRadioEngine::ResetPresetsL()
  1989 EXPORT_C TInt CRadioEngine::PresetUrlL( TInt aIndex, TDes& aUrl )
  2019     {
  1990     {
  2020     FTRACE( FPrint( _L("CRadioEngine::ResetPresetsL()" ) ) );
  1991     FTRACE( FPrint( _L("CRadioEngine::PresetUrlL( Index %d, url: %S)"), aIndex, &aUrl ) );
  2021     TInt maxNumberOfPresets;
  1992     TInt err = KErrNone;
  2022     TStationName channelName;
  1993     TFmPresetUrl presetUrl;
  2023     TInt channelFrequency;
  1994     
  2024     
  1995     if ( presetUrl.MaxLength() <= aUrl.MaxLength() )
  2025     iPresetUtility->GetMaxNumberOfPresets( maxNumberOfPresets );
  1996         {
  2026 
  1997         iPresetUtility->GetPresetUrlL( aIndex, presetUrl );
  2027     for ( TInt i = 0; i < maxNumberOfPresets; i++ )
  1998         aUrl.Copy( presetUrl );
  2028         {
  1999         if ( !aUrl.Length() )
  2029         iPresetUtility->GetPresetL( i, channelName, channelFrequency );
  2000             {
  2030         
  2001             err = KErrNotFound;
  2031         if ( channelName.Length() == 0 && channelFrequency != KErrNotFound )
  2002             }            
  2032             {
  2003         }
  2033             // set empty name and frequency to KErrNotFound
  2004     else
  2034             iPresetUtility->SetPresetL( i, channelName, KErrNotFound );
  2005         {
  2035             }
  2006         err = KErrOverflow;
  2036         }
  2007         }
       
  2008     return err;
  2037     }
  2009     }
  2038 
  2010 
  2039 // ---------------------------------------------------------------------------
  2011 // ---------------------------------------------------------------------------
  2040 // CRadioEngine::IsBTAccessoryConnectedL
  2012 // CRadioEngine::DeletePresetL
  2041 // Returns ETrue if queried accessory is connected
  2013 // Delete preset. With index -1 all preset are reseted
  2042 // ---------------------------------------------------------------------------
  2014 // ---------------------------------------------------------------------------
  2043 //
  2015 //
  2044 TBool CRadioEngine::IsBTAccessoryConnectedL ( )
  2016 EXPORT_C void CRadioEngine::DeletePresetL( TInt aIndex )
  2045     {
  2017     {
  2046     FTRACE(FPrint(_L("CRadioEngine::IsBTAccessoryConnectedL ()" ) ) );
  2018     FTRACE( FPrint( _L("CRadioEngine::DeletePresetL( i: %d )"), aIndex ) );
  2047     TBool result = EFalse;
  2019     iPresetUtility->DeletePresetL( aIndex );
  2048     CAccMonitor* accMonitor = CAccMonitor::NewLC();
  2020     }
  2049 
  2021 
  2050     RConnectedAccessories connectedAccessories;
  2022 // ---------------------------------------------------------------------------
  2051     CleanupClosePushL( connectedAccessories );
  2023 // CRadioEngine::SaveUrlToCurrentPresetL
  2052 
  2024 // ---------------------------------------------------------------------------
  2053     accMonitor->GetConnectedAccessoriesL( connectedAccessories );
  2025 //
  2054     CAccMonitorInfo* accInfo = CAccMonitorInfo::NewLC();
  2026 EXPORT_C void CRadioEngine::SaveUrlToPresetL( TInt aIndex, const TDesC& aUrl )
  2055     TInt countOfArray = connectedAccessories.Count();
  2027     {
  2056 
  2028     FTRACE( FPrint( _L("CRadioEngine::SaveUrlToCurrentPresetL( i: %d Url: %S)"), aIndex, &aUrl ) );
  2057     for( TInt i = 0; i != countOfArray; i++ )
  2029     TFmPresetUrl presetUrl;
  2058         {
  2030     if ( aUrl.Length() <= presetUrl.MaxLength() )
  2059         TAccMonCapability connectionType = connectedAccessories[ i ]->AccPhysicalConnection();
  2031         {
  2060         if( connectionType == KAccMonBluetooth )
  2032         presetUrl.Copy( aUrl );
  2061            {
  2033         iPresetUtility->SetPresetUrlL( aIndex, presetUrl );
  2062            accInfo->CopyL( connectedAccessories[ i ] );
  2034         }
  2063            if ( accInfo->Exists(KAccMonStereoAudio) ||
  2035     }
  2064                     accInfo->Exists(KAccMonMonoAudio) )
  2036 
  2065                {
       
  2066                result = ETrue;
       
  2067                }
       
  2068            }
       
  2069         }
       
  2070     // Destroy the pointers from the array, because those are owned by the client
       
  2071     CleanupStack::PopAndDestroy( accInfo );
       
  2072     CleanupStack::PopAndDestroy( &connectedAccessories );
       
  2073     CleanupStack::PopAndDestroy( accMonitor );
       
  2074     return result;
       
  2075     }
       
  2076 // End of file
  2037 // End of file