|
1 /* |
|
2 * Copyright (c) 2006-2009 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: USB Watcher session class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cusbwatchersession.h" |
|
20 #include "usbwatchershared.h" |
|
21 #include "cusbwatcher.h" |
|
22 #include "cusbwatcherserver.h" |
|
23 #include "debug.h" |
|
24 |
|
25 // ---------------------------------------------------------------------------- |
|
26 // Symbian two-phase constructor |
|
27 // ---------------------------------------------------------------------------- |
|
28 // |
|
29 CUsbWatcherSession* CUsbWatcherSession::NewL( CUsbWatcherServer* aServer ) |
|
30 { |
|
31 LOG_FUNC |
|
32 |
|
33 CUsbWatcherSession* r = new ( ELeave ) CUsbWatcherSession( aServer ); |
|
34 CleanupStack::PushL( r ); |
|
35 r->ConstructL(); |
|
36 CleanupStack::Pop(); |
|
37 return r; |
|
38 } |
|
39 |
|
40 // ---------------------------------------------------------------------------- |
|
41 // C++ constructor |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CUsbWatcherSession::CUsbWatcherSession( CUsbWatcherServer* aServer ) |
|
45 : iUsbWatcherServer( aServer ) |
|
46 { |
|
47 LOG_FUNC |
|
48 |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // Second-phase constructor |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 void CUsbWatcherSession::ConstructL() |
|
56 { |
|
57 LOG_FUNC |
|
58 |
|
59 iUsbWatcherServer->Watcher().RegisterObserverL( this ); |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------------------------- |
|
63 // Desstructor |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 CUsbWatcherSession::~CUsbWatcherSession() |
|
67 { |
|
68 LOG_FUNC |
|
69 |
|
70 // if server isn't exist then session can not be exist |
|
71 if ( iUsbWatcherServer ) |
|
72 { |
|
73 iUsbWatcherServer->Watcher().DeRegisterObserver( this ); |
|
74 } |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // Request handle entry point |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 void CUsbWatcherSession::ServiceL( const RMessage2& aMessage ) |
|
82 { |
|
83 LOG_FUNC |
|
84 |
|
85 DispatchMessageL( aMessage ); |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // Request dispatch function |
|
90 // ---------------------------------------------------------------------------- |
|
91 // |
|
92 void CUsbWatcherSession::DispatchMessageL( const RMessage2& aMessage ) |
|
93 { |
|
94 LOG_FUNC |
|
95 |
|
96 LOG1( "Message = %d", aMessage.Function() ); |
|
97 |
|
98 TBool complete( ETrue ); |
|
99 TInt ret( KErrNone ); |
|
100 |
|
101 |
|
102 switch ( aMessage.Function() ) |
|
103 { |
|
104 case EUsbWatcherSetPersonality: |
|
105 ret = SetPersonality( aMessage, complete ); |
|
106 break; |
|
107 |
|
108 case EUsbWatcherCancelSetPersonality: |
|
109 ret = CancelSetPersonality( aMessage, complete ); |
|
110 break; |
|
111 |
|
112 case EUsbWatcherSetPreviousPersonality: |
|
113 ret = SetPreviousPersonality( aMessage, complete ); |
|
114 break; |
|
115 |
|
116 case EUsbWatcherSetPreviousPersonalitySync: |
|
117 ret = SetPreviousPersonalitySync( aMessage, complete ); |
|
118 break; |
|
119 |
|
120 case EUsbWatcherCancelSetPreviousPersonality: |
|
121 ret = CancelSetPreviousPersonality( aMessage, complete ); |
|
122 break; |
|
123 |
|
124 case EUsbWatcherSetPreviousPersonalityOnDisconnect: |
|
125 ret = SetPreviousPersonalityOnDisconnect( aMessage, complete ); |
|
126 break; |
|
127 |
|
128 default: |
|
129 aMessage.Panic( KUsbWatcherCliPncCat, EUsbWatcherPanicIllegalIPC ); |
|
130 break; |
|
131 } |
|
132 |
|
133 if ( complete ) |
|
134 { |
|
135 aMessage.Complete( ret ); |
|
136 } |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------------------------- |
|
140 // Set certain personality |
|
141 // ---------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CUsbWatcherSession::SetPersonality( const RMessage2& aMessage, |
|
144 TBool& aComplete ) |
|
145 { |
|
146 LOG_FUNC |
|
147 |
|
148 if( iSetPersonalityOutstanding ) |
|
149 { |
|
150 LOG( "Completing outstanding" ); |
|
151 iSetPersonalityMessage.Complete( KErrNone ); |
|
152 iSetPersonalityOutstanding = EFalse; |
|
153 } |
|
154 |
|
155 // Cancel all other pending requests |
|
156 iUsbWatcherServer->Watcher().Notify( KErrCancel ); |
|
157 |
|
158 iSetPersonalityMessage = aMessage; |
|
159 aComplete = EFalse; |
|
160 iSetPersonalityOutstanding = ETrue; |
|
161 |
|
162 //Set force parameter to this session. |
|
163 SetAskOnConnectionSuppression( aMessage.Int1() ); |
|
164 |
|
165 iUsbWatcherServer->Watcher().SetPersonality( aMessage.Int0(), |
|
166 static_cast<TBool>( aMessage.Int2() ) ); |
|
167 |
|
168 return KErrNone; |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // Cancel pending set personality request |
|
173 // ---------------------------------------------------------------------------- |
|
174 // |
|
175 TInt CUsbWatcherSession::CancelSetPersonality( const RMessage2& aMessage, |
|
176 TBool& aComplete ) |
|
177 { |
|
178 LOG_FUNC |
|
179 |
|
180 if ( !iSetPersonalityOutstanding ) |
|
181 { |
|
182 LOG( "No outstanding SetPersonality request" ); |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 SetAskOnConnectionSuppression( EFalse ); |
|
187 aComplete = EFalse; |
|
188 iCancelSetPersonalityMessage = aMessage; |
|
189 iCancelSetPersonalityOutstanding = ETrue; |
|
190 |
|
191 iUsbWatcherServer->Watcher().CancelSetPersonality(); |
|
192 |
|
193 return KErrNone; |
|
194 } |
|
195 |
|
196 // ---------------------------------------------------------------------------- |
|
197 // Change to previous personality, asynchronous version |
|
198 // ---------------------------------------------------------------------------- |
|
199 // |
|
200 TInt CUsbWatcherSession::SetPreviousPersonality( const RMessage2& aMessage, |
|
201 TBool& aComplete ) |
|
202 { |
|
203 LOG_FUNC |
|
204 |
|
205 if( iSetPreviousPersonalityOutstanding ) |
|
206 { |
|
207 iSetPreviousPersonalityMessage.Complete( KErrNone ); |
|
208 iSetPreviousPersonalityOutstanding = EFalse; |
|
209 } |
|
210 |
|
211 // Cancel all other pending requests |
|
212 iUsbWatcherServer->Watcher().Notify( KErrCancel ); |
|
213 |
|
214 SetAskOnConnectionSuppression( EFalse ); |
|
215 iSetPreviousPersonalityOutstanding = ETrue; |
|
216 iSetPreviousPersonalityMessage = aMessage; |
|
217 aComplete = EFalse; |
|
218 |
|
219 iUsbWatcherServer->Watcher().SetPreviousPersonality(); |
|
220 |
|
221 return KErrNone; |
|
222 } |
|
223 |
|
224 // ---------------------------------------------------------------------------- |
|
225 // Change to previous personality, synchronous version |
|
226 // ---------------------------------------------------------------------------- |
|
227 // |
|
228 TInt CUsbWatcherSession::SetPreviousPersonalitySync( const RMessage2& /*aMsg*/, |
|
229 TBool& /*aComplete*/ ) |
|
230 { |
|
231 LOG_FUNC |
|
232 |
|
233 if( iSetPreviousPersonalityOutstanding ) |
|
234 { |
|
235 iSetPreviousPersonalityMessage.Complete( KErrNone ); |
|
236 iSetPreviousPersonalityOutstanding = EFalse; |
|
237 } |
|
238 |
|
239 // Cancel all other pending requests |
|
240 iUsbWatcherServer->Watcher().Notify( KErrCancel ); |
|
241 |
|
242 SetAskOnConnectionSuppression( EFalse ); |
|
243 iUsbWatcherServer->Watcher().SetPreviousPersonality(); |
|
244 |
|
245 return KErrNone; |
|
246 } |
|
247 |
|
248 // ---------------------------------------------------------------------------- |
|
249 // Cancel pending request to set previous personality |
|
250 // ---------------------------------------------------------------------------- |
|
251 // |
|
252 TInt CUsbWatcherSession::CancelSetPreviousPersonality( const RMessage2& aMsg, |
|
253 TBool& aComplete ) |
|
254 { |
|
255 LOG_FUNC |
|
256 |
|
257 if( !iSetPreviousPersonalityOutstanding ) |
|
258 { |
|
259 return KErrNone; |
|
260 } |
|
261 |
|
262 aComplete = EFalse; |
|
263 iCancelSetPreviousPersonalityMessage = aMsg; |
|
264 iCancelSetPreviousPersonalityOutstanding = ETrue; |
|
265 |
|
266 iUsbWatcherServer->Watcher().CancelSetPreviousPersonality(); |
|
267 |
|
268 return KErrNone; |
|
269 } |
|
270 |
|
271 // ---------------------------------------------------------------------------- |
|
272 // Set the flag to restore personality when disconnected |
|
273 // ---------------------------------------------------------------------------- |
|
274 // |
|
275 TInt CUsbWatcherSession::SetPreviousPersonalityOnDisconnect( const RMessage2& |
|
276 /*aMessage*/, TBool& /*aComplete*/ ) |
|
277 { |
|
278 LOG_FUNC |
|
279 |
|
280 //connected currently, so ask on connection can be enabled |
|
281 SetAskOnConnectionSuppression( EFalse ); |
|
282 iUsbWatcherServer->Watcher().SetPreviousPersonalityOnDisconnect(); |
|
283 |
|
284 return KErrNone; |
|
285 } |
|
286 |
|
287 // ---------------------------------------------------------------------------- |
|
288 // Complete request |
|
289 // ---------------------------------------------------------------------------- |
|
290 // |
|
291 void CUsbWatcherSession::Notify( TInt /*aPersonalityId*/, TInt aStatus ) |
|
292 { |
|
293 LOG_FUNC |
|
294 |
|
295 if( iCancelSetPersonalityOutstanding ) |
|
296 { |
|
297 iCancelSetPersonalityOutstanding = EFalse; |
|
298 iCancelSetPersonalityMessage.Complete( KErrNone ); |
|
299 |
|
300 iSetPersonalityMessage.Complete( aStatus ); |
|
301 iSetPersonalityOutstanding = EFalse; |
|
302 } |
|
303 |
|
304 if ( iSetPersonalityOutstanding ) |
|
305 { |
|
306 iSetPersonalityMessage.Complete( aStatus ); |
|
307 iSetPersonalityOutstanding = EFalse; |
|
308 } |
|
309 |
|
310 if ( iCancelSetPreviousPersonalityOutstanding ) |
|
311 { |
|
312 iCancelSetPreviousPersonalityOutstanding = EFalse; |
|
313 iCancelSetPreviousPersonalityMessage.Complete( KErrNone ); |
|
314 |
|
315 iSetPreviousPersonalityMessage.Complete( aStatus ); |
|
316 iSetPreviousPersonalityOutstanding = EFalse; |
|
317 } |
|
318 |
|
319 if ( iSetPreviousPersonalityOutstanding ) |
|
320 { |
|
321 iSetPreviousPersonalityMessage.Complete( aStatus ); |
|
322 iSetPreviousPersonalityOutstanding = EFalse; |
|
323 } |
|
324 } |
|
325 |
|
326 // ---------------------------------------------------------------------------- |
|
327 // Set or clear AskOnConnection suppression |
|
328 // ---------------------------------------------------------------------------- |
|
329 // |
|
330 void CUsbWatcherSession::SetAskOnConnectionSuppression( TBool aSuppress ) |
|
331 { |
|
332 LOG_FUNC |
|
333 |
|
334 iSuppressAskOnConnection = aSuppress; |
|
335 } |
|
336 |
|
337 // ---------------------------------------------------------------------------- |
|
338 // Check if AskOnConnection is suppressed |
|
339 // ---------------------------------------------------------------------------- |
|
340 // |
|
341 TBool CUsbWatcherSession::IsAskOnConnectionSuppressed() |
|
342 { |
|
343 LOG_FUNC |
|
344 |
|
345 return iSuppressAskOnConnection; |
|
346 } |
|
347 |
|
348 // End of file |