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