|
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 bassboost effect message handler class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "ListenerLocationMessageHandler.h" |
|
22 #include "ListenerLocationMessageTypes.h" |
|
23 #include <ListenerLocationBase.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 CListenerLocationMessageHandler::CListenerLocationMessageHandler( |
|
35 CListenerLocation* aListenerLocation ) |
|
36 : CMMFObject(KUidListenerLocationEffect), |
|
37 iListenerLocation(NULL), |
|
38 iMessage(NULL), |
|
39 iRegistered(EFalse), |
|
40 iEffectDataQue(NULL) |
|
41 { |
|
42 iListenerLocation = aListenerLocation; |
|
43 } |
|
44 |
|
45 |
|
46 EXPORT_C CListenerLocationMessageHandler* CListenerLocationMessageHandler::NewL( |
|
47 TAny* aCustomInterface ) |
|
48 { |
|
49 CListenerLocation* bassboost = (CListenerLocation*)aCustomInterface; |
|
50 CListenerLocationMessageHandler* self = new (ELeave) CListenerLocationMessageHandler(bassboost); |
|
51 self->ConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CListenerLocationMessageHandler::ConstructL |
|
58 // Symbian 2nd phase constructor can leave. |
|
59 // Create and initializes the effect data queue. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CListenerLocationMessageHandler::ConstructL() |
|
63 { |
|
64 iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink)); |
|
65 } |
|
66 |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CListenerLocationMessageHandler::~CListenerLocationMessageHandler |
|
70 // Before going away, unregister with the CI ListenerLocation object. |
|
71 // The observation message must be completed if outstanding. |
|
72 // The effect data queue must be emptied and destroyed. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CListenerLocationMessageHandler::~CListenerLocationMessageHandler() |
|
76 { |
|
77 |
|
78 #ifdef _DEBUG |
|
79 RDebug::Print(_L("CListenerLocationMessageHandler::~CListenerLocationMessageHandler")); |
|
80 #endif |
|
81 if(iListenerLocation) |
|
82 iListenerLocation->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 iListenerLocation; |
|
108 |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CListenerLocationMessageHandler::HandleRequest |
|
114 // (other items were commented in a header). |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 void CListenerLocationMessageHandler::HandleRequest( |
|
118 TMMFMessage& aMessage ) |
|
119 { |
|
120 ASSERT(aMessage.Destination().InterfaceId() == KUidListenerLocationEffect); |
|
121 TRAPD(error,DoHandleRequestL(aMessage)); |
|
122 if ( error ) |
|
123 { |
|
124 aMessage.Complete(error); |
|
125 } |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CListenerLocationMessageHandler::DoHandleRequestL |
|
130 // Dispatches the message to the appropriate handler. |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 void CListenerLocationMessageHandler::DoHandleRequestL( |
|
134 TMMFMessage& aMessage ) |
|
135 { |
|
136 switch( aMessage.Function() ) |
|
137 { |
|
138 case ELlfInitialize: // Request to initialize the bassboost |
|
139 { |
|
140 DoInitializeL(aMessage); |
|
141 break; |
|
142 } |
|
143 case ELlfApply: // Request to apply the bassboost settings |
|
144 { |
|
145 DoApplyL(aMessage); |
|
146 break; |
|
147 } |
|
148 case ELlfObserve: // Observation request |
|
149 { |
|
150 DoObserveL(aMessage); |
|
151 break; |
|
152 } |
|
153 default: |
|
154 { |
|
155 aMessage.Complete(KErrNotSupported); |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------- |
|
161 // CListenerLocationMessageHandler::DoInitializeL |
|
162 // --------------------------------------------------------- |
|
163 // |
|
164 void CListenerLocationMessageHandler::DoInitializeL(TMMFMessage& aMessage) |
|
165 { |
|
166 aMessage.WriteDataToClient(iListenerLocation->DoEffectData()); |
|
167 aMessage.Complete(KErrNone); |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // CListenerLocationMessageHandler::DoApplyL |
|
172 // Extracts the data from the message. The client bassboost data |
|
173 // is applied to the CI bassboost object. |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 void CListenerLocationMessageHandler::DoApplyL( |
|
177 TMMFMessage& aMessage ) |
|
178 { |
|
179 TEfLocationDataPckg locationPckgFromClient; |
|
180 aMessage.ReadData1FromClient(locationPckgFromClient); |
|
181 |
|
182 iListenerLocation->SetEffectData(locationPckgFromClient); |
|
183 iListenerLocation->ApplyL(); |
|
184 aMessage.Complete(KErrNone); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------- |
|
188 // CListenerLocationMessageHandler::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 CListenerLocationMessageHandler::DoObserveL( |
|
195 TMMFMessage& aMessage ) |
|
196 { |
|
197 |
|
198 #ifdef _DEBUG |
|
199 RDebug::Print(_L("CListenerLocationMessageHandler::DoObserveL")); |
|
200 #endif |
|
201 |
|
202 if ( !iRegistered ) // Don't register again if we're registered. |
|
203 { |
|
204 iListenerLocation->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 TEfLocationDataPckg 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 // CListenerLocationMessageHandler::EffectChanged |
|
227 // The CI bassboost object has changed state. |
|
228 // The observation message is completed if no data has been |
|
229 // queued up. Otherwise, the CI bassboost object's data is |
|
230 // packaged and queued. |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 void CListenerLocationMessageHandler::EffectChanged( |
|
234 const CAudioEffect* aAudioEffect, |
|
235 TUint8 /*aEvent*/ ) |
|
236 { |
|
237 #ifdef _DEBUG |
|
238 RDebug::Print(_L("CListenerLocationMessageHandler::EffectChanged")); |
|
239 #endif |
|
240 |
|
241 if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() ) |
|
242 { |
|
243 iMessage->WriteDataToClient(((CListenerLocation*)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 = ((CListenerLocation*)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("CListenerLocationMessageHandler::EffectChanged Error Allocating Memory %d"),err1); |
|
272 #endif |
|
273 } |
|
274 } |
|
275 } |
|
276 |
|
277 |
|
278 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 // End of File |