os/mm/devsoundextensions/effects/SrcDoppler/SourceDopplerProxy/Src/SourceDopplerProxy.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:   Implementation of the Source Doppler Proxy class
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 // INCLUDE FILES
    22 
    23 #ifdef _DEBUG
    24 #include <e32svr.h>
    25 #endif
    26 
    27 #include "SourceDopplerProxy.h"
    28 #include "SourceDopplerEventObserver.h"
    29 #include <CustomInterfaceUtility.h>
    30 
    31 
    32 // ============================ MEMBER FUNCTIONS ===============================
    33 
    34 // -----------------------------------------------------------------------------
    35 // CSourceDopplerProxy::CSourceDopplerProxy
    36 // C++ default constructor can NOT contain any code, that
    37 // might leave.
    38 // -----------------------------------------------------------------------------
    39 //
    40 CSourceDopplerProxy::CSourceDopplerProxy(
    41 	TMMFMessageDestinationPckg aMessageHandler,
    42 	MCustomCommand& aCustomCommand,
    43 	CCustomInterfaceUtility* aCustomInterfaceUtility )
    44 	: 	iCustomCommand(&aCustomCommand),
    45 		iMessageHandler(aMessageHandler),
    46 		iCustomInterfaceUtility(aCustomInterfaceUtility)
    47 
    48     {
    49     }
    50 
    51 // Destructor
    52 CSourceDopplerProxy::~CSourceDopplerProxy()
    53     {
    54     // Remove the custom interface message handler before we destroy the proxy.
    55     if(iCustomInterfaceUtility)
    56         iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
    57 	delete iDopplerEventObserver;
    58 	delete iCustomInterfaceUtility;
    59 	}
    60 
    61 // -----------------------------------------------------------------------------
    62 // CSourceDopplerProxy::NewL
    63 // Static function for creating an instance of the SourceDoppler object.
    64 // -----------------------------------------------------------------------------
    65 //
    66 EXPORT_C CSourceDopplerProxy* CSourceDopplerProxy::NewL(
    67 	TMMFMessageDestinationPckg aMessageHandler,
    68     MCustomCommand& aCustomCommand,
    69     CCustomInterfaceUtility* aCustomInterfaceUtility )
    70     {
    71     CSourceDopplerProxy* self = new (ELeave) CSourceDopplerProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility);
    72     CleanupStack::PushL(self);
    73     self->ConstructL();
    74     CleanupStack::Pop(self);
    75     return self;
    76 	}
    77 
    78 // -----------------------------------------------------------------------------
    79 // CSourceDopplerProxy::ConstructL
    80 // -----------------------------------------------------------------------------
    81 //
    82 void CSourceDopplerProxy::ConstructL()
    83     {
    84     iDopplerEventObserver = CSourceDopplerEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
    85     StartObserver();
    86 
    87     TEfDopplerDataPckg dataPckgFrom;
    88     // sends a message to fetch initial data.
    89 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ESourceDopplerOfInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
    90 	SetEffectData(dataPckgFrom);
    91 	}
    92 
    93 
    94 // -----------------------------------------------------------------------------
    95 // CSourceDopplerProxy::ApplyL
    96 // Apply the SourceDoppler settings.
    97 // -----------------------------------------------------------------------------
    98 //
    99 EXPORT_C void CSourceDopplerProxy::ApplyL()
   100 	{
   101 #ifdef _DEBUG
   102     RDebug::Print(_L("CSourceDopplerProxy::Apply"));
   103 #endif
   104 
   105 	if (iHaveUpdateRights )
   106 		{
   107 		iDopplerData.iEnabled = iEnabled;
   108 		iDopplerData.iEnforced = iEnforced;
   109 		iDopplerData.iHaveUpdateRights = iHaveUpdateRights;
   110 
   111 		iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ESourceDopplerOfApply, DoEffectData(), KNullDesC8);
   112 		}
   113 	else
   114 		{
   115 		User::Leave(KErrAccessDenied);
   116 		}
   117 	}
   118 
   119 // -----------------------------------------------------------------------------
   120 // CSourceDopplerProxy::StartObserver
   121 // Starts the event observer. The event observer monitors asynchronous events
   122 // from the message handler.
   123 // -----------------------------------------------------------------------------
   124 //
   125 void CSourceDopplerProxy::StartObserver()
   126 	{
   127 #ifdef _DEBUG
   128     RDebug::Print(_L("CSourceDopplerProxy::StartObserver"));
   129 #endif
   130 
   131 	iDopplerEventObserver->Start();
   132 	}
   133 
   134 // -----------------------------------------------------------------------------
   135 // CSourceDopplerProxy::DopplerEvent
   136 // Checks which data member has changed and notify the observers.
   137 // -----------------------------------------------------------------------------
   138 //
   139 void CSourceDopplerProxy::SourceDopplerEvent(
   140 	const TDesC8& aBuffer )
   141 	{
   142 #ifdef _DEBUG
   143     RDebug::Print(_L("CSourceDopplerProxy::SourceDopplerEvent"));
   144 #endif
   145 
   146 	TEfDopplerDataPckg dataPckgFrom;
   147 	dataPckgFrom.Copy(aBuffer);
   148 	TEfDoppler newDopplerData = dataPckgFrom();
   149 
   150 	TUint8 event = 0;
   151 
   152 	if ( newDopplerData.iEnabled != iDopplerData.iEnabled )
   153 		{
   154 		iDopplerData.iEnabled = newDopplerData.iEnabled;
   155 		iEnabled = newDopplerData.iEnabled;
   156 		if ( iDopplerData.iEnabled )
   157 			{
   158 			event = MAudioEffectObserver::KEnabled;
   159 			}
   160 		else
   161 			{
   162 			event = MAudioEffectObserver::KDisabled;
   163 			}
   164 		}
   165 	else if ( newDopplerData.iEnforced != iDopplerData.iEnforced )
   166 		{
   167 		iDopplerData.iEnforced = newDopplerData.iEnforced;
   168 		iEnforced = newDopplerData.iEnforced;
   169 		if ( iDopplerData.iEnforced )
   170 			{
   171 			event = MAudioEffectObserver::KEnforced;
   172 			}
   173 		else
   174 			{
   175 			event = MAudioEffectObserver::KNotEnforced;
   176 			}
   177 		}
   178 	else if ( newDopplerData.iHaveUpdateRights != iDopplerData.iHaveUpdateRights )
   179 		{
   180 		iDopplerData.iHaveUpdateRights = newDopplerData.iHaveUpdateRights;
   181 		iHaveUpdateRights = newDopplerData.iHaveUpdateRights;
   182 		if ( iDopplerData.iHaveUpdateRights )
   183 			{
   184 			event = MAudioEffectObserver::KGainedUpdateRights;
   185 			}
   186 		else
   187 			{
   188 			event = MAudioEffectObserver::KLostUpdateRights;
   189 			}
   190 		}
   191 
   192 		else if ( newDopplerData.iVelocityX != iDopplerData.iVelocityX )
   193 			{
   194 			iDopplerData.iVelocityX = newDopplerData.iVelocityX;
   195 			event = MSourceDopplerObserver::KCartesianVelocityChanged;
   196 			}
   197 		else if ( newDopplerData.iVelocityY != iDopplerData.iVelocityY )
   198 			{
   199 			iDopplerData.iVelocityY = newDopplerData.iVelocityY;
   200 			event = MSourceDopplerObserver::KCartesianVelocityChanged;
   201 			}
   202 		else if ( newDopplerData.iVelocityZ != iDopplerData.iVelocityZ )
   203 			{
   204 			iDopplerData.iVelocityZ = newDopplerData.iVelocityZ;
   205 			event = MSourceDopplerObserver::KCartesianVelocityChanged;
   206 			}
   207 		else if ( newDopplerData.iAzimuth != iDopplerData.iAzimuth )
   208 			{
   209 			iDopplerData.iAzimuth = newDopplerData.iAzimuth;
   210 			event = MSourceDopplerObserver::KSphericalVelocityChanged;
   211 			}
   212 		else if ( newDopplerData.iElevation != iDopplerData.iElevation )
   213 			{
   214 			iDopplerData.iElevation = newDopplerData.iElevation;
   215 			event = MSourceDopplerObserver::KSphericalVelocityChanged;
   216 			}
   217 		else if ( newDopplerData.iRadius != iDopplerData.iRadius )
   218 			{
   219 			iDopplerData.iRadius = newDopplerData.iRadius;
   220 			event = MSourceDopplerObserver::KSphericalVelocityChanged;
   221 			}
   222 		else if ( newDopplerData.iFactor != iDopplerData.iFactor )
   223 			{
   224 			iDopplerData.iFactor = newDopplerData.iFactor;
   225 			event = MSourceDopplerObserver::KFactorChanged;
   226 			}
   227 		else if ( newDopplerData.iMaxFactor != iDopplerData.iMaxFactor )
   228 			{
   229 			iDopplerData.iMaxFactor = newDopplerData.iMaxFactor;
   230 			event = MSourceDopplerObserver::KMaxFactorChanged;
   231 			}
   232 
   233 
   234 	if (!event)
   235 		return;
   236 
   237 	for ( TInt i = 0; i < iObservers.Count(); i++ )
   238 		{
   239 		iObservers[i]->EffectChanged(this, event);
   240 		}
   241 	}
   242 
   243 
   244 // ========================== OTHER EXPORTED FUNCTIONS =========================
   245 
   246 // End of File
   247