os/mm/devsoundextensions/effects/SrcLocation/SourceLocationMessageHandler/src/SourceLocationMessageHandler.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 "SourceLocationMessageHandler.h"
22 #include "SourceLocationMessageTypes.h"
23 #include <SourceLocationBase.h>
24 #include "EffectDataQueItem.h"
29 // ================= MEMBER FUNCTIONS =======================
31 // C++ default constructor can NOT contain any code, that
34 CSourceLocationMessageHandler::CSourceLocationMessageHandler(
35 CSourceLocation* aSourceLocation )
36 : CMMFObject(KUidSourceLocationEffect),
37 iSourceLocation(NULL),
42 iSourceLocation = aSourceLocation;
46 EXPORT_C CSourceLocationMessageHandler* CSourceLocationMessageHandler::NewL(
47 TAny* aCustomInterface )
49 CSourceLocation* bassboost = (CSourceLocation*)aCustomInterface;
50 CSourceLocationMessageHandler* self = new (ELeave) CSourceLocationMessageHandler(bassboost);
56 // -----------------------------------------------------------------------------
57 // CSourceLocationMessageHandler::ConstructL
58 // Symbian 2nd phase constructor can leave.
59 // Create and initializes the effect data queue.
60 // -----------------------------------------------------------------------------
62 void CSourceLocationMessageHandler::ConstructL()
64 iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink));
68 // -----------------------------------------------------------------------------
69 // CSourceLocationMessageHandler::~CSourceLocationMessageHandler
70 // Before going away, unregister with the CI SourceLocation object.
71 // The observation message must be completed if outstanding.
72 // The effect data queue must be emptied and destroyed.
73 // -----------------------------------------------------------------------------
75 CSourceLocationMessageHandler::~CSourceLocationMessageHandler()
79 RDebug::Print(_L("CSourceLocationMessageHandler::~CSourceLocationMessageHandler"));
82 iSourceLocation->UnRegisterObserver(*this);
87 if ( !iMessage->IsCompleted() )
89 iMessage->Complete(KErrCancel);
96 CEffectDataQueItem* queItem;
97 while ( !iEffectDataQue->IsEmpty() )
99 queItem = iEffectDataQue->First();
100 iEffectDataQue->Remove(*queItem);
104 delete iEffectDataQue;
107 delete iSourceLocation;
112 // ---------------------------------------------------------
113 // CSourceLocationMessageHandler::HandleRequest
114 // (other items were commented in a header).
115 // ---------------------------------------------------------
117 void CSourceLocationMessageHandler::HandleRequest(
118 TMMFMessage& aMessage )
120 ASSERT(aMessage.Destination().InterfaceId() == KUidSourceLocationEffect);
121 TRAPD(error,DoHandleRequestL(aMessage));
124 aMessage.Complete(error);
128 // ---------------------------------------------------------
129 // CSourceLocationMessageHandler::DoHandleRequestL
130 // Dispatches the message to the appropriate handler.
131 // ---------------------------------------------------------
133 void CSourceLocationMessageHandler::DoHandleRequestL(
134 TMMFMessage& aMessage )
136 switch( aMessage.Function() )
138 case ESlfInitialize: // Request to initialize the bassboost
140 DoInitializeL(aMessage);
143 case ESlfApply: // Request to apply the bassboost settings
148 case ESlfObserve: // Observation request
150 DoObserveL(aMessage);
155 aMessage.Complete(KErrNotSupported);
160 // ---------------------------------------------------------
161 // CSourceLocationMessageHandler::DoInitializeL
162 // ---------------------------------------------------------
164 void CSourceLocationMessageHandler::DoInitializeL(TMMFMessage& aMessage)
166 aMessage.WriteDataToClient(iSourceLocation->DoEffectData());
167 aMessage.Complete(KErrNone);
170 // ---------------------------------------------------------
171 // CSourceLocationMessageHandler::DoApplyL
172 // Extracts the data from the message. The client bassboost data
173 // is applied to the CI bassboost object.
174 // ---------------------------------------------------------
176 void CSourceLocationMessageHandler::DoApplyL(
177 TMMFMessage& aMessage )
179 TEfLocationDataPckg locationPckgFromClient;
180 aMessage.ReadData1FromClient(locationPckgFromClient);
182 iSourceLocation->SetEffectData(locationPckgFromClient);
183 iSourceLocation->ApplyL();
184 aMessage.Complete(KErrNone);
187 // ---------------------------------------------------------
188 // CSourceLocationMessageHandler::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 // ---------------------------------------------------------
194 void CSourceLocationMessageHandler::DoObserveL(
195 TMMFMessage& aMessage )
199 RDebug::Print(_L("CSourceLocationMessageHandler::DoObserveL"));
202 if ( !iRegistered ) // Don't register again if we're registered.
204 iSourceLocation->RegisterObserverL(*this);
208 if ( iEffectDataQue->IsEmpty() )
210 // Message is saved and completed when an event occurs
211 iMessage = new(ELeave) TMMFMessage(aMessage);
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);
225 // ---------------------------------------------------------
226 // CSourceLocationMessageHandler::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 // ---------------------------------------------------------
233 void CSourceLocationMessageHandler::EffectChanged(
234 const CAudioEffect* aAudioEffect,
238 RDebug::Print(_L("CSourceLocationMessageHandler::EffectChanged"));
241 if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() )
243 iMessage->WriteDataToClient(((CSourceLocation*)aAudioEffect)->DoEffectData());
244 iMessage->Complete(KErrNone);
248 else // no message pending and there is no event queued up
250 // Saves the data and complete an observation message next time when
251 // there is a pending message.
253 TRAPD(err1,data = ((CSourceLocation*)aAudioEffect)->DoEffectData().AllocL());
256 //CleanupStack::PushL(data);
257 CEffectDataQueItem* item = NULL;
258 TRAPD(err2,item = CEffectDataQueItem::NewL(data));
261 iEffectDataQue->AddLast(*item);
271 RDebug::Print(_L("CSourceLocationMessageHandler::EffectChanged Error Allocating Memory %d"),err1);
278 // ========================== OTHER EXPORTED FUNCTIONS =========================