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