telephonyserverplugins/multimodetsy/hayes/ATESCAPE.CPP
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // AT Escape to command (online) mode
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <commsdattypesv1_1.h>
       
    19 #include <cdblen.h>
       
    20 #include "ATESCAPE.H"
       
    21 #include "mSLOGGER.H"
       
    22 #include "PHONE.H"
       
    23 #include "ATIO.H"
       
    24 
       
    25 CATSetToOnlineCommandMode* CATSetToOnlineCommandMode::NewL(CATIO* aIo,CTelObject* aTelObject,CPhoneGlobals* aPhoneGlobals)
       
    26 	{
       
    27 	return new(ELeave) CATSetToOnlineCommandMode(aIo,aTelObject,aPhoneGlobals);
       
    28 	}
       
    29 
       
    30 CATSetToOnlineCommandMode::CATSetToOnlineCommandMode(CATIO* aIo,CTelObject* aTelObject,CPhoneGlobals* aPhoneGlobals)
       
    31 												: CATBase(aIo,aTelObject,aPhoneGlobals)
       
    32 	{}
       
    33 
       
    34 CATSetToOnlineCommandMode::~CATSetToOnlineCommandMode()
       
    35 	{}
       
    36 
       
    37 void CATSetToOnlineCommandMode::StartEscapeSequence(CATCommands* aPendingCommand,TTsyReqHandle aTsyReqHandle, TAny* aParams)
       
    38 //
       
    39 //	Begin the escape sequence with the guard time pause
       
    40 //
       
    41 	{
       
    42 	LOGTEXT(_L8("Starting Escape Command"));
       
    43 	iPendingCommand = aPendingCommand;
       
    44 	iReqHandle = aTsyReqHandle;
       
    45 	iParams = aParams;
       
    46 	iIo->SetTimeOut(this,KLengthOfGuardTime*20);
       
    47 	iState = EWaitForATSilence;
       
    48 	}
       
    49 
       
    50 void CATSetToOnlineCommandMode::StopEscapeSequence(TTsyReqHandle aTsyReqHandle)
       
    51 //
       
    52 //	Attempt to stop the escape sequence
       
    53 //
       
    54 	{
       
    55 	__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle));
       
    56 	LOGTEXT(_L8("Cancelling Escape Sequence"));
       
    57 	iIo->RemoveExpectString(iOKExpectString);
       
    58 	iOKExpectString=NULL;
       
    59 	iIo->WriteAndTimerCancel(this);
       
    60 	iPendingCommand->Owner()->ReqCompleted(iReqHandle,KErrCancel);
       
    61 	if (iState != EWaitForATSilence)
       
    62 		// if nothing has been sent yet, can remain in On line Data Mode
       
    63 		{
       
    64 		iPhoneGlobals->iPhoneStatus.iMode=RPhone::EModeOnlineCommand;
       
    65 		}
       
    66 	}
       
    67 
       
    68 void CATSetToOnlineCommandMode::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
       
    69 	{
       
    70 	LOGTEXT(_L8("Error in Escape sequence"));
       
    71 	iIo->WriteAndTimerCancel(this);
       
    72 	iPendingCommand->Owner()->ReqCompleted(iReqHandle, aStatus);
       
    73 	}
       
    74 
       
    75 void CATSetToOnlineCommandMode::EventSignal(TEventSource aSource)
       
    76 	{
       
    77 	if ((aSource==ETimeOutCompletion) && (iState!=EWaitForATSilence))
       
    78 		{
       
    79 		LOGTEXT(_L8("Timeout Error during Escape Sequence"));
       
    80 		iIo->RemoveExpectStrings(this);						
       
    81 		iOKExpectString=NULL;
       
    82 		iPhoneGlobals->iPhoneStatus.iInitStatus=EPhoneNotInitialised;
       
    83 		iPendingCommand->Owner()->ReqCompleted(iReqHandle,KErrTimedOut);
       
    84 		return;
       
    85 		}
       
    86 
       
    87 	switch(iState)
       
    88 		{
       
    89 	case EWaitForATSilence:
       
    90 			{
       
    91 			__ASSERT_ALWAYS(aSource==ETimeOutCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
       
    92 			TBuf8<KCommsDbSvrMaxFieldLength> escapeChar;
       
    93 			TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameEscapeCharacter),escapeChar);
       
    94 			if (ret)
       
    95 				{
       
    96 				iPendingCommand->Owner()->ReqCompleted(iReqHandle,ret);
       
    97 				break;
       
    98 				}
       
    99 			iTxBuffer.Format(_L8("%S%S%S"),&escapeChar,&escapeChar,&escapeChar);
       
   100 			iIo->Write(this,iTxBuffer);
       
   101 			iIo->SetTimeOut(this,KOneSecondPause);
       
   102 			if (!(iIo->ReadPending()))
       
   103 				iIo->Read();
       
   104 			iState=EWaitForWriteCompletion;
       
   105 			}
       
   106 		break;
       
   107 
       
   108 	case EWaitForWriteCompletion:
       
   109 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
       
   110 		if (!iOKExpectString)
       
   111 			iOKExpectString = iIo->AddExpectString(this,KOkString);
       
   112 		iIo->SetTimeOut(this);
       
   113 		iState=EWaitForATEscapeOK;
       
   114 		break;
       
   115 
       
   116 	case EWaitForATEscapeOK:
       
   117 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   118 		{
       
   119 		TInt ret(ValidateExpectString());
       
   120 		if (ret)
       
   121 			{
       
   122 			iPendingCommand->Owner()->ReqCompleted(iReqHandle,ret);
       
   123 			}
       
   124 		else
       
   125 			{
       
   126 			iPhoneGlobals->iPhoneStatus.iMode=RPhone::EModeOnlineCommand;
       
   127 			iPendingCommand->Start(iReqHandle,iParams);
       
   128 			}
       
   129 		}
       
   130 		iIo->WriteAndTimerCancel(this);
       
   131 		iIo->RemoveExpectString(iOKExpectString);
       
   132 		iOKExpectString=NULL;
       
   133 		break;
       
   134 		}
       
   135 	}