sl@0: /* sl@0: * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: Implementation of the Loudness proxy class sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: sl@0: // INCLUDE FILES sl@0: sl@0: #ifdef _DEBUG sl@0: #include sl@0: #endif sl@0: sl@0: #include "LoudnessProxy.h" sl@0: #include "LoudnessEventObserver.h" sl@0: #include sl@0: sl@0: sl@0: // ============================ MEMBER FUNCTIONS =============================== sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CLoudnessProxy::CLoudnessProxy sl@0: // C++ default constructor can NOT contain any code, that sl@0: // might leave. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: CLoudnessProxy::CLoudnessProxy( sl@0: TMMFMessageDestinationPckg aMessageHandler, sl@0: MCustomCommand& aCustomCommand, sl@0: CCustomInterfaceUtility* aCustomInterfaceUtility ) sl@0: : iCustomCommand(&aCustomCommand), sl@0: iMessageHandler(aMessageHandler), sl@0: iCustomInterfaceUtility(aCustomInterfaceUtility) sl@0: sl@0: { sl@0: } sl@0: sl@0: // Destructor sl@0: CLoudnessProxy::~CLoudnessProxy() sl@0: { sl@0: // Remove the custom interface message handler before we destroy the proxy. sl@0: if(iCustomInterfaceUtility) sl@0: iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler); sl@0: delete iLoudnessEventObserver; sl@0: delete iCustomInterfaceUtility; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CLoudnessProxy::NewL sl@0: // Static function for creating an instance of the Loudness object. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: EXPORT_C CLoudnessProxy* CLoudnessProxy::NewL( sl@0: TMMFMessageDestinationPckg aMessageHandler, sl@0: MCustomCommand& aCustomCommand, sl@0: CCustomInterfaceUtility* aCustomInterfaceUtility ) sl@0: { sl@0: CLoudnessProxy* self = new (ELeave) CLoudnessProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CLoudnessProxy::ConstructL sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CLoudnessProxy::ConstructL() sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("CLoudnessProxy::ConstructL")); sl@0: #endif sl@0: iLoudnessEventObserver = CLoudnessEventObserver::NewL(iMessageHandler, *iCustomCommand, *this); sl@0: StartObserver(); sl@0: // sends a message to fetch initial data. sl@0: TEfLoudnessDataPckg dataPckgFrom; sl@0: iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefInitialize, KNullDesC8, KNullDesC8, dataPckgFrom); sl@0: SetEffectData(dataPckgFrom); sl@0: } sl@0: sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CLoudnessProxy::ApplyL sl@0: // Apply the Loudness settings. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: EXPORT_C void CLoudnessProxy::ApplyL() sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("CLoudnessProxy::Apply")); sl@0: #endif sl@0: sl@0: if ( !iHaveUpdateRights ) sl@0: { sl@0: User::Leave(KErrAccessDenied); sl@0: } sl@0: sl@0: iLoudnessData.iEnabled = iEnabled; sl@0: iLoudnessData.iEnforced = iEnforced; sl@0: iLoudnessData.iHaveUpdateRights = iHaveUpdateRights; sl@0: iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefApply, DoEffectData(), KNullDesC8); sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CLoudnessProxy::StartObserver sl@0: // Starts the event observer. The event observer monitors asynchronous events sl@0: // from the message handler. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CLoudnessProxy::StartObserver() sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("CLoudnessProxy::StartObserver")); sl@0: #endif sl@0: sl@0: iLoudnessEventObserver->Start(); sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CLoudnessProxy::LoudnessEvent sl@0: // Checks which data member has changed and notify the observers. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CLoudnessProxy::LoudnessEvent( sl@0: const TDesC8& aBuffer ) sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("CLoudnessProxy::LoudnessEvent")); sl@0: #endif sl@0: sl@0: TEfLoudnessDataPckg dataPckgFrom; sl@0: dataPckgFrom.Copy(aBuffer); sl@0: TEfLoudnessData newLoudnessData = dataPckgFrom(); sl@0: sl@0: TUint8 event = 0; sl@0: sl@0: if ( newLoudnessData.iEnabled != iLoudnessData.iEnabled ) sl@0: { sl@0: iLoudnessData.iEnabled = newLoudnessData.iEnabled; sl@0: iEnabled = newLoudnessData.iEnabled; sl@0: if ( iLoudnessData.iEnabled ) sl@0: { sl@0: event = MAudioEffectObserver::KEnabled; sl@0: } sl@0: else sl@0: { sl@0: event = MAudioEffectObserver::KDisabled; sl@0: } sl@0: } sl@0: else if ( newLoudnessData.iEnforced != iLoudnessData.iEnforced ) sl@0: { sl@0: iLoudnessData.iEnforced = newLoudnessData.iEnforced; sl@0: iEnforced = newLoudnessData.iEnforced; sl@0: if ( iLoudnessData.iEnforced ) sl@0: { sl@0: event = MAudioEffectObserver::KEnforced; sl@0: } sl@0: else sl@0: { sl@0: event = MAudioEffectObserver::KNotEnforced; sl@0: } sl@0: } sl@0: else if ( newLoudnessData.iHaveUpdateRights != iLoudnessData.iHaveUpdateRights ) sl@0: { sl@0: iLoudnessData.iHaveUpdateRights = newLoudnessData.iHaveUpdateRights; sl@0: iHaveUpdateRights = newLoudnessData.iHaveUpdateRights; sl@0: if ( iLoudnessData.iHaveUpdateRights ) sl@0: { sl@0: event = MAudioEffectObserver::KGainedUpdateRights; sl@0: } sl@0: else sl@0: { sl@0: event = MAudioEffectObserver::KLostUpdateRights; sl@0: } sl@0: } sl@0: sl@0: if (!event) sl@0: return; sl@0: sl@0: for ( TInt i = 0; i < iObservers.Count(); i++ ) sl@0: { sl@0: iObservers[i]->EffectChanged(this, event); sl@0: } sl@0: } sl@0: sl@0: sl@0: // ========================== OTHER EXPORTED FUNCTIONS ========================= sl@0: sl@0: // End of File sl@0: sl@0: