cbsref/telephonyrefplugins/atltsy/atcommand/callcontrol/src/athangup.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
child 21 4814c5a49428
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
     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 // Hangup a ongoning call
       
    15 
       
    16 //system include
       
    17 
       
    18 //user include
       
    19 #include "athangup.h"
       
    20 #include "atmanager.h"
       
    21 #include "activecommandstore.h"
       
    22 #include "mslogger.h"
       
    23 #include "ltsycallinformationmanager.h"
       
    24 #include "allcallreleasecompleteobserver.h"
       
    25 
       
    26 //const define
       
    27 const TInt KLtsyHangupReadTimeout = 2;
       
    28 _LIT8(KLtsyHangUpAllCallCommand, "ATH\r"); //ATH0
       
    29 
       
    30 
       
    31 CATHangUp* CATHangUp::NewL(CGlobalPhonemanager& aGloblePhone,
       
    32 			               CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    33 	{
       
    34 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::NewL()"));
       
    35 	
       
    36 	CATHangUp* self = CATHangUp::NewLC(aGloblePhone, aCtsyDispatcherCallback);
       
    37 	CleanupStack::Pop(self);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 CATHangUp* CATHangUp::NewLC(CGlobalPhonemanager& aGloblePhone,
       
    42 			               CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    43 	{
       
    44 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::NewLC()"));
       
    45 	
       
    46 	CATHangUp* self = new (ELeave) CATHangUp(aGloblePhone, aCtsyDispatcherCallback);
       
    47 	CleanupStack::PushL(self);
       
    48 	self->ConstructL();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 CATHangUp::~CATHangUp()
       
    53 	{
       
    54 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::~CATHangUp()"));
       
    55 	}
       
    56 
       
    57 CATHangUp::CATHangUp(CGlobalPhonemanager& aGloblePhone,
       
    58 		             CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    59 					 :CAtCommandBase(aGloblePhone, aCtsyDispatcherCallback)
       
    60 	{
       
    61 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::CATHangUp()"));
       
    62 	
       
    63 	iAtType = ELtsyAT_Call_ATH;
       
    64 	iIOStatus = KErrNone;
       
    65 	iATResult = KErrNone;
       
    66 	iHangupStep = EATHangUpNotInProgress;
       
    67 	iHangupOperator = EUnknownAPI;
       
    68 	iAllCallReleaseObserver = NULL;
       
    69 	}
       
    70 
       
    71 void CATHangUp::ConstructL()
       
    72 	{
       
    73 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::ConstructL()"));
       
    74 	
       
    75 	//Invoke base class function
       
    76 	CAtCommandBase::ConstructL();
       
    77 	
       
    78 	//Set read and write timeout
       
    79 	SetTimeOut(KLtsyDefaultWriteTimeOut, KLtsyHangupReadTimeout);
       
    80 	}
       
    81 
       
    82 
       
    83 void CATHangUp::ExecuteCommand()
       
    84 	{
       
    85 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::ExecuteCommand()"));
       
    86 	
       
    87 	iTxBuffer.Copy(KLtsyHangUpAllCallCommand);
       
    88 	Write();
       
    89 	iHangupStep = EATHangUpWaitForWriteComplete;
       
    90 	}
       
    91 
       
    92 void CATHangUp::StartRequest()
       
    93 	{
       
    94 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::StartRequest()"));
       
    95 	
       
    96 	ExecuteCommand();
       
    97 	}
       
    98 
       
    99 void CATHangUp::AddAllCallReleaseObserver(MAllCallReleaseCompleteObserver* aObserver)
       
   100 	{
       
   101 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::AddAllCallReleaseObserver()"));
       
   102 	
       
   103 	iAllCallReleaseObserver = aObserver;
       
   104 	}
       
   105 
       
   106 void CATHangUp::InitVariable()
       
   107 	{
       
   108 	iAtType = ELtsyAT_Call_ATH;
       
   109 	iIOStatus = KErrNone;
       
   110 	iATResult = KErrNone;
       
   111 	iHangupStep = EATHangUpNotInProgress;
       
   112 	iHangupOperator = EUnknownAPI;	
       
   113 	}
       
   114 
       
   115 void CATHangUp::SetHangupOperator(THangupOperator aOperator)
       
   116 	{
       
   117 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::SetHangupOperator()"));
       
   118 	
       
   119 	iHangupOperator = aOperator;
       
   120 	}
       
   121 
       
   122 void CATHangUp::HandleIOError()
       
   123 	{
       
   124 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::HandleIOError()"));
       
   125 	
       
   126 	if (iHangupOperator == ECustomAPI)
       
   127 		{
       
   128 		iCtsyDispatcherCallback.CallbackCallControlTerminateAllCallsComp(iIOStatus);
       
   129 		}
       
   130 	else if (iHangupOperator == ERMobilePhoneAPI)
       
   131 		{
       
   132 		iCtsyDispatcherCallback.CallbackPhoneTerminateAllCallsComp(iIOStatus);
       
   133 		}
       
   134 	else
       
   135 		{
       
   136 		LOGTEXT(_L8("[Ltsy CallControl] Hangup unknown operator!!!!"));
       
   137 		}
       
   138 	}
       
   139 
       
   140 void CATHangUp::HandleResponseError()
       
   141 	{
       
   142 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::HandleResponseError()"));
       
   143 	
       
   144 	if (iHangupOperator == ECustomAPI)
       
   145 		{
       
   146 		iCtsyDispatcherCallback.CallbackCallControlTerminateAllCallsComp(iATResult);
       
   147 		}
       
   148 	else if (iHangupOperator == ERMobilePhoneAPI)
       
   149 		{
       
   150 		iCtsyDispatcherCallback.CallbackPhoneTerminateAllCallsComp(iATResult);
       
   151 		}
       
   152 	else
       
   153 		{
       
   154 		LOGTEXT(_L8("[Ltsy CallControl] Hangup unknown operator!!!!"));
       
   155 		}
       
   156 	}
       
   157 
       
   158 void CATHangUp::HandleDisconnectedComplete()
       
   159 	{
       
   160 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::HandleDisconnectedComplete()"));
       
   161 	
       
   162 	if (iHangupOperator == ECustomAPI)
       
   163 		{
       
   164 		iCtsyDispatcherCallback.CallbackCallControlTerminateAllCallsComp(iATResult);
       
   165 		}
       
   166 	else if (iHangupOperator == ERMobilePhoneAPI)
       
   167 		{
       
   168 		iCtsyDispatcherCallback.CallbackPhoneTerminateAllCallsComp(iATResult);
       
   169 		}
       
   170 	else 
       
   171 		{
       
   172 		LOGTEXT(_L8("[Ltsy CallControl] Hangup unknown operator!!!!"));
       
   173 		if (iAllCallReleaseObserver == NULL)
       
   174 			{
       
   175 			return;
       
   176 			}
       
   177 		}
       
   178 
       
   179 	//Notify CTSY all call idel
       
   180 	for (TInt n = KLtsyMinCallId; n <= KLtsyMaxCallId; n++)
       
   181 		{
       
   182 		TLtsyCallInformation& tCallInfo(iPhoneGlobals.GetCallInfoManager().GetCallInformationByCallId(n));
       
   183 		if (tCallInfo.GetCallIdIsUsedInfo() == TLtsyCallInformation::EUsed)
       
   184 			{
       
   185 			
       
   186 			if (tCallInfo.GetCallState() == TLtsyCallInformation::EInComingCall ||
       
   187 				tCallInfo.GetCallState() == TLtsyCallInformation::EWaitingCall	)
       
   188 				{
       
   189 				iCtsyDispatcherCallback.CallbackCallControlNotifyCallStatusChangeInd(KErrGsmCCCallRejected, 
       
   190 						                                                             n, 
       
   191 						                                                             RMobileCall::EStatusDisconnecting);			
       
   192 				iCtsyDispatcherCallback.CallbackCallControlNotifyCallStatusChangeInd(KErrGsmCCCallRejected, 
       
   193 																					 n,
       
   194 																					 RMobileCall::EStatusIdle);				
       
   195 				}
       
   196 			else
       
   197 				{
       
   198 				iCtsyDispatcherCallback.CallbackCallControlNotifyCallStatusChangeInd(KErrGsmCCNormalCallClearing, 
       
   199 						                                                             n, 
       
   200 						                                                             RMobileCall::EStatusDisconnecting);			
       
   201 				iCtsyDispatcherCallback.CallbackCallControlNotifyCallStatusChangeInd(KErrGsmCCNormalCallClearing, 
       
   202 																					 n,
       
   203 																					 RMobileCall::EStatusIdle);				
       
   204 				}
       
   205 			}		
       
   206 		}
       
   207 	
       
   208 	//Setting all call id state unused
       
   209 	iPhoneGlobals.GetCallInfoManager().ResetAllCalInformation();
       
   210 	}
       
   211 
       
   212 void CATHangUp::ParseResponseL(const TDesC8& aResponseBuf)
       
   213 	{
       
   214 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::ParseResponseL()"));
       
   215 	
       
   216 	if (aResponseBuf.Match(KLtsyOkString) == 0)
       
   217 		{
       
   218 		LOGTEXT(_L8("[Ltsy CallControl] Hang up call reponse is OK"));
       
   219 		
       
   220 		iATResult = KErrNone;
       
   221 		}
       
   222 	else if (aResponseBuf.Match(KLtsyErrorString) == 0)
       
   223 		{
       
   224 		LOGTEXT(_L8("[Ltsy CallControl] Hang up call reponse is Error"));
       
   225 		
       
   226 		iATResult = KErrArgument;
       
   227 		}
       
   228 	}
       
   229 
       
   230 void CATHangUp::Complete()
       
   231 	{
       
   232 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::Complete()"));
       
   233 	LOGTEXT2(_L8("[Ltsy CallControl] iIOStatus = %d"), iIOStatus);
       
   234 	LOGTEXT2(_L8("[Ltsy CallControl] iATResult = %d"), iATResult);
       
   235 	
       
   236 	//Remove Ative Command and stop timer
       
   237 	CAtCommandBase::Complete();
       
   238 		
       
   239 	//Let other command can use I/O port
       
   240 	if (iAllCallReleaseObserver == NULL)
       
   241 		{
       
   242 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   243 		}
       
   244 	else
       
   245 		{
       
   246 		if (iIOStatus != KErrNone)
       
   247 			{
       
   248 			iAllCallReleaseObserver->ReleaseAllCallComplete(iIOStatus);
       
   249 			}
       
   250 		else
       
   251 			{
       
   252 			iAllCallReleaseObserver->ReleaseAllCallComplete(iATResult);
       
   253 			}
       
   254 		}
       
   255 	}
       
   256 
       
   257 void CATHangUp::EventSignal(TAtEventSource /*aEventSource*/, TInt aStatus)
       
   258 	{
       
   259 	LOGTEXT(_L8("[Ltsy CallControl] Starting CATHangUp::EventSignal()"));
       
   260 	LOGTEXT2(_L8("[Ltsy CallControl] aEventSource = %d\taStatus = %d"),aStatus);
       
   261 	
       
   262 	iIOStatus = aStatus;
       
   263 	if (iIOStatus != KErrNone)
       
   264 		{
       
   265 		HandleIOError();
       
   266 		Complete();
       
   267 		return;
       
   268 		}
       
   269 	
       
   270 	switch (iHangupStep)
       
   271 		{
       
   272 		case EATHangUpWaitForWriteComplete:
       
   273 			iHangupStep = EATHangUpReadComplete;
       
   274 			break;
       
   275 			
       
   276 		case EATHangUpReadComplete:
       
   277 			if (iATResult == KErrNone)
       
   278 				{
       
   279 				HandleDisconnectedComplete();
       
   280 				}
       
   281 			else
       
   282 				{
       
   283 				HandleResponseError();
       
   284 				}
       
   285 			Complete();
       
   286 			break;
       
   287 			
       
   288 		default:
       
   289 			break;
       
   290 		}
       
   291 	}
       
   292 
       
   293 //End of file