|
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 RoomLevel proxy class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #ifdef _DEBUG |
|
24 #include <e32svr.h> |
|
25 #endif |
|
26 |
|
27 #include "RoomLevelProxy.h" |
|
28 #include "RoomLevelEventObserver.h" |
|
29 #include <CustomInterfaceUtility.h> |
|
30 #include "EnvironmentalReverbProxy.h" |
|
31 |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CRoomLevelProxy::CRoomLevelProxy |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CRoomLevelProxy::CRoomLevelProxy( |
|
42 TMMFMessageDestinationPckg aMessageHandler, |
|
43 MCustomCommand& aCustomCommand, |
|
44 CCustomInterfaceUtility* aCustomInterfaceUtility ) |
|
45 : iCustomCommand(&aCustomCommand), |
|
46 iMessageHandler(aMessageHandler), |
|
47 iCustomInterfaceUtility(aCustomInterfaceUtility) |
|
48 |
|
49 { |
|
50 } |
|
51 |
|
52 // Destructor |
|
53 CRoomLevelProxy::~CRoomLevelProxy() |
|
54 { |
|
55 |
|
56 // Remove the custom interface message handler before we destroy the proxy. |
|
57 if (iClientReverb) |
|
58 ((CEnvironmentalReverbProxy*)iClientReverb)->RoomLevelDetached(*this); |
|
59 if (iCustomInterfaceUtility) |
|
60 iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler); |
|
61 delete iRoomLevelEventObserver; |
|
62 delete iCustomInterfaceUtility; |
|
63 |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CRoomLevelProxy::NewL |
|
68 // Static function for creating an instance of the Environmental RoomLevel object. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C CRoomLevelProxy* CRoomLevelProxy::NewL( |
|
72 TMMFMessageDestinationPckg aMessageHandler, |
|
73 MCustomCommand& aCustomCommand, |
|
74 CCustomInterfaceUtility* aCustomInterfaceUtility ) |
|
75 { |
|
76 CRoomLevelProxy* self = new (ELeave) CRoomLevelProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility); |
|
77 CleanupStack::PushL(self); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop(self); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CRoomLevelProxy::ConstructL |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CRoomLevelProxy::ConstructL() |
|
89 { |
|
90 #ifdef _DEBUG |
|
91 RDebug::Print(_L("CRoomLevelProxy::ConstructL")); |
|
92 #endif |
|
93 iRoomLevelEventObserver = CRoomLevelEventObserver::NewL(iMessageHandler, *iCustomCommand, *this); |
|
94 StartObserver(); |
|
95 // sends a message to fetch initial data. |
|
96 TEfRoomLevelDataPckg dataPckgFrom; |
|
97 iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ERoomInitialize, KNullDesC8, KNullDesC8, dataPckgFrom); |
|
98 SetEffectData(dataPckgFrom); |
|
99 |
|
100 } |
|
101 |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CRoomLevelProxy::ApplyL |
|
105 // Apply the Environmental RoomLevel settings. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C void CRoomLevelProxy::ApplyL() |
|
109 { |
|
110 #ifdef _DEBUG |
|
111 RDebug::Print(_L("CRoomLevelProxy::Apply")); |
|
112 #endif |
|
113 |
|
114 if ( !iHaveUpdateRights ) |
|
115 { |
|
116 User::Leave(KErrAccessDenied); |
|
117 } |
|
118 |
|
119 iRoomLevelData.iEnabled = iEnabled; |
|
120 iRoomLevelData.iEnforced = iEnforced; |
|
121 iRoomLevelData.iHaveUpdateRights = iHaveUpdateRights; |
|
122 iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)ERoomApply, DoEffectData(), KNullDesC8); |
|
123 |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CRoomLevelProxy::StartObserver |
|
128 // Starts the event observer. The event observer monitors asynchronous events |
|
129 // from the message handler. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CRoomLevelProxy::StartObserver() |
|
133 { |
|
134 #ifdef _DEBUG |
|
135 RDebug::Print(_L("CRoomLevelProxy::StartObserver")); |
|
136 #endif |
|
137 |
|
138 iRoomLevelEventObserver->Start(); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CRoomLevelProxy::RoomLevelEvent |
|
143 // Checks which data member has changed and notify the observers. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CRoomLevelProxy::RoomLevelEvent( |
|
147 const TDesC8& aBuffer ) |
|
148 { |
|
149 #ifdef _DEBUG |
|
150 RDebug::Print(_L("CRoomLevelProxy::RoomLevelEvent")); |
|
151 #endif |
|
152 |
|
153 TEfRoomLevelDataPckg dataPckgFrom; |
|
154 dataPckgFrom.Copy(aBuffer); |
|
155 TEfRoomLevel newRoomLevelData = dataPckgFrom(); |
|
156 |
|
157 TUint8 event = 0; |
|
158 |
|
159 if ( newRoomLevelData.iEnabled != iRoomLevelData.iEnabled ) |
|
160 { |
|
161 iRoomLevelData.iEnabled = newRoomLevelData.iEnabled; |
|
162 iEnabled = newRoomLevelData.iEnabled; |
|
163 if ( iRoomLevelData.iEnabled ) |
|
164 { |
|
165 event = MAudioEffectObserver::KEnabled; |
|
166 } |
|
167 else |
|
168 { |
|
169 event = MAudioEffectObserver::KDisabled; |
|
170 } |
|
171 } |
|
172 else if ( newRoomLevelData.iEnforced != iRoomLevelData.iEnforced ) |
|
173 { |
|
174 iRoomLevelData.iEnforced = newRoomLevelData.iEnforced; |
|
175 iEnforced = newRoomLevelData.iEnforced; |
|
176 if ( iRoomLevelData.iEnforced ) |
|
177 { |
|
178 event = MAudioEffectObserver::KEnforced; |
|
179 } |
|
180 else |
|
181 { |
|
182 event = MAudioEffectObserver::KNotEnforced; |
|
183 } |
|
184 } |
|
185 else if ( newRoomLevelData.iHaveUpdateRights != iRoomLevelData.iHaveUpdateRights ) |
|
186 { |
|
187 iRoomLevelData.iHaveUpdateRights = newRoomLevelData.iHaveUpdateRights; |
|
188 iHaveUpdateRights = newRoomLevelData.iHaveUpdateRights; |
|
189 if ( iRoomLevelData.iHaveUpdateRights ) |
|
190 { |
|
191 event = MAudioEffectObserver::KGainedUpdateRights; |
|
192 } |
|
193 else |
|
194 { |
|
195 event = MAudioEffectObserver::KLostUpdateRights; |
|
196 } |
|
197 } |
|
198 |
|
199 else if ( newRoomLevelData.iEnvironmentalReverbId != iRoomLevelData.iEnvironmentalReverbId ) |
|
200 { |
|
201 iRoomLevelData.iEnvironmentalReverbId = newRoomLevelData.iEnvironmentalReverbId; |
|
202 // event = MRoomLevelObserver::KRoomLevelChanged; |
|
203 } |
|
204 |
|
205 else if ( newRoomLevelData.iStreamRoomLevel != iRoomLevelData.iStreamRoomLevel ) |
|
206 { |
|
207 iRoomLevelData.iStreamRoomLevel = newRoomLevelData.iStreamRoomLevel; |
|
208 event = MRoomLevelObserver::KRoomLevelChanged; |
|
209 } |
|
210 else if ( newRoomLevelData.iStreamMinRoomLevel != iRoomLevelData.iStreamMinRoomLevel ) |
|
211 { |
|
212 iRoomLevelData.iStreamMinRoomLevel = newRoomLevelData.iStreamMinRoomLevel; |
|
213 // event = MRoomLevelObserver::KMinRoomLevelChanged; |
|
214 } |
|
215 else if ( newRoomLevelData.iStreamMaxRoomLevel != iRoomLevelData.iStreamMaxRoomLevel ) |
|
216 { |
|
217 iRoomLevelData.iStreamMaxRoomLevel = newRoomLevelData.iStreamMaxRoomLevel; |
|
218 // event = MRoomLevelObserver::KMinRoomLevelChanged; |
|
219 } |
|
220 |
|
221 |
|
222 if (!event) |
|
223 return; |
|
224 |
|
225 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
226 { |
|
227 iObservers[i]->EffectChanged(this, event); |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CRoomLevelProxy::AttachReverb |
|
234 // Set room level's reverb ID |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TInt CRoomLevelProxy::AttachReverb(CEnvironmentalReverb& aReverb) |
|
238 { |
|
239 TInt err(KErrNone); |
|
240 iRoomLevelData.iEnvironmentalReverbId = ((CEnvironmentalReverbProxy&)aReverb).GetUniqueId(); |
|
241 TRAP(err,(((CEnvironmentalReverbProxy&)(aReverb)).RoomLevelAttached(*this))); |
|
242 |
|
243 return err; |
|
244 } |
|
245 |
|
246 |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CRoomLevelProxy::DettachReverb |
|
250 // |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 TInt CRoomLevelProxy::DettachReverb(CEnvironmentalReverb& aReverb) |
|
254 { |
|
255 TInt status(KErrNone); |
|
256 iClientReverb = NULL; |
|
257 if ( iCustomInterfaceUtility ) |
|
258 { |
|
259 iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler); |
|
260 } |
|
261 TRAP(status,(((CEnvironmentalReverbProxy&)(aReverb)).RoomLevelDetached(*this))); |
|
262 return status; |
|
263 } |
|
264 |
|
265 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
266 |
|
267 // End of File |
|
268 |
|
269 |