|
1 /* |
|
2 * Copyright (c) 2007-2008 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: VOIP Audio Services CMsgQueueHandler class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <voipaudiocommon.h> |
|
20 #include <voipuplinkstream.h> |
|
21 #include <voipdownlinkstream.h> |
|
22 #include <voipdtmftoneplayer.h> |
|
23 #include <voipringtoneplayer.h> |
|
24 #include "debugtracemacros.h" |
|
25 #include "VoIPSharedData.h" |
|
26 #include "VoIPDataBufferImpl.h" |
|
27 #include "VoIPQueueHandler.h" |
|
28 |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CQueueHandler::NewL |
|
32 // Symbian constructor |
|
33 // ---------------------------------------------------------------------------- |
|
34 // |
|
35 CQueueHandler* CQueueHandler::NewL(MQueueHandlerObserver* aObserver, |
|
36 RMsgQueue<TVoIPMsgBuf>* aMsgQueue, |
|
37 TInt aBufferLen) |
|
38 { |
|
39 CQueueHandler* self = new (ELeave) CQueueHandler(aMsgQueue); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(aObserver, aBufferLen); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CQueueHandler::ConstructL |
|
48 // Second phase constructor. |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 void CQueueHandler::ConstructL(MQueueHandlerObserver* aObserver, |
|
52 TInt aBufferLen) |
|
53 { |
|
54 iObserver = aObserver; |
|
55 |
|
56 // aBufferLen == 0 for MsgCom queue |
|
57 if (aBufferLen > 0) |
|
58 { |
|
59 iBuffer = CVoIPDataBufferImpl::NewL(aBufferLen); |
|
60 } |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // CQueueHandler::~CQueueHandler |
|
65 // Destructor. |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 CQueueHandler::~CQueueHandler() |
|
69 { |
|
70 Cancel(); |
|
71 iChunk.Close(); |
|
72 delete iBuffer; |
|
73 } |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // CQueueHandler::CQueueHandler |
|
77 // Constructor. |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 CQueueHandler::CQueueHandler(RMsgQueue<TVoIPMsgBuf>* aMsgQueue) : |
|
81 CActive(CActive::EPriorityStandard), |
|
82 // CActive(CActive::EPriorityHigh), |
|
83 iMsgQueue(aMsgQueue), |
|
84 iChunkDataPtr(0,0,0) |
|
85 { |
|
86 CActiveScheduler::Add(this); |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CQueueHandler::Start |
|
91 // Start listening for events on queue 0. |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 void CQueueHandler::Start() |
|
95 { |
|
96 if (!IsActive()) |
|
97 { |
|
98 iMsgQueue->NotifyDataAvailable(iStatus); |
|
99 SetActive(); |
|
100 } |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CQueueHandler::DoCancel |
|
105 // Cancel outstanding request |
|
106 // ---------------------------------------------------------------------------- |
|
107 // |
|
108 void CQueueHandler::DoCancel() |
|
109 { |
|
110 iMsgQueue->CancelDataAvailable(); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CQueueHandler::RunL |
|
115 // Process requests. |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 void CQueueHandler::RunL() |
|
119 { |
|
120 TVoIPMsgBuf msgBuf; |
|
121 TInt err = iMsgQueue->Receive(msgBuf); |
|
122 |
|
123 // Start monitoring for more events before calling the observer as client |
|
124 // may decide to destroy us before this RunL completes executing. |
|
125 Start(); |
|
126 |
|
127 if (err == KErrNone) |
|
128 { |
|
129 switch (msgBuf.iRequest) |
|
130 { |
|
131 case ECmdDownlinkInitComplete: |
|
132 { |
|
133 iObserver->Event(MVoIPDownlinkObserver::KOpenComplete, |
|
134 msgBuf.iStatus); |
|
135 break; |
|
136 } |
|
137 case ECmdUplinkInitComplete: |
|
138 { |
|
139 iObserver->Event(MVoIPUplinkObserver::KOpenComplete, |
|
140 msgBuf.iStatus); |
|
141 break; |
|
142 } |
|
143 case ECmdFillBuffer: |
|
144 { |
|
145 DoFillBuffer(msgBuf.iInt, msgBuf.iStatus); |
|
146 break; |
|
147 } |
|
148 case ECmdEmptyBuffer: |
|
149 { |
|
150 DoEmptyBuffer(msgBuf.iInt, msgBuf.iStatus); |
|
151 break; |
|
152 } |
|
153 case ECmdDownlinkThreadClosed: |
|
154 { |
|
155 iChunk.Close(); |
|
156 iObserver->Event(MVoIPDownlinkObserver::KDownlinkClosed, |
|
157 msgBuf.iStatus); |
|
158 break; |
|
159 } |
|
160 case ECmdUplinkThreadClosed: |
|
161 { |
|
162 iChunk.Close(); |
|
163 iObserver->Event(MVoIPUplinkObserver::KUplinkClosed, |
|
164 msgBuf.iStatus); |
|
165 break; |
|
166 } |
|
167 case ECmdRingToneOpenComplete: |
|
168 { |
|
169 iObserver->Event(MRingToneObserver::KOpenComplete, |
|
170 msgBuf.iStatus); |
|
171 break; |
|
172 } |
|
173 case ECmdRingTonePlayComplete: |
|
174 { |
|
175 iObserver->Event(MRingToneObserver::KPlaybackComplete, |
|
176 msgBuf.iStatus); |
|
177 break; |
|
178 } |
|
179 case ECmdDnLinkError: |
|
180 case ECmdDnLinkJBError: |
|
181 { |
|
182 iObserver->Event(MVoIPDownlinkObserver::KDownlinkError, |
|
183 msgBuf.iStatus); |
|
184 break; |
|
185 } |
|
186 case ECmdUpLinkError: |
|
187 { |
|
188 iObserver->Event(MVoIPUplinkObserver::KUplinkError, |
|
189 msgBuf.iStatus); |
|
190 break; |
|
191 } |
|
192 case ECmdDTMFOpenDnlinkComplete: |
|
193 { |
|
194 iObserver->Event(MDTMFToneObserver::KOpenCompleteDNL, |
|
195 msgBuf.iStatus); |
|
196 break; |
|
197 } |
|
198 case ECmdDTMFOpenUplinkComplete: |
|
199 { |
|
200 iObserver->Event(MDTMFToneObserver::KOpenCompleteUPL, |
|
201 msgBuf.iStatus); |
|
202 break; |
|
203 } |
|
204 case ECmdDTMFTonePlayFinished: |
|
205 { |
|
206 TRACE_PRN_N1(_L("VoIP->TonePlayFinished [%d]"), msgBuf.iStatus); |
|
207 break; |
|
208 } |
|
209 default: |
|
210 break; |
|
211 } |
|
212 } |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // CQueueHandler::DoFillBuffer |
|
217 // |
|
218 // ---------------------------------------------------------------------------- |
|
219 // |
|
220 void CQueueHandler::DoFillBuffer(TInt aBufLen, TInt aStatus) |
|
221 { |
|
222 TInt err = KErrNone; |
|
223 |
|
224 if (iChunk.Handle() == 0) |
|
225 { |
|
226 // aStatus is either RChunk handle or an error |
|
227 err = iChunk.OpenGlobal(KChunkDNL, EFalse); |
|
228 } |
|
229 |
|
230 if (err == KErrNone) |
|
231 { |
|
232 iChunkDataPtr.Set(iChunk.Base(), 0, aBufLen); |
|
233 iBuffer->SetPayloadPtr(iChunkDataPtr); |
|
234 iObserver->FillBuffer(iBuffer); |
|
235 } |
|
236 else |
|
237 { |
|
238 // returned error |
|
239 iObserver->Event(MVoIPDownlinkObserver::KDownlinkError, aStatus); |
|
240 } |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // CQueueHandler::DoEmptyBuffer |
|
245 // |
|
246 // ---------------------------------------------------------------------------- |
|
247 // |
|
248 void CQueueHandler::DoEmptyBuffer(TInt aBufLen, TInt aStatus) |
|
249 { |
|
250 TInt err = KErrNone; |
|
251 |
|
252 if (iChunk.Handle() == 0) |
|
253 { |
|
254 // aStatus is either RChunk handle or an error |
|
255 err = iChunk.OpenGlobal(KChunkUPL, EFalse); |
|
256 } |
|
257 |
|
258 if (err == KErrNone) |
|
259 { |
|
260 iChunkDataPtr.Set(iChunk.Base(), aBufLen, aBufLen); |
|
261 iBuffer->SetPayloadPtr(iChunkDataPtr); |
|
262 iObserver->EmptyBuffer(iBuffer); |
|
263 } |
|
264 else |
|
265 { |
|
266 iObserver->Event(MVoIPUplinkObserver::KUplinkError, aStatus); |
|
267 } |
|
268 } |
|
269 |
|
270 // ---------------------------------------------------------------------------- |
|
271 // CQueueHandler::RunError |
|
272 // Process requests. |
|
273 // ---------------------------------------------------------------------------- |
|
274 // |
|
275 TInt CQueueHandler::RunError(TInt /*aError*/) |
|
276 { |
|
277 // Current implementation of RunL does not leave |
|
278 return 0; |
|
279 } |
|
280 |
|
281 // ---------------------------------------------------------------------------- |
|
282 // CQueueHandler::Status |
|
283 // Return request status. |
|
284 // ---------------------------------------------------------------------------- |
|
285 // |
|
286 TRequestStatus* CQueueHandler::Status() |
|
287 { |
|
288 return &iStatus; |
|
289 } |
|
290 |
|
291 |
|
292 // End of File |