fmradio/fmradioengine/src/fmradiordsreceiverbase.cpp
changeset 0 f3d95d9c00ab
equal deleted inserted replaced
-1:000000000000 0:f3d95d9c00ab
       
     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:  The RDS receiver implementation for FM Radio
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "fmradiordsreceiverbase.h"
       
    20 #include "fmradiopubsub.h"
       
    21 #include "fmradioengineradiosettings.h"
       
    22 
       
    23 // The delay, in microseconds, after which RDS PS name is concidered static
       
    24 const TInt KFMRadioStaticRdsPsNameDelay = 10000000; 
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CFMRadioRdsReceiverBase::CFMRadioRdsReceiverBase
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CFMRadioRdsReceiverBase::CFMRadioRdsReceiverBase( TRadioSettings& aSettings ) : iSettings(aSettings)
       
    33     {
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CFMRadioRdsReceiverBase::BaseConstructL
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 void CFMRadioRdsReceiverBase::BaseConstructL()
       
    41     {
       
    42     iPsName = HBufC::NewL( TRdsPSName().MaxLength() );
       
    43     iRadioText = HBufC::NewL( TRdsRadioText().MaxLength() );
       
    44     iPsNameTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CFMRadioRdsReceiverBase::~CFMRadioRdsReceiverBase
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CFMRadioRdsReceiverBase::~CFMRadioRdsReceiverBase()
       
    52     {
       
    53     iObservers.Close();
       
    54     delete iPsName;
       
    55     delete iRadioText;
       
    56     delete iPsNameTimer;
       
    57     
       
    58     iProgramWebUrl.Close();
       
    59     iArtistName.Close();
       
    60     iSongName.Close();
       
    61     iAlbumName.Close();
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CFMRadioRdsReceiverBase::AddObserver
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C void CFMRadioRdsReceiverBase::AddObserver( MFMRadioRdsObserver* aObserver )
       
    69     {
       
    70     TInt index = iObservers.FindInAddressOrder( aObserver );
       
    71     if( index == KErrNotFound )
       
    72         {
       
    73         iObservers.InsertInAddressOrder( aObserver );
       
    74         }
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CFMRadioRdsReceiverBase::RemoveObserver
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C void CFMRadioRdsReceiverBase::RemoveObserver( MFMRadioRdsObserver* aObserver )
       
    82     {
       
    83     TInt index = iObservers.FindInAddressOrder( aObserver );
       
    84 
       
    85     if( index >= 0 )
       
    86         {
       
    87         iObservers.Remove( index );
       
    88         }
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CFMRadioRdsReceiverBase::AutomaticSwitchingEnabled
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C TBool CFMRadioRdsReceiverBase::AutomaticSwitchingEnabled() const
       
    96     {
       
    97     return iAfEnabled;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CFMRadioRdsReceiverBase::ProgrammeService
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 EXPORT_C const TDesC& CFMRadioRdsReceiverBase::ProgrammeService() const
       
   105     {
       
   106     return *iPsName;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CFMRadioRdsReceiverBase::ProgrammeServiceNameType
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C CFMRadioRdsReceiverBase::TFMRadioProgrammeSeviceType CFMRadioRdsReceiverBase::ProgrammeServiceNameType() const
       
   114     {
       
   115     return iPsNameType;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CFMRadioRdsReceiverBase::SignalAvailable
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C TBool CFMRadioRdsReceiverBase::SignalAvailable() const
       
   123     {
       
   124     return iSignalAvailable;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CFMRadioRdsReceiverBase::RtPlusWebUrl
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C const TDesC& CFMRadioRdsReceiverBase::RtPlusProgramUrl() const
       
   132     {
       
   133     return iProgramWebUrl;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CFMRadioRdsReceiverBase::RtPlusArtist
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C const TDesC& CFMRadioRdsReceiverBase::RtPlusArtist() const
       
   141     {
       
   142     return iArtistName;
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CFMRadioRdsReceiverBase::RtPlusAlbum
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C const TDesC& CFMRadioRdsReceiverBase::RtPlusAlbum() const
       
   150     {
       
   151     return iAlbumName;
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CFMRadioRdsReceiverBase::RtPlusSong
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 EXPORT_C const TDesC& CFMRadioRdsReceiverBase::RtPlusSong() const
       
   159     {
       
   160     return iSongName;
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CFMRadioRdsReceiverBase::SetAutomaticSwitchingL
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CFMRadioRdsReceiverBase::SetAutomaticSwitchingL( TBool aEnable )
       
   168     {
       
   169     iAfEnabled = aEnable;
       
   170     for( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   171         {
       
   172         iObservers[i]->RdsAfSearchStateChange( iAfEnabled );
       
   173         }
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CFMRadioRdsReceiverBase::ClearRdsInformation
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CFMRadioRdsReceiverBase::ClearRdsInformation()
       
   181     {
       
   182     TRdsPSName name;
       
   183     TRdsRadioText radioText;
       
   184     iPsNameTimer->Cancel();
       
   185     iPsNameType = EFMRadioPSNameStaticAssumed;
       
   186     MrroRdsDataPS( name );
       
   187     MrroRdsDataRT( radioText );
       
   188     iProgramWebUrl.Close();
       
   189     iArtistName.Close();
       
   190     iSongName.Close();
       
   191     iAlbumName.Close();
       
   192     MrroRdsEventSignalChange( EFalse );
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CFMRadioRdsReceiverBase::StaticPsNameTimerCallback
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 TInt CFMRadioRdsReceiverBase::StaticPsNameTimerCallback( TAny* aSelf )
       
   200     {
       
   201     CFMRadioRdsReceiverBase* self = static_cast<CFMRadioRdsReceiverBase*>( aSelf );
       
   202     if( self )
       
   203         {
       
   204         self->iPsNameTimer->Cancel();
       
   205         if ( self->iPsNameType == EFMRadioPSNameStaticAssumed )
       
   206             {
       
   207             self->iPsNameType = EFMRadioPSNameStatic;
       
   208             for( TInt i = 0 ; i < self->iObservers.Count() ; i++ )
       
   209                 {
       
   210                 self->iObservers[i]->RdsDataPsNameIsStatic( ETrue );
       
   211                 }
       
   212             }
       
   213         }
       
   214     return KErrNone;
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CFMRadioRdsReceiverBase::HandleRdsDataRTplusL
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CFMRadioRdsReceiverBase::HandleRdsDataRTplusL( TRdsRTplusClass aRtPlusClass, TRdsRadioText& aRtPlusData )
       
   222     {
       
   223     TBool dataChanged = EFalse;
       
   224     switch (aRtPlusClass)
       
   225         {
       
   226         case ERTplusItemTitle:
       
   227             if ( aRtPlusData != iSongName )
       
   228                 {
       
   229                 dataChanged = ETrue;
       
   230                 iSongName.Close();
       
   231                 iSongName.CreateL( aRtPlusData );
       
   232                 }
       
   233             break;
       
   234         case ERTplusItemArtist:
       
   235         case ERTplusItemBand:
       
   236             if ( aRtPlusData != iArtistName )
       
   237                 {
       
   238                 dataChanged = ETrue;
       
   239                 iArtistName.Close();
       
   240                 iArtistName.CreateL( aRtPlusData );
       
   241                 }
       
   242             break;
       
   243         case ERTplusItemAlbum:
       
   244             if ( aRtPlusData != iAlbumName )
       
   245                 {
       
   246                 dataChanged = ETrue;
       
   247                 iAlbumName.Close();
       
   248                 iAlbumName.CreateL( aRtPlusData );
       
   249                 }
       
   250             break;
       
   251         case ERTplusProgramHomepage:
       
   252             {
       
   253             if ( aRtPlusData != iProgramWebUrl )
       
   254                 {
       
   255                 dataChanged = ETrue;
       
   256                 iProgramWebUrl.Close();
       
   257                 iProgramWebUrl.CreateL( aRtPlusData );
       
   258                 }
       
   259             break;
       
   260             }
       
   261         default:
       
   262             // Let uncached values go through
       
   263             dataChanged = ETrue;
       
   264             break;
       
   265         }
       
   266     
       
   267     if ( dataChanged )
       
   268         {
       
   269         for( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   270             {
       
   271             iObservers[i]->RdsDataRadioTextPlus( aRtPlusClass, aRtPlusData );
       
   272             }
       
   273         }
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CFMRadioRdsReceiverBase::MrroStationSeekByPTYComplete
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CFMRadioRdsReceiverBase::MrroStationSeekByPTYComplete( TInt /*aError*/, TInt /*aFrequency*/ )
       
   281     {
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CFMRadioRdsReceiverBase::MrroStationSeekByTAComplete
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CFMRadioRdsReceiverBase::MrroStationSeekByTAComplete( TInt /*aError*/, TInt /*aFrequency*/ )
       
   289     {
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CFMRadioRdsReceiverBase::MrroStationSeekByTPComplete
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CFMRadioRdsReceiverBase::MrroStationSeekByTPComplete( TInt /*aError*/, TInt /*aFrequency*/ )
       
   297     {
       
   298     }
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // CFMRadioRdsReceiverBase::MrroGetFreqByPTYComplete
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CFMRadioRdsReceiverBase::MrroGetFreqByPTYComplete( TInt /*aError*/, RArray<TInt>& /*aFreqList*/ )
       
   305     {
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // CFMRadioRdsReceiverBase::MrroGetFreqByTAComplete
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 void CFMRadioRdsReceiverBase::MrroGetFreqByTAComplete( TInt /*aError*/, RArray<TInt>& /*aFreqList*/ )
       
   313     {
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CFMRadioRdsReceiverBase::MrroGetPSByPTYComplete
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CFMRadioRdsReceiverBase::MrroGetPSByPTYComplete( TInt /*aError*/, RArray<TRdsPSName>& /*aPsList*/ )
       
   321     {
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // CFMRadioRdsReceiverBase::MrroGetPSByTAComplete
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CFMRadioRdsReceiverBase::MrroGetPSByTAComplete( TInt /*aError*/, RArray<TRdsPSName>& /*aPsList*/ )
       
   329     {
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // CFMRadioRdsReceiverBase::MrroRdsDataPI
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 void CFMRadioRdsReceiverBase::MrroRdsDataPI( TInt /*aPi*/ )
       
   337     {
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // CFMRadioRdsReceiverBase::MrroRdsDataPTY
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 void CFMRadioRdsReceiverBase::MrroRdsDataPTY( TRdsProgrammeType /*aPty*/ )
       
   345     {
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // CFMRadioRdsReceiverBase::MrroRdsDataPS
       
   350 // Notifies of the New Programme Service data
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 void CFMRadioRdsReceiverBase::MrroRdsDataPS( TRdsPSName& aPs )
       
   354     {
       
   355     TBool reportStaticState = EFalse;
       
   356     if ( iPsName->Length() && aPs.Length() )
       
   357         {
       
   358         if ( *iPsName != aPs && iPsNameTimer->IsActive() )
       
   359             {
       
   360             // PS existed and it changed, cancel the timer as it is not static name anymore
       
   361             iPsNameTimer->Cancel();
       
   362             iPsNameType = EFMRadioPSNameDynamic;
       
   363             reportStaticState = ETrue;
       
   364             }
       
   365         else
       
   366             {
       
   367             if ( iPsNameType == EFMRadioPSNameStaticAssumed && !iPsNameTimer->IsActive() )
       
   368                 {
       
   369                 // The timer should be reactivated in order to complete the determination
       
   370                 iPsNameTimer->Start( KFMRadioStaticRdsPsNameDelay, 
       
   371                                      0, 
       
   372                                      TCallBack( CFMRadioRdsReceiverBase::StaticPsNameTimerCallback, this ) );
       
   373                 }
       
   374             }
       
   375         }
       
   376     else if ( !iPsName->Length() && aPs.Length() )
       
   377         {
       
   378         // PS name is set for the first time, start the timer to see if it is a static one
       
   379         iPsNameTimer->Cancel();
       
   380         iPsNameTimer->Start( KFMRadioStaticRdsPsNameDelay, 
       
   381                              0, 
       
   382                              TCallBack( CFMRadioRdsReceiverBase::StaticPsNameTimerCallback, this ) );
       
   383         }
       
   384     else
       
   385         {
       
   386         // PS name is reset
       
   387         }
       
   388     
       
   389     iPsName->Des().Copy( aPs );
       
   390     
       
   391     if ( iPubSub )
       
   392         {
       
   393         TRAP_IGNORE( iPubSub->PublishRDSProgramServiceL( *iPsName ));
       
   394         }
       
   395  
       
   396     for( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   397         {
       
   398         iObservers[i]->RdsDataProgrammeService( *iPsName );
       
   399         if( reportStaticState )
       
   400             {
       
   401             iObservers[i]->RdsDataPsNameIsStatic( iPsNameType == EFMRadioPSNameStatic );
       
   402             }
       
   403         }
       
   404     }
       
   405 
       
   406 // ---------------------------------------------------------------------------
       
   407 // CFMRadioRdsReceiverBase::MrroRdsDataRT
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 void CFMRadioRdsReceiverBase::MrroRdsDataRT( TRdsRadioText& aRt )
       
   411     { 
       
   412     iRadioText->Des().Copy( aRt );
       
   413     for( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   414         {
       
   415         iObservers[i]->RdsDataRadioText( *iRadioText );
       
   416         }
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // CFMRadioRdsReceiverBase::MrroRdsDataCT
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 void CFMRadioRdsReceiverBase::MrroRdsDataCT( TDateTime& /*aCt*/ )
       
   424     {
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // CFMRadioRdsReceiverBase::MrroRdsDataTA
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CFMRadioRdsReceiverBase::MrroRdsDataTA( TBool /*aTaOn*/ )
       
   432     {
       
   433     }
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // CFMRadioRdsReceiverBase::MrroRdsDataRTplus
       
   437 // ---------------------------------------------------------------------------
       
   438 //
       
   439 void CFMRadioRdsReceiverBase::MrroRdsDataRTplus( TRdsRTplusClass aRtPlusClass, TRdsRadioText& aRtPlusData )
       
   440     {
       
   441     TRAP_IGNORE( HandleRdsDataRTplusL( aRtPlusClass, aRtPlusData ) )
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // CFMRadioRdsReceiverBase::MrroRdsSearchBeginAF
       
   446 // Notifies of the start of Alternate Frequency search
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 void CFMRadioRdsReceiverBase::MrroRdsSearchBeginAF()
       
   450     {
       
   451     for( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   452         {
       
   453         iObservers[i]->RdsAfSearchBegin();
       
   454         }
       
   455     }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 // CFMRadioRdsReceiverBase::MrroRdsSearchBeginAF
       
   459 // Notifies of the end of Alternate Frequency search
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 void CFMRadioRdsReceiverBase::MrroRdsSearchEndAF( TInt aError, TInt aFrequency )
       
   463     {
       
   464     for( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   465         {
       
   466         // Radio utility uses Hz, UI uses kHz. It's ok to divide with 1000, possible lost fractions are useless.
       
   467         iObservers[i]->RdsAfSearchEnd( aFrequency / KFMRadioFreqMultiplier, aError );
       
   468         }
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // CFMRadioRdsReceiverBase::MrroRdsStationChangeTA
       
   473 // ---------------------------------------------------------------------------
       
   474 //
       
   475 void CFMRadioRdsReceiverBase::MrroRdsStationChangeTA( TInt /*aFrequency*/ )
       
   476     {
       
   477     }
       
   478 
       
   479 // ---------------------------------------------------------------------------
       
   480 // CFMRadioRdsReceiverBase::MrroRdsEventAutomaticSwitchingChange
       
   481 // ---------------------------------------------------------------------------
       
   482 //
       
   483 void CFMRadioRdsReceiverBase::MrroRdsEventAutomaticSwitchingChange( TBool /*aAuto*/ )
       
   484     {
       
   485     }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // CFMRadioRdsReceiverBase::MrroRdsEventAutomaticTrafficAnnouncement
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 void CFMRadioRdsReceiverBase::MrroRdsEventAutomaticTrafficAnnouncement( TBool /*aAuto*/ )
       
   492     {
       
   493     }
       
   494 
       
   495 // ---------------------------------------------------------------------------
       
   496 // CFMRadioRdsReceiverBase::MrroRdsEventSignalChange
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 void CFMRadioRdsReceiverBase::MrroRdsEventSignalChange( TBool aSignal )
       
   500     {
       
   501     if ( aSignal )
       
   502         {
       
   503         if ( iPsName->Length() )
       
   504             {
       
   505             if ( iPsNameType == EFMRadioPSNameStaticAssumed && !iPsNameTimer->IsActive() )
       
   506                 {
       
   507                 iPsNameTimer->Cancel();
       
   508                 iPsNameTimer->Start( KFMRadioStaticRdsPsNameDelay, 
       
   509                                      0, 
       
   510                                      TCallBack( CFMRadioRdsReceiverBase::StaticPsNameTimerCallback, this ) );
       
   511                 }
       
   512             }
       
   513         }
       
   514     else
       
   515         {
       
   516         // PS name type determination must be canceled on bad signal
       
   517         iPsNameTimer->Cancel();
       
   518         }
       
   519     iSignalAvailable = aSignal;
       
   520     for( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   521         {
       
   522         iObservers[i]->RdsAvailable( iSignalAvailable );
       
   523         }
       
   524     }