|
1 /* |
|
2 * Copyright (c) 2004 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: Implementation of the SourceDoppler effect message handler class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "SourceDopplerMessageHandler.h" |
|
22 #include "SourceDopplerMessageTypes.h" |
|
23 #include <SourceDopplerBase.h> |
|
24 #include "EffectDataQueItem.h" |
|
25 #ifdef _DEBUG |
|
26 #include <e32svr.h> |
|
27 #endif |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // |
|
34 CSourceDopplerMessageHandler::CSourceDopplerMessageHandler( |
|
35 CSourceDoppler* aDoppler ) |
|
36 : CMMFObject(KUidSourceDopplerEffect), |
|
37 iDoppler(NULL), |
|
38 iMessage(NULL), |
|
39 iRegistered(EFalse), |
|
40 iEffectDataQue(NULL) |
|
41 { |
|
42 iDoppler = aDoppler; |
|
43 } |
|
44 |
|
45 |
|
46 EXPORT_C CSourceDopplerMessageHandler* CSourceDopplerMessageHandler::NewL( |
|
47 TAny* aCustomInterface ) |
|
48 { |
|
49 CSourceDoppler* doppler = (CSourceDoppler*)aCustomInterface; |
|
50 CSourceDopplerMessageHandler* self = new (ELeave) CSourceDopplerMessageHandler(doppler); |
|
51 self->ConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CSourceDopplerMessageHandler::ConstructL |
|
58 // Symbian 2nd phase constructor can leave. |
|
59 // Create and initializes the effect data queue. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CSourceDopplerMessageHandler::ConstructL() |
|
63 { |
|
64 iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink)); |
|
65 } |
|
66 |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CSourceDopplerMessageHandler::~CSourceDopplerMessageHandler |
|
70 // Before going away, unregister with the CI Doppler object. |
|
71 // The observation message must be completed if outstanding. |
|
72 // The effect data queue must be emptied and destroyed. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CSourceDopplerMessageHandler::~CSourceDopplerMessageHandler() |
|
76 { |
|
77 |
|
78 #ifdef _DEBUG |
|
79 RDebug::Print(_L("CSourceDopplerMessageHandler::~CSourceDopplerMessageHandler")); |
|
80 #endif |
|
81 if(iDoppler) |
|
82 iDoppler->UnRegisterObserver(*this); |
|
83 iRegistered = EFalse; |
|
84 |
|
85 if(iMessage) |
|
86 { |
|
87 if ( !iMessage->IsCompleted() ) |
|
88 { |
|
89 iMessage->Complete(KErrCancel); |
|
90 delete iMessage; |
|
91 } |
|
92 } |
|
93 |
|
94 if ( iEffectDataQue ) |
|
95 { |
|
96 CEffectDataQueItem* queItem; |
|
97 while ( !iEffectDataQue->IsEmpty() ) |
|
98 { |
|
99 queItem = iEffectDataQue->First(); |
|
100 iEffectDataQue->Remove(*queItem); |
|
101 delete queItem; |
|
102 } |
|
103 |
|
104 delete iEffectDataQue; |
|
105 } |
|
106 |
|
107 delete iDoppler; |
|
108 |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CSourceDopplerMessageHandler::HandleRequest |
|
114 // (other items were commented in a header). |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 void CSourceDopplerMessageHandler::HandleRequest( |
|
118 TMMFMessage& aMessage ) |
|
119 { |
|
120 ASSERT(aMessage.Destination().InterfaceId() == KUidSourceDopplerEffect); |
|
121 TRAPD(error,DoHandleRequestL(aMessage)); |
|
122 if ( error ) |
|
123 { |
|
124 aMessage.Complete(error); |
|
125 } |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CSourceDopplerMessageHandler::DoHandleRequestL |
|
130 // Dispatches the message to the appropriate handler. |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 void CSourceDopplerMessageHandler::DoHandleRequestL( |
|
134 TMMFMessage& aMessage ) |
|
135 { |
|
136 switch( aMessage.Function() ) |
|
137 { |
|
138 case ESourceDopplerOfInitialize: // Request to initialize the SourceDoppler |
|
139 { |
|
140 DoInitializeL(aMessage); |
|
141 break; |
|
142 } |
|
143 case ESourceDopplerOfApply: // Request to apply the SourceDoppler settings |
|
144 { |
|
145 DoApplyL(aMessage); |
|
146 break; |
|
147 } |
|
148 case ESourceDopplerOfObserve: // Observation request |
|
149 { |
|
150 DoObserveL(aMessage); |
|
151 break; |
|
152 } |
|
153 default: |
|
154 { |
|
155 aMessage.Complete(KErrNotSupported); |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------- |
|
161 // CSourceDopplerMessageHandler::DoInitializeL |
|
162 // --------------------------------------------------------- |
|
163 // |
|
164 void CSourceDopplerMessageHandler::DoInitializeL(TMMFMessage& aMessage) |
|
165 { |
|
166 aMessage.WriteDataToClient(iDoppler->DoEffectData()); |
|
167 aMessage.Complete(KErrNone); |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // CSourceDopplerMessageHandler::DoApplyL |
|
172 // Extracts the data from the message. The client doppler data |
|
173 // is applied to the CI doppler object. |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 void CSourceDopplerMessageHandler::DoApplyL( |
|
177 TMMFMessage& aMessage ) |
|
178 { |
|
179 TEfDopplerDataPckg dopplerPckgFromClient; |
|
180 aMessage.ReadData1FromClient(dopplerPckgFromClient); |
|
181 |
|
182 iDoppler->SetEffectData(dopplerPckgFromClient); |
|
183 iDoppler->ApplyL(); |
|
184 aMessage.Complete(KErrNone); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------- |
|
188 // CSourceDopplerMessageHandler::DoObserveL |
|
189 // Receives the observation request message and depending |
|
190 // on the status of the effect data queue, the message is |
|
191 // completed immediately or saved for later completion. |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 void CSourceDopplerMessageHandler::DoObserveL( |
|
195 TMMFMessage& aMessage ) |
|
196 { |
|
197 |
|
198 #ifdef _DEBUG |
|
199 RDebug::Print(_L("CSourceDopplerMessageHandler::DoObserveL")); |
|
200 #endif |
|
201 |
|
202 if ( !iRegistered ) // Don't register again if we're registered. |
|
203 { |
|
204 iDoppler->RegisterObserverL(*this); |
|
205 iRegistered = ETrue; |
|
206 } |
|
207 |
|
208 if ( iEffectDataQue->IsEmpty() ) |
|
209 { |
|
210 // Message is saved and completed when an event occurs |
|
211 iMessage = new(ELeave) TMMFMessage(aMessage); |
|
212 } |
|
213 else |
|
214 { |
|
215 TEfDopplerDataPckg dataPckg; |
|
216 CEffectDataQueItem* item = iEffectDataQue->First(); |
|
217 dataPckg.Copy(item->EffectData()); |
|
218 aMessage.WriteDataToClient(dataPckg); |
|
219 aMessage.Complete(KErrNone); |
|
220 iEffectDataQue->Remove(*item); |
|
221 delete item; |
|
222 } |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CSourceDopplerMessageHandler::EffectChanged |
|
227 // The CI doppler object has changed state. |
|
228 // The observation message is completed if no data has been |
|
229 // queued up. Otherwise, the CI doppler object's data is |
|
230 // packaged and queued. |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 void CSourceDopplerMessageHandler::EffectChanged( |
|
234 const CAudioEffect* aAudioEffect, |
|
235 TUint8 /*aEvent*/ ) |
|
236 { |
|
237 #ifdef _DEBUG |
|
238 RDebug::Print(_L("CSourceDopplerMessageHandler::EffectChanged")); |
|
239 #endif |
|
240 |
|
241 if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() ) |
|
242 { |
|
243 iMessage->WriteDataToClient(((CSourceDoppler*)aAudioEffect)->DoEffectData()); |
|
244 iMessage->Complete(KErrNone); |
|
245 delete iMessage; |
|
246 iMessage = NULL; |
|
247 } |
|
248 else // no message pending and there is no event queued up |
|
249 { |
|
250 // Saves the data and complete an observation message next time when |
|
251 // there is a pending message. |
|
252 HBufC8* data = NULL; |
|
253 TRAPD(err1,data = ((CSourceDoppler*)aAudioEffect)->DoEffectData().AllocL()); |
|
254 if(!err1) |
|
255 { |
|
256 //CleanupStack::PushL(data); |
|
257 CEffectDataQueItem* item = NULL; |
|
258 TRAPD(err2,item = CEffectDataQueItem::NewL(data)); |
|
259 if(!err2) |
|
260 { |
|
261 iEffectDataQue->AddLast(*item); |
|
262 } |
|
263 else |
|
264 { |
|
265 delete data; |
|
266 } |
|
267 } |
|
268 else |
|
269 { |
|
270 #ifdef _DEBUG |
|
271 RDebug::Print(_L("CSourceDopplerMessageHandler::EffectChanged Error Allocating Memory %d"),err1); |
|
272 #endif |
|
273 } |
|
274 } |
|
275 } |
|
276 |
|
277 |
|
278 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
279 |
|
280 |
|
281 // End of File |