examples/Telephony/ETel3rdPartyExample/AutoDTMFDialler/CMainMenu.cpp

00001 /*
00002 Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #include "CMainMenu.h"
00032 
00039 CMainMenu* CMainMenu::NewLC(CConsoleBase& aConsole)
00040         {
00041         CMainMenu* self = new(ELeave) CMainMenu(aConsole);
00042         CleanupStack::PushL(self);
00043         self->ConstructL();
00044         return self;
00045         }
00046 
00053 CMainMenu::CMainMenu(CConsoleBase& aConsole)
00054         : CBaseMenuAsync(aConsole)
00055         , iCurrentTone(_L(""))
00056         , iCurrentToneLog(_L(""))
00057         , iTheNumber(KTheNumber)
00058         {
00059         iSingleString = ETrue;
00060         }
00061 
00065 void CMainMenu::ConstructL()
00066         {
00067         CBaseMenuAsync::ConstructL();
00068         iPhoneId = CPhoneId::NewL(this);
00069 
00070         iFlightModeInfo = CFlightModeInfo::NewL(this);
00071         iNetworkRegInfo = CNetworkRegInfo::NewL(this);
00072 
00073         iDialCall = CDialCall::NewL(this);
00074         iSendDTMF = CSendDTMF::NewL(this);
00075         iHangup = CHangup::NewL(this);
00076         iLineStatus = CLineStatus::NewL(this);
00077         }
00078 
00082 CMainMenu::~CMainMenu()
00083         {
00084         delete iTelephony;
00085         delete iPhoneId;
00086 
00087         delete iFlightModeInfo;
00088         delete iNetworkRegInfo;
00089 
00090         delete iDialCall;
00091         delete iHangup;
00092         delete iSendDTMF;
00093         delete iCallStatus;
00094         delete iLineStatus;
00095         }
00096 
00103 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType)
00104         {
00105         if      (iState==ESetNotifier || aDerivedType == KDialCall)
00106                 {
00107                 switch(aDerivedType)
00108                         {
00109                 case KSendDTMF:
00110                         iLastOperation = iSendDTMF;
00111                         break;
00112                 case KFlightModeInfo:
00113                         iLastOperation = iFlightModeInfo;
00114                         break;
00115                 case KNetworkRegInfo:
00116                         iLastOperation = iNetworkRegInfo;
00117                         break;
00118                 case KDialCall:
00119                         iLastOperation = iDialCall;
00120                         break;
00121                 case KHangup:
00122                         iLastOperation = iHangup;
00123                         break;
00124                 case KCallStatus:
00125                         iLastOperation = iCallStatus;
00126                         break;
00127                 default:
00128                         break;  
00129                         }
00130                 TRAPD(errNotify, iLastOperation->RequestNotificationL());
00131                 if (errNotify != KErrNone)
00132                         {
00133                         iConsole->Printf(_L("Notification Request for TTelISVExampleType"));
00134                         iConsole->Printf(_L("%d left with error code "), aDerivedType);
00135                         iConsole->Printf(_L("%d\n"), errNotify);
00136                         return;
00137                         }
00138                         
00139                 // Check the type of iLastOperation to see
00140                 // what it has been cast to.
00141                 switch(iLastOperation->GetExampleType())
00142                         {
00143                 case KFlightModeInfo:
00144                         iState = EGetNetworkRegStatus;
00145                         iLastOperation = iNetworkRegInfo;
00146                         SetActive();
00147                         CompleteOwnRequest(KErrNone);
00148                         break;
00149                 case KDialCall:
00150                         iCallId = reinterpret_cast<CDialCall*>
00151                                   (iDialCall)->iCallId;
00152                         TRAPD(err,      iCallStatus = CCallStatus::NewL(this, iCallId));
00153                         if (err != KErrNone)
00154                                 {
00155                                 iConsole->Printf(_L("CallStatus construction left "));
00156                                 iConsole->Printf(_L("with error code %d\n"), err);
00157                                 return;
00158                                 }
00159                         iState = EGetCallStatus;
00160                         iLastOperation = iCallStatus;
00161                         SetActive();
00162                         CompleteOwnRequest(KErrNone);
00163                         break;
00164                 case KCallStatus:
00165                         iConsole->ClearScreen();
00166                         iConsole->Printf(KMenuMsg);
00167                         iConsole->Printf(KDTMFQuestion);
00168                         iConsole->Printf(KiSingleString);
00169                         iConsole->Printf(KAsChar);
00170                         GetInput();
00171                         break;
00172                 case KSendDTMF:
00173                         iConsole->ClearScreen();
00174                         iConsole->Printf(KMenuMsg);
00175                         iConsole->Printf(KHangupMsg);
00176                         GetInput();
00177                         break;
00178                 default:
00179 
00180                         break;
00181                         }
00182                 }
00183         else if(aDerivedType == KPhoneId)
00184                 {
00185                 iLastOperation = iFlightModeInfo;
00186                 SetActive();
00187                 CompleteOwnRequest(KErrNone);
00188                 }
00189         }
00190 
00197 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType)
00198         {
00199         switch(aDerivedType)
00200                 {
00201         case KNetworkRegInfo:
00202                 TRAPD(err, iNetworkRegInfo->RequestNotificationL());
00203                 if (err != KErrNone)
00204                         {
00205                         iConsole->Printf(_L("Request left with error code "));
00206                         iConsole->Printf(_L("%d\n"),err);
00207                         return;
00208                         }
00209                 iState = EGetLineStatus;
00210                 iLastOperation = iLineStatus;
00211                 SetActive();
00212                 CompleteOwnRequest(KErrNone);
00213                 break;
00214         case KLineStatus:
00215                 // Waiting for dial request
00216                 TRAP(err, iLineStatus->RequestNotificationL());
00217                 if (err != KErrNone)
00218                         {
00219                         iConsole->Printf(_L("Request left with error code "));
00220                         iConsole->Printf(_L("%d\n"),err);
00221                         return;
00222                         }
00223                 iConsole->ClearScreen();
00224                 iConsole->Printf(KMenuMsg);
00225                 iConsole->Printf(KDialMsg);
00226                 GetInput();
00227                 break;
00228         case KCallStatus:
00229                 delete iCallStatus;
00230                 iCallStatus = NULL;
00231                 iState = EGetLineStatus;
00232                 iLastOperation = iLineStatus;
00233                 SetActive();
00234                 CompleteOwnRequest(KErrNone);
00235                 break;
00236         case KSendDTMF:
00237                 iConsole->ClearScreen();
00238                 iConsole->Printf(KMenuMsg);
00239                 iConsole->Printf(KAsChar);
00240                 GetInput();
00241                 break;
00242         default:
00243                 break;
00244                 }
00245         }
00246 
00250 void CMainMenu::RunL()
00251         {
00252         switch(iState)
00253                 {
00254         case EStart:
00255                 iState = EGetFlightModeInfo;
00256                 iLastOperation = iPhoneId;
00257                 TRAPD(errPhone, iLastOperation->StartRequestL());
00258                 if (errPhone != KErrNone)
00259                         {
00260                         iConsole->Printf(_L("Request left with error code "));
00261                         iConsole->Printf(_L("%d\n"), errPhone);
00262                         return;
00263                         }
00264                 break;
00265         case EEnd:
00266                 CActiveScheduler::Stop();
00267                 break;
00268         case EGetLineStatus:
00269         case EGetCallStatus:
00270         case EGetFlightModeInfo:
00271         case EGetNetworkRegStatus:
00272                 iState = ESetNotifier;
00273                 TRAPD(err, iLastOperation->StartRequestL());
00274                 if (err != KErrNone)
00275                         {
00276                         iConsole->Printf(_L("Request left with error code "));
00277                         iConsole->Printf(_L("%d\n"), err);
00278                         return;
00279                         }
00280                 break;
00281         case EHangup:
00282                 iState = ESetNotifier;
00283                 TRAPD(errArg, iLastOperation->StartRequestL(iCallId));
00284                 if (errArg != KErrNone)
00285                         {
00286                         iConsole->Printf(_L("Request left with error code "));
00287                         iConsole->Printf(_L("%d\n"), errArg);
00288                         return;
00289                         }
00290                 break;
00291         case EDialCall:
00292                 iState = ESetNotifier;
00293                 TRAPD(errArg3, iLastOperation->StartRequestL(KTheNumber));
00294                 if (errArg3 != KErrNone)
00295                         {
00296                         iConsole->Printf(_L("Request left with error code "));
00297                         iConsole->Printf(_L("%d\n"), errArg3);
00298                         return;
00299                         }
00300                 break;
00301         case ESendDTMF:
00302                 iState = ESetNotifier;
00303                 if (iSingleString)
00304                         {
00305                         TRAPD(errArg2, iLastOperation->StartRequestL(iTheNumber))
00306                         if (errArg2 != KErrNone)
00307                                 {
00308                                 iConsole->Printf(_L("Request left with error code "));
00309                                 iConsole->Printf(_L("%d\n"), errArg2);
00310                                 return;
00311                                 }
00312                         }
00313                 else
00314                         {
00315                         TRAPD(errArg2, iLastOperation->StartRequestL(iCurrentTone))
00316                         if (errArg2 != KErrNone)
00317                                 {
00318                                 iConsole->Printf(_L("Request left with error code "));
00319                                 iConsole->Printf(_L("%d\n"), errArg2);
00320                                 return;
00321                                 }
00322                         }
00323                 break;
00324         case EWaitingForKeyPress:
00325                 {
00326                 TInt c = iConsole->KeyCode();
00327                 switch(c)
00328                         {
00329                 case 'E':
00330                 case 'e':
00331                 case EKeyEscape:
00332                 // Cancel notifications
00333                         iNetworkRegInfo->Cancel();
00334                         iFlightModeInfo->Cancel();
00335                         if (iCallStatus != NULL)
00336                                 {
00337                                 iCallStatus->Cancel();
00338                                 }
00339                         if (iLineStatus->IsActive())
00340                                 {
00341                                 iLineStatus->Cancel();
00342                                 }
00343                         CActiveScheduler::Stop();
00344                         break;
00345                 case 'D':
00346                 case 'd':
00347                         if (iCallStatus == NULL)
00348                                 {
00349                                 iState = EDialCall;
00350                                 iLastOperation = iDialCall;
00351                                 SetActive();
00352                                 CompleteOwnRequest(KErrNone);
00353                                 break;
00354                                 }
00355                         else
00356                                 {
00357                                 // Print correct menu
00358                                 GetInput();
00359                                 break;
00360                                 }
00361                 case 'H':
00362                 case 'h':
00363                         if (iCallStatus != NULL)
00364                                 {
00365                                 iSingleString = ETrue;
00366                                 iState = EHangup;
00367                                 iLastOperation = iHangup;
00368                                 SetActive();
00369                                 CompleteOwnRequest(KErrNone);
00370                                 break;
00371                                 }
00372                         else
00373                                 {
00374                                 // Print correct menu
00375                                 GetInput();
00376                                 break;
00377                                 }
00378                 case 'S':
00379                 case 's':
00380                         if (iCallStatus != NULL && iSingleString)
00381                                 {
00382                                 iConsole->Printf(_L("Be Right Back\n"));
00383                                 iSingleString = ETrue;
00384                                 iCurrentToneLog.Append(iTheNumber);
00385                                 iCurrentToneLog.Append('#');
00386                                 iState = ESendDTMF;
00387                                 iLastOperation = iSendDTMF;
00388                                 SetActive();
00389                                 CompleteOwnRequest(KErrNone);
00390                                 break;
00391                                 }
00392                         else
00393                                 {
00394                                 // Print correct menu
00395                                 GetInput();
00396                                 break;
00397                                 }
00398                 // Send number
00399                 case '0':
00400                 case '1':
00401                 case '2':
00402                 case '3':
00403                 case '4':
00404                 case '5':
00405                 case '6':
00406                 case '7':
00407                 case '8':
00408                 case '9':
00409                 case '*':
00410                         if (iCallStatus != NULL)
00411                                 {
00412                                 iSingleString = EFalse;
00413                                 iCurrentTone.Delete(0,1);
00414                                 iCurrentTone.Append(c);
00415                                 iCurrentToneLog.Append(iCurrentTone);
00416                                 iState = ESendDTMF;
00417                                 iLastOperation = iSendDTMF;
00418                                 SetActive();
00419                                 CompleteOwnRequest(KErrNone);
00420                                 break;
00421                                 }
00422                         else
00423                                 {
00424                                 // Print correct menu
00425                                 GetInput();
00426                                 break;
00427                                 }
00428 
00429                 case '#':
00430                         if (iCallStatus != NULL && !iSingleString)
00431                                 {
00432                                 iConsole->Printf(_L("You sent "));
00433                                 iConsole->Printf(iCurrentToneLog);
00434                                 iConsole->Printf(KNewLine);
00435                                 iCurrentToneLog.Delete(0, iCurrentToneLog.Length());
00436                                 iConsole->Printf(KMenuMsg);
00437                                 iConsole->Printf(KHangupMsg);
00438                                 // Key presses finished!
00439                                 // Call is active, DTMF has been indicated to be
00440                                 // finished as # character has been received.
00441                                 }
00442                         else
00443                                 {
00444                                 // Print correct menu
00445                                 GetInput();
00446                                 break;
00447                                 }
00448                 default:
00449                         GetInput();
00450                         }
00451                 }
00452                 break;
00453         default:
00454                 break;
00455                 }
00456         }
00457         
00461 void CMainMenu::DoCancel()
00462         {
00463         if(iState == EStart)
00464                 {
00465                 CompleteOwnRequest(KErrCancel);
00466                 }
00467         else
00468                 {
00469                 iConsole->ReadCancel();
00470                 }
00471         }

Generated by  doxygen 1.6.2