cbsref/telephonyrefplugins/atltsy/atcommand/phone/src/atselectnetwork.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 // CATGetModemStatus
       
    15 // Description:
       
    16 // CATSelectNetwork
       
    17 
       
    18 #include "atselectnetwork.h"
       
    19 #include "mslogger.h"
       
    20 
       
    21 _LIT8(KSelectNetworkCommand,"AT+COPS=1,2,%d\r");
       
    22 // Class CATSelectNetwork
       
    23 // ---------------------------------------------------------------------------
       
    24 // CATSelectNetwork::NewL
       
    25 // other items were commented in a header
       
    26 // ---------------------------------------------------------------------------
       
    27 CATSelectNetwork* CATSelectNetwork::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    28 	                                     CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    29 	{
       
    30 	CATSelectNetwork* self = new(ELeave) CATSelectNetwork(aGloblePhone,
       
    31 			                                              aCtsyDispatcherCallback);
       
    32 	CleanupStack::PushL(self );
       
    33 	self->ConstructL();
       
    34 	CleanupStack::Pop(self );
       
    35 	return self ;
       
    36 	}
       
    37 // ---------------------------------------------------------------------------
       
    38 // CATSelectNetwork::CATSelectNetwork
       
    39 // other items were commented in a header
       
    40 // ---------------------------------------------------------------------------
       
    41 CATSelectNetwork::CATSelectNetwork(CGlobalPhonemanager& aGloblePhone, 
       
    42 	                               CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    43 		:CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    44 	{
       
    45 	}
       
    46 // ---------------------------------------------------------------------------
       
    47 // CATSelectNetwork::ConstructL
       
    48 // other items were commented in a header
       
    49 // ---------------------------------------------------------------------------
       
    50 void CATSelectNetwork::ConstructL()
       
    51 	{
       
    52 	CAtCommandBase::ConstructL();
       
    53 	iCommandRunning = EFalse;
       
    54 	iCommandCancel = EFalse;
       
    55 	iCommandSetBack = EFalse;
       
    56 	}
       
    57 // ---------------------------------------------------------------------------
       
    58 // CATSelectNetwork::~CATSelectNetwork
       
    59 // other items were commented in a header
       
    60 // ---------------------------------------------------------------------------
       
    61 CATSelectNetwork::~CATSelectNetwork()
       
    62 	{
       
    63 	}
       
    64 // ---------------------------------------------------------------------------
       
    65 // CATSelectNetwork::StartRequestL
       
    66 // other items were commented in a header
       
    67 // ---------------------------------------------------------------------------
       
    68 void CATSelectNetwork::StartRequest()
       
    69 	{
       
    70 	iCommandRunning = ETrue;
       
    71 	ExecuteCommand();
       
    72 	}
       
    73 // ---------------------------------------------------------------------------
       
    74 // CATSelectNetwork::ExecuteCommand
       
    75 // other items were commented in a header
       
    76 // ---------------------------------------------------------------------------
       
    77 void CATSelectNetwork::ExecuteCommand()
       
    78 	{
       
    79 	LOGTEXT(_L8("CATSelectNetwork::ExecuteCommand called"));
       
    80 	TBuf<5> tmpbuf;
       
    81 	tmpbuf.Append(iNetworkManualSelection.iCountry);
       
    82 	tmpbuf.Append(iNetworkManualSelection.iNetwork);
       
    83     TLex lex(tmpbuf);
       
    84     TInt tmpNum;
       
    85     lex.Val( tmpNum );
       
    86 	LOGTEXT2(_L8("tmpNum=%d"),tmpNum);
       
    87 	iTxBuffer.Format(KSelectNetworkCommand,tmpNum);
       
    88 	Write();
       
    89 	}
       
    90 // ---------------------------------------------------------------------------
       
    91 // CATSelectNetwork::CancelCommand
       
    92 // other items were commented in a header
       
    93 // ---------------------------------------------------------------------------
       
    94 void CATSelectNetwork::CancelCommand()
       
    95 	{	
       
    96 	iCommandCancel = ETrue;
       
    97 	}
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CATSelectNetwork::ExecuteSetBackCommand
       
   101 // other items were commented in a header
       
   102 // ---------------------------------------------------------------------------
       
   103 void CATSelectNetwork::ExecuteSetBackCommand()
       
   104 	{
       
   105 	LOGTEXT(_L8("CATSelectNetwork::ExecuteSetBackCommand called"));
       
   106 	TBuf<5> tmpbuf;
       
   107 	tmpbuf.Append(iPhoneGlobals.iPhoneStatus.iCurrentNetwork.iCountryCode);
       
   108 	tmpbuf.Append(iPhoneGlobals.iPhoneStatus.iCurrentNetwork.iNetworkId);
       
   109     TLex lex(tmpbuf);
       
   110     TInt tmpNum;
       
   111     lex.Val( tmpNum );
       
   112 	LOGTEXT2(_L8("tmpNum=%d"),tmpNum);
       
   113 	iTxBuffer.Format(KSelectNetworkCommand,tmpNum);
       
   114 	Write();
       
   115 	}
       
   116 // ---------------------------------------------------------------------------
       
   117 // CATSelectNetwork::ParseResponseL
       
   118 // other items were commented in a header
       
   119 // ---------------------------------------------------------------------------
       
   120 void CATSelectNetwork::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   121 	{
       
   122 	if (CurrentLine().Match(KLtsyOkString) == 0)
       
   123 		{
       
   124 		iError = KErrNone;
       
   125 		}
       
   126 	else
       
   127 		{
       
   128 		iError = KErrGeneral;
       
   129 		}
       
   130 	}
       
   131 // ---------------------------------------------------------------------------
       
   132 // CATSelectNetwork::SetNetworkSelection
       
   133 // other items were commented in a header
       
   134 // ---------------------------------------------------------------------------
       
   135 void CATSelectNetwork::SetNetworkSelection(const RMobilePhone::TMobilePhoneNetworkManualSelection& aNetworkManualSelection)
       
   136 	{
       
   137 	iNetworkManualSelection = aNetworkManualSelection;
       
   138 	}
       
   139 // ---------------------------------------------------------------------------
       
   140 // CATSelectNetwork::EventSignal
       
   141 // other items were commented in a header
       
   142 // ---------------------------------------------------------------------------
       
   143 void CATSelectNetwork::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   144 	{
       
   145 	if(KErrNone ==aStatus)
       
   146 		{
       
   147 		if(aEventSource == EReadCompletion)
       
   148 			{
       
   149 			aStatus = iError;
       
   150 			}
       
   151 		else
       
   152 			return;
       
   153 		}
       
   154 	if(iCommandCancel) //User runing cancel cmd
       
   155 		{
       
   156 		//We should set back network when selected network success
       
   157 		if((KErrNone ==aStatus)&&(!iCommandSetBack))
       
   158 			{
       
   159 			iCommandSetBack = ETrue;
       
   160 			//Set parameter
       
   161 			ExecuteSetBackCommand();
       
   162 			return;
       
   163 			}
       
   164 		if((iCommandSetBack)&&(KErrNone !=aStatus))
       
   165 			{
       
   166 			//Cancel fail because set back fail 
       
   167 			//Current Network Changed
       
   168 			iCtsyDispatcherCallback.CallbackPhoneSelectNetworkCancelComp(aStatus);
       
   169 			}
       
   170 		else
       
   171 			{
       
   172 			//First selectrd fail or set back success
       
   173 			//Cancel OK
       
   174 			iCtsyDispatcherCallback.CallbackPhoneSelectNetworkCancelComp(KErrNone);
       
   175 			}
       
   176 		}
       
   177 	else
       
   178 		{
       
   179 		iCtsyDispatcherCallback.CallbackPhoneSelectNetworkComp(aStatus);
       
   180 		}
       
   181 	CAtCommandBase::Complete();
       
   182 	iPhoneGlobals.iEventSignalActive = EFalse;
       
   183 	iCommandRunning = EFalse;
       
   184 	iCommandCancel = EFalse;
       
   185 	iCommandSetBack = EFalse;
       
   186 	}
       
   187 //
       
   188 // End of file
       
   189 
       
   190