telephonyprotocols/csdagt/src/Nd_Bases.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 27 4284d6390a82
child 44 8b72faa1200f
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 // NetDial State machine base class implementations
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file Nd_bases.cpp 
       
    20 */
       
    21 
       
    22 #include "Nd_Bases.h"
       
    23 #include "SLOGGER.H"
       
    24 #include <comms-infras/eventlogger.h>
       
    25 #include "ND_ETEL.H"
       
    26 #include "ND_DBACC.H"
       
    27 #include "ND_SCR.H"
       
    28 
       
    29 // Netdial SM base class 
       
    30 
       
    31 CNetdialSM::CNetdialSM(MAgentNotify& aControllerObserver, CDialogProcessor* aDlgPrc, CCommsDbAccess& aDbAccess)
       
    32 	: CAgentSMBase(aControllerObserver,aDlgPrc,aDbAccess)
       
    33 /**
       
    34 Constructor.
       
    35 
       
    36 @param aControllerObserver a reference to the observer.
       
    37 @param aDlgPrc a reference to the dialog processor.
       
    38 @param aDbAccess a reference to the CommDB accessor
       
    39 */
       
    40 	{}
       
    41 
       
    42 CNetdialSM::~CNetdialSM()
       
    43 /**
       
    44 Destructor.
       
    45 Deletes objects used by Netdial Statemachine
       
    46 */
       
    47 	{
       
    48 
       
    49 	if(iNdScript)
       
    50 		{
       
    51 		delete iNdScript;
       
    52 		}
       
    53 
       
    54 	if(iLogger)
       
    55 		{
       
    56 		delete iLogger;
       
    57 		}
       
    58 
       
    59 	if(iTelServer)
       
    60 		{
       
    61 		delete iTelServer;
       
    62 		}
       
    63 
       
    64 	if(iDbAccess)
       
    65 		{
       
    66 		delete iDbAccess;
       
    67 		}
       
    68 	}
       
    69 
       
    70 void CNetdialSM::ConstructL()
       
    71 /**
       
    72 2nd Phase of construction.
       
    73 Instantiate Member variables.
       
    74 */
       
    75 	{
       
    76 	iDbAccess=CCommsDbNetDialAccess::NewL(iDb);
       
    77 	iTelServer=CTelServerProcessor::NewL(iDbAccess,EPriorityStandard);
       
    78 	iLogger=CEventLogger::NewL();
       
    79 	}
       
    80 
       
    81 #ifdef SYMBIAN_NETWORKING_CSDAGENT_BCA_SUPPORT
       
    82 void CNetdialSM::GetUseScriptL()
       
    83 /**
       
    84 Determine if a script needs to be used.
       
    85 @see CNetdialSM::UseScript.
       
    86 */
       
    87 	{
       
    88 	TInt len = 0;
       
    89 	__FLOG_STMT(_LIT8(logString0,"Netdial:\tGetUseScriptL");)
       
    90 	__FLOG_STATIC(KNetDialLogFolder(), KNetDialLogFile(), logString0);
       
    91 	iDbAccess->GetScriptDetailsL(iUseScript, len);
       
    92 	__FLOG_STMT(_LIT8(logString1,"Netdial:\tGetUseScriptL. iUseScript [%d]");)
       
    93 	__FLOG_STATIC1(KNetDialLogFolder(), KNetDialLogFile(), logString1, iUseScript);
       
    94 	}
       
    95 #endif // SYMBIAN_NETWORKING_CSDAGENT_BCA_SUPPORT
       
    96 TInt CNetdialSM::GetExcessData(TDes8& aBuffer)
       
    97 /**
       
    98 Get excess data buffer from script engine.
       
    99 
       
   100 @param aBuffer a reference to the observer.
       
   101 @return KErrNotFound if script is not found.
       
   102 */
       
   103 	{
       
   104 	__FLOG_STMT(_LIT8(logString,"NetDial:\tGetting Excess Data");)
       
   105 	__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
   106 	if (iNdScript!=NULL)
       
   107 		return iNdScript->GetExcessData(aBuffer);
       
   108 	else
       
   109 		{	
       
   110 		aBuffer.Zero();
       
   111 		return KErrNotFound;
       
   112 		}
       
   113 	}
       
   114 
       
   115 void CNetdialSM::DeleteScript()
       
   116 /**
       
   117 Deletes script.
       
   118 */
       
   119 	{
       
   120 	iNdScript->CleanupScript();
       
   121 	iNdScript->Cancel();
       
   122 	delete iNdScript;
       
   123 	iNdScript=NULL;
       
   124 	}
       
   125 
       
   126 CGetLoginInfo::CGetLoginInfo(MAgentStateMachineEnv& aSMObserver, MNetdialEnv& aNdEnv)
       
   127 	: CAgentStateBase(aSMObserver),iNdEnv(&aNdEnv)
       
   128 /**
       
   129 Get Login Info State constructor.
       
   130 
       
   131 @param aSMObserver a reference to the state machine observer.
       
   132 @param aNdEnv a reference to the Netdial which defines a set of utility functions.
       
   133 */
       
   134 	{}
       
   135 
       
   136 CGetLoginInfo::~CGetLoginInfo()
       
   137 /**
       
   138 Destructor.
       
   139 Cancels active request.
       
   140 */
       
   141 	{
       
   142 	Cancel();
       
   143 	}
       
   144 
       
   145 void CGetLoginInfo::StartState()
       
   146 /**
       
   147 Get login info from database or from user.
       
   148 
       
   149 Updates current progress to the state machine observer, checks if the script is used
       
   150 and requests login parameters. If there is no error, sets the state active to wait for
       
   151 completition for login parameters. If script is not used, calls JumpToRunl to drive the
       
   152 state forward.
       
   153 */
       
   154 	{
       
   155 	iSMObserver->UpdateProgress(ECsdGettingLoginInfo,KErrNone);
       
   156 	TInt ret=KErrNone;
       
   157 	if (iNdEnv->UseScript())
       
   158 		{
       
   159 		TBool res=EFalse;
       
   160 		TRAP(ret,res=iNdEnv->Script()->GetLoginParamsL(*this,iNdEnv->BaseEnv()->IsReconnect()));
       
   161 		if(ret==KErrNone && !res)
       
   162 			{
       
   163 			iStatus=KRequestPending;
       
   164 			SetActive();
       
   165 			return;
       
   166 			}
       
   167 		}
       
   168 	JumpToRunl(ret);
       
   169 	return;
       
   170 	}
       
   171 
       
   172 void CGetLoginInfo::DoCancel()
       
   173 /**
       
   174 Cancel for active request.
       
   175 If dialog processor is used, cancels it's requests.
       
   176 If state is currently waiting for a request to be completed, calls ScriptFunctionComplete
       
   177 with KErrCancel to cancel the request.
       
   178 */
       
   179 	{
       
   180 	if (iNdEnv->Script()!=NULL)
       
   181  		{
       
   182  		(iNdEnv->Script())->Cancel();
       
   183  		}
       
   184 	if ((iNdEnv->BaseEnv())->DlgPrc()!=NULL)
       
   185 		{
       
   186 		(iNdEnv->BaseEnv())->DlgPrc()->Cancel();
       
   187 		}
       
   188 	if (iStatus == KRequestPending)
       
   189 		{
       
   190 		ScriptFunctionComplete(KErrCancel);
       
   191 		}
       
   192 	}
       
   193 
       
   194 void CGetLoginInfo::RunL()
       
   195 /**
       
   196 Getting login info completed (should not complete if connection cancelled)
       
   197 If there is an error then signal it. Pass login name and password from user 
       
   198 to script executor, otherwise advance phase to and call ServiceStarted() 
       
   199 */
       
   200 	{
       
   201 	if(iStatus!=KErrNone)
       
   202 		{
       
   203 		__FLOG_STMT(_LIT(logString3,"Get Login Info");)
       
   204 		__FLOG_STATIC2(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(KCompletedPhaseLogString()), &logString3(), iStatus.Int());
       
   205 		if (iNdEnv->Script()!=NULL)
       
   206 			iNdEnv->Script()->CloseScript();
       
   207 		iSMObserver->ConnectionComplete(ECsdGotLoginInfo,iStatus.Int());
       
   208 		return;
       
   209 		}
       
   210 	iSMObserver->UpdateProgress(ECsdGotLoginInfo,KErrNone);
       
   211 	
       
   212 	if (!(iNdEnv->BaseEnv())->IsReconnect())
       
   213 		{
       
   214 		__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),KServiceStartedLogString());
       
   215 		}
       
   216 	else
       
   217 		{
       
   218 		__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),KServiceStartedReconnLogString());
       
   219 		}
       
   220 	iSMObserver->ServiceStarted();
       
   221 	(iNdEnv->BaseEnv())->CompleteState(KErrNone);
       
   222 	}
       
   223 
       
   224 void CGetLoginInfo::ScriptFunctionComplete(TInt aError)
       
   225 /**
       
   226 Completes script function with the aError parameter.
       
   227 
       
   228 @param aError a error passed for completition.
       
   229 */
       
   230 	{
       
   231 	TRequestStatus* status=&iStatus;
       
   232 	User::RequestComplete(status,aError);
       
   233 	}
       
   234 
       
   235 CEventLogger* MNetdialEnv::Logger()
       
   236 /**
       
   237 @internalComponent
       
   238 */
       
   239 	{ NetDialPanic(ELoggerNotDefined);return NULL; };
       
   240 
       
   241 MAgentStateMachineEnv* CNetdialSM::BaseEnv()
       
   242 	{ return this; };
       
   243 
       
   244 CCommsDbNetDialAccess* CNetdialSM::NetDialDb()
       
   245 	{ return iDbAccess; };
       
   246 
       
   247 CNetDialScript* CNetdialSM::Script()
       
   248 	{ return iNdScript; };
       
   249 
       
   250 CTelServerProcessor* CNetdialSM::TelServPrc()
       
   251 	{ return iTelServer; };
       
   252 
       
   253 CEventLogger* CNetdialSM::Logger() 
       
   254 	{ return iLogger; };
       
   255 
       
   256 TBool CNetdialSM::UseScript() const 
       
   257 	{ return iUseScript; }