os/mm/devsoundextensions/effects/SrcOrientation/SourceOrientationMessageHandler/src/SourceOrientationMessageHandler.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsoundextensions/effects/SrcOrientation/SourceOrientationMessageHandler/src/SourceOrientationMessageHandler.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,282 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:   Implementation of the bassboost effect message handler class.
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +// INCLUDE FILES
    1.24 +#include "SourceOrientationMessageHandler.h"
    1.25 +#include "SourceOrientationMessageTypes.h"
    1.26 +#include <SourceOrientationBase.h>
    1.27 +#include "EffectDataQueItem.h"
    1.28 +#ifdef _DEBUG
    1.29 +#include <e32svr.h>
    1.30 +#endif
    1.31 +
    1.32 +// ================= MEMBER FUNCTIONS =======================
    1.33 +
    1.34 +// C++ default constructor can NOT contain any code, that
    1.35 +// might leave.
    1.36 +//
    1.37 +CSourceOrientationMessageHandler::CSourceOrientationMessageHandler(
    1.38 +	CSourceOrientation* aSourceOrientation )
    1.39 +    :	CMMFObject(KUidSourceOrientationEffect),
    1.40 +    	iSourceOrientation(NULL),
    1.41 +    	iMessage(NULL),
    1.42 +    	iRegistered(EFalse),
    1.43 +    	iEffectDataQue(NULL)
    1.44 +    {
    1.45 +    iSourceOrientation = aSourceOrientation;
    1.46 +    }
    1.47 +
    1.48 +
    1.49 +EXPORT_C CSourceOrientationMessageHandler* CSourceOrientationMessageHandler::NewL(
    1.50 +	TAny* aCustomInterface )
    1.51 +    {
    1.52 +    CSourceOrientation* bassboost = (CSourceOrientation*)aCustomInterface;
    1.53 +    CSourceOrientationMessageHandler* self = new (ELeave) CSourceOrientationMessageHandler(bassboost);
    1.54 +	self->ConstructL();
    1.55 +    return self;
    1.56 +    }
    1.57 +
    1.58 +
    1.59 +// -----------------------------------------------------------------------------
    1.60 +// CSourceOrientationMessageHandler::ConstructL
    1.61 +// Symbian 2nd phase constructor can leave.
    1.62 +// Create and initializes the effect data queue.
    1.63 +// -----------------------------------------------------------------------------
    1.64 +//
    1.65 +void CSourceOrientationMessageHandler::ConstructL()
    1.66 +	{
    1.67 +	iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink));
    1.68 +	}
    1.69 +
    1.70 +
    1.71 +// -----------------------------------------------------------------------------
    1.72 +// CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler
    1.73 +// Before going away, unregister with the CI SourceOrientation object.
    1.74 +// The observation message must be completed if outstanding.
    1.75 +// The effect data queue must be emptied and destroyed.
    1.76 +// -----------------------------------------------------------------------------
    1.77 +//
    1.78 +CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler()
    1.79 +	{
    1.80 +
    1.81 +#ifdef _DEBUG
    1.82 +    RDebug::Print(_L("CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler"));
    1.83 +#endif
    1.84 +    if(iSourceOrientation)
    1.85 +	    iSourceOrientation->UnRegisterObserver(*this);
    1.86 +	iRegistered = EFalse;
    1.87 +
    1.88 +	if(iMessage)
    1.89 +		{
    1.90 +			if ( !iMessage->IsCompleted() )
    1.91 +				{
    1.92 +				iMessage->Complete(KErrCancel);
    1.93 +				delete iMessage;
    1.94 +				}
    1.95 +		}
    1.96 +
    1.97 +    if ( iEffectDataQue )
    1.98 +        {
    1.99 +        CEffectDataQueItem* queItem;
   1.100 +        while ( !iEffectDataQue->IsEmpty() )
   1.101 +            {
   1.102 +            queItem = iEffectDataQue->First();
   1.103 +            iEffectDataQue->Remove(*queItem);
   1.104 +            delete queItem;
   1.105 +            }
   1.106 +
   1.107 +        delete iEffectDataQue;
   1.108 +        }
   1.109 +
   1.110 +     delete iSourceOrientation;
   1.111 +
   1.112 +	}
   1.113 +
   1.114 +
   1.115 +// ---------------------------------------------------------
   1.116 +// CSourceOrientationMessageHandler::HandleRequest
   1.117 +// (other items were commented in a header).
   1.118 +// ---------------------------------------------------------
   1.119 +//
   1.120 +void CSourceOrientationMessageHandler::HandleRequest(
   1.121 +	TMMFMessage& aMessage )
   1.122 +	{
   1.123 +	ASSERT(aMessage.Destination().InterfaceId() == KUidSourceOrientationEffect);
   1.124 +	TRAPD(error,DoHandleRequestL(aMessage));
   1.125 +	if ( error )
   1.126 +		{
   1.127 +		aMessage.Complete(error);
   1.128 +		}
   1.129 +	}
   1.130 +
   1.131 +// ---------------------------------------------------------
   1.132 +// CSourceOrientationMessageHandler::DoHandleRequestL
   1.133 +// Dispatches the message to the appropriate handler.
   1.134 +// ---------------------------------------------------------
   1.135 +//
   1.136 +void CSourceOrientationMessageHandler::DoHandleRequestL(
   1.137 +	TMMFMessage& aMessage )
   1.138 +	{
   1.139 +	switch( aMessage.Function() )
   1.140 +		{
   1.141 +		case ESofInitialize: // Request to initialize the bassboost
   1.142 +			{
   1.143 +			DoInitializeL(aMessage);
   1.144 +			break;
   1.145 +			}
   1.146 +		case ESofApply: // Request to apply the bassboost settings
   1.147 +			{
   1.148 +			DoApplyL(aMessage);
   1.149 +			break;
   1.150 +			}
   1.151 +		case ESofObserve: // Observation request
   1.152 +			{
   1.153 +			DoObserveL(aMessage);
   1.154 +			break;
   1.155 +			}
   1.156 +		default:
   1.157 +			{
   1.158 +			aMessage.Complete(KErrNotSupported);
   1.159 +			}
   1.160 +		}
   1.161 +	}
   1.162 +
   1.163 +// ---------------------------------------------------------
   1.164 +// CSourceOrientationMessageHandler::DoInitializeL
   1.165 +// ---------------------------------------------------------
   1.166 +//
   1.167 +void CSourceOrientationMessageHandler::DoInitializeL(TMMFMessage& aMessage)
   1.168 +	{
   1.169 +	aMessage.WriteDataToClient(iSourceOrientation->DoEffectData());
   1.170 +	aMessage.Complete(KErrNone);
   1.171 +	}
   1.172 +
   1.173 +// ---------------------------------------------------------
   1.174 +// CSourceOrientationMessageHandler::DoApplyL
   1.175 +// Extracts the data from the message. The client bassboost data
   1.176 +// is applied to the CI bassboost object.
   1.177 +// ---------------------------------------------------------
   1.178 +//
   1.179 +void CSourceOrientationMessageHandler::DoApplyL(
   1.180 +	TMMFMessage& aMessage )
   1.181 +	{
   1.182 +    TEfOrientationDataPckg orientationPckgFromClient;
   1.183 +    aMessage.ReadData1FromClient(orientationPckgFromClient);
   1.184 +
   1.185 +	iSourceOrientation->SetEffectData(orientationPckgFromClient);
   1.186 +	iSourceOrientation->ApplyL();
   1.187 +	aMessage.Complete(KErrNone);
   1.188 +	}
   1.189 +
   1.190 +// ---------------------------------------------------------
   1.191 +// CSourceOrientationMessageHandler::DoObserveL
   1.192 +// Receives the observation request message and depending
   1.193 +// on the status of the effect data queue, the message is
   1.194 +// completed immediately or saved for later completion.
   1.195 +// ---------------------------------------------------------
   1.196 +//
   1.197 +void CSourceOrientationMessageHandler::DoObserveL(
   1.198 +	TMMFMessage& aMessage )
   1.199 +	{
   1.200 +
   1.201 +#ifdef _DEBUG
   1.202 +    RDebug::Print(_L("CSourceOrientationMessageHandler::DoObserveL"));
   1.203 +#endif
   1.204 +
   1.205 +	if ( !iRegistered ) // Don't register again if we're registered.
   1.206 +		{
   1.207 +		iSourceOrientation->RegisterObserverL(*this);
   1.208 +		iRegistered = ETrue;
   1.209 +		}
   1.210 +
   1.211 +	if ( iEffectDataQue->IsEmpty() )
   1.212 +		{
   1.213 +		// Message is saved and completed when an event occurs
   1.214 +		iMessage = new(ELeave) TMMFMessage(aMessage);
   1.215 +		}
   1.216 +	else
   1.217 +		{
   1.218 +		TEfOrientationDataPckg dataPckg;
   1.219 +		CEffectDataQueItem* item = iEffectDataQue->First();
   1.220 +		dataPckg.Copy(item->EffectData());
   1.221 +		aMessage.WriteDataToClient(dataPckg);
   1.222 +		aMessage.Complete(KErrNone);
   1.223 +		iEffectDataQue->Remove(*item);
   1.224 +		delete item;
   1.225 +		}
   1.226 +	}
   1.227 +
   1.228 +// ---------------------------------------------------------
   1.229 +// CSourceOrientationMessageHandler::EffectChanged
   1.230 +// The CI bassboost object has changed state.
   1.231 +// The observation message is completed if no data has been
   1.232 +// queued up. Otherwise, the CI bassboost object's data is
   1.233 +// packaged and queued.
   1.234 +// ---------------------------------------------------------
   1.235 +//
   1.236 +void CSourceOrientationMessageHandler::EffectChanged(
   1.237 +	const CAudioEffect* aAudioEffect,
   1.238 +	 TUint8 /*aEvent*/ )
   1.239 +	{
   1.240 +#ifdef _DEBUG
   1.241 +    RDebug::Print(_L("CSourceOrientationMessageHandler::EffectChanged"));
   1.242 +#endif
   1.243 +
   1.244 +	if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() )
   1.245 +		{
   1.246 +		iMessage->WriteDataToClient(((CSourceOrientation*)aAudioEffect)->DoEffectData());
   1.247 +		iMessage->Complete(KErrNone);
   1.248 +		delete iMessage;
   1.249 +		iMessage = NULL;
   1.250 +		}
   1.251 +	else // no message pending and there is no event queued up
   1.252 +		{
   1.253 +		// Saves the data and complete an observation message next time when
   1.254 +		// there is a pending message.
   1.255 +		HBufC8* data = NULL;
   1.256 +		TRAPD(err1,data = ((CSourceOrientation*)aAudioEffect)->DoEffectData().AllocL());
   1.257 +		if(!err1)
   1.258 +			{
   1.259 +				//CleanupStack::PushL(data);
   1.260 +				CEffectDataQueItem* item = NULL;
   1.261 +				TRAPD(err2,item = CEffectDataQueItem::NewL(data));
   1.262 +				if(!err2)
   1.263 +				{
   1.264 +					iEffectDataQue->AddLast(*item);
   1.265 +				}
   1.266 +				else
   1.267 +				{
   1.268 +					delete data;
   1.269 +				}
   1.270 +			}
   1.271 +		else
   1.272 +			{
   1.273 +#ifdef _DEBUG
   1.274 +				RDebug::Print(_L("CSourceOrientationMessageHandler::EffectChanged Error Allocating Memory %d"),err1);
   1.275 +#endif
   1.276 +			}
   1.277 +		}
   1.278 +	}
   1.279 +
   1.280 +
   1.281 +// ========================== OTHER EXPORTED FUNCTIONS =========================
   1.282 +
   1.283 +
   1.284 +
   1.285 +// End of File