telephonyprotocols/csdagt/src/ND_SCR.CPP
changeset 0 3553901f7fa8
child 19 630d2f34d719
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2003-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 // Script Control definitions
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file Nd_scr.cpp 
       
    20 */
       
    21 
       
    22 #include "ND_SCR.H"
       
    23 #include "ND_STD.H"
       
    24 #include "SLOGGER.H"
       
    25 #include "SSCREXEC.H"
       
    26 #include "ND_DBACC.H"
       
    27 
       
    28 
       
    29 _LIT(KLoginNameVar,"login_name$");
       
    30 _LIT(KLoginPassVar,"login_pass$");
       
    31 _LIT(KLoginIpaddrVar,"login_ipaddr$");
       
    32 
       
    33 // CNetDialScript definitions
       
    34 
       
    35 CNetDialScript* CNetDialScript::NewL(CCommsDbNetDialAccess* aDb,CDialogProcessor* aDlgPrc,RCall::TCommPort& aCommPort,TCommRole aRole,TInt aLength)
       
    36 /**
       
    37 2 phased constructor for CNetDialScript, first phase.
       
    38 
       
    39 @param aDb a pointer to CommDB accessor.
       
    40 @param aDlgPrc a pointer to dialog processor.
       
    41 @param aCommPort is loaned COMM port from ETel server.
       
    42 @param aLength is lenght for used script.
       
    43 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
    44 @return a new CNetDialScript object.
       
    45 */
       
    46 	{
       
    47 	CNetDialScript* r=new(ELeave) CNetDialScript(aDb,aDlgPrc,aLength);
       
    48 	CleanupStack::PushL(r);
       
    49 	r->ConstructL(aCommPort,aRole);
       
    50 	CleanupStack::Pop();
       
    51 	return r;
       
    52 	}
       
    53 
       
    54 CNetDialScript::CNetDialScript(CCommsDbNetDialAccess* aDb,CDialogProcessor* aDlgPrc,TInt aLength) 
       
    55 	: CActive(EPriorityStandard), iState(EIdle), iDb(aDb), iDlgPrc(aDlgPrc), iUsePct(EFalse), iLength(aLength)
       
    56 /**
       
    57 Private constructor for CNetDialScript, used in the first phase of construction.
       
    58 
       
    59 @param aDb a pointer to CommDB accessor.
       
    60 @param aDlgPrc is pointer to dialog processor.
       
    61 @param aLength is length of the used script.
       
    62 */
       
    63 	{}
       
    64 
       
    65 void CNetDialScript::ConstructL(RCall::TCommPort& aCommPort,TCommRole aRole)
       
    66 /**
       
    67 Instantiate Member variable.
       
    68 Add this object into active scheduler.
       
    69 Create script executor.
       
    70 
       
    71 @param aCommPort a loaned COMM port from ETel server.
       
    72 @exception Leaves if CScriptExecutor::NewL() leaves.
       
    73 */
       
    74 	{
       
    75 	CActiveScheduler::Add(this);
       
    76 	iScriptExecutor=CScriptExecutor::NewL(this,aCommPort.iPort,iLength);
       
    77 	(void) aRole;
       
    78 	GetBcaStack();
       
    79 	GetIapIdL();
       
    80 	}
       
    81 
       
    82 CNetDialScript::~CNetDialScript()
       
    83 /**
       
    84 Destructor.
       
    85 Cancel active requests.
       
    86 If script executor is used, call Disconnect() to close it.
       
    87 Delete script executor.
       
    88 */
       
    89 	{
       
    90 	Cancel();
       
    91 	if(iScriptExecutor!=NULL)
       
    92 		iScriptExecutor->Disconnect();
       
    93 	delete iScriptExecutor;
       
    94 	}
       
    95 
       
    96 void CNetDialScript::ReConfigureAndCancelCommPort(TRequestStatus& aStatus)
       
    97 /**
       
    98 Request script executor to reconfigure COMM port.
       
    99 */
       
   100 	{
       
   101 	iScriptExecutor->ReConfigureAndCancelCommPort(aStatus);
       
   102 	}
       
   103 
       
   104 void CNetDialScript::DropSignals(TRequestStatus& aStatus)
       
   105 /**
       
   106 Request script executor to Drop signals on COMM port.
       
   107 */
       
   108 	{
       
   109 	iScriptExecutor->DropSignals(aStatus);
       
   110 	}
       
   111 
       
   112 void CNetDialScript::GetBcaStack()
       
   113 	{
       
   114 	TRAPD(ret, iDb->GetBcaStackL(iBcaStack););
       
   115 	if (ret != KErrNone || iBcaStack.Length() == 0) //Well it looks like there was not BcaStack therefore
       
   116 		{
       
   117 		_LIT(KDefaultBcaStack, "c32bca");
       
   118 		iBcaStack.Copy(KDefaultBcaStack());
       
   119 		}
       
   120 	}
       
   121 
       
   122 void CNetDialScript::GetIapIdL()
       
   123 	{
       
   124 	TInt iapOrError = iDb->GetIapId();
       
   125 	if (iapOrError == 0)
       
   126 		{
       
   127 		User::Leave(KErrNetDialDatabaseDefaultUndefined);
       
   128 		}
       
   129 	else
       
   130 	if (iapOrError > 0)
       
   131 		{
       
   132 		iIapId = iapOrError;
       
   133 		}
       
   134 	else
       
   135 		{
       
   136 		User::Leave(iapOrError);
       
   137 		}
       
   138 	}
       
   139 
       
   140 void CNetDialScript::CreateChannel(TRequestStatus& aStatus)
       
   141 	{
       
   142 	ASSERT(iScriptExecutor);
       
   143 	iScriptExecutor->CreateChannel(aStatus);
       
   144 	}
       
   145 
       
   146 void CNetDialScript::CancelCreateChannel()
       
   147 	{
       
   148 	ASSERT(iScriptExecutor);
       
   149 	iScriptExecutor->CancelCreateChannel();
       
   150 	}
       
   151 
       
   152 void CNetDialScript::ShutdownChannel(TRequestStatus& aStatus)
       
   153 	{
       
   154 	ASSERT(iScriptExecutor);
       
   155 	iScriptExecutor->ShutdownChannel(aStatus);
       
   156 	}
       
   157 
       
   158 
       
   159 void CNetDialScript::Scan(MNetDialScriptObserver& aObserver)
       
   160 /**
       
   161 Starts script scanning.
       
   162 Scan is synchronous, so just go straight to the RunL() and do it.
       
   163 
       
   164 @param aObserver a reference to script observer.
       
   165 */
       
   166 	{
       
   167 	__ASSERT_DEBUG(iLength>0, NetDialPanic(EZeroLengthScript));
       
   168 	__ASSERT_DEBUG(iState==EIdle, User::Invariant());
       
   169 
       
   170 	iCurrentObserver=&aObserver;
       
   171 	iStatus=KRequestPending;
       
   172 	SetActive();
       
   173 	iState=EScanScript;
       
   174 	ScriptOperationComplete(KErrNone);
       
   175 	}
       
   176 
       
   177 TBool CNetDialScript::GetLoginParamsL(MNetDialScriptObserver& aObserver, TBool aIsReconnect)
       
   178 /**
       
   179 Get login parameters. Assumes that there is a non-zero length script.
       
   180 Check from CommDB accessor if login dialog is shown, what are the login name and password and IP address.
       
   181 If the login params are in script, do not request them from user.
       
   182 If dialog is used, get login parameters from dialog processor, set object active and return EFalse.
       
   183 Else set state idle and return ETrue as login params should 
       
   184 
       
   185 @param aObserver a reference to login observer.
       
   186 @return EFalse if the request is not complete and ETrue if the request is already complete.
       
   187 @exception Leaves if GetLoginParamsL() leaves, panics if script length is zero or iState is not idle.
       
   188 */
       
   189 	{
       
   190 	__ASSERT_DEBUG(iLength>0, NetDialPanic(EZeroLengthScript));
       
   191 	__ASSERT_DEBUG(iState==EIdle, User::Invariant());
       
   192 
       
   193 	iCurrentObserver=&aObserver;
       
   194 	iDb->GetLoginParamsL(iUseLoginDialog,iLoginName,iLoginPass,iIPAddress);
       
   195 	if (iScriptExecutor->ReadFound())
       
   196 		iUseLoginDialog=EFalse;			// don't use prompt for password there is a READ command
       
   197 	if (iUseLoginDialog)
       
   198 		{
       
   199 		iDlgPrc->Login(*this,iLoginName,iLoginPass,aIsReconnect);
       
   200 		iStatus=KRequestPending;
       
   201 		SetActive();
       
   202 		iState=EGetLogin;
       
   203 		return EFalse;
       
   204 		}
       
   205 	else
       
   206 		{
       
   207 		iState=EIdle;
       
   208 		return ETrue;
       
   209 		}
       
   210 	}
       
   211 
       
   212 void CNetDialScript::ExecuteL(MNetDialScriptObserver& aObserver)
       
   213 /**
       
   214 Set up login script variables and execute script (will be valid if called).
       
   215 Get script from CommDB accessor and set it for script executor.
       
   216 Get login name, password and IP address from CommDB.
       
   217 If PCT is used, call OpenPct(), call DestroyPctNotification() to end notifications and set login params for script executor.
       
   218 Call RunScript() to start the script.
       
   219 Set object active and iState to EExecute.
       
   220 
       
   221 @param aObserver a reference to script observer.
       
   222 @exception Leaves if GetAndSetScriptL() or SetLoginVarsL() leaves, panics if script length is zero or iState is not idle.
       
   223 */
       
   224 	{
       
   225 	__ASSERT_DEBUG(iLength>0, NetDialPanic(EZeroLengthScript));
       
   226 	__ASSERT_DEBUG(iState==EIdle, User::Invariant());
       
   227 	
       
   228 	iCurrentObserver=&aObserver;
       
   229 	GetAndSetScriptL();
       
   230 	SetLoginVarsL();
       
   231 	if (iUsePct)
       
   232 		{
       
   233 		User::LeaveIfError(OpenPct());
       
   234 		DestroyPctNotification();
       
   235 		iScriptExecutor->SetLoginParams(iLoginName,iLoginPass);		// required for test dialog server
       
   236 		}	
       
   237 	iScriptExecutor->RunScript();
       
   238 	iStatus=KRequestPending;
       
   239 	SetActive();
       
   240 	iState=EExecute;
       
   241 	}
       
   242 
       
   243 void CNetDialScript::CloseScript()
       
   244 /**
       
   245 Close script.
       
   246 Call CloseScript() from script executor.
       
   247 */
       
   248 	{
       
   249 	iScriptExecutor->CloseScript();
       
   250 	}
       
   251 
       
   252 void CNetDialScript::CleanupScript()
       
   253 /**
       
   254 Cleanup script.
       
   255 Call Close() from script executor.
       
   256 */
       
   257 	{
       
   258 	iScriptExecutor->Close();
       
   259 	}
       
   260 
       
   261 void CNetDialScript::ScriptOperationComplete(TInt aError)
       
   262 /**
       
   263 Completes script request.
       
   264 */
       
   265 	{
       
   266 	TRequestStatus* statusPtr=&iStatus;
       
   267 	User::RequestComplete(statusPtr,aError);
       
   268 	}
       
   269 
       
   270 void CNetDialScript::ConfigureCommPort(TRequestStatus& aStatus, const TCommConfig& aConfig)
       
   271 /**
       
   272 Configures COMM port.
       
   273 Call ConfigureCommPort() from script executor.
       
   274 
       
   275 @param aConfig a reference to COMM port.
       
   276 @return error code for configuration.
       
   277 */
       
   278 	{
       
   279 	iScriptExecutor->ConfigureCommPort(aStatus, aConfig);
       
   280 	}
       
   281 
       
   282 void CNetDialScript::CancelConfigureCommPort()
       
   283 /**
       
   284 Cancels Configures COMM port.
       
   285 Call CancelConfigureCommPort() from script executor.
       
   286 */
       
   287 	{
       
   288 	iScriptExecutor->CancelConfigureCommPort();
       
   289 	}
       
   290 
       
   291 
       
   292 TInt CNetDialScript::GetExcessData(TDes8& aBuffer)
       
   293 /**
       
   294 Get excess data.
       
   295 Call GetExcessData() from script executor.
       
   296 
       
   297 @param aBuffer a reference for excess data.
       
   298 @return error code for GetExcessData() request.
       
   299 */
       
   300 	{
       
   301 	return iScriptExecutor->GetExcessData(aBuffer);
       
   302 	}
       
   303 
       
   304 void CNetDialScript::DropDTR(TRequestStatus* aStatusPtr)
       
   305 /**
       
   306 Drop DTR.
       
   307 Call DropDTR() from script executor.
       
   308 */
       
   309 	{
       
   310 	iScriptExecutor->DropDTR(aStatusPtr);
       
   311 	}
       
   312 
       
   313 
       
   314 TInt CNetDialScript::OpenPct()
       
   315 /**
       
   316 Open PCT.
       
   317 Call OpenPct() from dialog processor.
       
   318 
       
   319 @return error code for OpenPct() request.
       
   320 */
       
   321 	{
       
   322 	__FLOG_STMT(_LIT8(logString,"NetDial:\tOpening PCT");)
       
   323 	__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
   324 
       
   325 	const TInt ret = iDlgPrc->OpenPct();
       
   326 	if (ret == KErrNone)
       
   327 		iPctOpen = ETrue;
       
   328 	return ret;
       
   329 	}
       
   330 
       
   331 void CNetDialScript::DestroyPctNotification()
       
   332 /**
       
   333 Destroy PCT notification.
       
   334 Call DestroyPctNotification() from dialog processor.
       
   335 */
       
   336 	{
       
   337 	__FLOG_STMT(_LIT8(logString,"NetDial:\tRequesting Destroy PCT Notification");)
       
   338 	__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
   339 	
       
   340 	iDlgPrc->DestroyPctNotification(*this);
       
   341 	}	
       
   342 
       
   343 TInt CNetDialScript::WritePct(TDes& aBuffer)
       
   344 /**
       
   345 Write incoming data into PCT.
       
   346 
       
   347 @param aBuffer a reference for incoming data.
       
   348 @return error code for WritePct() request.
       
   349 */
       
   350 	{
       
   351 	__FLOG_STMT(_LIT8(logString,"NetDial:\tWriting To PCT");)
       
   352 	__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
   353 	
       
   354 	return iDlgPrc->WritePct(aBuffer);
       
   355 	}	
       
   356 
       
   357 void CNetDialScript::ReadPct(TDes& aBuffer)
       
   358 /**
       
   359 Read data from PCT.
       
   360 
       
   361 @param aBuffer a reference for read data.
       
   362 */
       
   363 	{
       
   364 	__FLOG_STMT(_LIT8(logString,"NetDial:\tReading From PCT");)
       
   365 	__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
   366 	
       
   367 	iDlgPrc->ReadPct(*this,aBuffer);
       
   368 	}
       
   369 
       
   370 void CNetDialScript::ClosePct()
       
   371 /**
       
   372 Close PCT.
       
   373 If PCT is open, call ClosePct() from dialog processor 
       
   374 */
       
   375 	{
       
   376 	if (iPctOpen)
       
   377 		{
       
   378 		__FLOG_STMT(_LIT8(logString,"NetDial:\tClosing PCT");)
       
   379 		__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
   380 	
       
   381 		iDlgPrc->ClosePct();
       
   382 		iPctOpen = EFalse;
       
   383 		iUsePct = EFalse;
       
   384 		}
       
   385 	}
       
   386 
       
   387 void CNetDialScript::CancelDialogServer()
       
   388 /**
       
   389 Cancel requests.
       
   390 Call CancelEverything() from dialog processor.
       
   391 */
       
   392 	{
       
   393 	iDlgPrc->CancelEverything();
       
   394 	}
       
   395 
       
   396 void CNetDialScript::MDPOLoginComplete(TInt aError)
       
   397 /**
       
   398 Login complete.
       
   399 Complete request with aError.
       
   400 
       
   401 @param aError a error code for completition.
       
   402 */
       
   403 	{
       
   404 	TRequestStatus* statusPtr=&iStatus;
       
   405 	User::RequestComplete(statusPtr,aError);
       
   406 	}
       
   407 
       
   408 void CNetDialScript::MDPOReadPctComplete(TInt aError)
       
   409 /**
       
   410 PCT read complete.
       
   411 Call ReadPctComplete() from script executor with aError to complete the ReadPct() request.
       
   412 
       
   413 @param aError a error code for completition.
       
   414 */
       
   415 	{
       
   416 	__FLOG_STMT(_LIT8(logString,"NetDial:\tRead PCT Complete with Error %d");)
       
   417 	__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC8>(logString()),aError);
       
   418 	iScriptExecutor->ReadPctComplete(aError);
       
   419 	}
       
   420 void CNetDialScript::MDPODestroyPctComplete(TInt aError)
       
   421 /**
       
   422 Destroy PCT complete.
       
   423 Call DestroyPctNotificationReceived() from script executor with aError to complete the DestroyPctNotification() request.
       
   424 
       
   425 @param aError a error code for completition.
       
   426 */
       
   427 	{
       
   428 	__FLOG_STMT(_LIT8(logString,"NetDial:\tDestroy PCT Notification Complete with Error %d");)
       
   429 	__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC8>(logString()),aError);
       
   430 
       
   431 	iScriptExecutor->DestroyPctNotificationReceived(aError);
       
   432 	}
       
   433 
       
   434 void CNetDialScript::RunL()
       
   435 /**
       
   436 RunL - Request completed.
       
   437 If iState is EScanScript, call DoScanScriptL() and trap error.
       
   438 Else copy iStatus.Int() into ret variable.
       
   439 Call ScriptFunctionComplete() with ret from current observer.
       
   440 Set state to EIdle.
       
   441 */
       
   442 	{
       
   443 	__ASSERT_DEBUG(iCurrentObserver!=NULL, User::Invariant());
       
   444 	__ASSERT_DEBUG(((iState==EScanScript) || (iState==EExecute) || (iState==EGetLogin)), User::Invariant());
       
   445 
       
   446 	TInt ret=KErrNone;
       
   447 	if (iState==EScanScript)
       
   448 		{
       
   449 		TRAP(ret,DoScanScriptL());
       
   450 		}
       
   451 	else
       
   452 		{
       
   453 		ret=iStatus.Int();
       
   454 		}
       
   455 
       
   456 	iCurrentObserver->ScriptFunctionComplete(ret);
       
   457 	iState=EIdle;
       
   458 	}
       
   459 
       
   460 void CNetDialScript::DoCancel()
       
   461 /**
       
   462 Cancels active requests.
       
   463 Call Cancel() from script executor.
       
   464 If request is pending, call ScriptFunctionComplete() with KErrCancel from current observer.
       
   465 */
       
   466 	{
       
   467 	iScriptExecutor->Cancel();
       
   468 	if(iStatus==KRequestPending)
       
   469 		{
       
   470 		iCurrentObserver->ScriptFunctionComplete(KErrCancel);
       
   471 		}
       
   472 	}
       
   473 
       
   474 void CNetDialScript::DoScanScriptL()
       
   475 /**
       
   476 Scan the script for a READ command.
       
   477 Call GetUsePctL() from CommDB accessor to find out if PCT is used.
       
   478 Call GetAndSetScript() to get script from CommDB accessor and set it for script executor.
       
   479 Call ScanScriptL() from script executor to start scanning.
       
   480 If PCT is not used and ReadFound() returns ETrue, set iUsePct to ETrue.
       
   481 We need to know if there is a READ whether or not the PCT flag is set to see if we need the login dialog.
       
   482 
       
   483 @exception Leaves if GetUsePctL(), GetAndSetScriptL() or ScanScriptL() leaves.
       
   484 */
       
   485 	{
       
   486 	iDb->GetUsePctL(iUsePct);
       
   487 	GetAndSetScriptL();
       
   488 	iScriptExecutor->ScanScriptL();
       
   489 	if (!iUsePct && iScriptExecutor->ReadFound())
       
   490 		iUsePct = ETrue;
       
   491 	}
       
   492 
       
   493 void CNetDialScript::GetAndSetScriptL()
       
   494 /**
       
   495 Get script from database and set script in script executor.
       
   496 */
       
   497 	{
       
   498 	if (!iScriptExecutor->IsScriptSet())
       
   499 		{
       
   500 		HBufC* buffer=iDb->GetScriptLC();
       
   501 		TPtr script(buffer->Des());
       
   502 		iScriptExecutor->SetScript(script);
       
   503 		CleanupStack::PopAndDestroy();
       
   504 		}
       
   505 	}
       
   506 
       
   507 void CNetDialScript::SetLoginVarsL()
       
   508 /**
       
   509 Set up values read from the database as variables.
       
   510 */
       
   511 	{
       
   512 	iScriptExecutor->SetVariableL(KLoginNameVar,iLoginName);
       
   513 	iScriptExecutor->SetVariableL(KLoginPassVar,iLoginPass);
       
   514 	iScriptExecutor->SetVariableL(KLoginIpaddrVar,iIPAddress);
       
   515 	}	
       
   516