|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Telephony Multimedia Service |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <etelmm.h> |
|
19 #include <mccpdtmfprovider.h> |
|
20 #include <mccpdtmfobserver.h> |
|
21 #include <rmmcustomapi.h> |
|
22 #include "cspdtmfprovider.h" |
|
23 #include "tmsutility.h" |
|
24 #include "cspeteldtmfmonitor.h" |
|
25 #include "cspeteldtmfstopmonitor.h" |
|
26 |
|
27 using namespace TMS; |
|
28 |
|
29 TMSDTMFProvider* TMSDTMFProvider::NewL() |
|
30 { |
|
31 TRACE_PRN_FN_ENT; |
|
32 TMSDTMFProvider* self = new (ELeave) TMSDTMFProvider(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 TRACE_PRN_FN_EXT; |
|
37 return self; |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // Destructor of the object. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 TMSDTMFProvider::~TMSDTMFProvider() |
|
45 { |
|
46 TRACE_PRN_FN_ENT; |
|
47 Cancel(); |
|
48 iObservers.Close(); |
|
49 delete iMonitor; |
|
50 delete iStopMonitor; |
|
51 |
|
52 iMmCustom.Close(); |
|
53 iPhone.Close(); |
|
54 iServer.UnloadPhoneModule(iTsyname); |
|
55 iServer.Close(); |
|
56 TRACE_PRN_FN_EXT; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // Notifies observers about a DTMF event |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void TMSDTMFProvider::NotifyDTMFEvent( |
|
64 const TMSCCPDTMFObserver::TCCPDtmfEvent aEvent, const gint aError, |
|
65 const TChar aTone) |
|
66 { |
|
67 TRACE_PRN_FN_ENT; |
|
68 for (gint i = 0; i < iObservers.Count(); i++) |
|
69 { |
|
70 TMSCCPDTMFObserver *obs = iObservers[i]; |
|
71 if (obs) |
|
72 { |
|
73 iObservers[i]->HandleDTMFEvent(aEvent, aError, aTone); |
|
74 } |
|
75 } |
|
76 TRACE_PRN_FN_EXT; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // Cancel DTMF string sending |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 TInt TMSDTMFProvider::CancelDtmfStringSending() |
|
84 { |
|
85 TRACE_PRN_FN_ENT; |
|
86 gint ret(KErrAlreadyExists); |
|
87 if (IsActive()) |
|
88 { |
|
89 Cancel(); |
|
90 ret = KErrNone; |
|
91 } |
|
92 TRACE_PRN_FN_EXT; |
|
93 return ret; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // Starts DTMF string sending |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TInt TMSDTMFProvider::StartDtmfTone(const TChar aTone) |
|
101 { |
|
102 TRACE_PRN_FN_ENT; |
|
103 gint ret(KErrAlreadyExists); |
|
104 if (!IsActive()) |
|
105 { |
|
106 ret = iPhone.StartDTMFTone(aTone); |
|
107 } |
|
108 TRACE_PRN_FN_EXT; |
|
109 return ret; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // Stop DTMF tone |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TInt TMSDTMFProvider::StopDtmfTone() |
|
117 { |
|
118 TRACE_PRN_FN_ENT; |
|
119 gint ret(KErrAlreadyExists); |
|
120 if (!IsActive()) |
|
121 { |
|
122 ret = iPhone.StopDTMFTone(); |
|
123 } |
|
124 TRACE_PRN_FN_EXT; |
|
125 return ret; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // Send DTMF string |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt TMSDTMFProvider::SendDtmfToneString(const TDesC& aString) |
|
133 { |
|
134 TRACE_PRN_FN_ENT; |
|
135 gint ret = KErrInUse; |
|
136 if (!IsActive()) |
|
137 { |
|
138 iStatus = KRequestPending; |
|
139 iPhone.SendDTMFTones(iStatus, aString); |
|
140 SetActive(); |
|
141 ret = KErrNone; |
|
142 } |
|
143 TRACE_PRN_FN_EXT; |
|
144 return ret; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // Continue DTMF string sending |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TInt TMSDTMFProvider::ContinueDtmfStringSending(const TBool aContinue) |
|
152 { |
|
153 TRACE_PRN_FN_ENT; |
|
154 gint status = iPhone.ContinueDTMFStringSending(aContinue); |
|
155 TRACE_PRN_FN_EXT; |
|
156 return status; |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // Adds observer. |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void TMSDTMFProvider::AddObserverL(const TMSCCPDTMFObserver& aObserver) |
|
164 { |
|
165 TRACE_PRN_FN_ENT; |
|
166 if (iObservers.Find(&aObserver) == KErrNotFound) |
|
167 { |
|
168 iObservers.Append(&aObserver); |
|
169 } |
|
170 TRACE_PRN_FN_EXT; |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // Removes given observer. |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TInt TMSDTMFProvider::RemoveObserver(const TMSCCPDTMFObserver& aObserver) |
|
178 { |
|
179 TRACE_PRN_FN_ENT; |
|
180 gint ret = KErrNotFound; |
|
181 gint found = iObservers.Find(&aObserver); |
|
182 if (found != KErrNotFound) |
|
183 { |
|
184 iObservers.Remove(found); |
|
185 ret = KErrNone; |
|
186 } |
|
187 TRACE_PRN_FN_EXT; |
|
188 return ret; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // From CActive. |
|
193 // Handles request completion. |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void TMSDTMFProvider::RunL() |
|
197 { |
|
198 TRACE_PRN_FN_ENT; |
|
199 if (iStatus == KErrNone) |
|
200 { |
|
201 TMSCCPDTMFObserver::TCCPDtmfEvent event = |
|
202 TMSCCPDTMFObserver::ECCPDtmfStringSendingCompleted; |
|
203 NotifyDTMFEvent(event, KErrNone, NULL); |
|
204 } |
|
205 else |
|
206 { |
|
207 gint error = iStatus.Int(); |
|
208 if (error != KErrCancel) |
|
209 { |
|
210 TMSCCPDTMFObserver::TCCPDtmfEvent event = |
|
211 TMSCCPDTMFObserver::ECCPDtmfStringSendingCompleted; |
|
212 NotifyDTMFEvent(event, error, NULL); |
|
213 } |
|
214 else |
|
215 { |
|
216 // Cancel is not notified |
|
217 } |
|
218 } |
|
219 TRACE_PRN_FN_EXT; |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // From CActive |
|
224 // Canceling functionality. |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void TMSDTMFProvider::DoCancel() |
|
228 { |
|
229 TRACE_PRN_FN_ENT; |
|
230 if (iStatus == KRequestPending) |
|
231 { |
|
232 iPhone.CancelAsyncRequest(EMobilePhoneSendDTMFTones); |
|
233 } |
|
234 TRACE_PRN_FN_EXT; |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // Constructs the requester. |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 TMSDTMFProvider::TMSDTMFProvider() : |
|
242 CActive(EPriorityStandard) |
|
243 { |
|
244 TRACE_PRN_FN_ENT; |
|
245 CActiveScheduler::Add(this); |
|
246 TRACE_PRN_FN_EXT; |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // Constructs the requester in the second phase. |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void TMSDTMFProvider::ConstructL() |
|
254 { |
|
255 TRACE_PRN_FN_ENT; |
|
256 |
|
257 CleanupClosePushL(iServer); |
|
258 User::LeaveIfError(iServer.Connect()); |
|
259 |
|
260 TRACE_PRN_N(_L("**TMS ETel iServer.Connect")); |
|
261 |
|
262 iServer.GetTsyName(0, iTsyname); |
|
263 |
|
264 //Load in the phone device driver |
|
265 User::LeaveIfError(iServer.LoadPhoneModule(iTsyname)); |
|
266 |
|
267 TRACE_PRN_N(_L("**TMS ETel iServer.LoadPhoneModule")); |
|
268 |
|
269 //Find the number of phones available from the tel server |
|
270 gint numberPhones; |
|
271 User::LeaveIfError(iServer.EnumeratePhones(numberPhones)); |
|
272 |
|
273 TRACE_PRN_N(_L("**TMS ETel iServer.EnumeratePhones")); |
|
274 |
|
275 //Check there are available phones |
|
276 if (numberPhones < 1) |
|
277 { |
|
278 User::Leave(KErrNotFound); |
|
279 } |
|
280 |
|
281 //Get info about the first available phone |
|
282 RTelServer::TPhoneInfo info; |
|
283 User::LeaveIfError(iServer.GetPhoneInfo(0, info)); |
|
284 |
|
285 TRACE_PRN_N(_L("**TMS ETel iServer.GetPhoneInfo")); |
|
286 |
|
287 CleanupClosePushL(iPhone); |
|
288 User::LeaveIfError(iPhone.Open(iServer, info.iName)); |
|
289 |
|
290 TRACE_PRN_N(_L("**TMS ETel iPhone.Open")); |
|
291 |
|
292 RMobilePhone::TLineInfo lineInfo; |
|
293 User::LeaveIfError(iPhone.GetLineInfo(0, lineInfo)); |
|
294 |
|
295 TRACE_PRN_N(_L("**TMS ETel iPhone.GetLineInfo")); |
|
296 |
|
297 gint errorCode = iMmCustom.Open(iPhone); |
|
298 |
|
299 if (!iPhone.SubSessionHandle() || !iMmCustom.SubSessionHandle()) |
|
300 { |
|
301 User::Leave(KErrArgument); |
|
302 } |
|
303 iMonitor = TMSEtelDtmfMonitor::NewL(*this, iMmCustom); |
|
304 iMonitor->StartMonitoring(); |
|
305 iStopMonitor = TMSEtelDtmfStopMonitor::NewL(*this, iPhone); |
|
306 // iStopMonitor->StartMonitoring(); |
|
307 |
|
308 CleanupStack::Pop(2);//telserver,phone |
|
309 TRACE_PRN_FN_EXT; |
|
310 } |
|
311 |
|
312 // End of File |