devicediagnostics/diagplugins/diagloudspeakerplugin/src/diagspeakerplugin.cpp
changeset 0 3ce708148e4d
child 54 9360ca28b668
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 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:  Class Definition of CDiagSpeakerPlugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 // From System
       
    22 #include <AknQueryDialog.h>            // CAknQueryDialog
       
    23 #include <aknmessagequerydialog.h>     // CAknMessageQueryDialog
       
    24 #include <AknProgressDialog.h>         // CAknProgressDialog
       
    25 #include <eikprogi.h>                  // CEikProgressInfo
       
    26 #include <eikbtgpc.h>                  // CEikButtonGroupContainer
       
    27 #include <AudioPreference.h>           // KAudioPriorityRecording
       
    28 #include <mdaaudiosampleeditor.h>      // CMdaAudioRecorderUtility
       
    29 #include <mdaaudiosampleplayer.h>      // CMdaAudioPlayerUtility
       
    30 #include <StringLoader.h>              // StringLoader
       
    31 #include <DiagTestObserver.h>          // MDiagTestObserver
       
    32 #include <DiagTestExecParam.h>         // TDiagTestExecParam
       
    33 #include <DiagEngineCommon.h>          // MDiagEngine
       
    34 #include <DiagPluginPool.h>            // CDiagPluginPool
       
    35 #include <DiagResultsDbItemBuilder.h>  // CDiagResultsDbItemBuilder
       
    36 #include <DiagResultDetailBasic.h>     // CDiagResultDetailBasic
       
    37 #include <DiagFrameworkDebug.h>        // LOGSTRING
       
    38 #include <DiagCommonDialog.h>          // for EDiagCommonDialogConfirmCancelAll
       
    39 
       
    40 // For Central Repository
       
    41 #include <centralrepository.h>
       
    42 #include "diagspeakertestprivatecrkeys.h"
       
    43 
       
    44 // Speaker Plugin Headerfile
       
    45 #include "diagspeakerplugin.h"       // CDiagSpeakerPlugin
       
    46 #include "diagspeakerplugin.hrh"     // Button Id defined
       
    47 #include <devdiagspeakerpluginrsc.rsg>  // Resource Definitions
       
    48 #include <avkon.hrh>
       
    49 
       
    50 
       
    51 // Local Macro
       
    52 #define ASSERT_ALWAYS(c) __ASSERT_ALWAYS((c), User::Invariant())
       
    53 
       
    54 // Local Data Types
       
    55 enum TSpeakerSteps
       
    56     {
       
    57     EStepTestTitle,
       
    58     EStepAskRecord,
       
    59     EStepProgressRecord,
       
    60     EStepAskPlay,
       
    61     EStepProgressPlay,
       
    62     EStepAskHeard,
       
    63     EStepAskRepeat,
       
    64     ESpeakerPluginTotalSteps
       
    65     };
       
    66 
       
    67 // To Exit from Query it should be EAknSoftkeyOk
       
    68 // can't include in .hrh because it requires <eikon.rh>
       
    69 // leads compilation fail
       
    70 enum TSpeakerExitCBA
       
    71     {
       
    72     ECBACmdPlay  = EAknSoftkeyOk,
       
    73     ECBACmdStop  = EAknSoftkeyOk,
       
    74     ECBACmdStart = EAknSoftkeyOk
       
    75     };
       
    76 
       
    77 // Local Constants
       
    78 const TInt KFinished      = 0;
       
    79 const TInt KMinFileSize   = 1024;
       
    80 const TInt KSamplingRate  = 8192;
       
    81 const TInt KStereo        = 2;
       
    82 const TInt KFive          = 5;
       
    83 const TInt KMicroSecond   = 1000*1000;
       
    84 const TInt KProgressDelay = 200000;
       
    85 const TInt KAudioServerRequestTimeoutValue = 16 * KMicroSecond;
       
    86 
       
    87 const TInt KProgressFinished    =  0;
       
    88 const TInt KProgressNotFinished =  1;
       
    89 const TUid KDiagSpeakerPluginUid  = { DIAG_SPEAKER_PLUGIN_UID };
       
    90 
       
    91 _LIT( KDiagSpeakerPluginResourceFileName, "z:DevDiagSpeakerPluginRsc.rsc" );
       
    92 _LIT( KDiagSpeakerPluginCategory,"DevDiagSpeakerPlugin" );
       
    93 
       
    94 const CAudioOutput::TAudioOutputPreference KTargetOutput = CAudioOutput::EPublic;
       
    95 
       
    96 
       
    97 // ========================= MEMBER FUNCTIONS ================================
       
    98 // ---------------------------------------------------------------------------
       
    99 // CDiagSpeakerPlugin::NewL()
       
   100 //
       
   101 // Symbian OS default constructor
       
   102 // ---------------------------------------------------------------------------
       
   103 MDiagPlugin* CDiagSpeakerPlugin::NewL( TAny* aInitParams )
       
   104     {
       
   105     CDiagSpeakerPlugin* self;
       
   106     CDiagPluginConstructionParam* param;
       
   107 
       
   108     ASSERT_ALWAYS( aInitParams );
       
   109 
       
   110     param = static_cast<CDiagPluginConstructionParam*>( aInitParams );
       
   111     CleanupStack::PushL( param );
       
   112     self  = new( ELeave ) CDiagSpeakerPlugin ( param );
       
   113     CleanupStack::Pop( param );
       
   114 
       
   115 
       
   116     CleanupStack::PushL( self );
       
   117     self->ConstructL();
       
   118     CleanupStack::Pop( self ); // self
       
   119 
       
   120     return self;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // CDiagSpeakerPlugin::~CDiagSpeakerPlugin
       
   125 //
       
   126 // Destructor
       
   127 // ----------------------------------------------------------------------------
       
   128 CDiagSpeakerPlugin::~CDiagSpeakerPlugin()
       
   129     {
       
   130     // Delete resources allocated during construction.
       
   131     // Nothing to do since no new resource is allocated in constructor.
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CDiagSpeakerPlugin::CDiagSpeakerPlugin()
       
   136 //
       
   137 // Constructor
       
   138 // ----------------------------------------------------------------------------
       
   139 //
       
   140 CDiagSpeakerPlugin::CDiagSpeakerPlugin( CDiagPluginConstructionParam* aParam )
       
   141     :    CDiagTestPluginBase( aParam )
       
   142     {
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CDiagSpeakerPlugin::ConstructL()
       
   147 //
       
   148 // Symbian OS two-phased constructor
       
   149 // ---------------------------------------------------------------------------
       
   150 void CDiagSpeakerPlugin::ConstructL()
       
   151     {
       
   152     LOGSTRING( "CDiagSpeakerPlugin::ConstructL: Plugin created. IN" )
       
   153 
       
   154     BaseConstructL ( KDiagSpeakerPluginResourceFileName );
       
   155 
       
   156     TInt recording_time;
       
   157 
       
   158     // Open Central Repository
       
   159     CRepository* audioRecorderRepository = CRepository::NewL( KCRUidDiagSpeakerTestPlugin );
       
   160     CleanupStack::PushL( audioRecorderRepository );
       
   161 
       
   162     // Read File Path from CR
       
   163     iRecordFilePath.FillZ();
       
   164     User::LeaveIfError(
       
   165         audioRecorderRepository->Get( KAudioRecorderFilePath, iRecordFilePath) );
       
   166 
       
   167     // Read File Size from CR
       
   168     User::LeaveIfError(
       
   169         audioRecorderRepository->Get( KAudioRecorderRecordingTime , recording_time) );
       
   170 
       
   171     iRecordFileSize = (recording_time * KSamplingRate * KStereo);    
       
   172 
       
   173     CleanupStack::PopAndDestroy( audioRecorderRepository );
       
   174     audioRecorderRepository = NULL;
       
   175 
       
   176     // Set Audio Output
       
   177     iOutput = KTargetOutput;
       
   178 
       
   179     LOGSTRING( "CDiagSpeakerPlugin::ConstructL: Plugin created. OUT" )
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CDiagSpeakerPlugin::StartRecordL
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CDiagSpeakerPlugin::StartRecordL()
       
   187     {
       
   188     LOGSTRING( "CDiagSpeakerPlugin::DoRunTest() IN" )
       
   189     TBool       goNext;
       
   190 
       
   191     // Delete Record File
       
   192     DeleteRecordFile();
       
   193 
       
   194     // Check Free Space
       
   195     if ( !EnoughFreeSpace() )
       
   196         {
       
   197         CompleteTestL( CDiagResultsDatabaseItem::ENotPerformed );
       
   198         return;
       
   199         }
       
   200 
       
   201     // Show Init Message Query
       
   202     do
       
   203         {
       
   204         goNext = ETrue;
       
   205 
       
   206         // Check session before launch before dialog starts
       
   207         if ( !iSessionValid )
       
   208             {
       
   209             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL - !iSessionValid 1" )
       
   210             return;
       
   211             }
       
   212 
       
   213         // Report current Progress to Engine
       
   214         ReportTestProgressL( EStepTestTitle );
       
   215 
       
   216         // Show Message Query Title
       
   217         TInt  buttonId;
       
   218         TBool result = EFalse;
       
   219 
       
   220         result = ShowMessageQueryL( R_MESSAGEQUERY_TITLE, buttonId );
       
   221 
       
   222         // Check session is valid after dialog dismissed
       
   223         if ( !result )
       
   224             {
       
   225             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL - !iSessionValid 2" )
       
   226             return;
       
   227             }
       
   228 
       
   229         // 1.1 Case for press Skip
       
   230         if ( buttonId == ECBACmdSkip )
       
   231             {
       
   232             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL: Skip has pressed" );
       
   233             // ADO & Platformization Changes
       
   234             TInt   cancelButtonId;
       
   235 
       
   236             //cancelResult = AskCancelExecutionL( cancelButtonId );
       
   237 			CAknDialog* dlg = ExecutionParam().Engine().
       
   238 							  CreateCommonDialogLC( EDiagCommonDialogConfirmSkipAll, NULL );
       
   239 							  
       
   240             if ( !RunWaitingDialogL( dlg, cancelButtonId ) )
       
   241                 {
       
   242                 LOGSTRING( "CDiagSpeakerPlugin::StartPlayL - !iSessionValid 3" )
       
   243                 return;
       
   244                 }
       
   245 
       
   246 			if(cancelButtonId)
       
   247 			return;
       
   248 			else
       
   249 			goNext = EFalse;          
       
   250             
       
   251 
       
   252 			// ADO & Platformization Changes
       
   253             //CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   254             //return;
       
   255             }
       
   256 
       
   257         // 1.2 case for press Cancel
       
   258         else if ( buttonId == ECBACmdCancel )
       
   259             {
       
   260             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL: Cancel has pressed" )
       
   261             CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   262             return;
       
   263             }
       
   264         }
       
   265     while ( goNext == EFalse );
       
   266 
       
   267 
       
   268     // Show Record Message Query
       
   269     do
       
   270         {
       
   271         goNext = ETrue;
       
   272 
       
   273         // Check session before launch before dialog starts
       
   274         if ( !iSessionValid )
       
   275             {
       
   276             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL - !iSessionValid 4" )
       
   277             return;
       
   278             }
       
   279 
       
   280         // Report current Progress to Engine
       
   281         ReportTestProgressL( EStepAskRecord );
       
   282 
       
   283         // Show Message Query Title
       
   284         TInt  buttonId;
       
   285         TBool result = EFalse;
       
   286 
       
   287         result = ShowMessageQueryL( R_MESSAGEQUERY_ASK_RECORD, buttonId );
       
   288 
       
   289         // Check session is valid after dialog dismissed
       
   290         if ( !result )
       
   291             {
       
   292             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL - !iSessionValid 5" )
       
   293             return;
       
   294             }
       
   295 
       
   296         // 2.2 Case for press Skip
       
   297         if ( buttonId == ECBACmdStart )
       
   298             {
       
   299             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL: Start has pressed" )
       
   300             RecordL();
       
   301             return;
       
   302             }
       
   303         else if ( buttonId == ECBACmdSkip )
       
   304             {
       
   305             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL: Skip has pressed" )
       
   306             CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   307             return;
       
   308             }
       
   309 
       
   310         // 2.3 case for press Cancel
       
   311         else if ( buttonId == ECBACmdCancel )
       
   312             {
       
   313             LOGSTRING( "CDiagSpeakerPlugin::StartRecordL: Cancel has pressed" )
       
   314 
       
   315             TInt  cancelButtonId;
       
   316             TBool cancelResult = EFalse;
       
   317 
       
   318             cancelResult = AskCancelExecutionL( cancelButtonId );
       
   319 
       
   320             if ( !cancelResult )
       
   321                 {
       
   322                 LOGSTRING( "CDiagSpeakerPlugin::StartPlayL - !iSessionValid 6" )
       
   323                 return;
       
   324                 }
       
   325             
       
   326             if(cancelButtonId == EAknSoftkeyYes)
       
   327                 {
       
   328                 CompleteTestL( CDiagResultsDatabaseItem::ECancelled );
       
   329                 return;
       
   330                 }
       
   331             else if(cancelButtonId)
       
   332                 {
       
   333                 return;
       
   334                 }
       
   335             else
       
   336                 {
       
   337                 goNext = EFalse;
       
   338                 }
       
   339             /*
       
   340             switch ( cancelButtonId )
       
   341                 {
       
   342                 case EAknSoftkeyYes:
       
   343                 	CompleteTestL( CDiagResultsDatabaseItem::ECancelled );	 //Added for NTEI-7EZ96S
       
   344                     return;
       
   345                 default:
       
   346                     goNext = EFalse;
       
   347                     break;
       
   348                 }
       
   349                 */
       
   350             }
       
   351         }
       
   352     while ( goNext == EFalse );
       
   353 
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // CDiagSpeakerPlugin::StartPlayL
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 void CDiagSpeakerPlugin::StartPlayL()
       
   361     {
       
   362     LOGSTRING( "CDiagSpeakerPlugin::StartPlayL() IN" )
       
   363     TBool goNext;
       
   364 
       
   365 
       
   366     // Check Record File
       
   367     if ( CheckRecordFile() == EFalse )
       
   368         {
       
   369         LOGSTRING( "CDiagSpeakerPlugin::StartPlayL() CheckRecordFile == EFalse" )
       
   370         CompleteTestL( CDiagResultsDatabaseItem::ENotPerformed );
       
   371         return;
       
   372         }
       
   373 
       
   374     do
       
   375         {
       
   376         goNext = ETrue;
       
   377 
       
   378         // Check session before launch before dialog starts
       
   379         if ( !iSessionValid )
       
   380             {
       
   381             LOGSTRING( "CDiagSpeakerPlugin::StartPlayL - !iSessionValid 1" )
       
   382             return;
       
   383             }
       
   384 
       
   385         // Report current Progress to Engine
       
   386         ReportTestProgressL( EStepAskPlay );
       
   387 
       
   388         // Show ConfQuery to ask Play
       
   389         TInt  buttonId;
       
   390         TBool result = EFalse;
       
   391 
       
   392         result = ShowConfQueryL( R_CONFQUERY_ASK_PLAY, buttonId );
       
   393 
       
   394         // Check session is valid after dialog dismissed
       
   395         if ( !result )
       
   396             {
       
   397             LOGSTRING( "CDiagSpeakerPlugin::StartPlayL - !iSessionValid 2" )
       
   398             return;
       
   399             }
       
   400 
       
   401         // 1.1 Case for press Skip
       
   402         if ( buttonId == ECBACmdSkip )
       
   403             {
       
   404             LOGSTRING( "CDiagSpeakerPlugin::StartPlayL: Skip has pressed" )
       
   405             CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
   406             return;
       
   407             }
       
   408 
       
   409         // 1.2 case for press Cancel
       
   410         else if ( buttonId == ECBACmdCancel )
       
   411             {
       
   412             LOGSTRING( "CDiagSpeakerPlugin::StartPlayL: Cancel has pressed" )
       
   413             TInt  cancelButtonId;
       
   414             TBool cancelResult = EFalse;
       
   415 
       
   416             cancelResult = AskCancelExecutionL( cancelButtonId );
       
   417 
       
   418             if ( !cancelResult )
       
   419                 {
       
   420                 LOGSTRING( "CDiagSpeakerPlugin::StartPlayL - !iSessionValid 3" )
       
   421                 return;
       
   422                 }
       
   423             
       
   424             
       
   425             if(cancelButtonId == EAknSoftkeyYes)
       
   426                 {
       
   427                 CompleteTestL( CDiagResultsDatabaseItem::ECancelled );
       
   428                 return;
       
   429                 }
       
   430             else if(cancelButtonId)
       
   431                 {
       
   432                 return;
       
   433                 }
       
   434             else
       
   435                 {
       
   436                 goNext = EFalse;
       
   437                 }
       
   438             /*
       
   439 
       
   440             switch ( cancelButtonId )
       
   441                 {
       
   442                 case EAknSoftkeyYes:
       
   443                     iState = EStateCancelled;
       
   444                     SetActive();
       
   445             		TRequestStatus* status = &iStatus;
       
   446             		User::RequestComplete(status, KErrNone);
       
   447                 	//CompleteTestL( CDiagResultsDatabaseItem::ECancelled );	 //Commented by Ganesh
       
   448                     return;
       
   449                 default:
       
   450                     goNext = EFalse;
       
   451                     break;
       
   452                 }
       
   453              */
       
   454             }
       
   455         // 1.3 case for press Play
       
   456         else if ( buttonId == ECBACmdPlay )
       
   457             {
       
   458             LOGSTRING( "CDiagSpeakerPlugin::StartPlayL: Play has pressed" )
       
   459             iState = EStateRecorded;
       
   460             PlayL();
       
   461             }
       
   462         } while ( !goNext );
       
   463     }
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CDiagSpeakerPlugin::RecordingL
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CDiagSpeakerPlugin::RecordingL()
       
   470     {
       
   471     LOGSTRING( "CDiagSpeakerPlugin::RecordingL IN" )
       
   472     const TTimeIntervalMicroSeconds     position   = 0;
       
   473 
       
   474     iFinalValue = iRecordFileSize / KSamplingRate / KStereo;
       
   475 
       
   476     ReportTestProgressL( EStepProgressRecord );
       
   477     ShowProgressNoteL( R_PROGRESS_NOTE_RECORDING, iFinalValue );
       
   478 
       
   479     iRecorder->SetPriority(
       
   480         KAudioPriorityAlarm + 1,
       
   481         TMdaPriorityPreference( KAudioPrefVoiceRec )
       
   482         );
       
   483 
       
   484     iRecorder->SetPosition( position );
       
   485     iRecorder->CropL();
       
   486     iRecorder->SetMaxWriteLength( iRecordFileSize );
       
   487 
       
   488     ResetWatchdog( KAudioServerRequestTimeoutValue, CDiagResultsDatabaseItem::EFailed ); 
       
   489     iRecorder->RecordL(); // MoscoStateChangeEvent() will be called as return
       
   490     LOGSTRING( "CDiagSpeakerPlugin::RecordingL OUT" )
       
   491     }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // CDiagSpeakerPlugin::PlayingL
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void CDiagSpeakerPlugin::PlayingL()
       
   498     {
       
   499     LOGSTRING( "CDiagSpeakerPlugin::PlayingL IN" )
       
   500 
       
   501     TInt64  interval   = 0;
       
   502     TInt    finalValue = 0;
       
   503 
       
   504     interval             = iMaxDurationMicroSec.Int64() / KMicroSecond;
       
   505     finalValue           = ((I64INT(interval)));
       
   506     iFinalValue          = finalValue;
       
   507 
       
   508     // Save Audio Output
       
   509     SaveAudioOutput();
       
   510 
       
   511     ReportTestProgressL( EStepProgressPlay );
       
   512     ShowProgressNoteL( R_PROGRESS_NOTE_PLAYING, iFinalValue );
       
   513 
       
   514     iAudioPlayer->SetPosition( iPositionMicroSec );
       
   515     iAudioPlayer->Play();
       
   516 
       
   517     LOGSTRING( "CDiagSpeakerPlugin::PlayingL OUT" )
       
   518     }
       
   519 
       
   520 // ---------------------------------------------------------------------------
       
   521 // CDiagSpeakerPlugin::AfterRecordL
       
   522 // ---------------------------------------------------------------------------
       
   523 //
       
   524 void CDiagSpeakerPlugin::AfterRecordL()
       
   525     {
       
   526     StartPlayL();
       
   527     }
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 // CDiagSpeakerPlugin::AfterPlayL
       
   531 // ---------------------------------------------------------------------------
       
   532 //
       
   533 void CDiagSpeakerPlugin::AfterPlayL()
       
   534     {
       
   535     LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL IN" )
       
   536 
       
   537 
       
   538     // Check session before launch before dialog starts
       
   539     if ( !iSessionValid )
       
   540         {
       
   541         LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL - !iSessionValid 1.1" )
       
   542         return;
       
   543         }
       
   544 
       
   545     // Report current Progress to Engine
       
   546     ReportTestProgressL( EStepAskHeard );
       
   547 
       
   548     // Show ConfQuery to ask Heard
       
   549     TInt  buttonId;
       
   550     TBool result = EFalse;
       
   551     result = ShowConfQueryL( R_CONFQUERY_ASK_HEARD, buttonId );
       
   552 
       
   553     // Check session is valid after dialog dismissed
       
   554     if ( !result )
       
   555         {
       
   556         LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL - !iSessionValid 1.2" )
       
   557         return;
       
   558         }
       
   559 
       
   560     // Report Success on Yes
       
   561     if ( buttonId == EAknSoftkeyYes )
       
   562         {
       
   563         LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL - Yes has pressed - return ESuccess" )
       
   564         CompleteTestL( CDiagResultsDatabaseItem::ESuccess );
       
   565         return;
       
   566         }
       
   567     else if ( buttonId != ECBACmdCustomNo )
       
   568         {
       
   569         //return;  // ADO & Platformization Changes
       
   570         }
       
   571 
       
   572     // Check session before launch before dialog starts
       
   573     if ( !iSessionValid )
       
   574         {
       
   575         LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL - !iSessionValid 2.1" )
       
   576         return;
       
   577         }
       
   578 
       
   579     // Report current Progress to Engine
       
   580     ReportTestProgressL( EStepAskRepeat );
       
   581 
       
   582     // Show ConfQuery to ask Heard
       
   583     result = ShowConfQueryL( R_CONFQUERY_ASK_REPEAT, buttonId );
       
   584 
       
   585    // Check session is valid after dialog dismissed
       
   586     if ( !result )
       
   587         {
       
   588         LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL - !iSessionValid 2.2" )
       
   589         return;
       
   590         }
       
   591 
       
   592     // Report Success on Yes
       
   593     if ( buttonId == EAknSoftkeyYes )
       
   594         {
       
   595         LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL - Yes has pressed - Start Record Again" )
       
   596 
       
   597         StartRecordL();
       
   598         return;
       
   599         }
       
   600     else if ( buttonId == ECBACmdCustomNo || buttonId == EAknSoftkeyNo )
       
   601         {
       
   602         LOGSTRING( "CDiagSpeakerPlugin::AfterPlayL - No has pressed - Start Record Again" )
       
   603         CompleteTestL( CDiagResultsDatabaseItem::EFailed );
       
   604         }
       
   605     else
       
   606         {
       
   607         CompleteTestL( CDiagResultsDatabaseItem::EFailed );
       
   608         return;
       
   609         }
       
   610     }
       
   611 
       
   612 // ---------------------------------------------------------------------------
       
   613 // CDiagSpeakerPlugin::RecordL
       
   614 // ---------------------------------------------------------------------------
       
   615 //
       
   616 void CDiagSpeakerPlugin::RecordL()
       
   617     {
       
   618     LOGSTRING( "CDiagSpeakerPlugin::RecordL IN" )
       
   619 
       
   620     iAudioState = CMdaAudioRecorderUtility::ERecording;
       
   621     
       
   622     iState = EStateUnknown;
       
   623 
       
   624     if ( iRecorder )
       
   625         {
       
   626         ResetWatchdog( KAudioServerRequestTimeoutValue, CDiagResultsDatabaseItem::EFailed );  
       
   627         iRecorder->OpenFileL( iRecordFilePath ); // MoscoStateChangeEvent() will be called as return
       
   628         }
       
   629 
       
   630     LOGSTRING( "CDiagSpeakerPlugin::RecordL OUT" )
       
   631     }
       
   632 
       
   633 // ---------------------------------------------------------------------------
       
   634 // CDiagSpeakerPlugin::PlayL
       
   635 // ---------------------------------------------------------------------------
       
   636 //
       
   637 void CDiagSpeakerPlugin::PlayL()
       
   638     {
       
   639     LOGSTRING( "CDiagSpeakerPlugin::PlayL IN" )
       
   640     iAudioState = CMdaAudioRecorderUtility::EPlaying;
       
   641 
       
   642     // Save Current Audio Output
       
   643     LOGSTRING( "CDiagSpeakerPlugin::PlayL:SaveAudioOutput" )
       
   644 
       
   645     // Invoke Play
       
   646     if ( iAudioPlayer )
       
   647         {
       
   648         LOGSTRING( "CDiagSpeakerPlugin::PlayL:OpenFileL(iRecordFilePath);" )
       
   649         ResetWatchdog( KAudioServerRequestTimeoutValue, CDiagResultsDatabaseItem::EFailed ); 
       
   650         iAudioPlayer->OpenFileL( iRecordFilePath ); // MapcInitComplete() will be called as return
       
   651         }
       
   652 
       
   653     LOGSTRING( "CDiagSpeakerPlugin::PlayL OUT" )
       
   654     }
       
   655 
       
   656 // ---------------------------------------------------------------------------
       
   657 // CDiagSpeakerPlugin::SaveAudioOutput()
       
   658 // ---------------------------------------------------------------------------
       
   659 //
       
   660 void CDiagSpeakerPlugin::SaveAudioOutput()
       
   661     {
       
   662     LOGSTRING( "CDiagSpeakerPlugin::SaveAudioOutput IN" )
       
   663 
       
   664     if ( iAudioOutput )
       
   665         {
       
   666         iPrevAudioOutput = iAudioOutput->AudioOutput();
       
   667         }
       
   668 
       
   669     LOGSTRING( "CDiagSpeakerPlugin::SaveAudioOutput OUT" )
       
   670     }
       
   671 
       
   672 // ---------------------------------------------------------------------------
       
   673 // CDiagSpeakerPlugin::RestoreAudioOutputL()
       
   674 // ---------------------------------------------------------------------------
       
   675 //
       
   676 void CDiagSpeakerPlugin::RestoreAudioOutputL()
       
   677     {
       
   678     LOGSTRING( "CDiagSpeakerPlugin::RestoreAudioOutputL IN" )
       
   679 
       
   680     if ( iAudioOutput )
       
   681         {
       
   682         iAudioOutput->SetAudioOutputL( iPrevAudioOutput );
       
   683         }
       
   684 
       
   685     LOGSTRING( "CDiagSpeakerPlugin::RestoreAudioOutputL OUT" )
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // CDiagSpeakerPlugin::ClosePeriodic
       
   690 // ---------------------------------------------------------------------------
       
   691 //
       
   692 void CDiagSpeakerPlugin::ClosePeriodic()
       
   693     {
       
   694     LOGSTRING( "CDiagSpeakerPlugin::ClosePeriodic IN" )
       
   695 
       
   696     if ( iPeriodic )
       
   697         {
       
   698         delete iPeriodic;
       
   699         iPeriodic = NULL;
       
   700         }
       
   701 
       
   702     LOGSTRING( "CDiagSpeakerPlugin::ClosePeriodic OUT" )
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // CDiagSpeakerPlugin::CheckRecordFile
       
   707 // ---------------------------------------------------------------------------
       
   708 //
       
   709 TBool CDiagSpeakerPlugin::CheckRecordFile()
       
   710     {
       
   711     LOGSTRING( "CDiagSpeakerPlugin::CheckRecordFile IN" )
       
   712 
       
   713     TInt        err;
       
   714     TEntry      entry;
       
   715     TBool       ret = EFalse;
       
   716 
       
   717     err  = CoeEnv().FsSession().Entry( iRecordFilePath, entry );
       
   718 
       
   719     // Check if there was an error
       
   720     if ( err != KErrNone)
       
   721         {
       
   722         ret = EFalse;
       
   723         }
       
   724 
       
   725     // Check File Size
       
   726     else
       
   727         {
       
   728         ret = entry.iSize >= KMinFileSize;
       
   729         }
       
   730 
       
   731     LOGSTRING2( "CDiagSpeakerPlugin::CheckRecordFile OUT ret=%d", ret )
       
   732     return ret;
       
   733     }
       
   734 
       
   735 // ---------------------------------------------------------------------------
       
   736 // CDiagAuioPlugin::DeleteRecordFile
       
   737 // ---------------------------------------------------------------------------
       
   738 //
       
   739 void CDiagSpeakerPlugin::DeleteRecordFile()
       
   740     {
       
   741     LOGSTRING( "CDiagSpeakerPlugin::DeleteRecordFile IN" )
       
   742 
       
   743     CoeEnv().FsSession().Delete( iRecordFilePath );
       
   744 
       
   745     LOGSTRING( "CDiagSpeakerPlugin::DeleteRecordFile OUT" )
       
   746     }
       
   747 
       
   748 // ---------------------------------------------------------------------------
       
   749 // CDiagSpeakerPlugin::EnoughFreeSpace
       
   750 // ---------------------------------------------------------------------------
       
   751 //
       
   752 TBool CDiagSpeakerPlugin::EnoughFreeSpace()
       
   753     {
       
   754     LOGSTRING( "CDiagSpeakerPlugin::EnoughFreeSpace IN" )
       
   755 
       
   756     TInt64      RecordFileSize64;
       
   757     TVolumeInfo vol_info;
       
   758     TBool       ret;
       
   759 
       
   760     RecordFileSize64 = iRecordFileSize;
       
   761     CoeEnv().FsSession().Volume( vol_info, EDriveC );
       
   762     ret = vol_info.iFree >= RecordFileSize64;
       
   763 
       
   764     LOGSTRING2( "CDiagSpeakerPlugin::EnoughFreeSpace OUT ret=%d", ret )
       
   765     return ret;
       
   766     }
       
   767 
       
   768 // ---------------------------------------------------------------------------
       
   769 // CDiagSpeakerPlugin::SetProgressDismissed
       
   770 // ---------------------------------------------------------------------------
       
   771 //
       
   772 void  CDiagSpeakerPlugin::SetProgressDismissed( TBool aDismissed )
       
   773     {
       
   774     LOGSTRING2( "CDiagSpeakerPlugin::SetProgressDismissed aDismissed=%d", aDismissed )
       
   775     iProgressDismissed = aDismissed;
       
   776     }
       
   777 
       
   778 // ---------------------------------------------------------------------------
       
   779 // CDiagSpeakerPlugin::ProgressDismissed
       
   780 // ---------------------------------------------------------------------------
       
   781 //
       
   782 TBool CDiagSpeakerPlugin::ProgressDismissed() const
       
   783     {
       
   784     LOGSTRING2( "CDiagSpeakerPlugin::ProgressDismissed iProgressDismissed=%d", iProgressDismissed )
       
   785 
       
   786     return iProgressDismissed;
       
   787     }
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // CDiagSpeakerPlugin::AskCancelExecutionL
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 TBool CDiagSpeakerPlugin::AskCancelExecutionL( TInt& aButtonId )
       
   794     {
       
   795     LOGSTRING( "CDiagSpeakerPlugin::AskCancelExecutionL() IN" )
       
   796 
       
   797     CAknDialog* dialog;
       
   798     TBool       result;
       
   799 
       
   800     // set softkey for single execution
       
   801     if ( !SinglePluginExecution() )
       
   802         {
       
   803     	// Create common dialog by invoking Engine
       
   804     	dialog = ExecutionParam().Engine().
       
   805              CreateCommonDialogLC( EDiagCommonDialogConfirmCancelAll, NULL );
       
   806 
       
   807     	// Launch dialog and get result from it
       
   808     	result = RunWaitingDialogL( dialog, aButtonId );
       
   809 	}	
       
   810     else 
       
   811        {
       
   812        //CompleteTestL( CDiagResultsDatabaseItem::ECancelled );	 //commented for NTEI-7EZ96S
       
   813        aButtonId = EAknSoftkeyYes;
       
   814        return ETrue;
       
   815        }
       
   816     
       
   817     LOGSTRING3( "CDiagSpeakerPlugin::AskCancelExecutionL() OUT aButtonId=%d result=%d", aButtonId, result )
       
   818     return result;
       
   819     }
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 // CDiagSpeakerPlugin::ShowConfQueryL
       
   823 // ---------------------------------------------------------------------------
       
   824 //
       
   825 TBool CDiagSpeakerPlugin::ShowConfQueryL( TInt aResourceId, TInt &aButtonId )
       
   826     {
       
   827     LOGSTRING( "CDiagSpeakerPlugin::ShowConfQueryL IN" )
       
   828     CAknQueryDialog* dlg    = NULL;
       
   829     TBool            result = EFalse;
       
   830 
       
   831     // Create CAknQueryDialog instance
       
   832     dlg = new ( ELeave ) CAknQueryDialog( CAknQueryDialog::ENoTone );
       
   833 
       
   834     dlg->PrepareLC( aResourceId );
       
   835 
       
   836     // set softkey for single execution
       
   837     /*
       
   838     if ( SinglePluginExecution() )
       
   839         { */  // ADO & Platformization Changes
       
   840         CEikButtonGroupContainer& cba = dlg->ButtonGroupContainer();
       
   841 
       
   842         switch ( aResourceId )
       
   843             {
       
   844             case R_CONFQUERY_ASK_PLAY: 
       
   845                 cba.SetCommandSetL( R_DIAG_SPEAKER_SOFTKEYS_PLAY_CANCEL );
       
   846                 break;
       
   847             default:
       
   848                 break;
       
   849             }
       
   850       /*  } */
       
   851 
       
   852     result = RunWaitingDialogL( dlg, aButtonId );
       
   853 
       
   854     LOGSTRING3( "CDiagSpeakerPlugin::ShowConfQueryL() OUT aButtonId=%d result=%d", aButtonId, result )
       
   855     return result;
       
   856     }
       
   857 
       
   858 // ---------------------------------------------------------------------------
       
   859 // CDiagSpeakerPlugin::ShowMessageQueryL
       
   860 // ---------------------------------------------------------------------------
       
   861 //
       
   862 TBool CDiagSpeakerPlugin::ShowMessageQueryL( TInt aResourceId, TInt &aButtonId  )
       
   863     {
       
   864     LOGSTRING( "CDiagSpeakerPlugin::ShowMessageQueryL IN" )
       
   865     CAknMessageQueryDialog* dlg    = NULL;
       
   866     TBool                   result = EFalse;
       
   867 
       
   868     // Create CAknMessageQueryDialog instance
       
   869     dlg = new ( ELeave ) CAknMessageQueryDialog();
       
   870 
       
   871     dlg->PrepareLC( aResourceId );
       
   872 
       
   873     // set softkey for single execution
       
   874     
       
   875     
       
   876         CEikButtonGroupContainer& cba = dlg->ButtonGroupContainer();
       
   877 
       
   878         switch ( aResourceId )
       
   879             {
       
   880             case R_MESSAGEQUERY_TITLE: 
       
   881         	if ( SinglePluginExecution() )
       
   882         		{
       
   883                 cba.SetCommandSetL( R_DIAG_SPEAKER_SOFTKEYS_OK_CANCEL );
       
   884         		}
       
   885         	else
       
   886         		{
       
   887         		cba.SetCommandSetL( R_DIAG_SPEAKER_SOFTKEYS_OK_SKIP );	
       
   888         		}
       
   889                 break;
       
   890             case R_MESSAGEQUERY_ASK_RECORD:
       
   891                 cba.SetCommandSetL( R_DIAG_SPEAKER_SOFTKEYS_START_CANCEL );
       
   892                 break;
       
   893             default:
       
   894                 break;
       
   895             }
       
   896             
       
   897     	
       
   898 
       
   899     result = RunWaitingDialogL( dlg, aButtonId );
       
   900 
       
   901     LOGSTRING3( "CDiagSpeakerPlugin::ShowMessageQueryL() OUT aButtonId=%d result=%d", aButtonId, result )
       
   902     return result;
       
   903     }
       
   904 
       
   905 // ---------------------------------------------------------------------------
       
   906 // CDiagSpeakerPlugin::ShowProgressNoteL
       
   907 // ---------------------------------------------------------------------------
       
   908 //
       
   909 void CDiagSpeakerPlugin::ShowProgressNoteL( TInt aResourceId, TInt aFinalValue )
       
   910     {
       
   911     LOGSTRING( "CDiagSpeakerPlugin::ShowProgressNoteL IN" )
       
   912 
       
   913     CAknProgressDialog* dlg;
       
   914 
       
   915     if ( iProgressDialog )
       
   916         {
       
   917         delete iProgressDialog;
       
   918         iProgressDialog = NULL;
       
   919         }
       
   920 
       
   921     SetProgressDismissed( EFalse );
       
   922 
       
   923     iProgressDialog = dlg = new ( ELeave ) CAknProgressDialog(
       
   924         reinterpret_cast <CEikDialog**> (&iProgressDialog),
       
   925         ETrue
       
   926         );
       
   927 
       
   928     dlg->SetCallback( this );
       
   929     dlg->PrepareLC( aResourceId );
       
   930 
       
   931     // set softkey for single execution
       
   932   /*  if ( SinglePluginExecution() ) 
       
   933         { */ // ADO & Platformization Changes
       
   934         CEikButtonGroupContainer& cba = dlg->ButtonGroupContainer();
       
   935         cba.SetCommandSetL( R_DIAG_SPEAKER_SOFTKEYS_STOP_CANCEL );
       
   936       /*  } */ // ADO & Platformization Changes
       
   937 
       
   938     iProgressInfo = dlg->GetProgressInfoL();
       
   939     iProgressInfo->SetFinalValue( aFinalValue * KFive );
       
   940 
       
   941     dlg->RunLD();
       
   942 
       
   943     // Set up Periodic
       
   944     ClosePeriodic();
       
   945 
       
   946     iPeriodic = CPeriodic::NewL( EPriorityNormal );
       
   947     TCallBack callback( CallbackIncrementProgressNoteL, this );
       
   948     iPeriodic->Start( 0, KProgressDelay, callback );
       
   949 
       
   950     LOGSTRING( "CDiagSpeakerPlugin::ShowProgressNoteL OUT" )
       
   951     }
       
   952 
       
   953 // ---------------------------------------------------------------------------
       
   954 // CDiagSpeakerPlugin::CallbackIncrementProgressNoteL
       
   955 // ---------------------------------------------------------------------------
       
   956 //
       
   957 TInt CDiagSpeakerPlugin::CallbackIncrementProgressNoteL( TAny* aThis )
       
   958     {
       
   959     TInt err = KErrNone;
       
   960     CDiagSpeakerPlugin* myThis  = (CDiagSpeakerPlugin *)aThis;
       
   961 
       
   962     TRAP( err, myThis->UpdateProgressNoteL() );
       
   963     if ( err != KErrNone )
       
   964         {
       
   965         LOGSTRING( "CDiagSpeakerPlugin::CallbackIncrementProgressNoteL:User::Panic() on UpdateProgressNoteL()" )
       
   966         User::Panic( KDiagSpeakerPluginCategory, err );
       
   967         }
       
   968 
       
   969     return KFinished;
       
   970     }
       
   971 
       
   972 // ---------------------------------------------------------------------------
       
   973 // CDiagSpeakerPlugin::UpdateProgressNoteL
       
   974 // ---------------------------------------------------------------------------
       
   975 //
       
   976 TInt CDiagSpeakerPlugin::UpdateProgressNoteL()
       
   977     {
       
   978     TTime              intervalTime;
       
   979     TTime              currentTime;
       
   980 
       
   981     // Prevent from Screen Saver
       
   982     User::ResetInactivityTime();
       
   983 
       
   984     if ( iProgressDialog )
       
   985         {
       
   986         iProgressInfo->IncrementAndDraw(1);
       
   987 
       
   988         if ( (iFinalValue * KFive) <= iProgressInfo->CurrentValue() )
       
   989             {
       
   990             if ( ProgressDismissed() == EFalse )
       
   991                 {
       
   992                 iProgressDialog->ProcessFinishedL();
       
   993                 }
       
   994 
       
   995             return KProgressFinished;
       
   996             }
       
   997         }
       
   998 
       
   999     return KProgressNotFinished;
       
  1000     }
       
  1001 
       
  1002 // ---------------------------------------------------------------------------
       
  1003 // From MDiagPlugin
       
  1004 // CDiagSpeakerPlugin::IsVisible()
       
  1005 // ---------------------------------------------------------------------------
       
  1006 TBool CDiagSpeakerPlugin::IsVisible() const
       
  1007     {
       
  1008     return ETrue;
       
  1009     }
       
  1010 
       
  1011 // ---------------------------------------------------------------------------
       
  1012 // From MDiagTestPlugin
       
  1013 // CDiagSpeakerPlugin::RunMode()
       
  1014 // ---------------------------------------------------------------------------
       
  1015 MDiagTestPlugin::TRunMode CDiagSpeakerPlugin::RunMode() const
       
  1016     {
       
  1017     return EInteractiveDialog;
       
  1018     }
       
  1019 
       
  1020 // ---------------------------------------------------------------------------
       
  1021 // From MDiagTestPlugin
       
  1022 // CDiagSpeakerPlugin::TotalSteps()
       
  1023 // ---------------------------------------------------------------------------
       
  1024 TUint CDiagSpeakerPlugin::TotalSteps() const
       
  1025     {
       
  1026     return ESpeakerPluginTotalSteps;
       
  1027     }
       
  1028 
       
  1029 // ---------------------------------------------------------------------------
       
  1030 // From MDiagPlugin
       
  1031 // CDiagSpeakerPlugin::GetPluginNameL
       
  1032 // ---------------------------------------------------------------------------
       
  1033 HBufC* CDiagSpeakerPlugin::GetPluginNameL( TNameLayoutType aLayoutType ) const
       
  1034     {
       
  1035     switch ( aLayoutType )
       
  1036         {
       
  1037         case ENameLayoutHeadingPane:
       
  1038             return StringLoader::LoadL( R_DIAG_SPEAKER_PLUGIN_HEADING_PANE );
       
  1039 
       
  1040         case ENameLayoutPopupInfoPane:
       
  1041             return StringLoader::LoadL( R_DIAG_SPEAKER_PLUGIN_POPUP_INFO_LIST_PANE );
       
  1042 
       
  1043         case ENameLayoutTitlePane:
       
  1044             return StringLoader::LoadL( R_DIAG_SPEAKER_PLUGIN_TITLE_PANE );
       
  1045 
       
  1046         case ENameLayoutListSingleGraphic:
       
  1047             return StringLoader::LoadL( R_DIAG_SPEAKER_PLUGIN_LIST_SINGLE_GRAPHIC_PANE );
       
  1048 
       
  1049         case ENameLayoutListSingle:           
       
  1050             return StringLoader::LoadL( R_DIAG_SPEAKER_PLUGIN_LIST_SINGLE_GRAPHIC_HEADING_PANE );
       
  1051 
       
  1052         default:
       
  1053             LOGSTRING2( "CDiagSpeakerPlugin::GetPluginNameL: "
       
  1054                 L"ERROR: Unsupported layout type %d", aLayoutType )
       
  1055             __ASSERT_DEBUG( 0, User::Invariant() );
       
  1056             return StringLoader::LoadL ( R_DIAG_SPEAKER_PLUGIN_LIST_SINGLE_GRAPHIC_HEADING_PANE );
       
  1057         }
       
  1058     }
       
  1059 
       
  1060 // ---------------------------------------------------------------------------
       
  1061 // From MDiagPlugin
       
  1062 // CDiagSpeakerPlugin::Uid
       
  1063 // ---------------------------------------------------------------------------
       
  1064 TUid CDiagSpeakerPlugin::Uid() const
       
  1065     {
       
  1066     return KDiagSpeakerPluginUid;
       
  1067     }
       
  1068 
       
  1069 // ---------------------------------------------------------------------------
       
  1070 // From CDiagTestPluginBase
       
  1071 // CDiagSpeakerPlugin::InitializeL()
       
  1072 // ---------------------------------------------------------------------------
       
  1073 void CDiagSpeakerPlugin::TestSessionBeginL(
       
  1074     MDiagEngineCommon& /*aEngine*/,
       
  1075     TBool              /*aSkipDependencyCheck*/,
       
  1076     TAny*              /*aCustomParams*/)
       
  1077     {
       
  1078     LOGSTRING( "CDiagSpeakerPlugin::TestSessionBeginL:: Deleting record file..." )
       
  1079     DeleteRecordFile();
       
  1080     }
       
  1081 
       
  1082 // ---------------------------------------------------------------------------
       
  1083 // From CDiagTestPluginBase
       
  1084 // CDiagSpeakerPlugin::CleanupL()
       
  1085 // ---------------------------------------------------------------------------
       
  1086 void CDiagSpeakerPlugin::TestSessionEndL(
       
  1087     MDiagEngineCommon& /*aEngine*/,
       
  1088     TBool              /*aSkipDependencyCheck*/,
       
  1089     TAny*              /*aCustomParams*/)
       
  1090     {
       
  1091     LOGSTRING( "CDiagSpeakerPlugin::TestSessionEndL:: Deleting record file..." )
       
  1092     DeleteRecordFile();
       
  1093     }
       
  1094 
       
  1095 // ---------------------------------------------------------------------------
       
  1096 // From CDiagTestPluginBase
       
  1097 // CDiagSpeakerPlugin::DoRunTestL()
       
  1098 // ---------------------------------------------------------------------------
       
  1099 void CDiagSpeakerPlugin::DoRunTestL()
       
  1100     {
       
  1101     LOGSTRING( "CDiagSpeakerPlugin::DoRunTest() IN" )
       
  1102 
       
  1103     // Framework should never call DoRunTestL() before previous test
       
  1104     ASSERT_ALWAYS( iRecorder == NULL );
       
  1105     ASSERT_ALWAYS( iAudioPlayer == NULL );
       
  1106     iSessionValid = ETrue;
       
  1107 
       
  1108     // Create Recorder
       
  1109     iRecorder = CMdaAudioRecorderUtility::NewL(
       
  1110         *this,
       
  1111         NULL,
       
  1112         KAudioPriorityRecording,
       
  1113         TMdaPriorityPreference( KAudioPrefRealOneLocalPlayback )
       
  1114         );
       
  1115 
       
  1116     // Create Audio Player
       
  1117     iAudioPlayer = CMdaAudioPlayerUtility::NewL( *this );
       
  1118 
       
  1119     // Check it has been recorded
       
  1120     if ( CheckRecordFile() == EFalse )
       
  1121         {
       
  1122         LOGSTRING( "CDiagSpeakerPlugin::DoRunTest() Record file does not exist. StartRecordL()" )
       
  1123         StartRecordL();
       
  1124         }
       
  1125      else
       
  1126         {
       
  1127         LOGSTRING( "CDiagSpeakerPlugin::DoRunTest() Record file exists. StartPlayL()" )
       
  1128         StartPlayL();
       
  1129         }
       
  1130 
       
  1131     LOGSTRING( "CDiagSpeakerPlugin::DoRunTest() OUT" )
       
  1132     }
       
  1133 
       
  1134 // ---------------------------------------------------------------------------
       
  1135 // CDiagSpeakerPlugin::DoStopAndCleanupL
       
  1136 // ---------------------------------------------------------------------------
       
  1137 //
       
  1138 void CDiagSpeakerPlugin::DoStopAndCleanupL()
       
  1139     {
       
  1140     LOGSTRING( "CDiagSpeakerPlugin::DoStopAndCleanupL IN" )
       
  1141     // All memory and resource allocated during test execution should be
       
  1142     // cleaned up here.
       
  1143 
       
  1144     // Set Session
       
  1145     iSessionValid = EFalse;
       
  1146 
       
  1147     // Close Recorder
       
  1148     if ( iRecorder )
       
  1149     {
       
  1150         LOGSTRING( "CDiagAudioPlugin::DoStopAndCleanupL: Stop & Close AudioPlayer" )
       
  1151         iRecorder->Stop();
       
  1152         iRecorder->Close();
       
  1153     }
       
  1154 
       
  1155     // Close Audio
       
  1156     if ( iAudioPlayer )
       
  1157     {
       
  1158         LOGSTRING( "CDiagSpeakerPlugin::DoStopAndCleanupL: Stop & Close AudioPlayer" )
       
  1159         iAudioPlayer->Stop();
       
  1160         iAudioPlayer->Close();
       
  1161     }
       
  1162 
       
  1163     // Restore AudioOutput
       
  1164    RestoreAudioOutputL();
       
  1165 
       
  1166     if ( ResultsDbItemBuilder().TestResult() == CDiagResultsDatabaseItem::ESuccess )
       
  1167         {
       
  1168         // Test was successful. Do not delete the temporary file.
       
  1169         LOGSTRING( "CDiagSpeakerPlugin::DoStopAndCleanupL: Keep file for next test." )
       
  1170         }
       
  1171     else
       
  1172         {
       
  1173         // test was not successful. Delete recorded file.
       
  1174         LOGSTRING( "CDiagSpeakerPlugin::DoStopAndCleanupL:DeleteRecordFile()" )
       
  1175         DeleteRecordFile();
       
  1176         }
       
  1177 
       
  1178     if ( iAudioState == CMdaAudioRecorderUtility::EPlaying )
       
  1179         {
       
  1180         LOGSTRING( "CDiagSpeakerPlugin::DoStopAndCleanupL:RestoreAudioOutputL" )
       
  1181         TRAP_IGNORE( RestoreAudioOutputL() );
       
  1182         }
       
  1183 
       
  1184     // Call Engine to Dismiss Any Dialog
       
  1185     DismissWaitingDialog();
       
  1186 
       
  1187     // Close which can be recovered by running doRunTestL()
       
  1188     ClosePeriodic();
       
  1189 
       
  1190     // Clean up resources allocated during object creation.
       
  1191     delete iRecorder;
       
  1192     iRecorder = NULL;
       
  1193 
       
  1194     delete iAudioPlayer;
       
  1195     iAudioPlayer = NULL;
       
  1196 
       
  1197     delete iAudioOutput;
       
  1198     iAudioOutput = NULL;
       
  1199 
       
  1200     // Cleanup Progress Dialog
       
  1201     LOGSTRING( "Cleanup Progress Dialog" )
       
  1202     if ( iProgressDialog )
       
  1203         {
       
  1204         delete iProgressDialog;
       
  1205         iProgressDialog = NULL;
       
  1206         }
       
  1207 
       
  1208     SetProgressDismissed( ETrue );
       
  1209 
       
  1210     LOGSTRING( "CDiagSpeakerPlugin::DoStopAndCleanupL OUT" )
       
  1211     }
       
  1212 
       
  1213 // ---------------------------------------------------------------------------
       
  1214 // From CActive
       
  1215 // CDiagSpeakerPlugin::RunL
       
  1216 // ---------------------------------------------------------------------------
       
  1217 void CDiagSpeakerPlugin::RunL()
       
  1218     {
       
  1219     switch(iState)
       
  1220         {
       
  1221         case EStateCancelled:
       
  1222             CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
  1223             return;
       
  1224         case EStateRecorded:
       
  1225             AfterRecordL();
       
  1226             break;
       
  1227         case EStatePlayed:
       
  1228             AfterPlayL();
       
  1229             break;
       
  1230         }
       
  1231     }
       
  1232 
       
  1233 // ---------------------------------------------------------------------------
       
  1234 // From CActive
       
  1235 // CDiagSpeakerPlugin::DoCancel
       
  1236 // ---------------------------------------------------------------------------
       
  1237 void CDiagSpeakerPlugin::DoCancel()
       
  1238     {
       
  1239     // Stop active request. This class does not use Async request using iStatus.
       
  1240     }
       
  1241 
       
  1242 // ---------------------------------------------------------------------------
       
  1243 // CDiagSpeakerPlugin::DialogDismissedL
       
  1244 // ---------------------------------------------------------------------------
       
  1245 //
       
  1246 void CDiagSpeakerPlugin::DialogDismissedL( TInt aButtonId )
       
  1247     {
       
  1248     LOGSTRING2( "CDiagSpeakerPlugin::DialogDismissedL: aButtonId = %d", aButtonId )
       
  1249 
       
  1250     TInt        prevState;
       
  1251 
       
  1252     SetProgressDismissed( ETrue );
       
  1253 
       
  1254     // Restore Audio Output in case of Playing
       
  1255     if ( iAudioState == CMdaAudioRecorderUtility::EPlaying )
       
  1256         {
       
  1257         LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL: Calling RestoreAudioOutputL" )
       
  1258         if ( iAudioOutput )
       
  1259         {
       
  1260             delete iAudioOutput;
       
  1261             iAudioOutput = NULL;
       
  1262         }
       
  1263 
       
  1264         //RestoreAudioOutputL();
       
  1265         }
       
  1266 
       
  1267     // Stop Recording / Playing
       
  1268     if ( iAudioState == CMdaAudioRecorderUtility::ERecording )
       
  1269         {
       
  1270         LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: Stop. Record" )
       
  1271         if ( iRecorder )
       
  1272             {
       
  1273             iRecorder->Stop();
       
  1274             iRecorder->Close();
       
  1275             }
       
  1276         }
       
  1277     else if ( iAudioState == CMdaAudioRecorderUtility::EPlaying )
       
  1278         {
       
  1279         LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: Stop. Play" )
       
  1280         if ( iAudioPlayer )
       
  1281             {
       
  1282             iAudioPlayer->Stop();
       
  1283             iAudioPlayer->Close();
       
  1284             }
       
  1285         }
       
  1286 
       
  1287     // If button has not pressed
       
  1288     if ( ( aButtonId != ECBACmdSkip )   &&
       
  1289          ( aButtonId != EEikBidCancel ) &&   // ADO & Platformization Changes
       
  1290          ( aButtonId != EAknSoftkeyOk ) &&
       
  1291          ( aButtonId != EAknSoftkeyDone) &&
       
  1292          ( aButtonId != ECBACmdCancel )
       
  1293        )
       
  1294         {
       
  1295         LOGSTRING2( "CDiagAudioPlugin::DialogDismissedL: Button not pressed. aButtonId = %d", aButtonId )
       
  1296         return;
       
  1297         }
       
  1298 
       
  1299     // Skip
       
  1300     if ( aButtonId == ECBACmdSkip )
       
  1301         {
       
  1302         LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: aButtonId == ECBACmdSkip" )
       
  1303         CompleteTestL( CDiagResultsDatabaseItem::ESkipped );
       
  1304         return;
       
  1305         }
       
  1306 
       
  1307     // Cancel
       
  1308     else if ( aButtonId == EEikBidCancel ) // ADO & Platformization Changes
       
  1309         {
       
  1310         LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: aButtonId == ECBACmdCancel" )
       
  1311 
       
  1312         prevState = iAudioState;
       
  1313         iAudioState    = CMdaAudioRecorderUtility::EOpen;
       
  1314 
       
  1315         TInt   cancelButtonId;
       
  1316         TBool  cancelResult = EFalse;
       
  1317 
       
  1318         cancelResult = AskCancelExecutionL( cancelButtonId );
       
  1319         
       
  1320         if ( !cancelResult )
       
  1321             {
       
  1322             LOGSTRING( "CDiagSpeakerPlugin::StartPlayL - !iSessionValid 3" )
       
  1323             return;
       
  1324             }
       
  1325 
       
  1326         switch ( cancelButtonId )
       
  1327             {
       
  1328             case EAknSoftkeyYes:
       
  1329                 SetAudioEvent(EStateCancelled);
       
  1330                 LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: EAknSoftkeyYes return NOW!!" )
       
  1331                 return;
       
  1332 
       
  1333             default:
       
  1334                 if ( prevState == CMdaAudioRecorderUtility::ERecording )
       
  1335                     {
       
  1336                     LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: Start RecordL" )
       
  1337                     RecordL();
       
  1338                     }
       
  1339                 else if ( prevState == CMdaAudioRecorderUtility::EPlaying )
       
  1340                     {
       
  1341                     LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: Start PlayL" )
       
  1342                     PlayL();
       
  1343                     }
       
  1344                 break;
       
  1345             }
       
  1346         return;
       
  1347         }
       
  1348 
       
  1349     // Stop
       
  1350     else
       
  1351         {
       
  1352         LOGSTRING2( "CDiagSpeakerPlugin::DialogDismissedL: State = %d", iAudioState )
       
  1353         if ( iAudioState == CMdaAudioRecorderUtility::ERecording )
       
  1354             {
       
  1355             LOGSTRING( "CDiagAudioPlugin::DialogDismissedL:: Stop. Record" )
       
  1356             if ( iRecorder &&  iState == EStateUnknown)
       
  1357                 {
       
  1358                 LOGSTRING( "CDiagAudioPlugin::DialogDismissedL:: Stop. Call AfterRecordL()" )
       
  1359                 SetAudioEvent(EStateRecorded);
       
  1360                 }
       
  1361             /*
       
  1362             LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: Stop. Call AfterRecordL()" )
       
  1363             // Stop playback/recording
       
  1364             AfterRecordL(); */
       
  1365             }
       
  1366         else if ( iAudioState == CMdaAudioRecorderUtility::EPlaying )
       
  1367             {  
       
  1368             LOGSTRING( "CDiagAudioPlugin::DialogDismissedL:: Stop. Play" )
       
  1369             if ( iAudioPlayer && iState == EStateRecorded)
       
  1370                 {
       
  1371                 LOGSTRING( "CDiagAudioPlugin::DialogDismissedL:: Stop. Call AfterPlayL()" )
       
  1372                 SetAudioEvent(EStatePlayed);
       
  1373                 }
       
  1374             /*
       
  1375             LOGSTRING( "CDiagSpeakerPlugin::DialogDismissedL:: Stop. Call AfterPlayL()" )
       
  1376             // Stop playback/recording
       
  1377             AfterPlayL(); */
       
  1378             }
       
  1379         }
       
  1380     }
       
  1381 
       
  1382 
       
  1383 void CDiagSpeakerPlugin::SetAudioEvent(TState aState)
       
  1384     {
       
  1385     iState = aState;
       
  1386     SetActive();
       
  1387     TRequestStatus* status = &iStatus;
       
  1388     User::RequestComplete(status, KErrNone);
       
  1389     }
       
  1390 
       
  1391 // ---------------------------------------------------------------------------
       
  1392 // CDiagSpeakerPlugin::MoscoStateChangeEvent
       
  1393 // ---------------------------------------------------------------------------
       
  1394 //
       
  1395 void CDiagSpeakerPlugin::MoscoStateChangeEvent(
       
  1396     CBase* /*aObject*/,
       
  1397     TInt   aPreviousState,
       
  1398     TInt   aCurrentState,
       
  1399     TInt   aErrorCode
       
  1400 )
       
  1401     {
       
  1402     TInt err = KErrNone;
       
  1403 
       
  1404     LOGSTRING4( "CDiagSpeakerPlugin::MoscoStateChangeEvent:IN (%d -> %d, %d )", aPreviousState, aCurrentState, aErrorCode )
       
  1405 
       
  1406     // 1. Record reaches to the end of file
       
  1407     if ( aErrorCode == KErrEof )
       
  1408         {
       
  1409         iState = EStateRecorded;
       
  1410         iAudioState = CMdaAudioRecorderUtility::EOpen;
       
  1411         TRAP( err, AfterRecordL() );
       
  1412         }
       
  1413 
       
  1414     // 2. Start - Recording
       
  1415     else if ( ( aPreviousState == CMdaAudioRecorderUtility::ENotReady)  &&
       
  1416               ( aCurrentState  == CMdaAudioRecorderUtility::EOpen    ) )
       
  1417         {
       
  1418         LOGSTRING( "CDiagSpeakerPlugin::MoscoStateChangeEvent: Leave on RecordingL()" )
       
  1419         TRAP( err, RecordingL() );
       
  1420         LOGSTRING2( "CDiagSpeakerPlugin::MoscoStateChangeEvent: RecordingL() err = %d", err )
       
  1421         }
       
  1422 
       
  1423     // 3. Stopped - Recording
       
  1424     else if ( ( aPreviousState == CMdaAudioRecorderUtility::ERecording ) &&
       
  1425               ( aCurrentState  == CMdaAudioRecorderUtility::EOpen )
       
  1426             )
       
  1427         {
       
  1428         iState = EStateRecorded;
       
  1429         LOGSTRING( "CDiagSpeakerPlugin::MoscoStateChangeEvent: Leave on AfterRecordL()" )
       
  1430         TRAP( err, AfterRecordL() );
       
  1431         LOGSTRING2( "CDiagSpeakerPlugin::MoscoStateChangeEvent: AfterRecordL() err = %d", err )
       
  1432         }
       
  1433 
       
  1434     // Handle for Trap
       
  1435     if (err != KErrNone)
       
  1436         {
       
  1437         LOGSTRING2( "CDiagSpeakerPlugin::MoscoStateChangeEvent:Call CompleteTestL with error = %d", err )
       
  1438         TRAP( err, CompleteTestL(CDiagResultsDatabaseItem::EFailed) );
       
  1439         if ( err != KErrNone )
       
  1440             {
       
  1441             LOGSTRING( "CDiagSpeakerPlugin::MoscoStateChangeEvent:User::Panic()" )
       
  1442             User::Panic( KDiagSpeakerPluginCategory, err );
       
  1443             }
       
  1444         return; // Fail Test
       
  1445         }
       
  1446     LOGSTRING( "CDiagSpeakerPlugin::MoscoStateChangeEvent OUT" )
       
  1447     }
       
  1448 
       
  1449 // ---------------------------------------------------------------------------
       
  1450 // CDiagSpeakerPlugin::MapcInitComplete
       
  1451 // ---------------------------------------------------------------------------
       
  1452 //
       
  1453 void CDiagSpeakerPlugin::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
       
  1454     {
       
  1455     LOGSTRING2( "CDiagSpeakerPlugin::MapcInitComplete: aError=%d", aError )
       
  1456     TInt err = KErrNone;
       
  1457 
       
  1458     // Set Duration
       
  1459     iPositionMicroSec    = 0;
       
  1460     iMaxDurationMicroSec = aDuration;
       
  1461 
       
  1462     // Set Priority of AudioPlayer
       
  1463     iAudioPlayer->SetPriority(
       
  1464         KAudioPriorityAlarm + 1,
       
  1465         TMdaPriorityPreference( KAudioPrefVoiceRec )
       
  1466         );
       
  1467 
       
  1468     // Set Audio Output
       
  1469     if ( iAudioOutput )
       
  1470     {
       
  1471         delete iAudioOutput;
       
  1472         iAudioOutput = NULL;
       
  1473     }
       
  1474 
       
  1475     // Create AudioOutput
       
  1476     TRAP(err,iAudioOutput = CAudioOutput::NewL( *iAudioPlayer ));
       
  1477     if ( err != KErrNone ) // Added for removing code scanner warning
       
  1478         {
       
  1479         LOGSTRING2( "CDiagSpeakerPlugin::MapcInitComplete:Call CompleteTestL with error = %d", err )
       
  1480         TRAP( err, CompleteTestL(CDiagResultsDatabaseItem::EFailed) );
       
  1481 
       
  1482         if ( err != KErrNone )
       
  1483             {
       
  1484             LOGSTRING( "CDiagSpeakerPlugin::MapcInitComplete:User::Panic()" )
       
  1485             User::Panic( KDiagSpeakerPluginCategory, err );
       
  1486             }
       
  1487 
       
  1488         return; // Fail Test
       
  1489         } 
       
  1490     
       
  1491     TRAP(err,iAudioOutput->SetAudioOutputL( iOutput ));
       
  1492     
       
  1493     if ( err != KErrNone ) // Added for removing code scanner warning
       
  1494         {
       
  1495         LOGSTRING2( "CDiagSpeakerPlugin::MapcInitComplete:Call CompleteTestL with error = %d", err )
       
  1496         TRAP( err, CompleteTestL(CDiagResultsDatabaseItem::EFailed) );
       
  1497 
       
  1498         if ( err != KErrNone )
       
  1499             {
       
  1500             LOGSTRING( "CDiagSpeakerPlugin::MapcInitComplete:User::Panic()" )
       
  1501             User::Panic( KDiagSpeakerPluginCategory, err );
       
  1502             }
       
  1503 
       
  1504         return; // Fail Test
       
  1505         } 
       
  1506 
       
  1507     // Start Playing
       
  1508     TRAP( err, PlayingL() );
       
  1509 
       
  1510     // Handle for Trap
       
  1511     if ( err != KErrNone )
       
  1512         {
       
  1513         LOGSTRING2( "CDiagSpeakerPlugin::MapcInitComplete:Call CompleteTestL with error = %d", err )
       
  1514         TRAP( err, CompleteTestL(CDiagResultsDatabaseItem::EFailed) );
       
  1515 
       
  1516         if ( err != KErrNone )
       
  1517             {
       
  1518             LOGSTRING( "CDiagSpeakerPlugin::MapcInitComplete:User::Panic()" )
       
  1519             User::Panic( KDiagSpeakerPluginCategory, err );
       
  1520             }
       
  1521 
       
  1522         return; // Fail Test
       
  1523         }
       
  1524     }
       
  1525 
       
  1526 // ---------------------------------------------------------------------------
       
  1527 // CDiagSpeakerPlugin::MapcPlayComplete
       
  1528 // ---------------------------------------------------------------------------
       
  1529 //
       
  1530 void CDiagSpeakerPlugin::MapcPlayComplete(TInt aError)
       
  1531     {
       
  1532     LOGSTRING2( "CDiagSpeakerPlugin::MapcPlayComplete: aError=%d", aError )
       
  1533 
       
  1534     if ( aError == KErrNone)
       
  1535         {
       
  1536         LOGSTRING( "CDiagSpeakerPlugin::MapcPlayComplete KErrNone" )
       
  1537         
       
  1538         if ( iAudioOutput )
       
  1539         {
       
  1540             delete iAudioOutput;
       
  1541             iAudioOutput = NULL;
       
  1542         }
       
  1543 
       
  1544        // RestoreAudioOutputL();
       
  1545 
       
  1546         
       
  1547         if(iState == EStateRecorded)
       
  1548             {
       
  1549         // Stop and Close Audio Player
       
  1550             if ( iAudioPlayer )
       
  1551                 {
       
  1552                 iAudioPlayer->Stop();
       
  1553                 iAudioPlayer->Close();
       
  1554                 iState = EStatePlayed;
       
  1555                 }
       
  1556     
       
  1557             TRAPD(err,AfterPlayL());
       
  1558             
       
  1559             // Handle for Trap
       
  1560 				    if ( err != KErrNone )
       
  1561 				        {
       
  1562 				        LOGSTRING2( "CDiagSpeakerPlugin::MapcInitComplete:Call CompleteTestL with error = %d", err )
       
  1563 				        TRAP( err, CompleteTestL(CDiagResultsDatabaseItem::EFailed) );
       
  1564 				
       
  1565 				        if ( err != KErrNone )
       
  1566 				            {
       
  1567 				            LOGSTRING( "CDiagSpeakerPlugin::MapcInitComplete:User::Panic()" )
       
  1568 				            User::Panic( KDiagSpeakerPluginCategory, err );
       
  1569 				            }
       
  1570 				
       
  1571 				        return; // Fail Test
       
  1572 				        }
       
  1573             }
       
  1574         return;
       
  1575         }
       
  1576     }
       
  1577 // End of File
       
  1578