examples/Telephony/ETel3rdPartyExample/IncomingCalls/CMainMenu.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 
00017 #include "CMainMenu.h"
00018 #include <simtsy.h>
00019 
00026 CMainMenu* CMainMenu::NewLC(CConsoleBase& aConsole)
00027         {
00028         CMainMenu* self = new(ELeave) CMainMenu(aConsole);
00029         CleanupStack::PushL(self);
00030         self->ConstructL();
00031         return self;
00032         }
00033 
00039 CMainMenu::CMainMenu(CConsoleBase& aConsole)
00040         : CBaseMenuAsync(aConsole)
00041         {
00042         iCount = 0;
00043         iMessages = 0;
00044         iRecievedCalls = 0;
00045         iCallWaitingOn = EFalse;
00046         }
00047 
00051 void CMainMenu::ConstructL()
00052         {
00053         CBaseMenuAsync::ConstructL();
00054         iPhoneId = CPhoneId::NewL(this);
00055 
00056         // Create active objects using their factory constructors.
00057         iCallForwarding = CCallForwardingStatus::NewL(this);
00058         iCallBarring = CCallBarringStatus::NewL(this);
00059         iFlightModeInfo = CFlightModeInfo::NewL(this);
00060         iIdentityService = CIdentityServiceStatus::NewL(this);
00061         iCallWaiting = CCallWaitingStatus::NewL(this);
00062 
00063         iLineStatus = CLineStatus::NewL(this);
00064         iAnswerIncomingCall = CAnswerIncomingCall::NewL(this);
00065         iCallInfo = CCallInfo::NewL(this);
00066         iDummyAnswer = CDummyAnswer::NewL(this);
00067         iHangup = CHangup::NewL(this);
00068 
00069         iCallStatus = NULL;
00070 
00071         }
00072 
00077 CMainMenu::~CMainMenu()
00078         {
00079         delete iTelephony;
00080         delete iPhoneId;
00081 
00082         delete iFlightModeInfo;
00083         delete iCallForwarding;
00084         delete iCallBarring;
00085         delete iIdentityService;
00086         delete iCallWaiting;
00087 
00088         delete iAnswerIncomingCall;
00089         delete iHangup;
00090         delete iCallStatus;
00091         delete iCallInfo;
00092         delete iDummyAnswer;
00093         delete iLineStatus;
00094         }
00095 
00102 void CMainMenu::ExecComplete(TTelISVExampleType aDerivedType)
00103         {
00104    if (iState==ESetNotifier)
00105                 {
00106                 switch(aDerivedType)
00107                         {
00108                 case KLineStatus:
00109                         iLastOperation = iLineStatus;
00110                         break;
00111                 case KCallInfo:
00112                         iLastOperation = iCallInfo;
00113                         break;
00114                 case KCallStatus:
00115                         iLastOperation = iCallStatus;
00116                         break;
00117                 case KAnswerIncomingCall:
00118                         iLastOperation = iAnswerIncomingCall;
00119                         break;
00120                 case KHangup:
00121                         iLastOperation = iHangup;
00122                         break;
00123                 case KCallForwardingStatus:
00124                         iLastOperation = iCallForwarding;
00125                         break;
00126                 case KCallBarringStatus:
00127                         iLastOperation = iCallBarring;
00128                         break;
00129                 case KFlightModeInfo:
00130                         iLastOperation = iFlightModeInfo;
00131                         break;
00132                 case KIdentityServiceStatus:
00133                         iLastOperation = iIdentityService;
00134                         break;
00135                 case KCallWaitingStatus:
00136                         iLastOperation = iCallWaiting;
00137                         break;
00138                 case KNotType:
00139                 case KPhoneId:
00140                 case KSubscriberId:
00141                 case KBatteryInfo:
00142                 case KSignalInfo:
00143                 case KGetIndicator:
00144                 case KLockInfo:
00145                 case KNetworkInfo:
00146                 case KNetworkName:
00147                 case KOperatorName:
00148                 case KNetworkRegInfo:
00149                 case KDialCall:
00150                 case KDynamicCaps:
00151                 case KHold:
00152                 case KResume:
00153                 case KSwap:
00154                 case KSendDTMF:
00155                 default:
00156                         break;          
00157                         }
00158                         
00159                 // Request to be told about particular events occurring.                
00160                 TRAPD(errNotify, iLastOperation->RequestNotificationL());
00161                 if (errNotify != KErrNone)
00162                         {
00163                         iConsole->Printf(_L("Notification Request for TTelISVExampleType"));
00164                         iConsole->Printf(_L("%d left with error code "), aDerivedType);
00165                         iConsole->Printf(_L("%d\n"), errNotify);
00166                         return;
00167                         };
00168                         
00169                 // Check the type of iLastOperation to see what it has been cast to.
00170                 switch(iLastOperation->GetExampleType())
00171                         {
00172                 case KLineStatus:
00173                         iConsole->ClearScreen();
00174                         iConsole->Printf(KMenuMsg);
00175                         CallsCount();
00176                         iConsole->Printf(KAnyMsg);
00177                         GetInput();
00178                         break;
00179                 case KAnswerIncomingCall:
00180                         iCallId = reinterpret_cast<CAnswerIncomingCall*>
00181                                   (iAnswerIncomingCall)->iCallId;
00182                         TRAPD(err,      iCallStatus = CCallStatus::NewL(this, iCallId));
00183                         if (err != KErrNone)
00184                                 {
00185                                 iConsole->Printf(_L("CallStatus construction left "));
00186                                 iConsole->Printf(_L("with error code %d\n"), err);
00187                                 return;
00188                                 }
00189                         iState = EGetCallStatus;
00190                         iLastOperation = iCallStatus;
00191                         SetActive();
00192                         CompleteOwnRequest(KErrNone);
00193                         break;
00194                 case KCallInfo:
00195                         iState = EAnswerIncomingCall;
00196                         iLastOperation = iAnswerIncomingCall;
00197                         SetActive();
00198                         CompleteOwnRequest(KErrNone);
00199                         break;
00200                 case KCallStatus:
00201                         iState = EDummyAnswer;
00202                         SetActive();
00203                         CompleteOwnRequest(KErrNone);
00204                         break;
00205                 case KFlightModeInfo:
00206                         if (IsActive())
00207                                 {
00208                                 Cancel();
00209                                 }
00210                         iState = ECallBarring;
00211                         iLastOperation = iCallBarring;
00212                         SetActive();
00213                         CompleteOwnRequest(KErrNone);
00214                         break;
00215                 case KCallBarringStatus:
00216                         iState = ECallForwarding;
00217                         iLastOperation = iCallForwarding;
00218                         SetActive();
00219                         CompleteOwnRequest(KErrNone);
00220                         break;
00221                 case KCallForwardingStatus:
00222                         iState = EIdentityService;
00223                         iLastOperation = iIdentityService;
00224                         SetActive();
00225                         CompleteOwnRequest(KErrNone);
00226                         break;
00227                 case KIdentityServiceStatus:
00228                         iState = ECallWaiting;
00229                         iLastOperation = iCallWaiting;
00230                         SetActive();
00231                         CompleteOwnRequest(KErrNone);
00232                         break;
00233                 case KCallWaitingStatus:
00234                         iCallWaitingOn = EFalse;
00235                         iState = EGetLineStatus;
00236                         iLastOperation = iLineStatus;
00237                         SetActive();
00238                         CompleteOwnRequest(KErrNone);
00239                         break;
00240                 default:
00241 
00242                         break;
00243                         }
00244                 }
00245         else if(aDerivedType == KPhoneId)
00246                 {
00247                 iLastOperation = iFlightModeInfo;
00248                 SetActive();
00249                 CompleteOwnRequest(KErrNone);
00250                 }
00251         else if (aDerivedType == KNotType)
00252                 {
00253                 iConsole->ClearScreen();
00254                 iConsole->Printf(KMenuMsg);
00255                 CallsCount();
00256                 iConsole->Printf(KHangupMsg);
00257                 GetInput();
00258                 }
00259         }
00260 
00267 void CMainMenu::ExecNotify(TTelISVExampleType aDerivedType)
00268         {
00269         switch(aDerivedType)
00270                 {
00271         case KAnswerIncomingCall:
00272                 iCallId = reinterpret_cast<CAnswerIncomingCall*>
00273                           (iAnswerIncomingCall)->iCallId;
00274                 TRAPD(err, iCallStatus = CCallStatus::NewL(this, iCallId));
00275                 if (err != KErrNone)
00276                         {
00277                         iConsole->Printf(_L("CallStatus construction left "));
00278                         iConsole->Printf(_L("with error code %d\n"), err);
00279                         return;
00280                         }
00281                 iState = EGetCallStatus;
00282                 iLastOperation = iCallStatus;
00283                 SetActive();
00284                 CompleteOwnRequest(KErrNone);
00285                 break;
00286         case KCallWaitingStatus:
00287                 iCallWaitingOn = ETrue;
00288                 iState = EGetLineStatus;
00289                 iLastOperation = iLineStatus;
00290                 SetActive();
00291                 CompleteOwnRequest(KErrNone);
00292                 break;
00293         case KLineStatus:
00294                 if (iCallStatus != NULL)
00295                         {
00296                         iConsole->Printf(_L("Call Waiting!\n"));
00297                         iRecievedCalls++;
00298                         iConsole->ClearScreen();
00299                         iConsole->Printf(KMenuMsg);
00300                         CallsCount();
00301                         iConsole->Printf(KHangupMsg);
00302                         GetInput();
00303                         }
00304                 else
00305                         {
00306                         // Request to be told about particular events occuring 
00307                         TRAPD(err, iLineStatus->RequestNotificationL());
00308                         if (err != KErrNone)
00309                                 {
00310                                 iConsole->Printf(_L("Request left with error code "));
00311                                 iConsole->Printf(_L("%d\n"),err);
00312                                 return;
00313                                 }
00314                         iRecievedCalls++;
00315                         iState = EGetCallInfo;
00316                         iLastOperation = iCallInfo;
00317                         SetActive();
00318                         CompleteOwnRequest(KErrNone);
00319                         }
00320                 break;
00321         case KCallStatus:
00322                 if (iFlightModeInfo->IsActive())
00323                         {
00324                         iFlightModeInfo->Cancel();
00325                         }
00326                 delete iCallStatus;
00327                 iCallStatus = NULL;
00328                 iLineStatus->Cancel();
00329                 iState = EStart;
00330                 SetActive();
00331                 CompleteOwnRequest(KErrNone);
00332                 break;
00333         case KCallForwardingStatus:
00334                 iState = ECallForwarding;
00335                 iLastOperation = iCallForwarding;
00336                 SetActive();
00337                 CompleteOwnRequest(KErrNone);
00338                 break;
00339         case KNotType:
00340         case KPhoneId:
00341         case KSubscriberId:
00342         case KBatteryInfo:
00343         case KSignalInfo:
00344         case KGetIndicator:
00345         case KLockInfo:
00346         case KNetworkInfo:
00347         case KNetworkName:
00348         case KOperatorName:
00349         case KCallInfo:
00350         case KFlightModeInfo:
00351         case KNetworkRegInfo:   
00352         case KDialCall:
00353         case KDynamicCaps:
00354         case KHold:
00355         case KResume:
00356         case KSwap:
00357         case KSendDTMF:
00358         case KHangup:
00359         case KCallBarringStatus:
00360         case KIdentityServiceStatus:
00361         default:
00362                 break;  
00363                 }
00364         }
00365 
00369 void CMainMenu::RunL()
00370         {
00371         switch(iState)
00372                 {
00373         case EStart:
00374                 iState = EGetFlightModeInfo;
00375                 if (iCount)
00376                         {
00377                         iCount = 0;
00378                         iLastOperation = iFlightModeInfo;
00379                         SetActive();
00380                         CompleteOwnRequest(KErrNone);
00381                         }
00382                 else
00383                         {
00384                         iLastOperation = iPhoneId;
00385                         TRAPD(errPhone, iLastOperation->StartRequestL());
00386                         if (errPhone != KErrNone)
00387                                 {
00388                                 iConsole->Printf(_L("Request left with error code "));
00389                                 iConsole->Printf(_L("%d\n"), errPhone);
00390                                 return;
00391                                 };
00392                         }
00393                 break;
00394         case EEnd:
00395                 iFlightModeInfo->Cancel();
00396                 CActiveScheduler::Stop();
00397                 break;
00398         case ECallWaiting:
00399         case EGetFlightModeInfo:
00400         case ECallForwarding:
00401         case ECallBarring:
00402         case EIdentityService:
00403         case EGetLineStatus:
00404         case EGetCallInfo:
00405         case EGetCallStatus:
00406         case EAnswerIncomingCall:
00407                 iState = ESetNotifier;
00408                 TRAPD(errAnswer, iLastOperation->StartRequestL());
00409                 if (errAnswer != KErrNone)
00410                         {
00411                         iConsole->Printf(_L("Request left with error code "));
00412                         iConsole->Printf(_L("%d\n"), errAnswer);
00413                         return;
00414                         };
00415                 break;
00416         case EHangup:
00417                 iDummyAnswer->Cancel();
00418                 TRAPD(errArg, iLastOperation->StartRequestL(iCallId));
00419                 if (errArg != KErrNone)
00420                         {
00421                         iConsole->Printf(_L("Request left with error code "));
00422                         iConsole->Printf(_L("%d\n"), errArg);
00423                         return;
00424                         }
00425                 break;
00426         case EDummyAnswer:
00427                 iMessages++;
00428                 iState = EHangup;
00429                 TRAPD(errDummy, iDummyAnswer->StartCount(1000000));
00430                 if (errDummy != KErrNone)
00431                         {
00432                         iConsole->Printf(_L("Request left with error code "));
00433                         iConsole->Printf(_L("%d\n"), errDummy);
00434                         return;
00435                         };
00436                 break;
00437         case EWaitingForKeyPress:
00438                 {
00439                 TInt c = iConsole->KeyCode();
00440                 switch(c)
00441                         {
00442                 case 'E':
00443                 case 'e':
00444                 case EKeyEscape:
00445                         // Cancel notifications
00446                         if (iAnswerIncomingCall->IsActive())
00447                                 {
00448                                 iAnswerIncomingCall->Cancel();
00449                                 }
00450                         if (iHangup->IsActive())
00451                                 {
00452                                 iHangup->Cancel();
00453                                 }
00454                         if (iCallStatus != NULL && iCallStatus->IsActive())
00455                                 {
00456                                 iCallStatus->Cancel();
00457                                 }
00458                         iFlightModeInfo->Cancel();
00459                         iLineStatus->Cancel();
00460                         CActiveScheduler::Stop();
00461                         break;
00462                 case 'h':
00463                 case 'H':
00464                         if (iDummyAnswer->IsActive())
00465                                 {
00466                                 iState = EHangup;
00467                                 iLastOperation = iHangup;
00468                                 SetActive();
00469                                 CompleteOwnRequest(KErrNone);
00470                                 break;
00471                                 }
00472                         else
00473                                 {
00474                                 GetInput();
00475                                 break;
00476                                 }
00477                 case 'i':
00478                 case 'I':
00479                         {
00480                         CTelephony::TPhoneLine line = CTelephony::EVoiceLine;
00481                         CTelephony::TCallStatusV1 iLineStatusV1;
00482                         CTelephony::TCallStatusV1Pckg iLineStatusV1Pckg(iLineStatusV1);
00483                         iTelephony->GetLineStatus(line, iLineStatusV1Pckg);
00484                         CTelephony::TCallStatus voiceLineStatus = iLineStatusV1.iStatus;
00485                         if (iCount >= 1
00486                                 && iCallWaitingOn
00487                                 && voiceLineStatus != CTelephony::EStatusRinging)
00488                                 {
00489                                 iCount++;
00490                                 TInt ret = RProperty::Set(KUidPSSimTsyCategory,
00491                                                                                   KPSSimTsyIncomingVoiceCall,
00492                                                                                   0);
00493                                 if(ret!=KErrNone)
00494                                         {
00495                                         iConsole->Printf(_L("Set failed : %d\n"),ret);  
00496                                         }
00497                                 break;
00498                                 }
00499                         else
00500                                 {
00501                                 GetInput();
00502                                 break;
00503                                 }
00504                         }
00505                 default:
00506                 // Pressed a non suggested key to simulate an incoming call
00507                         if (iCount == 0)
00508                                 {
00509                                 // For SIM TSY to simulate an incoming call
00510                                 iCount = 1;
00511                                 TInt ret = RProperty::Set(KUidPSSimTsyCategory,
00512                                                                                   KPSSimTsyIncomingVoiceCall,
00513                                                                                   0);
00514                                 if(ret!=KErrNone)
00515                                         {
00516                                         iConsole->Printf(_L("Set failed : %d\n"),ret);  
00517                                         }
00518                                                                                           
00519                                 }
00520                         else
00521                                 {
00522                                         GetInput();
00523                                 }
00524                                 break;
00525                         }
00526                 }
00527                 break;
00528         default:
00529                 break;
00530                 } // switch(iState)
00531         }
00532 
00537 void CMainMenu::CallsCount()
00538         {
00539         iConsole->Printf(_L("You have %d Messages\n"), iMessages);
00540         TInt difference = iRecievedCalls - iMessages;
00541         if (difference > 0)
00542                 {
00543                 iConsole->Printf(_L("%d people called and left no message\n"),
00544                                  difference);
00545                 }
00546         }
00547 
00551 void CMainMenu::DoCancel()
00552         {
00553         if(iState == EStart)
00554                 {
00555                 CompleteOwnRequest(KErrCancel);
00556                 }
00557         else
00558                 {
00559                 iConsole->ReadCancel();
00560                 }
00561         }

Generated by  doxygen 1.6.2