|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 #include <hwrmfmtxcommands.h> |
|
19 #include <implementationproxy.h> |
|
20 #include "hwrmfmtxwatcherplugin.h" |
|
21 //#include "hwrmfmtxaccobserver.h" |
|
22 //#include "hwrmfmtxusbobserver.h" |
|
23 #include "hwrmfmtxplugintimer.h" |
|
24 #ifdef INSECURE_AUDIO_POLICY_KEYS |
|
25 #include "hwrmfmtxtestobserver.h" |
|
26 #endif // INSECURE_AUDIO_POLICY_KEYS |
|
27 #include "trace.h" |
|
28 |
|
29 // Map the interface implementation UIDs to implementation factory functions |
|
30 const TImplementationProxy ImplementationTable[] = |
|
31 { |
|
32 IMPLEMENTATION_PROXY_ENTRY(0x20012402, CHWRMFmtxWatcherPlugin::NewL) |
|
33 }; |
|
34 |
|
35 // ======== OTHER EXPORTED FUNCTIONS ======== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // Exported proxy for instantiation method resolution. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) |
|
42 { |
|
43 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
44 return ImplementationTable; |
|
45 } |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CHWRMFmtxWatcherPlugin::NewL |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CHWRMFmtxWatcherPlugin* CHWRMFmtxWatcherPlugin::NewL() |
|
54 { |
|
55 FUNC_LOG; |
|
56 |
|
57 CHWRMFmtxWatcherPlugin* self = new(ELeave) CHWRMFmtxWatcherPlugin(); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CHWRMFmtxWatcherPlugin::NewL |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CHWRMFmtxWatcherPlugin::~CHWRMFmtxWatcherPlugin() |
|
69 { |
|
70 FUNC_LOG; |
|
71 |
|
72 iObservers.ResetAndDestroy(); |
|
73 iTimers.ResetAndDestroy(); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CHWRMFmtxWatcherPlugin::CHWRMFmtxWatcherPlugin |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CHWRMFmtxWatcherPlugin::CHWRMFmtxWatcherPlugin() |
|
81 { |
|
82 FUNC_LOG; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CHWRMFmtxWatcherPlugin::ConstructL |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CHWRMFmtxWatcherPlugin::ConstructL() |
|
90 { |
|
91 FUNC_LOG; |
|
92 |
|
93 // iConnected.Set( EFmtxWatcherObserverAccessory ); // assume connected |
|
94 MHWRMFmtxConnObserver* observer ;//= CHWRMFmtxAccObserver::NewL( *this ); |
|
95 /* CleanupStack::PushL( observer ); |
|
96 iObservers.AppendL( observer ); |
|
97 CleanupStack::Pop( observer ); |
|
98 |
|
99 #ifndef __WINS__ // RUsbMan not created because it does not behave well in emulator |
|
100 iConnected.Set( EFmtxWatcherObserverUsb ); // assume connected |
|
101 observer = CHWRMFmtxUsbObserver::NewL( *this ); |
|
102 CleanupStack::PushL( observer ); |
|
103 iObservers.AppendL( observer ); |
|
104 CleanupStack::Pop( observer ); |
|
105 #else // __WINS__ |
|
106 iObservers.AppendL( NULL ); |
|
107 #endif // __WINS__ |
|
108 |
|
109 */ |
|
110 |
|
111 // Test observer should be always the last |
|
112 #ifdef INSECURE_AUDIO_POLICY_KEYS |
|
113 observer = CHWRMFmtxTestObserver::NewL( *this ); |
|
114 CleanupStack::PushL( observer ); |
|
115 iObservers.AppendL( observer ); |
|
116 CleanupStack::Pop( observer ); |
|
117 #endif // INSECURE_AUDIO_POLICY_KEYS |
|
118 |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CHWRMFmtxWatcherPlugin::ProcessCommandL |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CHWRMFmtxWatcherPlugin::ProcessCommandL( const TInt aCommandId, |
|
126 const TUint8 aTransId, |
|
127 TDesC8& /*aData*/ ) |
|
128 { |
|
129 FUNC_LOG; |
|
130 |
|
131 INFO_LOG2( "CHWRMFmtxWatcherPlugin::ProcessCommandL, (0x%x, 0x%x)", |
|
132 aCommandId, aTransId ); |
|
133 |
|
134 TInt retVal( KErrNone ); |
|
135 |
|
136 switch (aCommandId) |
|
137 { |
|
138 case HWRMFmTxCommand::EConnStatusCmdId: |
|
139 TRAP( retVal, GetStatusL() ); |
|
140 break; |
|
141 |
|
142 case HWRMFmTxCommand::EStartObservingCmdId: |
|
143 TRAP( retVal, StartObservingL() ); |
|
144 break; |
|
145 |
|
146 case HWRMFmTxCommand::EStopObservingCmdId: |
|
147 StopObserving(); |
|
148 break; |
|
149 |
|
150 default : |
|
151 User::Leave( KErrNotSupported ); |
|
152 break; |
|
153 } |
|
154 |
|
155 // Create new timer for response. |
|
156 CHWRMFmtxPluginTimer* timer = CHWRMFmtxPluginTimer::NewL( aCommandId, aTransId, retVal, *this ); |
|
157 CleanupStack::PushL( timer ); |
|
158 iTimers.AppendL( timer ); |
|
159 CleanupStack::Pop( timer ); |
|
160 INFO_LOG1( "CHWRMFmtxWatcherPlugin::ProcessCommandL, timers now %d", |
|
161 iTimers.Count() ); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CHWRMFmtxWatcherPlugin::CancelCommandL |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CHWRMFmtxWatcherPlugin::CancelCommandL(const TUint8 aTransId, |
|
169 #if defined(FMTX_WATCHER_INFO_LOG_ENABLED) |
|
170 const TInt aCommandId) |
|
171 #else |
|
172 const TInt /*aCommandId*/) |
|
173 #endif |
|
174 { |
|
175 FUNC_LOG; |
|
176 |
|
177 INFO_LOG2( "CHWRMFmtxWatcherPlugin::CancelCommandL, (0x%x, 0x%x)", |
|
178 aCommandId, aTransId ); |
|
179 |
|
180 TInt count = iTimers.Count(); |
|
181 for( TInt i = 0; i < count; i++ ) |
|
182 { |
|
183 if ( iTimers[i]->TransId() == aTransId ) |
|
184 { |
|
185 delete iTimers[i]; |
|
186 iTimers.Remove(i); |
|
187 INFO_LOG1( "CHWRMFmtxWatcherPlugin::CancelCommandL, removed timer %d", i ); |
|
188 break; |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CHWRMFmtxWatcherPlugin::GenericTimerFired |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CHWRMFmtxWatcherPlugin::GenericTimerFired(TInt aCommandId, const TUint8 aTransId, |
|
198 TInt aRetVal) |
|
199 { |
|
200 FUNC_LOG; |
|
201 |
|
202 INFO_LOG3( "CHWRMFmtxWatcherPlugin: GenericTimerFired, (0x%x, 0x%x, %d)", |
|
203 aCommandId, aTransId, aRetVal ); |
|
204 |
|
205 TInt err = KErrNone; |
|
206 |
|
207 switch( aCommandId ) |
|
208 { |
|
209 case HWRMFmTxCommand::EConnStatusCmdId: |
|
210 case HWRMFmTxCommand::EStartObservingCmdId: |
|
211 { |
|
212 HWRMFmTxCommand::TConnStatusData data; |
|
213 data.iErrorCode = aRetVal; |
|
214 data.iConnected = iConnected.Value() ? ETrue : EFalse; |
|
215 HWRMFmTxCommand::TConnStatusPackage pckg( data ); |
|
216 TRAP(err, iResponseCallback->ProcessResponseL( aCommandId, aTransId, pckg )); |
|
217 break; |
|
218 } |
|
219 |
|
220 case HWRMFmTxCommand::EStopObservingCmdId: |
|
221 { |
|
222 HWRMFmTxCommand::TErrorCodeResponsePackage pckg( aRetVal ); |
|
223 TRAP(err, iResponseCallback->ProcessResponseL( aCommandId, aTransId, pckg )); |
|
224 break; |
|
225 } |
|
226 |
|
227 default : |
|
228 { |
|
229 HWRMFmTxCommand::TErrorCodeResponsePackage pckg( KErrNotSupported ); |
|
230 TRAP(err, iResponseCallback->ProcessResponseL( aCommandId, aTransId, pckg )); |
|
231 break; |
|
232 } |
|
233 } |
|
234 |
|
235 LOG_IF_ERROR1( err, "CHWRMFmtxWatcherPlugin::GenericTimerFired, err %d", err ); |
|
236 |
|
237 // delete obsolete (if any) timers |
|
238 for( TInt i = (iTimers.Count()-1); i >= 0 ; i-- ) |
|
239 { |
|
240 if ( !iTimers[i]->IsActive() ) |
|
241 { |
|
242 delete iTimers[i]; |
|
243 iTimers.Remove(i); |
|
244 } |
|
245 } |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CHWRMFmtxWatcherPlugin::GetStatusL |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 TBool CHWRMFmtxWatcherPlugin::GetStatusL() |
|
253 { |
|
254 FUNC_LOG; |
|
255 |
|
256 TInt count = iObservers.Count(); |
|
257 for( TInt i = 0; i < count; i++ ) |
|
258 { |
|
259 MHWRMFmtxConnObserver* observer = iObservers[i]; |
|
260 if ( observer ) |
|
261 { |
|
262 iConnected.Assign( i, observer->GetStatusL() ); |
|
263 } |
|
264 } |
|
265 |
|
266 return iConnected.Value(); |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CHWRMFmtxWatcherPlugin::StartObservingL |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CHWRMFmtxWatcherPlugin::StartObservingL() |
|
274 { |
|
275 FUNC_LOG; |
|
276 |
|
277 TInt count = iObservers.Count(); |
|
278 for( TInt i = 0; i < count; i++ ) |
|
279 { |
|
280 MHWRMFmtxConnObserver* observer = iObservers[i]; |
|
281 if ( observer ) |
|
282 { |
|
283 observer->StartObservingL(); |
|
284 } |
|
285 } |
|
286 |
|
287 GetStatusL(); |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CHWRMFmtxWatcherPlugin::StopObserving |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 void CHWRMFmtxWatcherPlugin::StopObserving() |
|
295 { |
|
296 FUNC_LOG; |
|
297 |
|
298 TInt count = iObservers.Count(); |
|
299 for( TInt i = 0; i < count; i++ ) |
|
300 { |
|
301 MHWRMFmtxConnObserver* observer = iObservers[i]; |
|
302 if ( observer ) |
|
303 { |
|
304 observer->StopObserving(); |
|
305 } |
|
306 } |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CHWRMFmtxWatcherPlugin::HandleConnectionChange |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CHWRMFmtxWatcherPlugin::HandleConnectionChange( TFmtxWatcherObserverTypes aType, |
|
314 TBool aConnected ) |
|
315 { |
|
316 FUNC_LOG; |
|
317 |
|
318 iConnected.Assign( aType, aConnected ); |
|
319 |
|
320 HWRMFmTxCommand::TConnStatusData data; |
|
321 data.iErrorCode = KErrNone; |
|
322 data.iConnected = iConnected.Value() ? ETrue : EFalse; |
|
323 HWRMFmTxCommand::TConnStatusPackage pckg( data ); |
|
324 TRAPD( err, iResponseCallback->EventL( HWRMFmTxCommand::ETxWatcherConnIndId, pckg ) ); |
|
325 |
|
326 LOG_IF_ERROR1( err, "CHWRMFmtxWatcherPlugin::HandleConnectionChange: err=%d", err ); |
|
327 } |