os/mm/devsoundextensions/effects/SrcDoppler/SourceDopplerProxy/Src/SourceDopplerProxy.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsoundextensions/effects/SrcDoppler/SourceDopplerProxy/Src/SourceDopplerProxy.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,247 @@
     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 Source Doppler Proxy class
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +
    1.24 +// INCLUDE FILES
    1.25 +
    1.26 +#ifdef _DEBUG
    1.27 +#include <e32svr.h>
    1.28 +#endif
    1.29 +
    1.30 +#include "SourceDopplerProxy.h"
    1.31 +#include "SourceDopplerEventObserver.h"
    1.32 +#include <CustomInterfaceUtility.h>
    1.33 +
    1.34 +
    1.35 +// ============================ MEMBER FUNCTIONS ===============================
    1.36 +
    1.37 +// -----------------------------------------------------------------------------
    1.38 +// CSourceDopplerProxy::CSourceDopplerProxy
    1.39 +// C++ default constructor can NOT contain any code, that
    1.40 +// might leave.
    1.41 +// -----------------------------------------------------------------------------
    1.42 +//
    1.43 +CSourceDopplerProxy::CSourceDopplerProxy(
    1.44 +	TMMFMessageDestinationPckg aMessageHandler,
    1.45 +	MCustomCommand& aCustomCommand,
    1.46 +	CCustomInterfaceUtility* aCustomInterfaceUtility )
    1.47 +	: 	iCustomCommand(&aCustomCommand),
    1.48 +		iMessageHandler(aMessageHandler),
    1.49 +		iCustomInterfaceUtility(aCustomInterfaceUtility)
    1.50 +
    1.51 +    {
    1.52 +    }
    1.53 +
    1.54 +// Destructor
    1.55 +CSourceDopplerProxy::~CSourceDopplerProxy()
    1.56 +    {
    1.57 +    // Remove the custom interface message handler before we destroy the proxy.
    1.58 +    if(iCustomInterfaceUtility)
    1.59 +        iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
    1.60 +	delete iDopplerEventObserver;
    1.61 +	delete iCustomInterfaceUtility;
    1.62 +	}
    1.63 +
    1.64 +// -----------------------------------------------------------------------------
    1.65 +// CSourceDopplerProxy::NewL
    1.66 +// Static function for creating an instance of the SourceDoppler object.
    1.67 +// -----------------------------------------------------------------------------
    1.68 +//
    1.69 +EXPORT_C CSourceDopplerProxy* CSourceDopplerProxy::NewL(
    1.70 +	TMMFMessageDestinationPckg aMessageHandler,
    1.71 +    MCustomCommand& aCustomCommand,
    1.72 +    CCustomInterfaceUtility* aCustomInterfaceUtility )
    1.73 +    {
    1.74 +    CSourceDopplerProxy* self = new (ELeave) CSourceDopplerProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility);
    1.75 +    CleanupStack::PushL(self);
    1.76 +    self->ConstructL();
    1.77 +    CleanupStack::Pop(self);
    1.78 +    return self;
    1.79 +	}
    1.80 +
    1.81 +// -----------------------------------------------------------------------------
    1.82 +// CSourceDopplerProxy::ConstructL
    1.83 +// -----------------------------------------------------------------------------
    1.84 +//
    1.85 +void CSourceDopplerProxy::ConstructL()
    1.86 +    {
    1.87 +    iDopplerEventObserver = CSourceDopplerEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
    1.88 +    StartObserver();
    1.89 +
    1.90 +    TEfDopplerDataPckg dataPckgFrom;
    1.91 +    // sends a message to fetch initial data.
    1.92 +	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ESourceDopplerOfInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
    1.93 +	SetEffectData(dataPckgFrom);
    1.94 +	}
    1.95 +
    1.96 +
    1.97 +// -----------------------------------------------------------------------------
    1.98 +// CSourceDopplerProxy::ApplyL
    1.99 +// Apply the SourceDoppler settings.
   1.100 +// -----------------------------------------------------------------------------
   1.101 +//
   1.102 +EXPORT_C void CSourceDopplerProxy::ApplyL()
   1.103 +	{
   1.104 +#ifdef _DEBUG
   1.105 +    RDebug::Print(_L("CSourceDopplerProxy::Apply"));
   1.106 +#endif
   1.107 +
   1.108 +	if (iHaveUpdateRights )
   1.109 +		{
   1.110 +		iDopplerData.iEnabled = iEnabled;
   1.111 +		iDopplerData.iEnforced = iEnforced;
   1.112 +		iDopplerData.iHaveUpdateRights = iHaveUpdateRights;
   1.113 +
   1.114 +		iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ESourceDopplerOfApply, DoEffectData(), KNullDesC8);
   1.115 +		}
   1.116 +	else
   1.117 +		{
   1.118 +		User::Leave(KErrAccessDenied);
   1.119 +		}
   1.120 +	}
   1.121 +
   1.122 +// -----------------------------------------------------------------------------
   1.123 +// CSourceDopplerProxy::StartObserver
   1.124 +// Starts the event observer. The event observer monitors asynchronous events
   1.125 +// from the message handler.
   1.126 +// -----------------------------------------------------------------------------
   1.127 +//
   1.128 +void CSourceDopplerProxy::StartObserver()
   1.129 +	{
   1.130 +#ifdef _DEBUG
   1.131 +    RDebug::Print(_L("CSourceDopplerProxy::StartObserver"));
   1.132 +#endif
   1.133 +
   1.134 +	iDopplerEventObserver->Start();
   1.135 +	}
   1.136 +
   1.137 +// -----------------------------------------------------------------------------
   1.138 +// CSourceDopplerProxy::DopplerEvent
   1.139 +// Checks which data member has changed and notify the observers.
   1.140 +// -----------------------------------------------------------------------------
   1.141 +//
   1.142 +void CSourceDopplerProxy::SourceDopplerEvent(
   1.143 +	const TDesC8& aBuffer )
   1.144 +	{
   1.145 +#ifdef _DEBUG
   1.146 +    RDebug::Print(_L("CSourceDopplerProxy::SourceDopplerEvent"));
   1.147 +#endif
   1.148 +
   1.149 +	TEfDopplerDataPckg dataPckgFrom;
   1.150 +	dataPckgFrom.Copy(aBuffer);
   1.151 +	TEfDoppler newDopplerData = dataPckgFrom();
   1.152 +
   1.153 +	TUint8 event = 0;
   1.154 +
   1.155 +	if ( newDopplerData.iEnabled != iDopplerData.iEnabled )
   1.156 +		{
   1.157 +		iDopplerData.iEnabled = newDopplerData.iEnabled;
   1.158 +		iEnabled = newDopplerData.iEnabled;
   1.159 +		if ( iDopplerData.iEnabled )
   1.160 +			{
   1.161 +			event = MAudioEffectObserver::KEnabled;
   1.162 +			}
   1.163 +		else
   1.164 +			{
   1.165 +			event = MAudioEffectObserver::KDisabled;
   1.166 +			}
   1.167 +		}
   1.168 +	else if ( newDopplerData.iEnforced != iDopplerData.iEnforced )
   1.169 +		{
   1.170 +		iDopplerData.iEnforced = newDopplerData.iEnforced;
   1.171 +		iEnforced = newDopplerData.iEnforced;
   1.172 +		if ( iDopplerData.iEnforced )
   1.173 +			{
   1.174 +			event = MAudioEffectObserver::KEnforced;
   1.175 +			}
   1.176 +		else
   1.177 +			{
   1.178 +			event = MAudioEffectObserver::KNotEnforced;
   1.179 +			}
   1.180 +		}
   1.181 +	else if ( newDopplerData.iHaveUpdateRights != iDopplerData.iHaveUpdateRights )
   1.182 +		{
   1.183 +		iDopplerData.iHaveUpdateRights = newDopplerData.iHaveUpdateRights;
   1.184 +		iHaveUpdateRights = newDopplerData.iHaveUpdateRights;
   1.185 +		if ( iDopplerData.iHaveUpdateRights )
   1.186 +			{
   1.187 +			event = MAudioEffectObserver::KGainedUpdateRights;
   1.188 +			}
   1.189 +		else
   1.190 +			{
   1.191 +			event = MAudioEffectObserver::KLostUpdateRights;
   1.192 +			}
   1.193 +		}
   1.194 +
   1.195 +		else if ( newDopplerData.iVelocityX != iDopplerData.iVelocityX )
   1.196 +			{
   1.197 +			iDopplerData.iVelocityX = newDopplerData.iVelocityX;
   1.198 +			event = MSourceDopplerObserver::KCartesianVelocityChanged;
   1.199 +			}
   1.200 +		else if ( newDopplerData.iVelocityY != iDopplerData.iVelocityY )
   1.201 +			{
   1.202 +			iDopplerData.iVelocityY = newDopplerData.iVelocityY;
   1.203 +			event = MSourceDopplerObserver::KCartesianVelocityChanged;
   1.204 +			}
   1.205 +		else if ( newDopplerData.iVelocityZ != iDopplerData.iVelocityZ )
   1.206 +			{
   1.207 +			iDopplerData.iVelocityZ = newDopplerData.iVelocityZ;
   1.208 +			event = MSourceDopplerObserver::KCartesianVelocityChanged;
   1.209 +			}
   1.210 +		else if ( newDopplerData.iAzimuth != iDopplerData.iAzimuth )
   1.211 +			{
   1.212 +			iDopplerData.iAzimuth = newDopplerData.iAzimuth;
   1.213 +			event = MSourceDopplerObserver::KSphericalVelocityChanged;
   1.214 +			}
   1.215 +		else if ( newDopplerData.iElevation != iDopplerData.iElevation )
   1.216 +			{
   1.217 +			iDopplerData.iElevation = newDopplerData.iElevation;
   1.218 +			event = MSourceDopplerObserver::KSphericalVelocityChanged;
   1.219 +			}
   1.220 +		else if ( newDopplerData.iRadius != iDopplerData.iRadius )
   1.221 +			{
   1.222 +			iDopplerData.iRadius = newDopplerData.iRadius;
   1.223 +			event = MSourceDopplerObserver::KSphericalVelocityChanged;
   1.224 +			}
   1.225 +		else if ( newDopplerData.iFactor != iDopplerData.iFactor )
   1.226 +			{
   1.227 +			iDopplerData.iFactor = newDopplerData.iFactor;
   1.228 +			event = MSourceDopplerObserver::KFactorChanged;
   1.229 +			}
   1.230 +		else if ( newDopplerData.iMaxFactor != iDopplerData.iMaxFactor )
   1.231 +			{
   1.232 +			iDopplerData.iMaxFactor = newDopplerData.iMaxFactor;
   1.233 +			event = MSourceDopplerObserver::KMaxFactorChanged;
   1.234 +			}
   1.235 +
   1.236 +
   1.237 +	if (!event)
   1.238 +		return;
   1.239 +
   1.240 +	for ( TInt i = 0; i < iObservers.Count(); i++ )
   1.241 +		{
   1.242 +		iObservers[i]->EffectChanged(this, event);
   1.243 +		}
   1.244 +	}
   1.245 +
   1.246 +
   1.247 +// ========================== OTHER EXPORTED FUNCTIONS =========================
   1.248 +
   1.249 +// End of File
   1.250 +