|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "mmfdevsoundproxy.h" |
|
20 #include "mmfdevsoundcallbackhandler.h" |
|
21 |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS ============================== |
|
24 |
|
25 // ---------------------------------------------------------------------------- |
|
26 // CMsgQueueHandler::NewL |
|
27 // Two-phased constructor. |
|
28 // ---------------------------------------------------------------------------- |
|
29 // |
|
30 CMsgQueueHandler* CMsgQueueHandler::NewL( |
|
31 RMMFDevSoundProxy* aDevSoundProxy, |
|
32 MDevSoundObserver& aDevSoundObserver, |
|
33 RMsgQueue<TMMFDevSoundQueueItem>* aMsgQueue, |
|
34 MMMFDevSoundCustomInterfaceObserver& aDevSoundCIObserver) |
|
35 { |
|
36 CMsgQueueHandler* self = new(ELeave) CMsgQueueHandler(aDevSoundProxy, |
|
37 aDevSoundObserver, |
|
38 aMsgQueue, |
|
39 aDevSoundCIObserver); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CMsgQueueHandler::CMsgQueueHandler |
|
48 // C++ default constructor can NOT contain any code, that might leave. |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 CMsgQueueHandler::CMsgQueueHandler (RMMFDevSoundProxy* aDevSoundProxy, |
|
52 MDevSoundObserver& aDevSoundObserver, |
|
53 RMsgQueue<TMMFDevSoundQueueItem>* aMsgQueue, |
|
54 MMMFDevSoundCustomInterfaceObserver& aDevSoundCIObserver) |
|
55 : CActive(EPriorityStandard), |
|
56 iDevSoundProxy(aDevSoundProxy), |
|
57 iDevSoundObserver(aDevSoundObserver), |
|
58 iMsgQueue(aMsgQueue), |
|
59 iChunkDataPtr(0, 0, 0), |
|
60 iDevSoundCIObserver(aDevSoundCIObserver) |
|
61 { |
|
62 CActiveScheduler::Add(this); |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // CMsgQueueHandler::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 void CMsgQueueHandler::ConstructL() |
|
71 { |
|
72 iEmptyBuffer = CMMFDescriptorBuffer::NewL(0); |
|
73 iAsyncQueueFinish = new (ELeave) CAsyncCallBack(CActive::EPriorityStandard); |
|
74 TCallBack asyncCallback(AsyncQueueFinishCallback, this); |
|
75 iAsyncQueueFinish->Set(asyncCallback); |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // CMsgQueueHandler::~CMsgQueueHandler |
|
80 // Destructor. |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 CMsgQueueHandler::~CMsgQueueHandler() |
|
84 { |
|
85 Cancel(); |
|
86 if ( iMsgQueue ) |
|
87 { |
|
88 iMsgQueue->Close(); |
|
89 } |
|
90 iChunk.Close(); |
|
91 |
|
92 delete iDataBuffer; |
|
93 delete iEmptyBuffer; |
|
94 delete iAsyncQueueFinish; |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // CMsgQueueHandler::ReceiveEvents |
|
99 // Subscribes for Play Error event from the DevSound server. |
|
100 // ---------------------------------------------------------------------------- |
|
101 // |
|
102 void CMsgQueueHandler::ReceiveEvents() |
|
103 { |
|
104 if (!IsActive()) |
|
105 { |
|
106 iMsgQueue->NotifyDataAvailable(iStatus); |
|
107 SetActive(); |
|
108 } |
|
109 } |
|
110 |
|
111 // ---------------------------------------------------------------------------- |
|
112 // CMsgQueueHandler::RunL |
|
113 // Handles active object’s request completion event. |
|
114 // |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 void CMsgQueueHandler::RunL() |
|
118 { |
|
119 TInt err = iMsgQueue->Receive(iCurrentItem); |
|
120 |
|
121 if (err == KErrNone || err == KErrUnderflow) |
|
122 { |
|
123 // Signal that we're ready to process the next message |
|
124 ReceiveEvents(); |
|
125 } |
|
126 |
|
127 if (err == KErrNone) |
|
128 { |
|
129 switch (iCurrentItem.iRequest) |
|
130 { |
|
131 case EMMFDevSoundProxyICEvent: |
|
132 { |
|
133 DoInitComplete(); |
|
134 break; |
|
135 } |
|
136 case EMMFDevSoundProxyBTBFEvent: |
|
137 { |
|
138 iAsyncQueueFinish->Cancel(); // if still active, means previous cycle did not Finish(). Cancel. |
|
139 TRAP(err, DoBTBFCompleteL()); |
|
140 if (err) |
|
141 { |
|
142 iAsyncQueueFinish->CallBack(); // async call to Finish() |
|
143 iDevSoundObserver.PlayError(err); |
|
144 } |
|
145 } |
|
146 break; |
|
147 case EMMFDevSoundProxyBTBEEvent: |
|
148 { |
|
149 iAsyncQueueFinish->Cancel(); // if still active, means previous cycle did not Finish(). Cancel. |
|
150 TRAP(err, DoBTBECompleteL()); |
|
151 if (err) |
|
152 { |
|
153 iAsyncQueueFinish->CallBack(); // async call to Finish() |
|
154 iDevSoundObserver.RecordError(err); |
|
155 } |
|
156 } |
|
157 break; |
|
158 case EMMFDevSoundProxyPEEvent: |
|
159 { |
|
160 if (iCurrentItem.iErrorCode == KErrDied || |
|
161 iCurrentItem.iErrorCode == KErrNotReady) |
|
162 { |
|
163 DoPlayErrorComplete(); |
|
164 // "this" pointer is no longer valid here as the associated |
|
165 // instance of the DevSound has been deleted along with this |
|
166 // CMsgQueueHandler object. So, we can only return here. |
|
167 return; |
|
168 } |
|
169 else |
|
170 { |
|
171 DoPlayErrorComplete(); |
|
172 break; |
|
173 } |
|
174 } |
|
175 case EMMFDevSoundProxyREEvent: |
|
176 { |
|
177 DoRecordErrorComplete(); |
|
178 break; |
|
179 } |
|
180 case EMMFDevSoundProxyTFEvent: |
|
181 { |
|
182 DoToneFinishedComplete(); |
|
183 break; |
|
184 } |
|
185 case EMMFDevSoundProxySETCEvent: |
|
186 { |
|
187 DoSendEventToClientComplete(); |
|
188 break; |
|
189 } |
|
190 case EMMFDevSoundCustomCommandCloseMuxDemuxPair: |
|
191 { |
|
192 TMMFEvent pckgevent = iCurrentItem.iEventPckg(); |
|
193 TInt handle = pckgevent.iEventType.iUid; |
|
194 iDevSoundCIObserver.CloseCustomInterface(handle); |
|
195 break; |
|
196 } |
|
197 case EMMFDevSoundProxyPausedRecordCompleteEvent: |
|
198 { |
|
199 DoPausedRecordComplete(); |
|
200 break; |
|
201 } |
|
202 default: |
|
203 { |
|
204 break; |
|
205 } |
|
206 } |
|
207 } |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // CMsgQueueHandler::RunError |
|
212 // Called by CActive object framework if RunL leaves. |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 TInt CMsgQueueHandler::RunError(TInt aError) |
|
216 { |
|
217 TMMFEvent event; |
|
218 event.iErrorCode = aError; |
|
219 iDevSoundObserver.SendEventToClient(event); |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // CMsgQueueHandler::DoCancel |
|
225 // Called when client cancels the wait for a completion of an outstanding |
|
226 // request. |
|
227 // ---------------------------------------------------------------------------- |
|
228 // |
|
229 void CMsgQueueHandler::DoCancel() |
|
230 { |
|
231 iMsgQueue->CancelDataAvailable(); |
|
232 } |
|
233 |
|
234 // ---------------------------------------------------------------------------- |
|
235 // CMsgQueueHandler::DoInitComplete |
|
236 // Handles initialization completion event. |
|
237 // ---------------------------------------------------------------------------- |
|
238 // |
|
239 void CMsgQueueHandler::DoInitComplete() |
|
240 { |
|
241 iDevSoundObserver.InitializeComplete(iCurrentItem.iErrorCode); |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CMsgQueueHandler::DoPlayErrorComplete |
|
246 // Handles play completion or cancel event. |
|
247 // ---------------------------------------------------------------------------- |
|
248 // |
|
249 void CMsgQueueHandler::DoPlayErrorComplete() |
|
250 { |
|
251 iAsyncQueueFinish->CallBack(); // async call to Finish() |
|
252 iDevSoundObserver.PlayError(iCurrentItem.iErrorCode); |
|
253 } |
|
254 |
|
255 // ---------------------------------------------------------------------------- |
|
256 // CMsgQueueHandler::DoBTBFCompleteL |
|
257 // Handles CMMFDevSound object's data request event to supply CMMFDevSound |
|
258 // with the buffer that it needs to play. |
|
259 // ---------------------------------------------------------------------------- |
|
260 // |
|
261 void CMsgQueueHandler::DoBTBFCompleteL() |
|
262 { |
|
263 // Returns either chunk handle or NULL |
|
264 // any error is assumed to be due to a pending PlayError(), so the error here is ignored - the PlayError() call will ensure the client remains lively |
|
265 // the chunk has been closed by the server. No action should be taken. |
|
266 TBool requestChunk = iDataBuffer==NULL; // if we have no buffer, tell server we need a chunk handle |
|
267 TInt handle = iDevSoundProxy->BufferToBeFilledData(requestChunk, iSetPckg); |
|
268 if(handle >= KErrNone) |
|
269 { |
|
270 if ( iSetPckg().iChunkOp == EOpen ) |
|
271 { |
|
272 AssignDataBufferToChunkL(handle); |
|
273 } |
|
274 else |
|
275 { |
|
276 UpdateDataBufferL(); |
|
277 } |
|
278 iDataBuffer->SetStatus(EAvailable); |
|
279 |
|
280 // Let the MMF fill the buffer with data |
|
281 |
|
282 iDevSoundObserver.BufferToBeFilled(iDataBuffer); |
|
283 } |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------------------------------- |
|
287 // CMsgQueueHandler::DoBTBECompleteL |
|
288 // Handles CMMFDevSound object's data request event to supply CMMFDevSound |
|
289 // with the buffer that it needs to record. |
|
290 // ---------------------------------------------------------------------------- |
|
291 // |
|
292 void CMsgQueueHandler::DoBTBECompleteL() |
|
293 { |
|
294 // Returns either chunk handle or NULL |
|
295 // any error is assumed to be due to a pending RecordError(), so the error here is ignored - the RecordError() call will ensure the client remains lively |
|
296 // the chunk has been closed by the server. No action should be taken. |
|
297 TInt handle = iDevSoundProxy->BufferToBeEmptiedData(iSetPckg); |
|
298 if(handle >= KErrNone) |
|
299 { |
|
300 if ( iSetPckg().iChunkOp == EOpen ) |
|
301 { |
|
302 AssignDataBufferToChunkL(handle); |
|
303 } |
|
304 iDataBuffer->SetStatus(EFull); |
|
305 iDataBuffer->Data().SetLength(iSetPckg().iRequestSize); |
|
306 iDevSoundObserver.BufferToBeEmptied(iDataBuffer); |
|
307 } |
|
308 } |
|
309 |
|
310 // ---------------------------------------------------------------------------- |
|
311 // CMsgQueueHandler::DoRecordErrorComplete |
|
312 // Handles record completion or cancel event. |
|
313 // ---------------------------------------------------------------------------- |
|
314 // |
|
315 void CMsgQueueHandler::DoRecordErrorComplete() |
|
316 { |
|
317 iAsyncQueueFinish->CallBack(); // async call to Finish() |
|
318 iDevSoundObserver.RecordError(iCurrentItem.iErrorCode); |
|
319 } |
|
320 |
|
321 // ---------------------------------------------------------------------------- |
|
322 // CMsgQueueHandler::DoToneFinishedComplete |
|
323 // Handles tone play completion event. |
|
324 // ---------------------------------------------------------------------------- |
|
325 // |
|
326 void CMsgQueueHandler::DoToneFinishedComplete() |
|
327 { |
|
328 iDevSoundObserver.ToneFinished(iCurrentItem.iErrorCode); |
|
329 } |
|
330 |
|
331 // ---------------------------------------------------------------------------- |
|
332 // CMsgQueueHandler::DoSendEventToClientComplete |
|
333 // Sends DevSound server event completion notification to the client. |
|
334 // ---------------------------------------------------------------------------- |
|
335 // |
|
336 void CMsgQueueHandler::DoSendEventToClientComplete() |
|
337 { |
|
338 iDevSoundObserver.SendEventToClient(iCurrentItem.iEventPckg()); |
|
339 } |
|
340 |
|
341 // ---------------------------------------------------------------------------- |
|
342 // CMsgQueueHandler::DoPausedRecordComplete |
|
343 // Handles CMMFDevSound object's data request event to supply CMMFDevSound |
|
344 // with the last buffer that it needs to record. |
|
345 // ---------------------------------------------------------------------------- |
|
346 // |
|
347 void CMsgQueueHandler::DoPausedRecordComplete() |
|
348 { |
|
349 ASSERT(iEmptyBuffer); |
|
350 iEmptyBuffer->SetLastBuffer(ETrue); |
|
351 iDevSoundObserver.BufferToBeEmptied(iEmptyBuffer); |
|
352 } |
|
353 |
|
354 // ---------------------------------------------------------------------------- |
|
355 // CMsgQueueHandler::AssignDataBufferToChunkL |
|
356 // Updates chunk handle. |
|
357 // ---------------------------------------------------------------------------- |
|
358 // |
|
359 void CMsgQueueHandler::AssignDataBufferToChunkL(TInt aHandle) |
|
360 { |
|
361 if ( iChunk.Handle() ) |
|
362 { |
|
363 iChunk.Close(); |
|
364 } |
|
365 User::LeaveIfError(iChunk.SetReturnedHandle(aHandle)); |
|
366 // Adjust ptr to map only requested size |
|
367 // The existing clients should handle TPtr with length zero and max length |
|
368 // iSetPckg().iBufferSize. |
|
369 // When we make sure every client handles it, replace second parameter with |
|
370 // zero. |
|
371 //iChunkDataPtr.Set(iChunk.Base(), 0, iSetPckg().iBufferSize); |
|
372 iChunkDataPtr.Set(iChunk.Base(), iSetPckg().iBufferSize, iSetPckg().iBufferSize); |
|
373 if (!iDataBuffer) |
|
374 { |
|
375 iDataBuffer = CMMFPtrBuffer::NewL(); |
|
376 } |
|
377 UpdateDataBufferL(); |
|
378 } |
|
379 |
|
380 void CMsgQueueHandler::UpdateDataBufferL() |
|
381 { |
|
382 ASSERT(iDataBuffer); // to get here, we should have a data buffer |
|
383 iDataBuffer->SetPtr(iChunkDataPtr); |
|
384 iDataBuffer->SetRequestSizeL(iSetPckg().iRequestSize); |
|
385 iDataBuffer->SetLastBuffer(EFalse); |
|
386 } |
|
387 |
|
388 void CMsgQueueHandler::Finish() |
|
389 { |
|
390 if (iDataBuffer) |
|
391 { |
|
392 delete iDataBuffer; |
|
393 iDataBuffer = NULL; |
|
394 } |
|
395 if (iChunk.Handle()) |
|
396 { |
|
397 iChunk.Close(); |
|
398 } |
|
399 } |
|
400 |
|
401 // AsyncQueueStartCallback |
|
402 |
|
403 |
|
404 TInt CMsgQueueHandler::AsyncQueueFinishCallback(TAny* aPtr) |
|
405 { |
|
406 CMsgQueueHandler* self = static_cast<CMsgQueueHandler*>(aPtr); |
|
407 self->DoAsyncQueueFinishCallback(); |
|
408 return KErrNone; |
|
409 } |
|
410 |
|
411 void CMsgQueueHandler::DoAsyncQueueFinishCallback() |
|
412 { |
|
413 Finish(); |
|
414 } |
|
415 |
|
416 |
|
417 // End of File |