os/mm/devsoundextensions/effects/Loudness/LoudnessProxy/Src/LoudnessProxy.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 Loudness proxy class
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 // INCLUDE FILES
    22 
    23 #ifdef _DEBUG
    24 #include <e32svr.h>
    25 #endif
    26 
    27 #include "LoudnessProxy.h"
    28 #include "LoudnessEventObserver.h"
    29 #include <CustomInterfaceUtility.h>
    30 
    31 
    32 // ============================ MEMBER FUNCTIONS ===============================
    33 
    34 // -----------------------------------------------------------------------------
    35 // CLoudnessProxy::CLoudnessProxy
    36 // C++ default constructor can NOT contain any code, that
    37 // might leave.
    38 // -----------------------------------------------------------------------------
    39 //
    40 CLoudnessProxy::CLoudnessProxy(
    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 CLoudnessProxy::~CLoudnessProxy()
    53     {
    54     // Remove the custom interface message handler before we destroy the proxy.
    55     if(iCustomInterfaceUtility)    
    56         iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
    57 	delete iLoudnessEventObserver;
    58 	delete iCustomInterfaceUtility;
    59 	}
    60 
    61 // -----------------------------------------------------------------------------
    62 // CLoudnessProxy::NewL
    63 // Static function for creating an instance of the Loudness object.
    64 // -----------------------------------------------------------------------------
    65 //
    66 EXPORT_C CLoudnessProxy* CLoudnessProxy::NewL(
    67 	TMMFMessageDestinationPckg aMessageHandler,
    68     MCustomCommand& aCustomCommand,
    69     CCustomInterfaceUtility* aCustomInterfaceUtility )
    70     {
    71     CLoudnessProxy* self = new (ELeave) CLoudnessProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility);
    72     CleanupStack::PushL(self);
    73     self->ConstructL();
    74     CleanupStack::Pop(self);
    75     return self;
    76 	}
    77 
    78 // -----------------------------------------------------------------------------
    79 // CLoudnessProxy::ConstructL
    80 // -----------------------------------------------------------------------------
    81 //
    82 void CLoudnessProxy::ConstructL()
    83     {
    84 #ifdef _DEBUG
    85     RDebug::Print(_L("CLoudnessProxy::ConstructL"));
    86 #endif
    87     iLoudnessEventObserver = CLoudnessEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
    88     StartObserver();
    89     // sends a message to fetch initial data.
    90     TEfLoudnessDataPckg dataPckgFrom;
    91 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
    92 	SetEffectData(dataPckgFrom);
    93 	}
    94 
    95 
    96 // -----------------------------------------------------------------------------
    97 // CLoudnessProxy::ApplyL
    98 // Apply the Loudness settings.
    99 // -----------------------------------------------------------------------------
   100 //
   101 EXPORT_C void CLoudnessProxy::ApplyL()
   102 	{
   103 #ifdef _DEBUG
   104     RDebug::Print(_L("CLoudnessProxy::Apply"));
   105 #endif
   106 
   107 	if ( !iHaveUpdateRights )
   108 		{
   109 		User::Leave(KErrAccessDenied);
   110 		}
   111 
   112 	iLoudnessData.iEnabled = iEnabled;
   113 	iLoudnessData.iEnforced = iEnforced;
   114 	iLoudnessData.iHaveUpdateRights = iHaveUpdateRights;
   115 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefApply, DoEffectData(), KNullDesC8);
   116 	}
   117 
   118 // -----------------------------------------------------------------------------
   119 // CLoudnessProxy::StartObserver
   120 // Starts the event observer. The event observer monitors asynchronous events
   121 // from the message handler.
   122 // -----------------------------------------------------------------------------
   123 //
   124 void CLoudnessProxy::StartObserver()
   125 	{
   126 #ifdef _DEBUG
   127     RDebug::Print(_L("CLoudnessProxy::StartObserver"));
   128 #endif
   129 
   130 	iLoudnessEventObserver->Start();
   131 	}
   132 
   133 // -----------------------------------------------------------------------------
   134 // CLoudnessProxy::LoudnessEvent
   135 // Checks which data member has changed and notify the observers.
   136 // -----------------------------------------------------------------------------
   137 //
   138 void CLoudnessProxy::LoudnessEvent(
   139 	const TDesC8& aBuffer )
   140 	{
   141 #ifdef _DEBUG
   142     RDebug::Print(_L("CLoudnessProxy::LoudnessEvent"));
   143 #endif
   144 
   145 	TEfLoudnessDataPckg dataPckgFrom;
   146 	dataPckgFrom.Copy(aBuffer);
   147 	TEfLoudnessData newLoudnessData = dataPckgFrom();
   148 
   149 	TUint8 event = 0;
   150 
   151 		if ( newLoudnessData.iEnabled != iLoudnessData.iEnabled )
   152 			{
   153 			iLoudnessData.iEnabled = newLoudnessData.iEnabled;
   154 			iEnabled = newLoudnessData.iEnabled;
   155 			if ( iLoudnessData.iEnabled )
   156 				{
   157 				event = MAudioEffectObserver::KEnabled;
   158 				}
   159 			else
   160 				{
   161 				event = MAudioEffectObserver::KDisabled;
   162 				}
   163 			}
   164 		else if ( newLoudnessData.iEnforced != iLoudnessData.iEnforced )
   165 			{
   166 			iLoudnessData.iEnforced = newLoudnessData.iEnforced;
   167 			iEnforced = newLoudnessData.iEnforced;
   168 			if ( iLoudnessData.iEnforced )
   169 				{
   170 				event = MAudioEffectObserver::KEnforced;
   171 				}
   172 			else
   173 				{
   174 				event = MAudioEffectObserver::KNotEnforced;
   175 				}
   176 			}
   177 		else if ( newLoudnessData.iHaveUpdateRights != iLoudnessData.iHaveUpdateRights )
   178 			{
   179 			iLoudnessData.iHaveUpdateRights = newLoudnessData.iHaveUpdateRights;
   180 			iHaveUpdateRights = newLoudnessData.iHaveUpdateRights;
   181 			if ( iLoudnessData.iHaveUpdateRights )
   182 				{
   183 				event = MAudioEffectObserver::KGainedUpdateRights;
   184 				}
   185 			else
   186 				{
   187 				event = MAudioEffectObserver::KLostUpdateRights;
   188 				}
   189 			}
   190 
   191 	if (!event)
   192 		return;
   193 
   194 	for ( TInt i = 0; i < iObservers.Count(); i++ )
   195 		{
   196 		iObservers[i]->EffectChanged(this, event);
   197 		}
   198 	}
   199 
   200 
   201 // ========================== OTHER EXPORTED FUNCTIONS =========================
   202 
   203 // End of File
   204 
   205