telephonyserverplugins/multimodetsy/hayes/ATO.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 // Go to On-Line(data) state from On-Line Command state
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <commsdattypesv1_1.h>
       
    19 #include <cdblen.h>
       
    20 #include "ATO.H"
       
    21 #include "mSLOGGER.H"
       
    22 #include "PHONE.H"
       
    23 #include "NOTIFY.H"
       
    24 #include "ATIO.H"
       
    25 
       
    26 CATSetToOnlineDataMode* CATSetToOnlineDataMode::NewL(CATIO* aIo, CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
    27 	{
       
    28 	CATSetToOnlineDataMode* ato=new(ELeave) CATSetToOnlineDataMode(aIo, aTelObject, aInit, aPhoneGlobals);
       
    29 	CleanupStack::PushL(ato);
       
    30 	ato->ConstructL();
       
    31 	CleanupStack::Pop();
       
    32 	return ato;
       
    33 	}
       
    34 
       
    35 CATSetToOnlineDataMode::CATSetToOnlineDataMode(CATIO* aIo, CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
    36 											: CATCallAlterCommands(aIo,aTelObject,aInit,aPhoneGlobals)
       
    37 	{}
       
    38 
       
    39 CATSetToOnlineDataMode::~CATSetToOnlineDataMode()
       
    40 	{
       
    41 	iIo->RemoveExpectStrings(this);
       
    42 	}
       
    43 
       
    44 void CATSetToOnlineDataMode::Start(TTsyReqHandle aTsyReqHandle, TAny* /*aParams*/)
       
    45 	{
       
    46 	LOGTEXT(_L8("Starting ATO Command to force into On-Line Data Mode"));
       
    47 	iReqHandle=aTsyReqHandle;
       
    48 	TBuf8<KCommsDbSvrMaxFieldLength> toOnLineDataCommand;
       
    49 	TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameOnLine), toOnLineDataCommand);
       
    50 	if (ret)
       
    51 		{
       
    52 		iTelObject->ReqCompleted(iReqHandle, ret);
       
    53 		}
       
    54 	else
       
    55 		{
       
    56 		iTxBuffer.Format(KATAndStringFormatString,&toOnLineDataCommand);
       
    57 		iIo->Write(this,iTxBuffer);
       
    58 		iIo->SetTimeOut(this,KOneSecondPause);
       
    59 		iState=EATOWaitForWriteComplete;
       
    60 		}
       
    61 	}
       
    62 
       
    63 void CATSetToOnlineDataMode::Stop(TTsyReqHandle aTsyReqHandle)
       
    64 	{
       
    65 	__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle));
       
    66 	__ASSERT_ALWAYS(iState!=EATNotInProgress,Panic(EATCommand_NotInProgress));
       
    67 	iIo->SetTimeOut(this,KOneSecondPause);
       
    68 	iState = EATCancelling;
       
    69 	}
       
    70 
       
    71 void CATSetToOnlineDataMode::ValidateExpectStringWithConnectL()
       
    72 	{
       
    73 	if(iIo->FoundChatString()==iErrorExpectString)
       
    74 		{
       
    75 		LOGTEXT(_L8("Modem returned ERROR in response to command"));
       
    76 		User::Leave(KErrGeneral);
       
    77 		}
       
    78 	if(iIo->FoundChatString()==iConnectExpectString)
       
    79 		return;
       
    80 	LOGTEXT(_L8("Modem returned unknown response to command"));
       
    81 	User::Leave(KErrGeneral);
       
    82 	}
       
    83 
       
    84 void CATSetToOnlineDataMode::RemoveATOExpectStrings()
       
    85 	{
       
    86 	iIo->RemoveExpectString(iConnectExpectString);
       
    87 	iConnectExpectString=NULL;
       
    88 	iIo->RemoveExpectString(iErrorExpectString);
       
    89 	iErrorExpectString=NULL;
       
    90 	}
       
    91 
       
    92 void CATSetToOnlineDataMode::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
       
    93 	{
       
    94 	if (iState!=EATNotInProgress)
       
    95 		{
       
    96 		iIo->WriteAndTimerCancel(this);
       
    97 		iTelObject->ReqCompleted(iReqHandle, aStatus);
       
    98 		iState = EATNotInProgress;
       
    99 		}
       
   100 	}
       
   101 
       
   102 void CATSetToOnlineDataMode::EventSignal(TEventSource aSource)
       
   103 	{
       
   104 	if (aSource==ETimeOutCompletion)
       
   105 		{
       
   106 		LOGTEXT(_L8("Timeout Error during ATO"));
       
   107 		RemoveATOExpectStrings();
       
   108 		iPhoneGlobals->iPhoneStatus.iInitStatus=EPhoneNotInitialised;
       
   109 		iTelObject->ReqCompleted(iReqHandle,KErrTimedOut);
       
   110 		iState=EATNotInProgress;
       
   111 		return;
       
   112 		}
       
   113 	switch(iState)
       
   114 		{
       
   115 	case EATOWaitForWriteComplete:
       
   116 		{
       
   117 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
   118 		if (!iConnectExpectString)
       
   119 			{
       
   120 			TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameConnect),iConnectString);
       
   121 			if (ret)
       
   122 				{
       
   123 				iTelObject->ReqCompleted(iReqHandle, ret);
       
   124 				return;
       
   125 				}
       
   126 			AppendWildCardChar(iConnectString);
       
   127 			iConnectExpectString=iIo->AddExpectString(this,iConnectString);
       
   128 			}
       
   129 		if (!iErrorExpectString)
       
   130 			iErrorExpectString=iIo->AddExpectString(this,KErrorString);
       
   131 		iIo->SetTimeOut(this);
       
   132 		iState=EATOReadCompleted;
       
   133 		}
       
   134 		break;
       
   135 
       
   136 	case EATOReadCompleted:
       
   137 		{
       
   138 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
   139 		TRAPD(ret,ValidateExpectStringWithConnectL());
       
   140 		Complete(ret,aSource);
       
   141 		}
       
   142 		break;
       
   143 
       
   144 	case EATCancelling:
       
   145 		{
       
   146 		if (aSource==EWriteCompletion)
       
   147 			{
       
   148 			iIo->SetTimeOut(this,KOneSecondPause);
       
   149 			}
       
   150 		else
       
   151 			{
       
   152 			Complete(KErrCancel,aSource);
       
   153 			}
       
   154 		}
       
   155 		break;
       
   156 
       
   157 	default:
       
   158 		break;
       
   159 		}
       
   160 	}
       
   161 
       
   162 void CATSetToOnlineDataMode::Complete(TInt aError,TEventSource aSource)
       
   163 	{
       
   164 	RemoveATOExpectStrings();
       
   165 	iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeOnlineData;
       
   166 	if (aError==KErrNone)
       
   167 		iIo->Cancel();	// OK as long as this command is only called from LoanDataPort
       
   168 	CATCommands::Complete(aError,aSource);
       
   169 	iTelObject->ReqCompleted(iReqHandle, aError);
       
   170 	iState=EATNotInProgress;
       
   171 	}