os/mm/devsoundextensions/effects/SrcOrientation/SourceOrientationProxy/Src/SourceOrientationProxy.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 bassboost proxy class
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 // INCLUDE FILES
    22 
    23 #ifdef _DEBUG
    24 #include <e32svr.h>
    25 #endif
    26 
    27 #include "SourceOrientationProxy.h"
    28 #include "SourceOrientationEventObserver.h"
    29 #include <CustomInterfaceUtility.h>
    30 
    31 
    32 // ============================ MEMBER FUNCTIONS ===============================
    33 
    34 // -----------------------------------------------------------------------------
    35 // CSourceOrientationProxy::CSourceOrientationProxy
    36 // C++ default constructor can NOT contain any code, that
    37 // might leave.
    38 // -----------------------------------------------------------------------------
    39 //
    40 CSourceOrientationProxy::CSourceOrientationProxy(
    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 CSourceOrientationProxy::~CSourceOrientationProxy()
    53     {
    54     // Remove the custom interface message handler before we destroy the proxy.
    55     if(iCustomInterfaceUtility)
    56         iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
    57 	delete iSourceOrientationEventObserver;
    58 	delete iCustomInterfaceUtility;
    59 	}
    60 
    61 // -----------------------------------------------------------------------------
    62 // CSourceOrientationProxy::NewL
    63 // Static function for creating an instance of the SourceOrientation object.
    64 // -----------------------------------------------------------------------------
    65 //
    66 EXPORT_C CSourceOrientationProxy* CSourceOrientationProxy::NewL(
    67 	TMMFMessageDestinationPckg aMessageHandler,
    68     MCustomCommand& aCustomCommand,
    69     CCustomInterfaceUtility* aCustomInterfaceUtility )
    70     {
    71     CSourceOrientationProxy* self = new (ELeave) CSourceOrientationProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility);
    72     CleanupStack::PushL(self);
    73     self->ConstructL();
    74     CleanupStack::Pop(self);
    75     return self;
    76 	}
    77 
    78 // -----------------------------------------------------------------------------
    79 // CSourceOrientationProxy::ConstructL
    80 // -----------------------------------------------------------------------------
    81 //
    82 void CSourceOrientationProxy::ConstructL()
    83     {
    84     iSourceOrientationEventObserver = CSourceOrientationEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
    85     StartObserver();
    86 
    87     TEfOrientationDataPckg dataPckgFrom;
    88     // sends a message to fetch initial data.
    89 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ESofInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
    90 	SetEffectData(dataPckgFrom);
    91 	}
    92 
    93 
    94 // -----------------------------------------------------------------------------
    95 // CSourceOrientationProxy::ApplyL
    96 // Apply the bassboost settings.
    97 // -----------------------------------------------------------------------------
    98 //
    99 EXPORT_C void CSourceOrientationProxy::ApplyL()
   100 	{
   101 #ifdef _DEBUG
   102     RDebug::Print(_L("CSourceOrientationProxy::Apply"));
   103 #endif
   104 
   105 	if (iHaveUpdateRights )
   106 		{
   107 		iOrientationData.iEnabled = iEnabled;
   108 		iOrientationData.iEnforced = iEnforced;
   109 		iOrientationData.iHaveUpdateRights = iHaveUpdateRights;
   110 
   111 		iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ESofApply, DoEffectData(), KNullDesC8);
   112 		}
   113 	else
   114 		{
   115 		User::Leave(KErrAccessDenied);
   116 		}
   117 	}
   118 
   119 // -----------------------------------------------------------------------------
   120 // CSourceOrientationProxy::StartObserver
   121 // Starts the event observer. The event observer monitors asynchronous events
   122 // from the message handler.
   123 // -----------------------------------------------------------------------------
   124 //
   125 void CSourceOrientationProxy::StartObserver()
   126 	{
   127 #ifdef _DEBUG
   128     RDebug::Print(_L("CSourceOrientationProxy::StartObserver"));
   129 #endif
   130 
   131 	iSourceOrientationEventObserver->Start();
   132 	}
   133 
   134 // -----------------------------------------------------------------------------
   135 // CSourceOrientationProxy::SourceOrientationEvent
   136 // Checks which data member has changed and notify the observers.
   137 // -----------------------------------------------------------------------------
   138 //
   139 void CSourceOrientationProxy::SourceOrientationEvent(
   140 	const TDesC8& aBuffer )
   141 	{
   142 #ifdef _DEBUG
   143     RDebug::Print(_L("CSourceOrientationProxy::SourceOrientationEvent"));
   144 #endif
   145 
   146 	TEfOrientationDataPckg dataPckgFrom;
   147 	dataPckgFrom.Copy(aBuffer);
   148 	TEfOrientation newOrientationData = dataPckgFrom();
   149 
   150 	TUint8 event = 0;
   151 
   152 	if ( newOrientationData.iEnabled != iOrientationData.iEnabled )
   153 		{
   154 		iOrientationData.iEnabled = newOrientationData.iEnabled;
   155 		iEnabled = newOrientationData.iEnabled;
   156 		if ( iOrientationData.iEnabled )
   157 			{
   158 			event = MAudioEffectObserver::KEnabled;
   159 			}
   160 		else
   161 			{
   162 			event = MAudioEffectObserver::KDisabled;
   163 			}
   164 		}
   165 	else if ( newOrientationData.iEnforced != iOrientationData.iEnforced )
   166 		{
   167 		iOrientationData.iEnforced = newOrientationData.iEnforced;
   168 		iEnforced = newOrientationData.iEnforced;
   169 		if ( iOrientationData.iEnforced )
   170 			{
   171 			event = MAudioEffectObserver::KEnforced;
   172 			}
   173 		else
   174 			{
   175 			event = MAudioEffectObserver::KNotEnforced;
   176 			}
   177 		}
   178 	else if ( newOrientationData.iHaveUpdateRights != iOrientationData.iHaveUpdateRights )
   179 		{
   180 		iOrientationData.iHaveUpdateRights = newOrientationData.iHaveUpdateRights;
   181 		iHaveUpdateRights = newOrientationData.iHaveUpdateRights;
   182 		if ( iOrientationData.iHaveUpdateRights )
   183 			{
   184 			event = MAudioEffectObserver::KGainedUpdateRights;
   185 			}
   186 		else
   187 			{
   188 			event = MAudioEffectObserver::KLostUpdateRights;
   189 			}
   190 		}
   191 	else if ( newOrientationData.iHeading != iOrientationData.iHeading )
   192 			{
   193 			iOrientationData.iHeading = newOrientationData.iHeading;
   194 			event = MSourceOrientationObserver::KOrientationChanged;
   195 			}
   196 	else if ( newOrientationData.iPitch != iOrientationData.iPitch )
   197 			{
   198 			iOrientationData.iPitch = newOrientationData.iPitch;
   199 			event = MSourceOrientationObserver::KOrientationChanged;
   200 			}
   201 	else if ( newOrientationData.iRoll != iOrientationData.iRoll )
   202 			{
   203 			iOrientationData.iRoll = newOrientationData.iRoll;
   204 			event = MSourceOrientationObserver::KOrientationChanged;
   205 			}
   206 	else if ( newOrientationData.iFrontX != iOrientationData.iFrontX )
   207 			{
   208 			iOrientationData.iFrontX = newOrientationData.iFrontX;
   209 			event = MSourceOrientationObserver::KOrientationVectorsChanged;
   210 			}
   211 	else if ( newOrientationData.iFrontY != iOrientationData.iFrontY )
   212 			{
   213 			iOrientationData.iFrontY = newOrientationData.iFrontY;
   214 			event = MSourceOrientationObserver::KOrientationVectorsChanged;
   215 			}
   216 	else if ( newOrientationData.iFrontZ != iOrientationData.iFrontZ )
   217 			{
   218 			iOrientationData.iFrontZ = newOrientationData.iFrontZ;
   219 			event = MSourceOrientationObserver::KOrientationVectorsChanged;
   220 			}
   221 	else if ( newOrientationData.iAboveX != iOrientationData.iAboveX )
   222 			{
   223 			iOrientationData.iAboveX = newOrientationData.iAboveX;
   224 			event = MSourceOrientationObserver::KOrientationVectorsChanged;
   225 			}
   226 	else if ( newOrientationData.iFrontY != iOrientationData.iAboveY )
   227 			{
   228 			iOrientationData.iAboveY = newOrientationData.iAboveY;
   229 			event = MSourceOrientationObserver::KOrientationVectorsChanged;
   230 			}
   231 	else if ( newOrientationData.iAboveZ != iOrientationData.iAboveZ )
   232 			{
   233 			iOrientationData.iAboveZ = newOrientationData.iAboveZ;
   234 			event = MSourceOrientationObserver::KOrientationVectorsChanged;
   235 			}
   236 
   237 	if (!event)
   238 		return;
   239 
   240 	for ( TInt i = 0; i < iObservers.Count(); i++ )
   241 		{
   242 		iObservers[i]->EffectChanged(this, event);
   243 		}
   244 	}
   245 
   246 
   247 // ========================== OTHER EXPORTED FUNCTIONS =========================
   248 
   249 // End of File