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