javauis/amms_qt/src_tuner/native/src/cammstunercontrol.cpp
branchRCL_3
changeset 24 0fd27995241b
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  This class is used to control tuner
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CAMMSTunerControl.h"
       
    22 #include    "CAMMSTunerPlayer.h"
       
    23 #include    "CAMMSTunerPresetsHandler.h"
       
    24 #include    "TAMMSTunerPreset.h"
       
    25 #include    "AMMSTunerFactory.h"
       
    26 
       
    27 #include    <tuner.h>
       
    28 #include <logger.h>
       
    29 
       
    30 
       
    31 // CONSTANTS
       
    32 _LIT(KControlImplName, "com.nokia.amms.control.tuner.TunerControlImpl");
       
    33 _LIT(KControlPublicName, "javax.microedition.amms.control.tuner.TunerControl");
       
    34 
       
    35 const TInt KStereoModeMono   = 1;
       
    36 const TInt KStereoModeStereo = 2;
       
    37 const TInt KStereoModeAuto   = 3;
       
    38 
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CAMMSTunerControl::CAMMSTunerControl
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CAMMSTunerControl::CAMMSTunerControl()
       
    49 {
       
    50 }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CAMMSTunerControl::NewL
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CAMMSTunerControl* CAMMSTunerControl::NewL()
       
    58 {
       
    59     CAMMSTunerControl* self = new(ELeave) CAMMSTunerControl;
       
    60 
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop();
       
    64 
       
    65     return self;
       
    66 }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CAMMSTunerControl::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CAMMSTunerControl::ConstructL()
       
    74 {
       
    75     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::ConstructL +");
       
    76 
       
    77     iTunerUtility = CMMTunerUtility::NewL(*this,
       
    78                                           CMMTunerUtility::ETunerBandFm,
       
    79                                           1,
       
    80                                           CMMTunerUtility::ETunerAccessPriorityNormal);
       
    81 
       
    82     iActiveSchedulerWait = new(ELeave) CActiveSchedulerWait();
       
    83 
       
    84     iPresetsHandler = CAMMSTunerPresetsHandler::NewL();
       
    85 
       
    86     iMinFreq = MinFreqL();
       
    87     iMaxFreq = MaxFreqL();
       
    88 
       
    89     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::ConstructL -");
       
    90 }
       
    91 
       
    92 
       
    93 // Destructor
       
    94 CAMMSTunerControl::~CAMMSTunerControl()
       
    95 {
       
    96     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::~CAMMSTunerControl +");
       
    97     delete iTunerUtility;
       
    98     delete iActiveSchedulerWait;
       
    99     delete iPresetsHandler;
       
   100     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::~CAMMSTunerControl -");
       
   101 }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CAMMSTunerControl::TunerUtility()
       
   105 // -----------------------------------------------------------------------------
       
   106 CMMTunerUtility* CAMMSTunerControl::TunerUtility()
       
   107 {
       
   108     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::TunerUtility");
       
   109     return iTunerUtility;
       
   110 }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CAMMSTunerControl::MinFreq()
       
   114 // -----------------------------------------------------------------------------
       
   115 TInt CAMMSTunerControl::MinFreqL()
       
   116 {
       
   117     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MinFreqL +");
       
   118     TFrequency minFreq;
       
   119     TFrequency maxFreq;
       
   120     User::LeaveIfError(iTunerUtility->GetFrequencyBandRange(minFreq,
       
   121                        maxFreq));
       
   122     LOG1( EJavaAMMS, EInfo, "CAMMSTunerControl::MinFreqL = %d", minFreq.iFrequency);
       
   123     return minFreq.iFrequency;
       
   124 }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CAMMSTunerControl::MaxFreq()
       
   128 // -----------------------------------------------------------------------------
       
   129 TInt CAMMSTunerControl::MaxFreqL()
       
   130 {
       
   131     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MaxFreqL +");
       
   132     TFrequency minFreq;
       
   133     TFrequency maxFreq;
       
   134     User::LeaveIfError(iTunerUtility->GetFrequencyBandRange(minFreq,
       
   135                        maxFreq));
       
   136     LOG1( EJavaAMMS, EInfo, "CAMMSTunerControl::MaxFreqL = %d", maxFreq.iFrequency);
       
   137     return maxFreq.iFrequency;
       
   138 }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CAMMSTunerControl::SetFrequency()
       
   142 // -----------------------------------------------------------------------------
       
   143 void CAMMSTunerControl::SetFrequencyL(TInt aFreq)
       
   144 {
       
   145     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SetFrequency +");
       
   146     if (aFreq < iMinFreq || aFreq > iMaxFreq)
       
   147     {
       
   148         User::Leave(KErrArgument);
       
   149     }
       
   150 
       
   151     TFrequency freq = TFrequency(aFreq);
       
   152 
       
   153     TUint32 state = 0;
       
   154     iTunerUtility->GetState(state);
       
   155     LOG1( EJavaAMMS, EInfo, "CAMMSTunerControl::SetFrequency, state = %d", state);
       
   156 
       
   157     LOG1( EJavaAMMS, EInfo, "CAMMSTunerControl::SetFrequency = %d", freq.iFrequency);
       
   158 
       
   159     iTunerUtility->Tune(freq);
       
   160     if (!iActiveSchedulerWait->IsStarted())
       
   161     {
       
   162         iActiveSchedulerWait->Start();  // CSI: 10 Active object state already checked. #
       
   163     }
       
   164     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SetFrequency -");
       
   165 }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CAMMSTunerControl::Frequency()
       
   169 // -----------------------------------------------------------------------------
       
   170 TInt CAMMSTunerControl::FrequencyL()
       
   171 {
       
   172     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::Frequency +");
       
   173     TFrequency freq;
       
   174 
       
   175     User::LeaveIfError(iTunerUtility->GetFrequency(freq));
       
   176     TInt frequency = freq.iFrequency;
       
   177     LOG1( EJavaAMMS, EInfo, "CAMMSTunerControl::Frequency frequency = %d", frequency);
       
   178     return frequency;
       
   179 }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CAMMSTunerControl::SeekL()
       
   183 // -----------------------------------------------------------------------------
       
   184 TInt CAMMSTunerControl::SeekL(TInt aStartFreq, TBool aUpwards)
       
   185 {
       
   186     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SeekL +");
       
   187     if (aStartFreq < iMinFreq || aStartFreq > iMaxFreq)
       
   188     {
       
   189         User::Leave(KErrArgument);
       
   190     }
       
   191 
       
   192     if (aUpwards)
       
   193     {
       
   194         iTunerUtility->StationSeek(CMMTunerUtility::ESearchDirectionUp);
       
   195         if (!iActiveSchedulerWait->IsStarted())
       
   196         {
       
   197             iActiveSchedulerWait->Start();  // CSI: 10 Active object state already checked. #
       
   198         }
       
   199     }
       
   200     else
       
   201     {
       
   202         iTunerUtility->StationSeek(CMMTunerUtility::ESearchDirectionDown);
       
   203         if (!iActiveSchedulerWait->IsStarted())
       
   204         {
       
   205             iActiveSchedulerWait->Start();  // CSI: 10 Active object state already checked. #
       
   206         }
       
   207     }
       
   208 
       
   209     return FrequencyL();
       
   210 }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CAMMSTunerControl::SquelchL()
       
   214 // -----------------------------------------------------------------------------
       
   215 TBool CAMMSTunerControl::SquelchL()
       
   216 {
       
   217     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SquelchL +");
       
   218     TBool enabled = EFalse;
       
   219     User::LeaveIfError(iTunerUtility->GetSquelch(enabled));
       
   220     return enabled;
       
   221 }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CAMMSTunerControl::SetSquelchL()
       
   225 // -----------------------------------------------------------------------------
       
   226 void CAMMSTunerControl::SetSquelchL(TBool aSquelch)
       
   227 {
       
   228     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SetSquelchL +");
       
   229     User::LeaveIfError(iTunerUtility->SetSquelch(aSquelch));
       
   230 }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CAMMSTunerControl::SignalStrengthL()
       
   234 // -----------------------------------------------------------------------------
       
   235 TInt CAMMSTunerControl::SignalStrengthL()
       
   236 {
       
   237     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SignalStrengthL +");
       
   238     TInt maxSignalStrength = 0;
       
   239     TInt signalStrength = 0;
       
   240 
       
   241     User::LeaveIfError(iTunerUtility->GetMaxSignalStrength(maxSignalStrength));
       
   242     LOG1( EJavaAMMS, EInfo, "CAMMSTunerControl::SignalStrengthL, maxSignalStrength = %d", maxSignalStrength);
       
   243     User::LeaveIfError(iTunerUtility->GetSignalStrength(signalStrength));
       
   244     LOG1( EJavaAMMS, EInfo, "CAMMSTunerControl::SignalStrengthL, signalStrength = %d", signalStrength);
       
   245     if (maxSignalStrength > 0)
       
   246     {
       
   247         return signalStrength / maxSignalStrength * 100; // CSI: 47 signal strength must be between 0 and 100 #
       
   248     }
       
   249     return KErrNotSupported;
       
   250 }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CAMMSTunerControl::StereoModeL()
       
   254 // -----------------------------------------------------------------------------
       
   255 TInt CAMMSTunerControl::StereoModeL()
       
   256 {
       
   257     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::StereoModeL +");
       
   258     TBool mono = EFalse;
       
   259     TBool stereo = EFalse;
       
   260 
       
   261     User::LeaveIfError(iTunerUtility->GetForcedMonoReception(mono));
       
   262     if (mono)
       
   263     {
       
   264         return KStereoModeMono;
       
   265     }
       
   266 
       
   267     //User::LeaveIfError( iTunerUtility->IsStereoSignal( stereo ) );
       
   268     TInt err = iTunerUtility->IsStereoSignal(stereo);
       
   269     //this is for emulator testing, FIX IT
       
   270     if (err == KErrNotReady)
       
   271     {
       
   272         return KStereoModeAuto;
       
   273     }
       
   274     else if (err != KErrNone)
       
   275     {
       
   276         User::LeaveIfError(err);
       
   277     }
       
   278 
       
   279     if (stereo)
       
   280     {
       
   281         return KStereoModeStereo;
       
   282     }
       
   283 
       
   284     return KStereoModeAuto;
       
   285 }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CAMMSTunerControl::SetStereoMode()
       
   289 // -----------------------------------------------------------------------------
       
   290 void CAMMSTunerControl::SetStereoModeL(TInt aMode)
       
   291 {
       
   292     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SetStereoModeL +");
       
   293     if (aMode == KStereoModeMono)
       
   294     {
       
   295         User::LeaveIfError(iTunerUtility->ForceMonoReception(ETrue));
       
   296     }
       
   297 
       
   298     if (aMode == KStereoModeStereo)
       
   299     {
       
   300         User::LeaveIfError(iTunerUtility->ForceMonoReception(EFalse));
       
   301         TBool stereo = EFalse;
       
   302         User::LeaveIfError(iTunerUtility->IsStereoSignal(stereo));
       
   303         if (!stereo)
       
   304         {
       
   305             User::Leave(KErrNotSupported);
       
   306         }
       
   307     }
       
   308 
       
   309     if (aMode == KStereoModeAuto)
       
   310     {
       
   311         User::LeaveIfError(iTunerUtility->ForceMonoReception(EFalse));
       
   312     }
       
   313 }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CAMMSTunerControl::UsePresetL()
       
   317 // -----------------------------------------------------------------------------
       
   318 void CAMMSTunerControl::UsePresetL(TInt aPreset)
       
   319 {
       
   320     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::UsePresetL +");
       
   321     TAMMSTunerPreset tunerPreset;
       
   322 
       
   323     //get presets
       
   324     iPresetsHandler->GetPresetL(aPreset, tunerPreset);
       
   325 
       
   326     //set presets to tunerutility
       
   327     SetFrequencyL(tunerPreset.PresetFrequency());
       
   328     SetStereoModeL(tunerPreset.PresetStereoMode());
       
   329 }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CAMMSTunerControl::SetPresetL()
       
   333 // -----------------------------------------------------------------------------
       
   334 void CAMMSTunerControl::SetPresetL(TInt aPreset)
       
   335 {
       
   336     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SetPresetL1 +");
       
   337     TAMMSTunerPreset tunerPreset;
       
   338 
       
   339     //get current frequency
       
   340     tunerPreset.SetPresetFrequency(FrequencyL());
       
   341     //get current stereo mode
       
   342     tunerPreset.SetPresetStereoMode(StereoModeL());
       
   343 
       
   344     iPresetsHandler->SavePresetL(aPreset, tunerPreset);
       
   345 }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CAMMSTunerControl::SetPresetL()
       
   349 // -----------------------------------------------------------------------------
       
   350 void CAMMSTunerControl::SetPresetL(TInt aPreset,
       
   351                                    TInt aFrequency,
       
   352                                    TInt aStereoMode)
       
   353 {
       
   354     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SetPresetL2 +");
       
   355     TAMMSTunerPreset tunerPreset;
       
   356 
       
   357     tunerPreset.SetPresetFrequency(aFrequency);
       
   358     tunerPreset.SetPresetStereoMode(aStereoMode);
       
   359 
       
   360     iPresetsHandler->SavePresetL(aPreset, tunerPreset);
       
   361 }
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // CAMMSTunerControl::PresetFrequencyL()
       
   365 // -----------------------------------------------------------------------------
       
   366 TInt CAMMSTunerControl::PresetFrequencyL(TInt aPreset)
       
   367 {
       
   368     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::PresetFrequencyL +");
       
   369     TAMMSTunerPreset tunerPreset;
       
   370 
       
   371     iPresetsHandler->GetPresetL(aPreset, tunerPreset);
       
   372 
       
   373     return tunerPreset.PresetFrequency();
       
   374 }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CAMMSTunerControl::PresetStereoModeL()
       
   378 // -----------------------------------------------------------------------------
       
   379 TInt CAMMSTunerControl::PresetStereoModeL(TInt aPreset)
       
   380 {
       
   381     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::PresetStereoModeL +");
       
   382     TAMMSTunerPreset tunerPreset;
       
   383 
       
   384     iPresetsHandler->GetPresetL(aPreset, tunerPreset);
       
   385 
       
   386     return tunerPreset.PresetStereoMode();
       
   387 }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CAMMSTunerControl::SetPresetNameL()
       
   391 // -----------------------------------------------------------------------------
       
   392 void CAMMSTunerControl::SetPresetNameL(TInt aPreset, const TDesC* aPresetName)
       
   393 {
       
   394     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::SetPresetNameL +");
       
   395     TAMMSTunerPreset tunerPreset;
       
   396 
       
   397     iPresetsHandler->GetPresetL(aPreset, tunerPreset);
       
   398 
       
   399     tunerPreset.SetPresetName(aPresetName);
       
   400 
       
   401     iPresetsHandler->SavePresetL(aPreset, tunerPreset);
       
   402 }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // CAMMSTunerControl::GetPresetNameL()
       
   406 // -----------------------------------------------------------------------------
       
   407 void CAMMSTunerControl::GetPresetNameL(TInt aPreset, TPtrC* aPresetName)
       
   408 {
       
   409     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::GetPresetNameL +");
       
   410     TAMMSTunerPreset tunerPreset;
       
   411 
       
   412     iPresetsHandler->GetPresetL(aPreset, tunerPreset);
       
   413 
       
   414     aPresetName->Set(tunerPreset.PresetName());
       
   415 }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CAMMSTunerControl::ClassName()
       
   419 // -----------------------------------------------------------------------------
       
   420 const TDesC& CAMMSTunerControl::ClassName() const
       
   421 {
       
   422     return KControlImplName;
       
   423 }
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CAMMSTunerControl::PublicClassName()
       
   427 // -----------------------------------------------------------------------------
       
   428 const TDesC& CAMMSTunerControl::PublicClassName() const
       
   429 {
       
   430     return KControlPublicName;
       
   431 }
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // CAMMSTunerControl::MToTuneComplete()
       
   435 // -----------------------------------------------------------------------------
       
   436 void CAMMSTunerControl::MToTuneComplete(TInt aError)
       
   437 {
       
   438     if (iActiveSchedulerWait->IsStarted())
       
   439     {
       
   440         LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MToTuneComplete AsyncStop");
       
   441         iActiveSchedulerWait->AsyncStop();
       
   442     }
       
   443     ELOG1( EJavaAMMS, "CAMMSTunerControl::MToTuneComplete ERROR = %d", aError);
       
   444 }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CAMMSTunerControl::MTcoFrequencyChanged
       
   448 // -----------------------------------------------------------------------------
       
   449 void CAMMSTunerControl::MTcoFrequencyChanged(const TFrequency& /*aOldFrequency*/,
       
   450         const TFrequency& /*aNewFrequency*/)
       
   451 {
       
   452     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MTcoFrequencyChanged");
       
   453 }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CAMMSTunerControl::MTcoStateChanged
       
   457 // -----------------------------------------------------------------------------
       
   458 void CAMMSTunerControl::MTcoStateChanged(const TUint32& /*aOldState*/,
       
   459         const TUint32& /*aNewState*/)
       
   460 {
       
   461     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MTcoStateChanged");
       
   462 }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CAMMSTunerControl::MTcoAntennaDetached
       
   466 // -----------------------------------------------------------------------------
       
   467 void CAMMSTunerControl::MTcoAntennaDetached()
       
   468 {
       
   469     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MTcoAntennaDetached");
       
   470 }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CAMMSTunerControl::MTcoAntennaAttached
       
   474 // -----------------------------------------------------------------------------
       
   475 void CAMMSTunerControl::MTcoAntennaAttached()
       
   476 {
       
   477     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MTcoAntennaAttached");
       
   478 }
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // CAMMSTunerControl::FlightModeChanged
       
   482 // -----------------------------------------------------------------------------
       
   483 void CAMMSTunerControl::FlightModeChanged(TBool /*aFlightMode*/)
       
   484 {
       
   485     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::FlightModeChanged");
       
   486 }
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CAMMSTunerControl::MTsoStereoReceptionChanged
       
   490 // -----------------------------------------------------------------------------
       
   491 void CAMMSTunerControl::MTsoStereoReceptionChanged(TBool /*aStereo*/)
       
   492 {
       
   493     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MTsoStereoReceptionChanged");
       
   494 }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CAMMSTunerControl::MTsoForcedMonoChanged
       
   498 // -----------------------------------------------------------------------------
       
   499 void CAMMSTunerControl::MTsoForcedMonoChanged(TBool /*aForcedMono*/)
       
   500 {
       
   501     LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MTsoForcedMonoChanged");
       
   502 }
       
   503 
       
   504 //  End of File