16 * notification of the MTP printer disconnection. |
16 * notification of the MTP printer disconnection. |
17 * |
17 * |
18 */ |
18 */ |
19 |
19 |
20 |
20 |
21 #include <e32debug.h> |
|
22 #include <usbstates.h> |
21 #include <usbstates.h> |
23 #include <rptp.h> |
22 #include <rptp.h> |
24 #include "dpsusbnotifier.h" |
23 #include "dpsusbnotifier.h" |
25 #include "dpsconst.h" |
24 #include "dpsconst.h" |
26 #include "dpsptpnotifier.h" |
25 #include "dpsptpnotifier.h" |
27 #include "dpsconnectnotifier.h" |
26 #include "dpsconnectnotifier.h" |
28 |
27 #include "mtpdebug.h" |
29 #ifdef _DEBUG |
28 #include "OstTraceDefinitions.h" |
30 # define IF_DEBUG(t) {RDebug::t;} |
29 #ifdef OST_TRACE_COMPILER_IN_USE |
31 #else |
30 #include "dpsusbnotifierTraces.h" |
32 # define IF_DEBUG(t) |
|
33 #endif |
31 #endif |
|
32 |
34 |
33 |
35 const TInt KUnknownPersonality = 0; |
34 const TInt KUnknownPersonality = 0; |
36 |
35 |
37 // --------------------------------------------------------------------------- |
36 // --------------------------------------------------------------------------- |
38 // |
37 // |
39 // --------------------------------------------------------------------------- |
38 // --------------------------------------------------------------------------- |
40 // |
39 // |
41 CDpsUsbNotifier* CDpsUsbNotifier::NewL(CDpsEngine* aEngine) |
40 CDpsUsbNotifier* CDpsUsbNotifier::NewL(CDpsEngine* aEngine) |
42 { |
41 { |
43 IF_DEBUG(Print(_L("CDpsUsbNotifier::NewL"))); |
|
44 CDpsUsbNotifier* self = new(ELeave) CDpsUsbNotifier(aEngine); |
42 CDpsUsbNotifier* self = new(ELeave) CDpsUsbNotifier(aEngine); |
45 CleanupStack::PushL(self); |
43 CleanupStack::PushL(self); |
46 self->ConstructL(); |
44 self->ConstructL(); |
47 CleanupStack::Pop(); |
45 CleanupStack::Pop(); |
48 return self; |
46 return self; |
56 CActive(EPriorityNormal), iEngine(aEngine), |
54 CActive(EPriorityNormal), iEngine(aEngine), |
57 iPersonality(KUnknownPersonality), |
55 iPersonality(KUnknownPersonality), |
58 iConnectState(EUsbDeviceStateUndefined), iConfigured(EFalse), |
56 iConnectState(EUsbDeviceStateUndefined), iConfigured(EFalse), |
59 iConnection(CDpsEngine::ENotConnected), iRollback(EFalse) |
57 iConnection(CDpsEngine::ENotConnected), iRollback(EFalse) |
60 { |
58 { |
61 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::Ctor"))); |
59 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_CDPSUSBNOTIFIER_CONS_ENTRY ); |
62 CActiveScheduler::Add(this); |
60 CActiveScheduler::Add(this); |
63 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::Ctor"))); |
61 OstTraceFunctionExit0( CDPSUSBNOTIFIER_CDPSUSBNOTIFIER_CONS_EXIT ); |
64 } |
62 } |
65 |
63 |
66 // --------------------------------------------------------------------------- |
64 // --------------------------------------------------------------------------- |
67 // |
65 // |
68 // --------------------------------------------------------------------------- |
66 // --------------------------------------------------------------------------- |
69 // |
67 // |
70 CDpsUsbNotifier::~CDpsUsbNotifier() |
68 CDpsUsbNotifier::~CDpsUsbNotifier() |
71 { |
69 { |
72 IF_DEBUG(Print(_L(">>>~CDpsUsbNotifier"))); |
70 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_CDPSUSBNOTIFIER_DES_ENTRY ); |
73 Cancel(); |
71 Cancel(); |
74 Rollback(); |
72 Rollback(); |
75 delete iPtpP; iPtpP = NULL; |
73 delete iPtpP; iPtpP = NULL; |
76 delete iConnectP; iConnectP = NULL; |
74 delete iConnectP; iConnectP = NULL; |
77 iUsbM.Close(); |
75 iUsbM.Close(); |
78 iUsbW.Close(); |
76 iUsbW.Close(); |
79 IF_DEBUG(Print(_L("<<<~CDpsUsbNotifier"))); |
77 OstTraceFunctionExit0( CDPSUSBNOTIFIER_CDPSUSBNOTIFIER_DES_EXIT ); |
80 } |
78 } |
81 |
79 |
82 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
83 // |
81 // |
84 // --------------------------------------------------------------------------- |
82 // --------------------------------------------------------------------------- |
85 // |
83 // |
86 void CDpsUsbNotifier::ConstructL() |
84 void CDpsUsbNotifier::ConstructL() |
87 { |
85 { |
88 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::ConstructL"))); |
86 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_CONSTRUCTL_ENTRY ); |
89 User::LeaveIfError(iUsbM.Connect()); |
87 LEAVEIFERROR(iUsbM.Connect(), |
90 User::LeaveIfError(iUsbW.Connect()); |
88 OstTrace1( TRACE_ERROR, CDPSUSBNOTIFIER_CONSTRUCTL, |
|
89 "Connect to iUsbM failed! error code %d", munged_err)); |
|
90 LEAVEIFERROR(iUsbW.Connect(), |
|
91 OstTrace1( TRACE_ERROR, DUP1_CDPSUSBNOTIFIER_CONSTRUCTL, |
|
92 "Connect to iUsbM failed! error code %d", munged_err)); |
91 iPtpP = CDpsPtpNotifier::NewL(this); |
93 iPtpP = CDpsPtpNotifier::NewL(this); |
92 iConnectP = CDpsConnectNotifier::NewL(this); |
94 iConnectP = CDpsConnectNotifier::NewL(this); |
93 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::ConstructL"))); |
95 OstTraceFunctionExit0( CDPSUSBNOTIFIER_CONSTRUCTL_EXIT ); |
94 } |
96 } |
95 |
97 |
96 // --------------------------------------------------------------------------- |
98 // --------------------------------------------------------------------------- |
97 // |
99 // |
98 // --------------------------------------------------------------------------- |
100 // --------------------------------------------------------------------------- |
99 // |
101 // |
100 void CDpsUsbNotifier::WaitForPrinterNotify() |
102 void CDpsUsbNotifier::WaitForPrinterNotify() |
101 { |
103 { |
102 IF_DEBUG(Print(_L("CDpsUsbNotifier::WaitForPrinterNotify"))); |
104 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_WAITFORPRINTERNOTIFY_ENTRY ); |
103 iPtpP->ChangePtpPersonality(); |
105 iPtpP->ChangePtpPersonality(); |
|
106 OstTraceFunctionExit0( CDPSUSBNOTIFIER_WAITFORPRINTERNOTIFY_EXIT ); |
104 } |
107 } |
105 |
108 |
106 // --------------------------------------------------------------------------- |
109 // --------------------------------------------------------------------------- |
107 // |
110 // |
108 // --------------------------------------------------------------------------- |
111 // --------------------------------------------------------------------------- |
109 // |
112 // |
110 void CDpsUsbNotifier::CancelPrinterNotify() |
113 void CDpsUsbNotifier::CancelPrinterNotify() |
111 { |
114 { |
112 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::CancelPrinterNotify"))); |
115 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_CANCELPRINTERNOTIFY_ENTRY ); |
113 if (CDpsEngine::ENotConnected == iConnection) |
116 if (CDpsEngine::ENotConnected == iConnection) |
114 { |
117 { |
115 iPtpP->Cancel(); |
118 iPtpP->Cancel(); |
116 iConfigured = EFalse; |
119 iConfigured = EFalse; |
117 } |
120 } |
123 // iPrinterConnectRequest will be NULL and we don't need to cancel anything |
126 // iPrinterConnectRequest will be NULL and we don't need to cancel anything |
124 if (iEngine->PrinterConnectRequest()) |
127 if (iEngine->PrinterConnectRequest()) |
125 { |
128 { |
126 User::RequestComplete(iEngine->PrinterConnectRequest(), KErrCancel); |
129 User::RequestComplete(iEngine->PrinterConnectRequest(), KErrCancel); |
127 } |
130 } |
128 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::CancelWaitForPrinterNotify"))); |
131 OstTraceFunctionExit0( CDPSUSBNOTIFIER_CANCELPRINTERNOTIFY_EXIT ); |
129 } |
132 } |
130 |
133 |
131 // --------------------------------------------------------------------------- |
134 // --------------------------------------------------------------------------- |
132 // |
135 // |
133 // --------------------------------------------------------------------------- |
136 // --------------------------------------------------------------------------- |
134 // |
137 // |
135 void CDpsUsbNotifier::ConnectNotify() |
138 void CDpsUsbNotifier::ConnectNotify() |
136 { |
139 { |
137 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::ConnectNotify"))); |
140 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_CONNECTNOTIFY_ENTRY ); |
138 iConnectP->ConnectNotify(); |
141 iConnectP->ConnectNotify(); |
139 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::ConnectNotify"))); |
142 OstTraceFunctionExit0( CDPSUSBNOTIFIER_CONNECTNOTIFY_EXIT ); |
140 } |
143 } |
141 |
144 |
142 // --------------------------------------------------------------------------- |
145 // --------------------------------------------------------------------------- |
143 // |
146 // |
144 // --------------------------------------------------------------------------- |
147 // --------------------------------------------------------------------------- |
145 // |
148 // |
146 void CDpsUsbNotifier::Rollback() |
149 void CDpsUsbNotifier::Rollback() |
147 { |
150 { |
148 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::Rollback"))); |
151 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_ROLLBACK_ENTRY ); |
149 // only when the personality has changed, we switch back to the previous |
152 // only when the personality has changed, we switch back to the previous |
150 // personality |
153 // personality |
151 if (iPersonality) |
154 if (iPersonality) |
152 { |
155 { |
153 TInt personalityId = KUsbPersonalityIdMTP; |
156 TInt personalityId = KUsbPersonalityIdMTP; |
154 iUsbM.GetCurrentPersonalityId(personalityId); |
157 iUsbM.GetCurrentPersonalityId(personalityId); |
155 IF_DEBUG(Print(_L("CDpsUsbNotifier::Rollback, current personality= %d"), personalityId)); |
158 OstTrace1( TRACE_NORMAL, CDPSUSBNOTIFIER_ROLLBACK, "current personality= %d", personalityId ); |
156 if(KUsbPersonalityIdPCSuiteMTP != personalityId) |
159 if(KUsbPersonalityIdPCSuiteMTP != personalityId) |
157 { |
160 { |
158 if (!iConfigured || iRollback) |
161 if (!iConfigured || iRollback) |
159 { |
162 { |
160 iUsbW.SetPreviousPersonality(); |
163 iUsbW.SetPreviousPersonality(); |
163 { |
166 { |
164 iUsbW.SetPreviousPersonalityOnDisconnect(); |
167 iUsbW.SetPreviousPersonalityOnDisconnect(); |
165 } |
168 } |
166 } |
169 } |
167 } |
170 } |
168 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::Rollback"))); |
171 OstTraceFunctionExit0( CDPSUSBNOTIFIER_ROLLBACK_EXIT ); |
169 } |
172 } |
170 |
173 |
171 // --------------------------------------------------------------------------- |
174 // --------------------------------------------------------------------------- |
172 // |
175 // |
173 // --------------------------------------------------------------------------- |
176 // --------------------------------------------------------------------------- |
174 // |
177 // |
175 void CDpsUsbNotifier::PtpNotify(TInt aErr) |
178 void CDpsUsbNotifier::PtpNotify(TInt aErr) |
176 { |
179 { |
177 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::PtpNotify %x %d"), |
180 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_PTPNOTIFY_ENTRY ); |
178 iConnectState, aErr)); |
181 OstTraceExt2( TRACE_NORMAL, CDPSUSBNOTIFIER_PTPNOTIFY, "connect status %x, error no %d", iConnectState, aErr ); |
|
182 |
179 if (aErr == KErrNone) |
183 if (aErr == KErrNone) |
180 { |
184 { |
181 // personality changed to MTP, but cable is not connected |
185 // personality changed to MTP, but cable is not connected |
182 if (iConnectState != EUsbDeviceStateUndefined) |
186 if (iConnectState != EUsbDeviceStateUndefined) |
183 { |
187 { |
196 else |
200 else |
197 { |
201 { |
198 iConnection = CDpsEngine::EWrongPrintModeConnected; |
202 iConnection = CDpsEngine::EWrongPrintModeConnected; |
199 User::RequestComplete(iEngine->PrinterConnectRequest(), iConnection); |
203 User::RequestComplete(iEngine->PrinterConnectRequest(), iConnection); |
200 } |
204 } |
201 |
205 |
202 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::PtpNotify"))); |
206 OstTraceFunctionExit0( CDPSUSBNOTIFIER_PTPNOTIFY_EXIT ); |
203 } |
207 } |
204 |
208 |
205 // --------------------------------------------------------------------------- |
209 // --------------------------------------------------------------------------- |
206 // |
210 // |
207 // --------------------------------------------------------------------------- |
211 // --------------------------------------------------------------------------- |
208 // |
212 // |
209 void CDpsUsbNotifier::PersonalityChanged() |
213 void CDpsUsbNotifier::PersonalityChanged() |
210 { |
214 { |
211 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::PersonalityChanged %x"), |
215 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_PERSONALITYCHANGED_ENTRY ); |
212 iPersonality)); |
216 OstTrace1( TRACE_NORMAL, CDPSUSBNOTIFIER_PERSONALITYCHANGED, "iPersonality %x", iPersonality ); |
|
217 |
213 if (iPersonality != KUsbPersonalityIdMTP) |
218 if (iPersonality != KUsbPersonalityIdMTP) |
214 { |
219 { |
215 iConnection = CDpsEngine::EWrongPrintModeConnected; |
220 iConnection = CDpsEngine::EWrongPrintModeConnected; |
216 iConfigured = EFalse; |
221 iConfigured = EFalse; |
217 if (iEngine->PrinterConnectRequest()) |
222 if (iEngine->PrinterConnectRequest()) |
220 iConnection); |
225 iConnection); |
221 } |
226 } |
222 } |
227 } |
223 // when UI gets this notification, it must quit. As the result, the dps |
228 // when UI gets this notification, it must quit. As the result, the dps |
224 // engine will be deleted so we do not need to care the further change. |
229 // engine will be deleted so we do not need to care the further change. |
225 |
230 |
226 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::PersonalityChanged "))); |
231 OstTraceFunctionExit0( CDPSUSBNOTIFIER_PERSONALITYCHANGED_EXIT ); |
227 } |
232 } |
228 |
233 |
229 // --------------------------------------------------------------------------- |
234 // --------------------------------------------------------------------------- |
230 // |
235 // |
231 // --------------------------------------------------------------------------- |
236 // --------------------------------------------------------------------------- |
232 // |
237 // |
233 void CDpsUsbNotifier::RunL() |
238 void CDpsUsbNotifier::RunL() |
234 { |
239 { |
235 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::RunL"))); |
240 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_RUNL_ENTRY ); |
236 |
241 |
237 if (EPrinterAvailable == iStatus.Int()) |
242 if (EPrinterAvailable == iStatus.Int()) |
238 { |
243 { |
239 iConnection = CDpsEngine::EPrinterConnected; |
244 iConnection = CDpsEngine::EPrinterConnected; |
240 iConfigured = ETrue; |
245 iConfigured = ETrue; |
243 else if (iStatus.Int() != KErrCancel) |
248 else if (iStatus.Int() != KErrCancel) |
244 { |
249 { |
245 iConnection = CDpsEngine::EOtherConnected; |
250 iConnection = CDpsEngine::EOtherConnected; |
246 } |
251 } |
247 User::RequestComplete(iEngine->PrinterConnectRequest(), iConnection); |
252 User::RequestComplete(iEngine->PrinterConnectRequest(), iConnection); |
248 |
253 |
249 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::RunL"))); |
254 OstTraceFunctionExit0( CDPSUSBNOTIFIER_RUNL_EXIT ); |
250 } |
255 } |
251 |
256 |
252 // --------------------------------------------------------------------------- |
257 // --------------------------------------------------------------------------- |
253 // |
258 // |
254 // --------------------------------------------------------------------------- |
259 // --------------------------------------------------------------------------- |
255 // |
260 // |
256 void CDpsUsbNotifier::DoCancel() |
261 void CDpsUsbNotifier::DoCancel() |
257 { |
262 { |
258 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::DoCancel"))); |
263 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_DOCANCEL_ENTRY ); |
259 iEngine->Ptp().CancelIsDpsPrinter(); |
264 iEngine->Ptp().CancelIsDpsPrinter(); |
260 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::DoCancel"))); |
265 OstTraceFunctionExit0( CDPSUSBNOTIFIER_DOCANCEL_EXIT ); |
261 } |
266 } |
262 |
267 |
263 // --------------------------------------------------------------------------- |
268 // --------------------------------------------------------------------------- |
264 // |
269 // |
265 // --------------------------------------------------------------------------- |
270 // --------------------------------------------------------------------------- |
266 // |
271 // |
267 TInt CDpsUsbNotifier::RunError(TInt aErr) |
272 TInt CDpsUsbNotifier::RunError(TInt aErr) |
268 { |
273 { |
269 IF_DEBUG(Print(_L("CDpsUsbNotifier::RunError is %d"), aErr)); |
274 OstTraceDef1( OST_TRACE_CATEGORY_PRODUCTION, TRACE_IMPORTANT, CDPSUSBNOTIFIER_RUNERROR, |
|
275 "error code %d", aErr); |
270 return aErr; |
276 return aErr; |
271 } |
277 } |
272 |
278 |
273 // --------------------------------------------------------------------------- |
279 // --------------------------------------------------------------------------- |
274 // |
280 // |
275 // --------------------------------------------------------------------------- |
281 // --------------------------------------------------------------------------- |
276 // |
282 // |
277 void CDpsUsbNotifier::DisconnectNotify(TUsbDeviceState aState) |
283 void CDpsUsbNotifier::DisconnectNotify(TUsbDeviceState aState) |
278 { |
284 { |
279 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::DisconnectNotify %d"), aState)); |
285 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_DISCONNECTNOTIFY_ENTRY ); |
|
286 OstTrace1( TRACE_NORMAL, CDPSUSBNOTIFIER_DISCONNECTNOTIFY, "status %d", aState ); |
|
287 |
280 if (iConfigured) |
288 if (iConfigured) |
281 { |
289 { |
282 iConnection = CDpsEngine::EPrinterDisconnected; |
290 iConnection = CDpsEngine::EPrinterDisconnected; |
283 } |
291 } |
284 else |
292 else |
292 } |
300 } |
293 if (iEngine->PrinterConnectRequest()) |
301 if (iEngine->PrinterConnectRequest()) |
294 { |
302 { |
295 User::RequestComplete(iEngine->PrinterConnectRequest(), iConnection); |
303 User::RequestComplete(iEngine->PrinterConnectRequest(), iConnection); |
296 } |
304 } |
297 |
305 |
298 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::DisconnectNotify"))); |
306 OstTraceFunctionExit0( CDPSUSBNOTIFIER_DISCONNECTNOTIFY_EXIT ); |
299 } |
307 } |
300 |
308 |
301 // --------------------------------------------------------------------------- |
309 // --------------------------------------------------------------------------- |
302 // |
310 // |
303 // --------------------------------------------------------------------------- |
311 // --------------------------------------------------------------------------- |
304 // |
312 // |
305 TInt CDpsUsbNotifier::ConnectState() |
313 TInt CDpsUsbNotifier::ConnectState() |
306 { |
314 { |
307 IF_DEBUG(Print(_L(">>>CDpsUsbNotifier::ConnectState"))); |
315 OstTraceFunctionEntry0( CDPSUSBNOTIFIER_CONNECTSTATE_ENTRY ); |
308 TInt ret = iUsbM.GetDeviceState(iConnectState); |
316 TInt ret = iUsbM.GetDeviceState(iConnectState); |
309 IF_DEBUG(Print(_L("<<<CDpsUsbNotifier::ConnectState %x"), iConnectState)); |
317 OstTraceFunctionExit0( CDPSUSBNOTIFIER_CONNECTSTATE_EXIT ); |
|
318 OstTrace1( TRACE_NORMAL, CDPSUSBNOTIFIER_CONNECTSTATE, "ConnectState %x", iConnectState ); |
|
319 |
310 return ret; |
320 return ret; |
311 } |
321 } |
312 |
322 |
313 // --------------------------------------------------------------------------- |
323 // --------------------------------------------------------------------------- |
314 // |
324 // |