cbsref/telephonyrefplugins/atltsy/atcommand/callcontrol/src/atclcc.cpp
changeset 44 8b72faa1200f
equal deleted inserted replaced
39:2473f5e227f9 44:8b72faa1200f
       
     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 // @file atclcc.cpp
       
    15 // This contains CATClcc which query incoming or waitting call information.
       
    16 // 
       
    17 
       
    18 //system include
       
    19 
       
    20 //user include
       
    21 #include "mslogger.h"
       
    22 #include "atmanager.h"
       
    23 #include "activecommandstore.h"
       
    24 #include "atclcc.h"
       
    25 #include "callinformationquerycompletenotify.h"
       
    26 #include "ltsycommondefine.h"
       
    27 #include "ltsycallinformationmanager.h"
       
    28 
       
    29 //const define
       
    30 const TInt KLtsyClccReadTimeout = 2;
       
    31 
       
    32 //List current call information 
       
    33 _LIT8(KLtsyCLCCCommand, "AT+CLCC\r");
       
    34 _LIT8(KLtsyCLCCMatchString, "+CLCC:*");
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CATClcc::NewL
       
    39 // other items were commented in a header
       
    40 // ---------------------------------------------------------------------------
       
    41 CATClcc* CATClcc::NewL(CGlobalPhonemanager& aGloblePhone,
       
    42 			           CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    43 	{
       
    44 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::NewL()"));
       
    45 	
       
    46 	CATClcc* self = CATClcc::NewLC(aGloblePhone, aCtsyDispatcherCallback);
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CATClcc::NewLC
       
    53 // other items were commented in a header
       
    54 // ---------------------------------------------------------------------------
       
    55 CATClcc* CATClcc::NewLC(CGlobalPhonemanager& aGloblePhone,
       
    56 		                CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    57 	{
       
    58 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::NewLC()"));
       
    59 	
       
    60 	CATClcc* self = new (ELeave) CATClcc(aGloblePhone, aCtsyDispatcherCallback);
       
    61 	CleanupStack::PushL(self);
       
    62 	self->ConstructL();
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CATClcc::~CATClcc
       
    69 // other items were commented in a header
       
    70 // ---------------------------------------------------------------------------
       
    71 CATClcc::~CATClcc()
       
    72 	{
       
    73 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::~CATClcc()"));
       
    74 	}
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CATClcc::CATClcc
       
    78 // other items were commented in a header
       
    79 // ---------------------------------------------------------------------------
       
    80 CATClcc::CATClcc(CGlobalPhonemanager& aGloblePhone, 
       
    81 		         CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    82 				 :CAtCommandBase(aGloblePhone, aCtsyDispatcherCallback)
       
    83 	{
       
    84 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::CATClcc()"));
       
    85 	
       
    86 	iAtType = ELtsyAT_General_CLCC;
       
    87 	
       
    88 	iQueryCallInfoNotify = NULL;
       
    89 	InitVariable();
       
    90 	}
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CATClcc::ConstructL
       
    94 // other items were commented in a header
       
    95 // ---------------------------------------------------------------------------
       
    96 void CATClcc::ConstructL()
       
    97 	{
       
    98 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::ConstructL()"));
       
    99 	
       
   100 	//Invoke base class function
       
   101 	CAtCommandBase::ConstructL();
       
   102 	
       
   103 	//Set read and write timeout
       
   104 	SetTimeOut(KLtsyDefaultWriteTimeOut, KLtsyClccReadTimeout);
       
   105 	
       
   106 	//Add expecting string
       
   107 	AddExpectStringL(KLtsyCLCCMatchString);
       
   108 	}
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CATClcc::ExecuteCommand
       
   112 // other items were commented in a header
       
   113 // ---------------------------------------------------------------------------
       
   114 void CATClcc::ExecuteCommand()
       
   115 	{
       
   116 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::ExecuteCommand()"));
       
   117 	
       
   118 	iOKFounded = EFalse;
       
   119 	iTxBuffer.Copy(KLtsyCLCCCommand);
       
   120 	Write();
       
   121 	iATStep = EATWaitForWriteComplete;
       
   122 	iProcessStates = EProcessInProgress;
       
   123 	}
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CATClcc::InitVariable
       
   127 // other items were commented in a header
       
   128 // ---------------------------------------------------------------------------
       
   129 void CATClcc::InitVariable()
       
   130 	{
       
   131 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::InitVariable()"));
       
   132 	
       
   133 	iOKFounded = EFalse;
       
   134 	iIOStatus = KErrNone;
       
   135 	iATResult = KErrNone;
       
   136 	iATStep = EATNotInProgress;
       
   137 	iProcessStates = EProcessNotInProgress;	
       
   138 	}
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CATClcc::AddQueryCallInformationCompleteNotify
       
   142 // other items were commented in a header
       
   143 // ---------------------------------------------------------------------------
       
   144 void CATClcc::AddQueryCallInformationCompleteNotify(MCallInformationQueryCompleteNotify* aQueryCallInfoNotify)
       
   145 	{
       
   146 	iQueryCallInfoNotify = aQueryCallInfoNotify;
       
   147 	}
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CATClcc::GetProcessStates
       
   151 // other items were commented in a header
       
   152 // ---------------------------------------------------------------------------
       
   153 CATClcc::TATProcessStates CATClcc::GetProcessStates() const
       
   154 	{
       
   155 	return iProcessStates;
       
   156 	}
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CATClcc::SetProcessStates
       
   160 // other items were commented in a header
       
   161 // ---------------------------------------------------------------------------
       
   162 void CATClcc::SetProcessStates(CATClcc::TATProcessStates aProcessState)
       
   163 	{
       
   164 	iProcessStates = aProcessState;
       
   165 	}
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CATClcc::StartRequest
       
   169 // other items were commented in a header
       
   170 // ---------------------------------------------------------------------------
       
   171 void CATClcc::StartRequest()
       
   172 	{
       
   173 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::StartRequest()"));
       
   174 	
       
   175 	ExecuteCommand();
       
   176 	}
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CATClcc::ParseCLCCResponseL
       
   180 // other items were commented in a header
       
   181 // ---------------------------------------------------------------------------
       
   182 void CATClcc::ParseCLCCResponseL(const TDesC8& aResponseBuf)
       
   183 	{
       
   184 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::ParseCLCCResponseL()"));
       
   185 	
       
   186 	RArray<TPtrC8> array;
       
   187 	CleanupClosePushL(array);
       
   188 	iParser->ParseRespondedBuffer(array, aResponseBuf);
       
   189 	TInt nCount = array.Count();
       
   190 	
       
   191 	//  1       2      3      4       5       6
       
   192 	//+CLCC : <id1>, <dir>, <stat>, <mode>, <mpty>
       
   193 	//Its count must >= 6
       
   194 	if (nCount < 6)	  
       
   195 		{
       
   196 		CleanupStack::PopAndDestroy(1);
       
   197 		return;
       
   198 		}
       
   199 	
       
   200 	//Parse +CLCC :* buffer
       
   201 	//Only care Waiting call and incoming call
       
   202 	TInt nVal(0);
       
   203 	TLex8 tLex(array[3]);
       
   204 	if (tLex.Val(nVal) == KErrNone)
       
   205 		{		
       
   206 		if (nVal == TLtsyCallInformation::EActiveCall ||
       
   207 			nVal == TLtsyCallInformation::EHeldCall ||
       
   208 			nVal == TLtsyCallInformation::EDialingCall ||
       
   209 			nVal == TLtsyCallInformation::EAlertingCall )
       
   210 			{
       
   211 			CleanupStack::PopAndDestroy(1);
       
   212 			LOGTEXT(_L8("[Ltsy CallControl] First Parse state of the call not find incoming call and waiting call"));
       
   213 			return;			
       
   214 			}
       
   215 		
       
   216 		}
       
   217 	else
       
   218 		{
       
   219 		CleanupStack::PopAndDestroy(1);
       
   220 		LOGTEXT(_L8("[Ltsy CallControl] First Parse state of the call Failing"));
       
   221 		return;
       
   222 		}
       
   223 	
       
   224 	//Parse incoming call or waiting call
       
   225 	
       
   226 	//Call id
       
   227 	tLex.Assign(array[1]);
       
   228 	if ((tLex.Val(nVal) != KErrNone)||
       
   229 	    (nVal < KLtsyMinCallId)	||
       
   230 		(nVal > KLtsyMaxCallId))
       
   231 		{
       
   232 		CleanupStack::PopAndDestroy(1);
       
   233 		LOGTEXT(_L8("[Ltsy CallControl] Parse call id of the call Failing"));
       
   234 		return;
       
   235 		}
       
   236    
       
   237 	//Parse call id success
       
   238 	TLtsyCallInformation& callinfo(iPhoneGlobals.GetCallInfoManager().GetCallInformationByCallId(nVal));
       
   239 	callinfo.SetCallIdIsUsedInfo(TLtsyCallInformation::EUsed);
       
   240 	callinfo.SetCallId(nVal);
       
   241 	
       
   242 	TBool bSuccess(ETrue);
       
   243 	for (TInt n = 2; bSuccess && n < nCount; n++)
       
   244 		{
       
   245 		//Direction Call
       
   246 		if (n == 2)
       
   247 			{
       
   248 			tLex.Assign(array[n]);
       
   249 			if (tLex.Val(nVal) == KErrNone)
       
   250 				{
       
   251 				if (TLtsyCallInformation::EMoCall == nVal)
       
   252 					{
       
   253 					callinfo.SetCallDirection(TLtsyCallInformation::EMoCall);
       
   254 					}
       
   255 				else
       
   256 					{
       
   257 					callinfo.SetCallDirection(TLtsyCallInformation::EMtCall);
       
   258 					}
       
   259 				}
       
   260 			else
       
   261 				{
       
   262 				bSuccess = EFalse;
       
   263 				LOGTEXT(_L8("[Ltsy CallControl] Parse direction call Failing"));
       
   264 				}
       
   265 			}
       
   266 		
       
   267 		//State of the Call
       
   268 		if (n == 3)
       
   269 			{
       
   270 			tLex.Assign(array[n]);
       
   271 			if (tLex.Val(nVal) == KErrNone)
       
   272 				{
       
   273 				if (TLtsyCallInformation::EInComingCall == nVal)
       
   274 					{
       
   275 					callinfo.SetCallState(TLtsyCallInformation::EInComingCall);
       
   276 					}
       
   277 				else
       
   278 					{
       
   279 					callinfo.SetCallState(TLtsyCallInformation::EWaitingCall);
       
   280 					}
       
   281 				}
       
   282 			else
       
   283 				{
       
   284 				bSuccess = EFalse;
       
   285 				LOGTEXT(_L8("[Ltsy CallControl] Parse state of the call Failing"));				
       
   286 				}
       
   287 			}
       
   288 		
       
   289 		//Teleservice
       
   290 		if (n == 4)
       
   291 			{
       
   292 			tLex.Assign(array[n]);
       
   293 			if (tLex.Val(nVal) == KErrNone)
       
   294 				{
       
   295 				if (TLtsyCallInformation::EVoiceCall == nVal)
       
   296 					{
       
   297 					callinfo.SetCallMode(TLtsyCallInformation::EVoiceCall);
       
   298 					}
       
   299 				else if (TLtsyCallInformation::EDataCall == nVal)
       
   300 					{
       
   301 					callinfo.SetCallMode(TLtsyCallInformation::EDataCall);
       
   302 					}
       
   303 				else if (TLtsyCallInformation::EFaxCall == nVal)
       
   304 					{
       
   305 					callinfo.SetCallMode(TLtsyCallInformation::EFaxCall);
       
   306 					}
       
   307 				else
       
   308 					{
       
   309 					callinfo.SetCallMode(TLtsyCallInformation::EUnKnowCall);
       
   310 					}
       
   311 				}
       
   312 			else
       
   313 				{
       
   314 				bSuccess = EFalse;
       
   315 				LOGTEXT(_L8("[Ltsy CallControl] Parse teleservice Failing"));					
       
   316 				}
       
   317 			}
       
   318 
       
   319 		//multiparty
       
   320 		if (n == 5)
       
   321 			{
       
   322 			tLex.Assign(array[n]);
       
   323 			if (tLex.Val(nVal) == KErrNone)
       
   324 				{
       
   325 				if (TLtsyCallInformation::ENotConference == nVal)
       
   326 					{
       
   327 					callinfo.SetConferenceCall(TLtsyCallInformation::ENotConference);
       
   328 					}
       
   329 				else
       
   330 					{
       
   331 					callinfo.SetConferenceCall(TLtsyCallInformation::EIsConference);
       
   332 					}
       
   333 				}
       
   334 			else
       
   335 				{
       
   336 				bSuccess = EFalse;
       
   337 				LOGTEXT(_L8("[Ltsy CallControl] Parse multiparty Failing"));				
       
   338 				}
       
   339 			}
       
   340 		
       
   341 		//telenum
       
   342 		if (n == 6)
       
   343 			{
       
   344 			callinfo.SetMobileTelNum(array[n]);
       
   345 			}		
       
   346 
       
   347 		//type of address
       
   348 		if (n == 7)
       
   349 			{
       
   350 			tLex.Assign(array[n]);
       
   351 			if (tLex.Val(nVal) == KErrNone)
       
   352 				{
       
   353 				callinfo.SetAddressType(nVal);
       
   354 				}
       
   355 			else
       
   356 				{
       
   357 				bSuccess = EFalse;
       
   358 				LOGTEXT(_L8("[Ltsy CallControl] Parse type of address Failing"));				
       
   359 				}
       
   360 			}
       
   361 		
       
   362 		//alpah
       
   363 		if (n == 8)
       
   364 			{
       
   365 			callinfo.SetMobileName(array[n]);
       
   366 			}
       
   367 		}
       
   368 	
       
   369 	//Parse failer
       
   370 	if (!bSuccess)
       
   371 		{
       
   372 		iPhoneGlobals.GetCallInfoManager().ResetCallInformationByCallId(callinfo.GetCallId());
       
   373 		}
       
   374 	
       
   375 	CleanupStack::PopAndDestroy(1);
       
   376 	}
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // CATClcc::ParseResponseL
       
   380 // other items were commented in a header
       
   381 // ---------------------------------------------------------------------------
       
   382 void CATClcc::ParseResponseL(const TDesC8& aResponseBuf)
       
   383 	{
       
   384 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::ParseResponseL()"));
       
   385 	
       
   386 	//Process expecting string +CLCC : *
       
   387 	if (aResponseBuf.Match(KLtsyCLCCMatchString) == 0)
       
   388 		{
       
   389 		ParseCLCCResponseL(aResponseBuf);
       
   390 		}
       
   391 	else if (aResponseBuf.Match(KLtsyOkString) == 0) //Process expecting string OK
       
   392 		{
       
   393 		iATResult = KErrNone;
       
   394 		iProcessStates = EProcessOK;
       
   395 		iOKFounded = ETrue;		
       
   396 		}
       
   397 	else if (aResponseBuf.Match(KLtsyErrorString) == 0) //Process expecting string ERROR
       
   398 		{
       
   399 		iATResult = KErrArgument;
       
   400 		iProcessStates = EProcessError;
       
   401 		iOKFounded = EFalse;		
       
   402 		}
       
   403 	}
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // CATClcc::HandleIOError
       
   407 // other items were commented in a header
       
   408 // ---------------------------------------------------------------------------
       
   409 void CATClcc::HandleIOError()
       
   410 	{
       
   411 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::HandleIOError()"));
       
   412 	
       
   413 	iProcessStates = EProcessError;
       
   414 	
       
   415 	if (iQueryCallInfoNotify != NULL)
       
   416 		{
       
   417 		iQueryCallInfoNotify->QueryCallInformationComplete(iIOStatus);
       
   418 		}
       
   419 	}
       
   420 
       
   421 // ---------------------------------------------------------------------------
       
   422 // CATClcc::HandleResponseError
       
   423 // other items were commented in a header
       
   424 // ---------------------------------------------------------------------------
       
   425 void CATClcc::HandleResponseError()
       
   426 	{
       
   427 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::HandleResponseError()"));
       
   428 	
       
   429 	if (iQueryCallInfoNotify != NULL)
       
   430 		{
       
   431 		iQueryCallInfoNotify->QueryCallInformationComplete(iATResult);
       
   432 		}	
       
   433 	}
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // CATClcc::HandleCLCCComplete
       
   437 // other items were commented in a header
       
   438 // ---------------------------------------------------------------------------
       
   439 void CATClcc::HandleCLCCComplete()
       
   440 	{
       
   441 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::HandleCLCCComplete()"));
       
   442 	
       
   443 	if (iQueryCallInfoNotify != NULL)
       
   444 		{
       
   445 		iQueryCallInfoNotify->QueryCallInformationComplete(KErrNone);
       
   446 		}
       
   447 	}
       
   448 
       
   449 // ---------------------------------------------------------------------------
       
   450 // CATClcc::Complete
       
   451 // other items were commented in a header
       
   452 // ---------------------------------------------------------------------------
       
   453 void CATClcc::Complete()
       
   454 	{
       
   455 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::Complete()"));
       
   456 	LOGTEXT2(_L8("[Ltsy CallControl] iIOStatus = %d"), iIOStatus);
       
   457 	LOGTEXT2(_L8("[Ltsy CallControl] iATResult = %d"), iATResult);
       
   458 	
       
   459 	//Remove Ative Command and stop timer
       
   460 	CAtCommandBase::Complete();
       
   461 	
       
   462 	//Let other command can use I/O port
       
   463 	iPhoneGlobals.iEventSignalActive = EFalse;
       
   464 	}
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // CATClcc::EventSignal
       
   468 // other items were commented in a header
       
   469 // ---------------------------------------------------------------------------
       
   470 void CATClcc::EventSignal(TAtEventSource /*aEventSource*/, TInt aStatus)
       
   471 	{  
       
   472 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATClcc::EventSignal()"));
       
   473 	LOGTEXT2(_L8("[Ltsy CallControl] aEventSource = %d\taStatus = %d"),aStatus);
       
   474 	
       
   475 	iIOStatus = aStatus;
       
   476 	if (iIOStatus != KErrNone)
       
   477 		{
       
   478 		HandleIOError();	
       
   479 		Complete();
       
   480 		return;
       
   481 		}
       
   482 	
       
   483 	switch (iATStep)
       
   484 		{
       
   485 		case EATWaitForWriteComplete:
       
   486 			iATStep = EATReadComplete;
       
   487 			break;
       
   488 			
       
   489 		case EATReadComplete:
       
   490 			ClearCurrentLine();
       
   491 			if (iATResult == KErrNone)
       
   492 				{
       
   493 				if (iOKFounded)
       
   494 					{
       
   495 					HandleCLCCComplete();
       
   496 					Complete();
       
   497 					}
       
   498 				}
       
   499 			else
       
   500 				{
       
   501 				HandleResponseError();
       
   502 				Complete();
       
   503 				}
       
   504 			break;
       
   505 			
       
   506 		default:
       
   507 			break;
       
   508 		}
       
   509 	}
       
   510 
       
   511 //End of file