os/mm/devsoundextensions/effects/BassBoost/BassBoostMessageHandler/src/BassBoostMessageHandler.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 bassboost effect message handler class.
21 #include "BassBoostMessageHandler.h"
22 #include "BassBoostMessageTypes.h"
23 #include "EffectDataQueItem.h"
24 #include <BassBoostBase.h>
29 // ================= MEMBER FUNCTIONS =======================
31 // C++ default constructor can NOT contain any code, that
34 CBassBoostMessageHandler::CBassBoostMessageHandler(
35 CBassBoost* aBassBoost )
36 : CMMFObject(KUidBassBoostEffect),
42 iBassBoost = aBassBoost;
46 EXPORT_C CBassBoostMessageHandler* CBassBoostMessageHandler::NewL(
47 TAny* aCustomInterface )
49 CBassBoost* bassboost = (CBassBoost*)aCustomInterface;
50 CBassBoostMessageHandler* self = new (ELeave) CBassBoostMessageHandler(bassboost);
56 // -----------------------------------------------------------------------------
57 // CBassBoostMessageHandler::ConstructL
58 // Symbian 2nd phase constructor can leave.
59 // Create and initializes the effect data queue.
60 // -----------------------------------------------------------------------------
62 void CBassBoostMessageHandler::ConstructL()
64 iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink));
68 // -----------------------------------------------------------------------------
69 // CBassBoostMessageHandler::~CBassBoostMessageHandler
70 // Before going away, unregister with the CI BassBoost object.
71 // The observation message must be completed if outstanding.
72 // The effect data queue must be emptied and destroyed.
73 // -----------------------------------------------------------------------------
75 CBassBoostMessageHandler::~CBassBoostMessageHandler()
79 RDebug::Print(_L("CBassBoostMessageHandler::~CBassBoostMessageHandler"));
83 iBassBoost->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 // CBassBoostMessageHandler::HandleRequest
115 // (other items were commented in a header).
116 // ---------------------------------------------------------
118 void CBassBoostMessageHandler::HandleRequest(
119 TMMFMessage& aMessage )
121 ASSERT(aMessage.Destination().InterfaceId() == KUidBassBoostEffect);
122 TRAPD(error,DoHandleRequestL(aMessage));
125 aMessage.Complete(error);
129 // ---------------------------------------------------------
130 // CBassBoostMessageHandler::DoHandleRequestL
131 // Dispatches the message to the appropriate handler.
132 // ---------------------------------------------------------
134 void CBassBoostMessageHandler::DoHandleRequestL(
135 TMMFMessage& aMessage )
137 switch( aMessage.Function() )
139 case EBfInitialize: // Request to initialize the bassboost
141 DoInitializeL(aMessage);
144 case EBfApply: // Request to apply the bassboost settings
149 case EBfObserve: // Observation request
151 DoObserveL(aMessage);
156 aMessage.Complete(KErrNotSupported);
161 // ---------------------------------------------------------
162 // CBassBoostMessageHandler::DoInitializeL
163 // ---------------------------------------------------------
165 void CBassBoostMessageHandler::DoInitializeL(TMMFMessage& aMessage)
167 aMessage.WriteDataToClient(iBassBoost->DoEffectData());
168 aMessage.Complete(KErrNone);
171 // ---------------------------------------------------------
172 // CBassBoostMessageHandler::DoApplyL
173 // Extracts the data from the message. The client bassboost data
174 // is applied to the CI bassboost object.
175 // ---------------------------------------------------------
177 void CBassBoostMessageHandler::DoApplyL(
178 TMMFMessage& aMessage )
180 TEfBassBoostDataPckg bassboostPckgFromClient;
181 aMessage.ReadData1FromClient(bassboostPckgFromClient);
183 iBassBoost->SetEffectData(bassboostPckgFromClient);
184 iBassBoost->ApplyL();
185 aMessage.Complete(KErrNone);
188 // ---------------------------------------------------------
189 // CBassBoostMessageHandler::DoObserveL
190 // Receives the observation request message and depending
191 // on the status of the effect data queue, the message is
192 // completed immediately or saved for later completion.
193 // ---------------------------------------------------------
195 void CBassBoostMessageHandler::DoObserveL(
196 TMMFMessage& aMessage )
200 RDebug::Print(_L("CBassBoostMessageHandler::DoObserveL"));
203 if ( !iRegistered ) // Don't register again if we're registered.
205 iBassBoost->RegisterObserverL(*this);
209 if ( iEffectDataQue->IsEmpty() )
211 // Message is saved and completed when an event occurs
212 iMessage = new(ELeave) TMMFMessage(aMessage);
216 TEfBassBoostDataPckg dataPckg;
217 CEffectDataQueItem* item = iEffectDataQue->First();
218 dataPckg.Copy(item->EffectData());
219 aMessage.WriteDataToClient(dataPckg);
220 aMessage.Complete(KErrNone);
221 iEffectDataQue->Remove(*item);
226 // ---------------------------------------------------------
227 // CBassBoostMessageHandler::EffectChanged
228 // The CI bassboost object has changed state.
229 // The observation message is completed if no data has been
230 // queued up. Otherwise, the CI bassboost object's data is
231 // packaged and queued.
232 // ---------------------------------------------------------
234 void CBassBoostMessageHandler::EffectChanged(
235 const CAudioEffect* aAudioEffect,
239 RDebug::Print(_L("CBassBoostMessageHandler::EffectChanged"));
242 if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() )
244 iMessage->WriteDataToClient(((CBassBoost*)aAudioEffect)->DoEffectData());
245 iMessage->Complete(KErrNone);
249 else // no message pending and there is no event queued up
251 // Saves the data and complete an observation message next time when
252 // there is a pending message.
253 // Saves the data and complete an observation message next time around.
255 TRAPD(err1,data = ((CBassBoost*)aAudioEffect)->DoEffectData().AllocL());
258 //CleanupStack::PushL(data);
259 CEffectDataQueItem* item = NULL;
260 TRAPD(err2,item = CEffectDataQueItem::NewL(data));
263 iEffectDataQue->AddLast(*item);
273 RDebug::Print(_L("CBassBoostMessageHandler::EffectChanged Error Allocating Memory %d"),err1);
280 // ========================== OTHER EXPORTED FUNCTIONS =========================