Update contrib.
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Implementation of the Loudness proxy class
27 #include "LoudnessProxy.h"
28 #include "LoudnessEventObserver.h"
29 #include <CustomInterfaceUtility.h>
32 // ============================ MEMBER FUNCTIONS ===============================
34 // -----------------------------------------------------------------------------
35 // CLoudnessProxy::CLoudnessProxy
36 // C++ default constructor can NOT contain any code, that
38 // -----------------------------------------------------------------------------
40 CLoudnessProxy::CLoudnessProxy(
41 TMMFMessageDestinationPckg aMessageHandler,
42 MCustomCommand& aCustomCommand,
43 CCustomInterfaceUtility* aCustomInterfaceUtility )
44 : iCustomCommand(&aCustomCommand),
45 iMessageHandler(aMessageHandler),
46 iCustomInterfaceUtility(aCustomInterfaceUtility)
52 CLoudnessProxy::~CLoudnessProxy()
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;
61 // -----------------------------------------------------------------------------
62 // CLoudnessProxy::NewL
63 // Static function for creating an instance of the Loudness object.
64 // -----------------------------------------------------------------------------
66 EXPORT_C CLoudnessProxy* CLoudnessProxy::NewL(
67 TMMFMessageDestinationPckg aMessageHandler,
68 MCustomCommand& aCustomCommand,
69 CCustomInterfaceUtility* aCustomInterfaceUtility )
71 CLoudnessProxy* self = new (ELeave) CLoudnessProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility);
72 CleanupStack::PushL(self);
74 CleanupStack::Pop(self);
78 // -----------------------------------------------------------------------------
79 // CLoudnessProxy::ConstructL
80 // -----------------------------------------------------------------------------
82 void CLoudnessProxy::ConstructL()
85 RDebug::Print(_L("CLoudnessProxy::ConstructL"));
87 iLoudnessEventObserver = CLoudnessEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
89 // sends a message to fetch initial data.
90 TEfLoudnessDataPckg dataPckgFrom;
91 iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
92 SetEffectData(dataPckgFrom);
96 // -----------------------------------------------------------------------------
97 // CLoudnessProxy::ApplyL
98 // Apply the Loudness settings.
99 // -----------------------------------------------------------------------------
101 EXPORT_C void CLoudnessProxy::ApplyL()
104 RDebug::Print(_L("CLoudnessProxy::Apply"));
107 if ( !iHaveUpdateRights )
109 User::Leave(KErrAccessDenied);
112 iLoudnessData.iEnabled = iEnabled;
113 iLoudnessData.iEnforced = iEnforced;
114 iLoudnessData.iHaveUpdateRights = iHaveUpdateRights;
115 iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ELefApply, DoEffectData(), KNullDesC8);
118 // -----------------------------------------------------------------------------
119 // CLoudnessProxy::StartObserver
120 // Starts the event observer. The event observer monitors asynchronous events
121 // from the message handler.
122 // -----------------------------------------------------------------------------
124 void CLoudnessProxy::StartObserver()
127 RDebug::Print(_L("CLoudnessProxy::StartObserver"));
130 iLoudnessEventObserver->Start();
133 // -----------------------------------------------------------------------------
134 // CLoudnessProxy::LoudnessEvent
135 // Checks which data member has changed and notify the observers.
136 // -----------------------------------------------------------------------------
138 void CLoudnessProxy::LoudnessEvent(
139 const TDesC8& aBuffer )
142 RDebug::Print(_L("CLoudnessProxy::LoudnessEvent"));
145 TEfLoudnessDataPckg dataPckgFrom;
146 dataPckgFrom.Copy(aBuffer);
147 TEfLoudnessData newLoudnessData = dataPckgFrom();
151 if ( newLoudnessData.iEnabled != iLoudnessData.iEnabled )
153 iLoudnessData.iEnabled = newLoudnessData.iEnabled;
154 iEnabled = newLoudnessData.iEnabled;
155 if ( iLoudnessData.iEnabled )
157 event = MAudioEffectObserver::KEnabled;
161 event = MAudioEffectObserver::KDisabled;
164 else if ( newLoudnessData.iEnforced != iLoudnessData.iEnforced )
166 iLoudnessData.iEnforced = newLoudnessData.iEnforced;
167 iEnforced = newLoudnessData.iEnforced;
168 if ( iLoudnessData.iEnforced )
170 event = MAudioEffectObserver::KEnforced;
174 event = MAudioEffectObserver::KNotEnforced;
177 else if ( newLoudnessData.iHaveUpdateRights != iLoudnessData.iHaveUpdateRights )
179 iLoudnessData.iHaveUpdateRights = newLoudnessData.iHaveUpdateRights;
180 iHaveUpdateRights = newLoudnessData.iHaveUpdateRights;
181 if ( iLoudnessData.iHaveUpdateRights )
183 event = MAudioEffectObserver::KGainedUpdateRights;
187 event = MAudioEffectObserver::KLostUpdateRights;
194 for ( TInt i = 0; i < iObservers.Count(); i++ )
196 iObservers[i]->EffectChanged(this, event);
201 // ========================== OTHER EXPORTED FUNCTIONS =========================