mmserv/sts/tsrc/ststester/src/ststester.cpp
branchRCL_3
changeset 19 095bea5f582e
equal deleted inserted replaced
18:a36789189b53 19:095bea5f582e
       
     1 /*
       
     2  * Copyright (c) 2010 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:
       
    15  * The file contains the implementation of the STS Tester.
       
    16  */
       
    17 
       
    18 #include "ststester.h"
       
    19 
       
    20 #include <systemtoneservice.h>
       
    21 #define PROFILE_TIME 1
       
    22 #include "profileutilmacro.h"
       
    23 
       
    24 const TInt KKeyMapPageCount = 1;
       
    25 
       
    26 const TInt KFontSize = 15;
       
    27 
       
    28 const TOperationsPage KKeyMap[KKeyMapPageCount] =
       
    29     {
       
    30         {
       
    31         STR("Standard controls"), 5, // default softkey index
       
    32                     {
       
    33                     // Enter
       
    34                                 {
       
    35                                 STR(""), KOperation_ExecuteOption
       
    36                                 },
       
    37                             // Up / Down / Left / Right
       
    38                                 {
       
    39                                 STR(""), KOperation_PreviousOption
       
    40                                 },
       
    41                                 {
       
    42                                 STR(""), KOperation_NextOption
       
    43                                 },
       
    44                                 {
       
    45                                 STR(""), KOperation_PreviousOptionPage
       
    46                                 },
       
    47                                 {
       
    48                                 STR(""), KOperation_NextOptionPage
       
    49                                 },
       
    50                             // 0 - 9
       
    51                                 {
       
    52                                         STR("Stop Current Alarm"),
       
    53                                         EOperation_StopCurrentAlarm
       
    54                                 },
       
    55                                 {
       
    56                                         STR("Play Default Beep"),
       
    57                                         EOperation_PlayDefaultBeep
       
    58                                 },
       
    59                                 {
       
    60                                         STR("Play Default Alarm"),
       
    61                                         EOperation_PlayDefaultAlarm
       
    62                                 },
       
    63                                 {
       
    64                                         STR("Play Default Beep as Alarm"),
       
    65                                         EOperation_PlayDefaultasAlarm
       
    66                                 },
       
    67                                 {
       
    68                                         STR("Play Incoming Call Alarm"),
       
    69                                         EOperation_PlayIncomingCallAlarm
       
    70                                 },
       
    71                                 {
       
    72                                         STR("Play Warning Beep"),
       
    73                                         EOperation_PlayWarningBeep
       
    74                                 },
       
    75                                 {
       
    76                                 STR(""), KOperation_None
       
    77                                 },
       
    78                                 {
       
    79                                 STR(""), KOperation_None
       
    80                                 },
       
    81                                 {
       
    82                                 STR(""), KOperation_None
       
    83                                 },
       
    84                                 {
       
    85                                 STR("Exit"), KOperation_Exit
       
    86                                 }
       
    87                     }
       
    88         }
       
    89     };
       
    90 
       
    91 void CStsTester::ExecuteL()
       
    92     {
       
    93     CStsTester* self = new (ELeave) CStsTester;
       
    94     CleanupStack::PushL(self);
       
    95     self->InitL();
       
    96     self->Main();
       
    97     CleanupStack::PopAndDestroy(self);
       
    98     }
       
    99 
       
   100 CStsTester::CStsTester() :
       
   101     CTestAppBase(KFontSize), iPlayState(EStopped)
       
   102     {
       
   103     }
       
   104 
       
   105 CStsTester::~CStsTester()
       
   106     {
       
   107     CSystemToneService::Delete(iSts);
       
   108     }
       
   109 
       
   110 void CStsTester::InitL()
       
   111     {
       
   112     BaseConstructL(KKeyMap, KKeyMapPageCount);
       
   113     iSts = CSystemToneService::Create();
       
   114     }
       
   115 
       
   116 void CStsTester::Main()
       
   117     {
       
   118     TRAP_IGNORE(MainL());
       
   119     }
       
   120 
       
   121 void CStsTester::MainL()
       
   122     {
       
   123     _LIT(KStopCurrentAlarm, "Stop Current Alarm");
       
   124     _LIT(KPlayDefault, "Play Default Beep");
       
   125     _LIT(KPlayDefaultAlarm, "Play Default Alarm");
       
   126     _LIT(KPlayDefaultAsAlarm, "Play Default Beep as Alarm");
       
   127     _LIT(KPlayIncomingCallAlarm, "Play Incoming Call Alarm");
       
   128     _LIT(KPlayWarningBeep, "Play Warning Beep");
       
   129     _LIT(KExit, "Exit");
       
   130 
       
   131     bool done = false;
       
   132 
       
   133     while (!done)
       
   134         {
       
   135         RPointerArray<TDesC> operations;
       
   136         operations.Append(&KStopCurrentAlarm);
       
   137         operations.Append(&KPlayDefault);
       
   138         operations.Append(&KPlayDefaultAlarm);
       
   139         operations.Append(&KPlayDefaultAsAlarm);
       
   140         operations.Append(&KPlayIncomingCallAlarm);
       
   141         operations.Append(&KPlayWarningBeep);
       
   142         operations.Append(&KExit);
       
   143 
       
   144         TInt index = SelectFromListL(TPoint(0, 0), iDisplaySize, _L(
       
   145                 "Select STS operation to perform:"), operations);
       
   146 
       
   147         operations.Reset();
       
   148 
       
   149         TPtrC operationName(STR("Play Default Beep"));
       
   150 
       
   151         switch (index)
       
   152             {
       
   153             case -1:
       
   154                 done = true;
       
   155                 break;
       
   156             case 0:
       
   157                 ExecuteOperation(EOperation_StopCurrentAlarm, operationName);
       
   158                 break;
       
   159             case 1:
       
   160                 ExecuteOperation(EOperation_PlayDefaultBeep, operationName);
       
   161                 break;
       
   162             case 2:
       
   163                 ExecuteOperation(EOperation_PlayDefaultAlarm, operationName);
       
   164                 break;
       
   165             case 3:
       
   166                 ExecuteOperation(EOperation_PlayDefaultasAlarm, operationName);
       
   167                 break;
       
   168             case 4:
       
   169                 ExecuteOperation(EOperation_PlayIncomingCallAlarm, operationName);
       
   170                 break;
       
   171             case 5:
       
   172                 ExecuteOperation(EOperation_PlayWarningBeep, operationName);
       
   173                 break;
       
   174             case 6:
       
   175                 done = true;
       
   176                 break;
       
   177             }
       
   178         }
       
   179     }
       
   180 
       
   181 void CStsTester::ExecuteOperation(TInt aOperation, const TDesC& /*aOperationText*/)
       
   182     {
       
   183     switch (aOperation)
       
   184         {
       
   185         case EOperation_StopCurrentAlarm:
       
   186             {
       
   187             TAG_TIME_PROFILING_BEGIN;
       
   188             iSts->StopAlarm(iCurrentContext);
       
   189             TAG_TIME_PROFILING_END;
       
   190             PRINT_TO_CONSOLE_TIME_DIFF;
       
   191             iPlayState = EStopped;
       
   192             break;
       
   193             }
       
   194         case EOperation_PlayDefaultBeep:
       
   195             {
       
   196             TAG_TIME_PROFILING_BEGIN;
       
   197             iSts->PlayTone(CSystemToneService::EDefaultBeep);
       
   198             TAG_TIME_PROFILING_END;
       
   199             PRINT_TO_CONSOLE_TIME_DIFF;
       
   200             break;
       
   201             }
       
   202         case EOperation_PlayDefaultAlarm:
       
   203             {
       
   204             // Only play if not already playing
       
   205             if (iPlayState != EPlaying)
       
   206                 {
       
   207                 iPlayState = EPlaying;
       
   208                 TAG_TIME_PROFILING_BEGIN;
       
   209                 iSts->PlayAlarm(CSystemToneService::EClockAlarm,
       
   210                         iCurrentContext, *this);
       
   211                 TAG_TIME_PROFILING_END;
       
   212                 PRINT_TO_CONSOLE_TIME_DIFF;
       
   213                 }
       
   214             break;
       
   215             }
       
   216         case EOperation_PlayDefaultasAlarm:
       
   217             {
       
   218             // Only play if not already playing
       
   219             if (iPlayState != EPlaying)
       
   220                 {
       
   221                 iPlayState = EPlaying;
       
   222                 TAG_TIME_PROFILING_BEGIN;
       
   223                 iSts->PlayAlarm(CSystemToneService::EDefaultBeep,
       
   224                         iCurrentContext, *this);
       
   225                 TAG_TIME_PROFILING_END;
       
   226                 PRINT_TO_CONSOLE_TIME_DIFF;
       
   227                 }
       
   228             break;
       
   229             }
       
   230         case EOperation_PlayIncomingCallAlarm:
       
   231             {
       
   232             // Only play if not already playing
       
   233             if (iPlayState != EPlaying)
       
   234                 {
       
   235                 iPlayState = EPlaying;
       
   236                 TAG_TIME_PROFILING_BEGIN;
       
   237                 iSts->PlayAlarm(CSystemToneService::EIncomingCall,
       
   238                         iCurrentContext, *this);
       
   239                 TAG_TIME_PROFILING_END;
       
   240                 PRINT_TO_CONSOLE_TIME_DIFF;
       
   241                 }
       
   242             break;
       
   243             }
       
   244         case EOperation_PlayWarningBeep:
       
   245             {
       
   246             // Only play if not already playing
       
   247                 TAG_TIME_PROFILING_BEGIN;
       
   248                 iSts->PlayTone(CSystemToneService::EWarningBeep);
       
   249                 TAG_TIME_PROFILING_END;
       
   250                 PRINT_TO_CONSOLE_TIME_DIFF;
       
   251             break;
       
   252             }
       
   253         default:
       
   254             {
       
   255             break;
       
   256             }
       
   257         }
       
   258     }
       
   259 
       
   260 void CStsTester::PlayAlarmComplete(unsigned int aAlarmContext)
       
   261     {
       
   262     if (aAlarmContext == iCurrentContext)
       
   263         {
       
   264         iPlayState = EStopped;
       
   265         }
       
   266     }