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

Generated by  doxygen 1.6.2