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