cbsref/telephonyrefplugins/atltsy/atcommand/generic/src/atswitchonlinemode.cpp
changeset 49 f50f4094acd7
equal deleted inserted replaced
48:14460bf2a402 49:f50f4094acd7
       
     1 // Copyright (c) 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 // This contains CATSwitchOnLineMode which switch to online mode
       
    15 // 
       
    16 
       
    17 #include "atswitchonlinemode.h"
       
    18 #include "mslogger.h"
       
    19 #include "commengine.h"
       
    20 #include "tsyconfg.h"
       
    21 
       
    22 // Class CATSwitchOnLineMode
       
    23 // ---------------------------------------------------------------------------
       
    24 // CATSwitchOnLineMode::NewL
       
    25 // other items were commented in a header
       
    26 // ---------------------------------------------------------------------------
       
    27 CATSwitchOnLineMode* CATSwitchOnLineMode::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    28 	                                           CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    29 	{
       
    30 	CATSwitchOnLineMode* self = new(ELeave) CATSwitchOnLineMode(aGloblePhone,
       
    31 			                                                    aCtsyDispatcherCallback);
       
    32 	CleanupStack::PushL(self );
       
    33 	self->ConstructL();
       
    34 	CleanupStack::Pop(self );
       
    35 	return self ;
       
    36 	}
       
    37 // ---------------------------------------------------------------------------
       
    38 // CATSwitchOnLineMode::CATSwitchOnLineMode
       
    39 // other items were commented in a header
       
    40 // ---------------------------------------------------------------------------
       
    41 CATSwitchOnLineMode::CATSwitchOnLineMode(CGlobalPhonemanager& aGloblePhone, 
       
    42 	                                     CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    43 		:CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    44 	{
       
    45 	}
       
    46 // ---------------------------------------------------------------------------
       
    47 // CATSwitchOnLineMode::ConstructL
       
    48 // other items were commented in a header
       
    49 // ---------------------------------------------------------------------------
       
    50 void CATSwitchOnLineMode::ConstructL()
       
    51 	{
       
    52 	CAtCommandBase::ConstructL();
       
    53 	RemoveAllExpectString();
       
    54 	AddExpectStringL(KLtsyNoCarrierString());
       
    55 	iWhichTimer = ETimerNone;
       
    56 	iCallbackTimer = CCallbackTimer::NewL(*this);
       
    57 	}
       
    58 // ---------------------------------------------------------------------------
       
    59 // CATSwitchOnLineMode::~CATSwitchOnLineMode
       
    60 // other items were commented in a header
       
    61 // ---------------------------------------------------------------------------
       
    62 CATSwitchOnLineMode::~CATSwitchOnLineMode()
       
    63 	{
       
    64 	if(iCallbackTimer)
       
    65 		{
       
    66 		iCallbackTimer->Cancel();
       
    67 		delete iCallbackTimer;
       
    68 		iCallbackTimer = NULL;
       
    69 		}
       
    70 	}
       
    71 // ---------------------------------------------------------------------------
       
    72 // CATSwitchOnLineMode::ExecuteCommand
       
    73 // other items were commented in a header
       
    74 // ---------------------------------------------------------------------------
       
    75 void CATSwitchOnLineMode::ExecuteCommand()
       
    76 	{
       
    77 	}
       
    78 // ---------------------------------------------------------------------------
       
    79 // CATSwitchOnLineMode::ParseResponseL
       
    80 // other items were commented in a header
       
    81 // ---------------------------------------------------------------------------
       
    82 void CATSwitchOnLineMode::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
    83 	{
       
    84 	if(CurrentLine().Match(KLtsyNoCarrierString) == 0)
       
    85 		{
       
    86 		iError = KErrNone;
       
    87 		}
       
    88 	}
       
    89 // ---------------------------------------------------------------------------
       
    90 // CATSwitchOnLineMode::StartSwitchOnLineModeL
       
    91 // other items were commented in a header
       
    92 // ---------------------------------------------------------------------------
       
    93 void CATSwitchOnLineMode::StartSwitchOnLineMode(CAtCommandBase* aAtCommandBase,
       
    94 		                  MAtCommandExecuteObserver* aAtCommandObserver)
       
    95 	{
       
    96 	iAtCommandBase = aAtCommandBase;
       
    97 	iAtCommandObserver = aAtCommandObserver;
       
    98 	RemoveAtCommandObserver();
       
    99 	iPhoneGlobals.iCommEngine->CommCancel();		// This required to avoid a panic in C32 when we call iIo->ConfigurePort
       
   100 	TCommConfig configPckg;
       
   101 	TInt ret = KErrNone;
       
   102 	ret = iPhoneGlobals.iConfiguration->PortConfig(configPckg,EConfigTypeHangUp);	
       
   103 	if (ret==KErrNone)
       
   104 		ret = iPhoneGlobals.iCommEngine->ConfigurePort(configPckg);		
       
   105 	if (ret!=KErrNone)
       
   106 		{
       
   107 		iAtCommandBase->EventSignal(EWriteCompletion,ret);
       
   108 		}
       
   109 	iPhoneGlobals.iCommEngine->DropDtr();
       
   110 	iWhichTimer = ETimerDrop;
       
   111 	StartTimer(500000L);
       
   112 	}
       
   113 // ---------------------------------------------------------------------------
       
   114 // CATSwitchOnLineMode::EventSignal
       
   115 // other items were commented in a header
       
   116 // ---------------------------------------------------------------------------
       
   117 void CATSwitchOnLineMode::EventSignal(TAtEventSource /*aEventSource*/, TInt aStatus)
       
   118 	{
       
   119 	if(KErrNone ==aStatus)
       
   120 		{
       
   121 		aStatus = iError;
       
   122 		}
       
   123 	CAtCommandBase::Complete();
       
   124 	if(KErrNone ==aStatus)
       
   125 		{
       
   126 		//iPhoneGlobals.iPhoneStatus.iMode = RPhone::EModeOnlineCommand;
       
   127 		Disable();
       
   128 		StartTimer(1000000L);
       
   129 		iWhichTimer = ETimerWait;
       
   130 		}
       
   131 	else
       
   132 		{
       
   133 		Disable();
       
   134 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   135 		iAtCommandBase->EventSignal(EWriteCompletion,KErrNotReady);
       
   136 		}
       
   137 	
       
   138 	}
       
   139 // ---------------------------------------------------------------------------
       
   140 // CATSwitchOnLineMode::Enable
       
   141 // other items were commented in a header
       
   142 // ---------------------------------------------------------------------------
       
   143 void CATSwitchOnLineMode::Enable()
       
   144 	{
       
   145 	AddUnsolicitedAtCommand();
       
   146 	}
       
   147 // ---------------------------------------------------------------------------
       
   148 // CATSwitchOnLineMode::Disable
       
   149 // other items were commented in a header
       
   150 // ---------------------------------------------------------------------------
       
   151 void CATSwitchOnLineMode::Disable()
       
   152 	{
       
   153 	RemoveAtCommand();
       
   154 	}
       
   155 // ---------------------------------------------------------------------------
       
   156 // CATSwitchOnLineMode::StartTimer
       
   157 // other items were commented in a header
       
   158 // ---------------------------------------------------------------------------
       
   159 void CATSwitchOnLineMode::StartTimer(const TInt aTimeout)
       
   160 	{
       
   161 	if (iCallbackTimer->IsActive())
       
   162 		iCallbackTimer->Cancel();
       
   163 	iCallbackTimer->After(aTimeout);
       
   164 	}
       
   165 /**
       
   166  * 
       
   167  * 
       
   168  */
       
   169 void CATSwitchOnLineMode::TimerRun(TInt aError)
       
   170     {
       
   171 	if(aError == KErrNone)
       
   172 	    {
       
   173 		switch(iWhichTimer)
       
   174 			{
       
   175 			case ETimerDrop:
       
   176 			    LOGTEXT(_L8("[Ltsy] CATSwitchOnLineMode::ETimerDrop time out."));
       
   177 				iPhoneGlobals.iCommEngine->RaiseDTR();
       
   178 				iPhoneGlobals.iPhoneStatus.iMode = RPhone::EModeOnlineCommand;
       
   179 				iPhoneGlobals.iEventSignalActive = ETrue;
       
   180 				iWhichTimer = ETimerRaise;
       
   181 				StartTimer(1000000L);
       
   182 				break;
       
   183 			case ETimerRaise:
       
   184                 LOGTEXT(_L8("[Ltsy] CATSwitchOnLineMode::ETimerRaise time out."));
       
   185 				iPhoneGlobals.iCommEngine->ResetBuffers();
       
   186 				iWhichTimer = ETimerReset;
       
   187 				StartTimer(1000000L);
       
   188 				break;
       
   189 			case ETimerReset:
       
   190                 LOGTEXT(_L8("[Ltsy] CATSwitchOnLineMode::ETimerReset time out."));
       
   191 				ClearBuffer();
       
   192 				iPhoneGlobals.iCommEngine->Read();
       
   193 				iWhichTimer = ETimerRead;
       
   194 				Enable();
       
   195 				StartTimer(1000000L);
       
   196 				break;
       
   197 			case ETimerRead:
       
   198                 LOGTEXT(_L8("[Ltsy] CATSwitchOnLineMode::ETimerRead time out."));
       
   199 				StartTimer(1000000L);
       
   200 				iWhichTimer = ETimerWait;
       
   201 				break;
       
   202 			case ETimerWait:
       
   203                 LOGTEXT(_L8("[Ltsy] CATSwitchOnLineMode::ETimerWait time out."));
       
   204 			    if(iAtCommandObserver)
       
   205 			    	{
       
   206 			    	SetAtCommandObserver(iAtCommandObserver);
       
   207 			    	}
       
   208 			    Disable();
       
   209 			    iAtCommandBase->StartRequest(); 
       
   210 			    iWhichTimer = ETimerNone;
       
   211 				break;
       
   212 			default:
       
   213 				Disable();
       
   214 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   215 				iAtCommandBase->EventSignal(EWriteCompletion,KErrNotReady);
       
   216 				break;
       
   217 			}
       
   218 		}
       
   219 	else
       
   220 		{
       
   221 		Disable();
       
   222 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   223 		iAtCommandBase->EventSignal(EWriteCompletion,KErrNotReady);
       
   224 		}
       
   225 	}
       
   226 //
       
   227 // End of file