telephonyserverplugins/multimodetsy/Multimode/gprs/ATGprsAttach.CPP
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2001-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 //
       
    15 
       
    16 #include "gprs.h"
       
    17 #include "Gprscontext.h"
       
    18 #include "mSLOGGER.H"
       
    19 #include <pcktcs.h>
       
    20 #include "ATGprsAttach.H"
       
    21 #include "ATIO.H"
       
    22 #include <etelpckt.h>
       
    23 #include "TSYCONFG.H"
       
    24 #include "NOTIFY.H"
       
    25 #include "Matstd.h"
       
    26 
       
    27 /** 
       
    28  * @file
       
    29  * This file implements the CATGprsAttach class which is one of the state machine used by the
       
    30  * GPRS AT TSY library.
       
    31  */
       
    32 
       
    33 /**
       
    34  * This state machine uses the "AT+CGATT" command to connect to the GPRS network.
       
    35  */
       
    36 _LIT8(KAttachCommand, "AT+CGATT=1\r");
       
    37 
       
    38 CATGprsAttach* CATGprsAttach::NewL(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals )
       
    39 /**
       
    40  *  Standard 2 phase constructor.
       
    41  *
       
    42  * @param aIo pointer to communication object.
       
    43  * @param aTelObject pointer to parent.
       
    44  * @param aPhoneGlobals pointer to phone global wide states.
       
    45  */
       
    46 	{
       
    47 	CATGprsAttach* p =new(ELeave) CATGprsAttach(aIo, aTelObject, aInit, aPhoneGlobals);
       
    48 	CleanupStack::PushL(p);
       
    49 	p->ConstructL();
       
    50 	CleanupStack::Pop();
       
    51 
       
    52 	return p;
       
    53 	}
       
    54 
       
    55 void CATGprsAttach::ConstructL()
       
    56 /**
       
    57  * Construct all objects that can leave.
       
    58  */
       
    59 	{
       
    60 	CATCommands::ConstructL();
       
    61 	}
       
    62 
       
    63 CATGprsAttach::CATGprsAttach(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals)
       
    64 	:CATCommands(aIo, aTelObject, aInit, aPhoneGlobals)
       
    65 /**
       
    66  * Constructor.
       
    67  *
       
    68  * @param aIo pointer to communication object.
       
    69  * @param aTelObject pointer to parent.
       
    70  * @param aInit pointer to AT phone init object.
       
    71  * @param aPhoneGlobals pointer to phone global wide states.
       
    72  */
       
    73 	{
       
    74 	LOGTEXT(_L8("CATGprsAttach::CATGprsAttach called"));
       
    75 	}
       
    76 
       
    77 
       
    78 CATGprsAttach::~CATGprsAttach()
       
    79 /**
       
    80  * Destructor.
       
    81  */
       
    82 	{
       
    83 	LOGTEXT(_L8("CATGprsAttach::~CATGprsAttach called"));
       
    84 	iIo->RemoveExpectStrings(this);				
       
    85 	}
       
    86 
       
    87 
       
    88 void CATGprsAttach::Start(TTsyReqHandle aTsyReqHandle, TAny* /*aParams*/)
       
    89 /**
       
    90  * This is the standard entry point for sending attach command.
       
    91  * @param aTsyReqHandle handle to the client.
       
    92  */
       
    93 	{
       
    94 	LOGTEXT(_L8("CATGprsAttach::Start called"));
       
    95 	iReqHandle = aTsyReqHandle;
       
    96 	iState=ESendAttachCommand;
       
    97 	Write(KAttachCommand, KGprsCommandTimeOut);	
       
    98 	}
       
    99 
       
   100 
       
   101 void CATGprsAttach::Stop(TTsyReqHandle aTsyReqHandle)
       
   102 /**
       
   103  * This funciton stops this AT state machine
       
   104  */
       
   105 	{
       
   106 	LOGTEXT(_L8("CATGprsAttach::Stop called"));
       
   107 	if(iState!=EATNotInProgress && aTsyReqHandle==iReqHandle)
       
   108 		{
       
   109 		LOGTEXT(_L8("CATGprsAttach::Stop Completing client request with KErrCancel"));
       
   110 		Complete(KErrCancel,ETimeOutCompletion);		// Pretend we have had a timeout
       
   111 		}
       
   112 	}
       
   113 
       
   114 
       
   115 void CATGprsAttach::CompleteWithIOError(TEventSource aSource,TInt aStatus)
       
   116 /**
       
   117  * This Function completes the command from the client with an error.
       
   118  * @param aSource source of event from communication class.
       
   119  * @param aStatus status of event.
       
   120  */
       
   121 	{
       
   122 	LOGTEXT(_L8("CATGprsAttach::CompleteWithIOError called"));
       
   123 	Complete(aStatus, aSource);
       
   124 	}
       
   125 
       
   126 
       
   127 void CATGprsAttach::Complete(TInt aError,TEventSource aSource)
       
   128 /**
       
   129  * This Function completes the command from the client.
       
   130  * @param aError an error code to relay to client.
       
   131  */
       
   132 	{
       
   133 	LOGTEXT2(_L8("CATGprsAttach::Complete called error: %d"), aError);
       
   134 	RemoveStdExpectStrings();
       
   135 	iIo->WriteAndTimerCancel(this);	
       
   136 	iIo->RemoveExpectStrings(this);
       
   137 	if (aError==KErrNone)
       
   138 		{
       
   139 		((CGprs*)iTelObject)->SetStatus(RPacketService::EStatusAttached);
       
   140 		iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject, EPacketStatusChanged);
       
   141 		}
       
   142 	
       
   143 	// Allow our base class to do its thing and then complete the client request
       
   144 	CATCommands::Complete(aError,aSource);		
       
   145 	iTelObject->ReqCompleted(iReqHandle, aError);
       
   146 
       
   147 	iState = EATNotInProgress;
       
   148 	}
       
   149 
       
   150 
       
   151 void CATGprsAttach::EventSignal(TEventSource aSource)
       
   152 /**
       
   153  * This function contains the state machine for the command.  The states flow consecutively and are
       
   154  * described below.
       
   155  * @par ESendAttachCommand
       
   156  * Reads the Modem's response to the AT+CGATT=1 command and completes the request.
       
   157  */
       
   158 	{
       
   159 	LOGTEXT2(_L8("CATGprsAttach::EventSignal called with iState=%d"),iState);
       
   160 
       
   161 	if ((aSource==ETimeOutCompletion))
       
   162 		{
       
   163 		LOGTEXT(_L8("CATGprsAttach::EventSignal, Timeout"));
       
   164 		Complete(KErrTimedOut,aSource);
       
   165 		return;
       
   166 		}
       
   167 
       
   168 	switch(iState)
       
   169 		{
       
   170 		case ESendAttachCommand:
       
   171 			__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
   172 			{
       
   173 			LOGTEXT(_L8("CATGprsAttach::EventSignal, ESendConnectCommand"));
       
   174 			__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
   175 			StandardWriteCompletionHandler(aSource, KGprsLongCommandTimeOut);
       
   176 			iState = EAttachReadComplete;
       
   177 			}
       
   178 			break;
       
   179 		case EAttachReadComplete:
       
   180 			__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
   181 			{
       
   182 			LOGTEXT(_L8("CATGprsAttach::EventSignal, EConnectReadComplete"));
       
   183 			__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   184 			TInt ret = ValidateExpectString();
       
   185 			Complete(ret, aSource);
       
   186 			}
       
   187 			break;
       
   188 		case EATNotInProgress:
       
   189 			break;
       
   190 		default:
       
   191 			{
       
   192 			LOGTEXT(_L8("CATGprsAttach::EventSignal, Default, panic"));
       
   193 			Panic(EIllegalEvent);
       
   194 			}
       
   195 		}		
       
   196 	}