|
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 atdtmfvts.h |
|
15 // This contains CATDtmfVts which dial a voice call. |
|
16 // |
|
17 |
|
18 //system include |
|
19 |
|
20 //user include |
|
21 #include "atdtmfvts.h" |
|
22 #include "mslogger.h" |
|
23 #include "ltsycommondefine.h" |
|
24 #include "ltsycallinformationmanager.h" |
|
25 |
|
26 //const define |
|
27 _LIT8(KLtsyVTSFirstCharFormat, "AT+VTS=%c"); |
|
28 _LIT8(KLtsyVTSMoreCharFormat, ";+VTS=%c"); |
|
29 _LIT8(KLtsyCarriageReturn,"\r"); |
|
30 const TInt KLtsyVTSReadTimeout = 2; |
|
31 const TInt KLtsyStopAndCancelTimeOut = 100000; // 0.1 second |
|
32 |
|
33 |
|
34 CATDtmfVts* CATDtmfVts::NewL(CGlobalPhonemanager& aGloblePhone, |
|
35 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
36 { |
|
37 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::NewL()")); |
|
38 |
|
39 CATDtmfVts* self = CATDtmfVts::NewLC(aGloblePhone, aCtsyDispatcherCallback); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CATDtmfVts* CATDtmfVts::NewLC(CGlobalPhonemanager& aGloblePhone, |
|
45 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
46 { |
|
47 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::NewLC()")); |
|
48 |
|
49 CATDtmfVts* self = new (ELeave) CATDtmfVts(aGloblePhone, aCtsyDispatcherCallback); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CATDtmfVts::~CATDtmfVts() |
|
56 { |
|
57 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::~CATDtmfVts()")); |
|
58 } |
|
59 |
|
60 CATDtmfVts::CATDtmfVts(CGlobalPhonemanager& aGloblePhone, |
|
61 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
62 :CAtCommandBase(aGloblePhone, aCtsyDispatcherCallback) |
|
63 { |
|
64 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::CATDtmfVts()")); |
|
65 |
|
66 InitVariable(); |
|
67 } |
|
68 |
|
69 void CATDtmfVts::InitVariable() |
|
70 { |
|
71 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::InitVariable()")); |
|
72 |
|
73 iDtmfWorkType = EDtmfUnknow; |
|
74 iOKFounded = EFalse; |
|
75 iAnswerStep = EATNotInProgress; |
|
76 iCallId = KLtsyErrorCallId; |
|
77 iIOStatus = KErrNone; |
|
78 iATResult = KErrNone; |
|
79 } |
|
80 |
|
81 void CATDtmfVts::SetDtmfWorkType(TDtmfWorkType aDtmfWorkType) |
|
82 { |
|
83 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::SetDtmfWorkType()")); |
|
84 |
|
85 iDtmfWorkType = aDtmfWorkType; |
|
86 } |
|
87 |
|
88 void CATDtmfVts::ConstructL() |
|
89 { |
|
90 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::ConstructL()")); |
|
91 |
|
92 //Invoke base class function |
|
93 CAtCommandBase::ConstructL(); |
|
94 |
|
95 //Create Timer |
|
96 iCallbackTimer = CCallbackTimer::NewL(*this); |
|
97 |
|
98 //Set read and write timeout |
|
99 SetTimeOut(KLtsyDefaultWriteTimeOut, KLtsyVTSReadTimeout); |
|
100 } |
|
101 |
|
102 void CATDtmfVts::ExecuteCommand() |
|
103 { |
|
104 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::ExecuteCommand()")); |
|
105 |
|
106 if (iDtmfWorkType == EDtmfStopOneTone || |
|
107 iDtmfWorkType == EDtmfCancelMoreTones) |
|
108 { |
|
109 StartTimer(); |
|
110 } |
|
111 else |
|
112 { |
|
113 iOKFounded = EFalse; |
|
114 if (iTxBuffer.Length() > 0) |
|
115 { |
|
116 LOGTEXT2(_L8("[Ltsy CallControl] VTS = %S"), &iTxBuffer); |
|
117 Write(); |
|
118 iAnswerStep = EATWaitForWriteComplete; |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 TBool CATDtmfVts::IsHaveActiveCall(TInt aActiveCallId) |
|
124 { |
|
125 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::IsHaveActiveCall()")); |
|
126 |
|
127 if (aActiveCallId >= KLtsyMinCallId && aActiveCallId <= KLtsyMaxCallId) |
|
128 { |
|
129 const TLtsyCallInformation& tCallInfo = iPhoneGlobals.GetCallInfoManager().GetCallInformationByCallId(aActiveCallId); |
|
130 if (TLtsyCallInformation::EUsed == tCallInfo.GetCallIdIsUsedInfo() && |
|
131 TLtsyCallInformation::EActiveCall == tCallInfo.GetCallState()) |
|
132 { |
|
133 return ETrue; |
|
134 } |
|
135 } |
|
136 return EFalse; |
|
137 } |
|
138 |
|
139 void CATDtmfVts::StartRequest() |
|
140 { |
|
141 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::StartRequest()")); |
|
142 |
|
143 ExecuteCommand(); |
|
144 } |
|
145 |
|
146 TInt CATDtmfVts::SetCallId(TInt aCallId) |
|
147 { |
|
148 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::SetCallId()")); |
|
149 |
|
150 if (!IsHaveActiveCall(aCallId)) |
|
151 { |
|
152 return KErrEtelCallNotActive; |
|
153 } |
|
154 |
|
155 iCallId = aCallId; |
|
156 |
|
157 return KErrNone; |
|
158 } |
|
159 |
|
160 TInt CATDtmfVts::SetDtmfString(const TDesC& aDtmfString) |
|
161 { |
|
162 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::SetDtmfString()")); |
|
163 |
|
164 if (!StringIsDtmf(aDtmfString)) |
|
165 { |
|
166 return KErrArgument; |
|
167 } |
|
168 |
|
169 TInt nLen = aDtmfString.Length(); |
|
170 for (TInt n = 0; n < nLen; n++) |
|
171 { |
|
172 if (n == 0) |
|
173 { |
|
174 iTxBuffer.Format(KLtsyVTSFirstCharFormat, (TUint8)(aDtmfString[n])); |
|
175 } |
|
176 else |
|
177 { |
|
178 TBuf8<16> buf; |
|
179 buf.Format(KLtsyVTSMoreCharFormat, (TUint8)(aDtmfString[n])); |
|
180 |
|
181 if ((buf.Length() + iTxBuffer.Length()) >= KLtsyGenericBufferSize) |
|
182 { |
|
183 return KErrOverflow; |
|
184 } |
|
185 iTxBuffer.Append(buf); |
|
186 } |
|
187 } |
|
188 |
|
189 //Converts the content of this descriptor to upper case. |
|
190 iTxBuffer.UpperCase(); |
|
191 iTxBuffer.Append(KLtsyCarriageReturn); |
|
192 |
|
193 return KErrNone; |
|
194 } |
|
195 |
|
196 TBool CATDtmfVts::CharIsDtmf(const TChar& aDtmfChar) |
|
197 { |
|
198 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::IsDtmf()")); |
|
199 |
|
200 TUint uC = aDtmfChar.GetUpperCase(); |
|
201 |
|
202 switch(uC) |
|
203 { |
|
204 case '0': |
|
205 case '1': |
|
206 case '2': |
|
207 case '3': |
|
208 case '4': |
|
209 case '5': |
|
210 case '6': |
|
211 case '7': |
|
212 case '8': |
|
213 case '9': |
|
214 case 'A': |
|
215 case 'B': |
|
216 case 'C': |
|
217 case 'D': |
|
218 case '*': |
|
219 case '#': |
|
220 return ETrue; |
|
221 } |
|
222 return EFalse; |
|
223 } |
|
224 |
|
225 TBool CATDtmfVts::StringIsDtmf(const TDesC& aDtmfString) |
|
226 { |
|
227 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::StringIsDtmf()")); |
|
228 |
|
229 TInt nLen = aDtmfString.Length(); |
|
230 if (nLen == 0) |
|
231 { |
|
232 return EFalse; |
|
233 } |
|
234 |
|
235 for (TInt n = 0; n < nLen; n++) |
|
236 { |
|
237 if (!CharIsDtmf(aDtmfString[n])) |
|
238 { |
|
239 return EFalse; |
|
240 } |
|
241 } |
|
242 |
|
243 return ETrue; |
|
244 } |
|
245 |
|
246 void CATDtmfVts::Complete() |
|
247 { |
|
248 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::Complete()")); |
|
249 LOGTEXT2(_L8("[Ltsy CallControl] iIOStatus = %d"), iIOStatus); |
|
250 LOGTEXT2(_L8("[Ltsy CallControl] iATResult = %d"), iATResult); |
|
251 |
|
252 //Remove Ative Command and stop timer |
|
253 CAtCommandBase::Complete(); |
|
254 |
|
255 //Init |
|
256 InitVariable(); |
|
257 |
|
258 //Let other command can use I/O port |
|
259 iPhoneGlobals.iEventSignalActive = EFalse; |
|
260 } |
|
261 |
|
262 void CATDtmfVts::StartTimer() |
|
263 { |
|
264 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::StartTimer()")); |
|
265 |
|
266 if (iCallbackTimer->IsActive()) |
|
267 { |
|
268 iCallbackTimer->Cancel(); |
|
269 } |
|
270 iCallbackTimer->After(KLtsyStopAndCancelTimeOut); |
|
271 } |
|
272 |
|
273 void CATDtmfVts::TimerRun(TInt aError) |
|
274 { |
|
275 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::TimerRun()")); |
|
276 |
|
277 if (aError != KErrNone) |
|
278 { |
|
279 User::After(KLtsyStopAndCancelTimeOut); |
|
280 } |
|
281 |
|
282 if (iDtmfWorkType == EDtmfStopOneTone) |
|
283 { |
|
284 iCtsyDispatcherCallback.CallbackCallControlStopDtmfToneComp(KErrNone); |
|
285 } |
|
286 else if (iDtmfWorkType == EDtmfCancelMoreTones) |
|
287 { |
|
288 iCtsyDispatcherCallback.CallbackCallControlSendDtmfTonesCancelComp(KErrNone); |
|
289 } |
|
290 |
|
291 //Init |
|
292 InitVariable(); |
|
293 |
|
294 //Let other command can use I/O port |
|
295 iPhoneGlobals.iEventSignalActive = EFalse; |
|
296 } |
|
297 |
|
298 void CATDtmfVts::HandleIOError() |
|
299 { |
|
300 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::HandleIOError()")); |
|
301 |
|
302 if (iDtmfWorkType == EDtmfSendOneTone) |
|
303 { |
|
304 iCtsyDispatcherCallback.CallbackCallControlStartDtmfToneComp(iIOStatus); |
|
305 } |
|
306 else if (iDtmfWorkType == EDtmfSendMoreTones) |
|
307 { |
|
308 iCtsyDispatcherCallback.CallbackCallControlSendDtmfTonesComp(iIOStatus); |
|
309 } |
|
310 } |
|
311 |
|
312 void CATDtmfVts::HandleResponseError() |
|
313 { |
|
314 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::HandleResponseError()")); |
|
315 |
|
316 if (iDtmfWorkType == EDtmfSendOneTone) |
|
317 { |
|
318 iCtsyDispatcherCallback.CallbackCallControlStartDtmfToneComp(iATResult); |
|
319 } |
|
320 else if (iDtmfWorkType == EDtmfSendMoreTones) |
|
321 { |
|
322 iCtsyDispatcherCallback.CallbackCallControlSendDtmfTonesComp(iATResult); |
|
323 } |
|
324 } |
|
325 |
|
326 void CATDtmfVts::HandleSendDtmfTonesSuccess() |
|
327 { |
|
328 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::HandleSendDtmfTonesSuccess()")); |
|
329 |
|
330 if (iDtmfWorkType == EDtmfSendOneTone) |
|
331 { |
|
332 iCtsyDispatcherCallback.CallbackCallControlStartDtmfToneComp(KErrNone); |
|
333 } |
|
334 else if (iDtmfWorkType == EDtmfSendMoreTones) |
|
335 { |
|
336 iCtsyDispatcherCallback.CallbackCallControlSendDtmfTonesComp(KErrNone); |
|
337 } |
|
338 } |
|
339 |
|
340 void CATDtmfVts::ParseResponseL(const TDesC8& aResponseBuf) |
|
341 { |
|
342 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::ParseResponseL()")); |
|
343 |
|
344 if (aResponseBuf.Match(KLtsyOkString) == 0) |
|
345 { |
|
346 iATResult = KErrNone; |
|
347 iOKFounded = ETrue; |
|
348 } |
|
349 else if(aResponseBuf.Match(KLtsyErrorString) == 0) |
|
350 { |
|
351 iATResult = KErrArgument; |
|
352 } |
|
353 } |
|
354 |
|
355 void CATDtmfVts::EventSignal(TAtEventSource /*aEventSource*/, TInt aStatus) |
|
356 { |
|
357 LOGTEXT(_L8("[Ltsy CallControl] Starting CATDtmfVts::EventSignal()")); |
|
358 LOGTEXT2(_L8("[Ltsy CallControl] aEventSource = %d\taStatus = %d"),aStatus); |
|
359 |
|
360 iIOStatus = aStatus; |
|
361 |
|
362 //Process I/O Error |
|
363 if (iIOStatus != KErrNone) |
|
364 { |
|
365 HandleResponseError(); |
|
366 Complete(); |
|
367 return; |
|
368 } |
|
369 |
|
370 //Process at step |
|
371 switch(iAnswerStep) |
|
372 { |
|
373 case EATWaitForWriteComplete: |
|
374 iAnswerStep = EATReadComplete; |
|
375 break; |
|
376 |
|
377 case EATReadComplete: |
|
378 ClearCurrentLine(); |
|
379 if (iATResult == KErrNone) |
|
380 { |
|
381 HandleSendDtmfTonesSuccess(); |
|
382 } |
|
383 else |
|
384 { |
|
385 HandleResponseError(); |
|
386 } |
|
387 Complete(); |
|
388 break; |
|
389 |
|
390 default: |
|
391 break; |
|
392 } |
|
393 } |
|
394 |
|
395 //End of file |