os/mm/devsoundextensions/effects/RoomLevel/RoomLevelMessageHandler/src/RoomLevelMessageHandler.cpp
Update contrib.
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Implementation of the RoomLevel effect message handler class.
21 #include "RoomLevelMessageHandler.h"
22 #include "RoomLevelMessageTypes.h"
23 #include <RoomLevelBase.h>
24 #include "EffectDataQueItem.h"
25 #include <RoomLevelBase.h>
30 // ================= MEMBER FUNCTIONS =======================
32 // C++ default constructor can NOT contain any code, that
35 CRoomLevelMessageHandler::CRoomLevelMessageHandler(
36 CRoomLevel* aRoomLevel )
37 : CMMFObject(KUidRoomLevelEffect),
43 iRoomLevel = aRoomLevel;
47 EXPORT_C CRoomLevelMessageHandler* CRoomLevelMessageHandler::NewL(
48 TAny* aCustomInterface )
50 CRoomLevel* roomLevel = (CRoomLevel*)aCustomInterface;
51 CRoomLevelMessageHandler* self = new (ELeave) CRoomLevelMessageHandler(roomLevel);
57 // -----------------------------------------------------------------------------
58 // CRoomLevelMessageHandler::ConstructL
59 // Symbian 2nd phase constructor can leave.
60 // Create and initializes the effect data queue.
61 // -----------------------------------------------------------------------------
63 void CRoomLevelMessageHandler::ConstructL()
65 iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink));
69 // -----------------------------------------------------------------------------
70 // CRoomLevelMessageHandler::~CRoomLevelMessageHandler
71 // Before going away, unregister with the CI RoomLevel object.
72 // The observation message must be completed if outstanding.
73 // The effect data queue must be emptied and destroyed.
74 // -----------------------------------------------------------------------------
76 CRoomLevelMessageHandler::~CRoomLevelMessageHandler()
80 RDebug::Print(_L("CRoomLevelMessageHandler::~CRoomLevelMessageHandler"));
83 iRoomLevel->UnRegisterObserver(*this);
88 if ( !iMessage->IsCompleted() )
90 iMessage->Complete(KErrCancel);
97 CEffectDataQueItem* queItem;
98 while ( !iEffectDataQue->IsEmpty() )
100 queItem = iEffectDataQue->First();
101 iEffectDataQue->Remove(*queItem);
105 delete iEffectDataQue;
113 // ---------------------------------------------------------
114 // CRoomLevelMessageHandler::HandleRequest
115 // (other items were commented in a header).
116 // ---------------------------------------------------------
118 void CRoomLevelMessageHandler::HandleRequest(
119 TMMFMessage& aMessage )
121 ASSERT(aMessage.Destination().InterfaceId() == KUidRoomLevelEffect);
122 TRAPD(error,DoHandleRequestL(aMessage));
125 aMessage.Complete(error);
129 // ---------------------------------------------------------
130 // CRoomLevelMessageHandler::DoHandleRequestL
131 // Dispatches the message to the appropriate handler.
132 // ---------------------------------------------------------
134 void CRoomLevelMessageHandler::DoHandleRequestL(
135 TMMFMessage& aMessage )
137 switch( aMessage.Function() )
139 case ERoomInitialize:
141 DoInitializeL(aMessage);
151 DoObserveL(aMessage);
156 aMessage.Complete(KErrNotSupported);
161 // ---------------------------------------------------------
162 // CRoomLevelMessageHandler::DoInitializeL
163 // ---------------------------------------------------------
165 void CRoomLevelMessageHandler::DoInitializeL(TMMFMessage& aMessage)
168 RDebug::Print(_L("CRoomLevelMessageHandler::DoInitializeL"));
170 aMessage.WriteDataToClient(iRoomLevel->DoEffectData());
171 aMessage.Complete(KErrNone);
174 // ---------------------------------------------------------
175 // CRoomLevelMessageHandler::DoApplyL
176 // Extracts the data from the message. The client RoomLevel
177 // data is applied to the CI RoomLevel object.
178 // ---------------------------------------------------------
180 void CRoomLevelMessageHandler::DoApplyL(
181 TMMFMessage& aMessage )
184 RDebug::Print(_L("CRoomLevelMessageHandler::DoApplyL"));
186 TEfRoomLevelDataPckg RoomLevelPckgFromClient;
187 aMessage.ReadData1FromClient(RoomLevelPckgFromClient);
188 iRoomLevel->SetEffectData(RoomLevelPckgFromClient);
189 iRoomLevel->ApplyL();
190 aMessage.Complete(KErrNone);
193 // ---------------------------------------------------------
194 // CRoomLevelMessageHandler::DoObserveL
195 // Receives the observation request message and depending
196 // on the status of the effect data queue, the message is
197 // completed immediately or saved for later completion.
198 // ---------------------------------------------------------
200 void CRoomLevelMessageHandler::DoObserveL(
201 TMMFMessage& aMessage )
205 RDebug::Print(_L("CRoomLevelMessageHandler::DoObserveL"));
210 iRoomLevel->RegisterObserverL(*this);
214 if ( iEffectDataQue->IsEmpty() )
216 //iMessage = &aMessage;
217 iMessage = new(ELeave) TMMFMessage(aMessage);
221 TEfRoomLevelDataPckg dataPckg;
222 CEffectDataQueItem* item = iEffectDataQue->First();
223 dataPckg.Copy(item->EffectData());
224 aMessage.WriteDataToClient(dataPckg);
225 aMessage.Complete(KErrNone);
226 iEffectDataQue->Remove(*item);
231 // ---------------------------------------------------------
232 // CRoomLevelMessageHandler::EffectChanged
233 // The CI RoomLevel object has changed state.
234 // The observation message is completed if no data has been
235 // queued up. Otherwise, the CI RoomLevel object's data is
236 // packaged and queued.
237 // ---------------------------------------------------------
239 void CRoomLevelMessageHandler::EffectChanged(
240 const CAudioEffect* aAudioEffect,
244 RDebug::Print(_L("CRoomLevelMessageHandler::EffectChanged"));
247 if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() )
249 iMessage->WriteDataToClient(((CRoomLevel*)aAudioEffect)->DoEffectData());
250 iMessage->Complete(KErrNone);
256 // Saves the data and complete an observation message next time around.
258 TRAPD(err1,data = ((CRoomLevel*)aAudioEffect)->DoEffectData().AllocL());
261 //CleanupStack::PushL(data);
262 CEffectDataQueItem* item = NULL;
263 TRAPD(err2,item = CEffectDataQueItem::NewL(data));
266 iEffectDataQue->AddLast(*item);
276 RDebug::Print(_L("CRoomLevelMessageHandler::EffectChanged Error Allocating Memory %d"),err1);
284 // ========================== OTHER EXPORTED FUNCTIONS =========================