os/mm/devsoundextensions/effects/SrcOrientation/SourceOrientationMessageHandler/src/SourceOrientationMessageHandler.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 "SourceOrientationMessageHandler.h"
22 #include "SourceOrientationMessageTypes.h"
23 #include <SourceOrientationBase.h>
24 #include "EffectDataQueItem.h"
29 // ================= MEMBER FUNCTIONS =======================
31 // C++ default constructor can NOT contain any code, that
34 CSourceOrientationMessageHandler::CSourceOrientationMessageHandler(
35 CSourceOrientation* aSourceOrientation )
36 : CMMFObject(KUidSourceOrientationEffect),
37 iSourceOrientation(NULL),
42 iSourceOrientation = aSourceOrientation;
46 EXPORT_C CSourceOrientationMessageHandler* CSourceOrientationMessageHandler::NewL(
47 TAny* aCustomInterface )
49 CSourceOrientation* bassboost = (CSourceOrientation*)aCustomInterface;
50 CSourceOrientationMessageHandler* self = new (ELeave) CSourceOrientationMessageHandler(bassboost);
56 // -----------------------------------------------------------------------------
57 // CSourceOrientationMessageHandler::ConstructL
58 // Symbian 2nd phase constructor can leave.
59 // Create and initializes the effect data queue.
60 // -----------------------------------------------------------------------------
62 void CSourceOrientationMessageHandler::ConstructL()
64 iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink));
68 // -----------------------------------------------------------------------------
69 // CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler
70 // Before going away, unregister with the CI SourceOrientation object.
71 // The observation message must be completed if outstanding.
72 // The effect data queue must be emptied and destroyed.
73 // -----------------------------------------------------------------------------
75 CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler()
79 RDebug::Print(_L("CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler"));
81 if(iSourceOrientation)
82 iSourceOrientation->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 iSourceOrientation;
112 // ---------------------------------------------------------
113 // CSourceOrientationMessageHandler::HandleRequest
114 // (other items were commented in a header).
115 // ---------------------------------------------------------
117 void CSourceOrientationMessageHandler::HandleRequest(
118 TMMFMessage& aMessage )
120 ASSERT(aMessage.Destination().InterfaceId() == KUidSourceOrientationEffect);
121 TRAPD(error,DoHandleRequestL(aMessage));
124 aMessage.Complete(error);
128 // ---------------------------------------------------------
129 // CSourceOrientationMessageHandler::DoHandleRequestL
130 // Dispatches the message to the appropriate handler.
131 // ---------------------------------------------------------
133 void CSourceOrientationMessageHandler::DoHandleRequestL(
134 TMMFMessage& aMessage )
136 switch( aMessage.Function() )
138 case ESofInitialize: // Request to initialize the bassboost
140 DoInitializeL(aMessage);
143 case ESofApply: // Request to apply the bassboost settings
148 case ESofObserve: // Observation request
150 DoObserveL(aMessage);
155 aMessage.Complete(KErrNotSupported);
160 // ---------------------------------------------------------
161 // CSourceOrientationMessageHandler::DoInitializeL
162 // ---------------------------------------------------------
164 void CSourceOrientationMessageHandler::DoInitializeL(TMMFMessage& aMessage)
166 aMessage.WriteDataToClient(iSourceOrientation->DoEffectData());
167 aMessage.Complete(KErrNone);
170 // ---------------------------------------------------------
171 // CSourceOrientationMessageHandler::DoApplyL
172 // Extracts the data from the message. The client bassboost data
173 // is applied to the CI bassboost object.
174 // ---------------------------------------------------------
176 void CSourceOrientationMessageHandler::DoApplyL(
177 TMMFMessage& aMessage )
179 TEfOrientationDataPckg orientationPckgFromClient;
180 aMessage.ReadData1FromClient(orientationPckgFromClient);
182 iSourceOrientation->SetEffectData(orientationPckgFromClient);
183 iSourceOrientation->ApplyL();
184 aMessage.Complete(KErrNone);
187 // ---------------------------------------------------------
188 // CSourceOrientationMessageHandler::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 CSourceOrientationMessageHandler::DoObserveL(
195 TMMFMessage& aMessage )
199 RDebug::Print(_L("CSourceOrientationMessageHandler::DoObserveL"));
202 if ( !iRegistered ) // Don't register again if we're registered.
204 iSourceOrientation->RegisterObserverL(*this);
208 if ( iEffectDataQue->IsEmpty() )
210 // Message is saved and completed when an event occurs
211 iMessage = new(ELeave) TMMFMessage(aMessage);
215 TEfOrientationDataPckg 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 // CSourceOrientationMessageHandler::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 CSourceOrientationMessageHandler::EffectChanged(
234 const CAudioEffect* aAudioEffect,
238 RDebug::Print(_L("CSourceOrientationMessageHandler::EffectChanged"));
241 if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() )
243 iMessage->WriteDataToClient(((CSourceOrientation*)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 = ((CSourceOrientation*)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("CSourceOrientationMessageHandler::EffectChanged Error Allocating Memory %d"),err1);
278 // ========================== OTHER EXPORTED FUNCTIONS =========================