1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsoundextensions/effects/Loudness/LoudnessProxy/Src/LoudnessProxy.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,205 @@
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 Loudness 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 "LoudnessProxy.h"
1.31 +#include "LoudnessEventObserver.h"
1.32 +#include <CustomInterfaceUtility.h>
1.33 +
1.34 +
1.35 +// ============================ MEMBER FUNCTIONS ===============================
1.36 +
1.37 +// -----------------------------------------------------------------------------
1.38 +// CLoudnessProxy::CLoudnessProxy
1.39 +// C++ default constructor can NOT contain any code, that
1.40 +// might leave.
1.41 +// -----------------------------------------------------------------------------
1.42 +//
1.43 +CLoudnessProxy::CLoudnessProxy(
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 +CLoudnessProxy::~CLoudnessProxy()
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 iLoudnessEventObserver;
1.61 + delete iCustomInterfaceUtility;
1.62 + }
1.63 +
1.64 +// -----------------------------------------------------------------------------
1.65 +// CLoudnessProxy::NewL
1.66 +// Static function for creating an instance of the Loudness object.
1.67 +// -----------------------------------------------------------------------------
1.68 +//
1.69 +EXPORT_C CLoudnessProxy* CLoudnessProxy::NewL(
1.70 + TMMFMessageDestinationPckg aMessageHandler,
1.71 + MCustomCommand& aCustomCommand,
1.72 + CCustomInterfaceUtility* aCustomInterfaceUtility )
1.73 + {
1.74 + CLoudnessProxy* self = new (ELeave) CLoudnessProxy(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 +// CLoudnessProxy::ConstructL
1.83 +// -----------------------------------------------------------------------------
1.84 +//
1.85 +void CLoudnessProxy::ConstructL()
1.86 + {
1.87 +#ifdef _DEBUG
1.88 + RDebug::Print(_L("CLoudnessProxy::ConstructL"));
1.89 +#endif
1.90 + iLoudnessEventObserver = CLoudnessEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
1.91 + StartObserver();
1.92 + // sends a message to fetch initial data.
1.93 + TEfLoudnessDataPckg dataPckgFrom;
1.94 + iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
1.95 + SetEffectData(dataPckgFrom);
1.96 + }
1.97 +
1.98 +
1.99 +// -----------------------------------------------------------------------------
1.100 +// CLoudnessProxy::ApplyL
1.101 +// Apply the Loudness settings.
1.102 +// -----------------------------------------------------------------------------
1.103 +//
1.104 +EXPORT_C void CLoudnessProxy::ApplyL()
1.105 + {
1.106 +#ifdef _DEBUG
1.107 + RDebug::Print(_L("CLoudnessProxy::Apply"));
1.108 +#endif
1.109 +
1.110 + if ( !iHaveUpdateRights )
1.111 + {
1.112 + User::Leave(KErrAccessDenied);
1.113 + }
1.114 +
1.115 + iLoudnessData.iEnabled = iEnabled;
1.116 + iLoudnessData.iEnforced = iEnforced;
1.117 + iLoudnessData.iHaveUpdateRights = iHaveUpdateRights;
1.118 + iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefApply, DoEffectData(), KNullDesC8);
1.119 + }
1.120 +
1.121 +// -----------------------------------------------------------------------------
1.122 +// CLoudnessProxy::StartObserver
1.123 +// Starts the event observer. The event observer monitors asynchronous events
1.124 +// from the message handler.
1.125 +// -----------------------------------------------------------------------------
1.126 +//
1.127 +void CLoudnessProxy::StartObserver()
1.128 + {
1.129 +#ifdef _DEBUG
1.130 + RDebug::Print(_L("CLoudnessProxy::StartObserver"));
1.131 +#endif
1.132 +
1.133 + iLoudnessEventObserver->Start();
1.134 + }
1.135 +
1.136 +// -----------------------------------------------------------------------------
1.137 +// CLoudnessProxy::LoudnessEvent
1.138 +// Checks which data member has changed and notify the observers.
1.139 +// -----------------------------------------------------------------------------
1.140 +//
1.141 +void CLoudnessProxy::LoudnessEvent(
1.142 + const TDesC8& aBuffer )
1.143 + {
1.144 +#ifdef _DEBUG
1.145 + RDebug::Print(_L("CLoudnessProxy::LoudnessEvent"));
1.146 +#endif
1.147 +
1.148 + TEfLoudnessDataPckg dataPckgFrom;
1.149 + dataPckgFrom.Copy(aBuffer);
1.150 + TEfLoudnessData newLoudnessData = dataPckgFrom();
1.151 +
1.152 + TUint8 event = 0;
1.153 +
1.154 + if ( newLoudnessData.iEnabled != iLoudnessData.iEnabled )
1.155 + {
1.156 + iLoudnessData.iEnabled = newLoudnessData.iEnabled;
1.157 + iEnabled = newLoudnessData.iEnabled;
1.158 + if ( iLoudnessData.iEnabled )
1.159 + {
1.160 + event = MAudioEffectObserver::KEnabled;
1.161 + }
1.162 + else
1.163 + {
1.164 + event = MAudioEffectObserver::KDisabled;
1.165 + }
1.166 + }
1.167 + else if ( newLoudnessData.iEnforced != iLoudnessData.iEnforced )
1.168 + {
1.169 + iLoudnessData.iEnforced = newLoudnessData.iEnforced;
1.170 + iEnforced = newLoudnessData.iEnforced;
1.171 + if ( iLoudnessData.iEnforced )
1.172 + {
1.173 + event = MAudioEffectObserver::KEnforced;
1.174 + }
1.175 + else
1.176 + {
1.177 + event = MAudioEffectObserver::KNotEnforced;
1.178 + }
1.179 + }
1.180 + else if ( newLoudnessData.iHaveUpdateRights != iLoudnessData.iHaveUpdateRights )
1.181 + {
1.182 + iLoudnessData.iHaveUpdateRights = newLoudnessData.iHaveUpdateRights;
1.183 + iHaveUpdateRights = newLoudnessData.iHaveUpdateRights;
1.184 + if ( iLoudnessData.iHaveUpdateRights )
1.185 + {
1.186 + event = MAudioEffectObserver::KGainedUpdateRights;
1.187 + }
1.188 + else
1.189 + {
1.190 + event = MAudioEffectObserver::KLostUpdateRights;
1.191 + }
1.192 + }
1.193 +
1.194 + if (!event)
1.195 + return;
1.196 +
1.197 + for ( TInt i = 0; i < iObservers.Count(); i++ )
1.198 + {
1.199 + iObservers[i]->EffectChanged(this, event);
1.200 + }
1.201 + }
1.202 +
1.203 +
1.204 +// ========================== OTHER EXPORTED FUNCTIONS =========================
1.205 +
1.206 +// End of File
1.207 +
1.208 +