22 #include "mmtptransportconnection.h" |
22 #include "mmtptransportconnection.h" |
23 |
23 |
24 // Class constants. |
24 // Class constants. |
25 __FLOG_STMT(_LIT8(KComponent,"ConnectionMgr");) |
25 __FLOG_STMT(_LIT8(KComponent,"ConnectionMgr");) |
26 |
26 |
|
27 const TUint KMTPUsbTransportUid = 0x102827B2; |
|
28 const TUint KMTPBTTransportUid = 0x10286FCB; |
|
29 |
27 /** |
30 /** |
28 CMTPConnectionMgr factory method. |
31 CMTPConnectionMgr factory method. |
29 @leave If a failure occurs, one of the system wide error codes. |
32 @leave If a failure occurs, one of the system wide error codes. |
30 */ |
33 */ |
31 CMTPConnectionMgr* CMTPConnectionMgr::NewL() |
34 CMTPConnectionMgr* CMTPConnectionMgr::NewL() |
95 } |
98 } |
96 |
99 |
97 void CMTPConnectionMgr::ConnectionCloseComplete(const TUint& /*aConnUid*/) |
100 void CMTPConnectionMgr::ConnectionCloseComplete(const TUint& /*aConnUid*/) |
98 { |
101 { |
99 __FLOG(_L8("ConnectionCloseComplete - Entry")); |
102 __FLOG(_L8("ConnectionCloseComplete - Entry")); |
100 ResumeSuspendedTransport(); |
103 if (iTransportUid.iUid != KMTPUsbTransportUid ) |
|
104 { |
|
105 ResumeSuspendedTransport(); |
|
106 } |
|
107 else |
|
108 { |
|
109 iResumeCalled = ETrue; |
|
110 } |
|
111 |
101 __FLOG(_L8("ConnectionCloseComplete - exit")); |
112 __FLOG(_L8("ConnectionCloseComplete - exit")); |
102 } |
113 } |
103 |
114 |
104 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport) |
115 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport) |
105 { |
116 { |
106 |
117 __FLOG(_L8("StartTransportL - Entry")); |
107 TInt32 bluetoothUid = 0x10286FCB; |
118 |
108 |
|
109 RUsb usb; |
119 RUsb usb; |
110 User::LeaveIfError(usb.Connect()); |
120 User::LeaveIfError(usb.Connect()); |
|
121 __FLOG(_L8("after connect, and before call get currentpersonalityid")); |
111 TInt usbMode; |
122 TInt usbMode; |
112 TUsbServiceState usbStat; |
123 TUsbServiceState usbStat; |
113 TInt err = usb.GetCurrentPersonalityId(usbMode); |
124 TInt err = usb.GetCurrentPersonalityId(usbMode); |
114 __FLOG_1(_L8("The return value of GetCurrentPersonalityId is %d"), err); |
125 __FLOG_1(_L8("The return value of GetCurrentPersonalityId is %d"), err); |
115 |
126 |
131 } |
142 } |
132 |
143 |
133 |
144 |
134 |
145 |
135 //When USB plug out, BT will start Master mode to reconnect remote device. Else BT will start slave mode to listen connection. |
146 //When USB plug out, BT will start Master mode to reconnect remote device. Else BT will start slave mode to listen connection. |
136 if(aTransport.iUid == bluetoothUid && iRemoteDevice.iDeviceAddr != 0 && aTransport != iTransportUid) |
147 if(aTransport.iUid == KMTPBTTransportUid && iRemoteDevice.iDeviceAddr != 0 && aTransport != iTransportUid) |
137 { |
148 { |
138 __FLOG(_L8("StartTransportL with parameter!")); |
149 __FLOG(_L8("StartTransportL with parameter!")); |
139 TMTPBTRemoteDeviceBuf tmpdata(iRemoteDevice); |
150 TMTPBTRemoteDeviceBuf tmpdata(iRemoteDevice); |
140 StartTransportL( aTransport, &tmpdata ); |
151 StartTransportL( aTransport, &tmpdata ); |
141 iRemoteDevice.iDeviceAddr = 0; |
152 iRemoteDevice.iDeviceAddr = 0; |
144 else |
155 else |
145 { |
156 { |
146 __FLOG(_L8("StartTransportL without parameter!")); |
157 __FLOG(_L8("StartTransportL without parameter!")); |
147 StartTransportL( aTransport, NULL ); |
158 StartTransportL( aTransport, NULL ); |
148 } |
159 } |
149 |
160 __FLOG(_L8("StartTransportL - Exit")); |
150 } |
161 } |
151 |
162 |
152 /** |
163 /** |
153 Loads and starts up the MTP transport plug-in with the specified |
164 Loads and starts up the MTP transport plug-in with the specified |
154 CMTPTransportPlugin interface implementation UID. Only one MTP transport |
165 CMTPTransportPlugin interface implementation UID. Only one MTP transport |
161 */ |
172 */ |
162 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport, const TAny* aParameter) |
173 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport, const TAny* aParameter) |
163 { |
174 { |
164 __FLOG(_L8("StartTransportL - Entry")); |
175 __FLOG(_L8("StartTransportL - Entry")); |
165 |
176 |
166 TInt32 bluetoothUid = 0x10286FCB; |
|
167 |
|
168 if (iTransport) |
177 if (iTransport) |
169 { |
178 { |
170 __FLOG(_L8("The transport is not none.")); |
179 __FLOG(_L8("The transport is not none.")); |
171 if (aTransport != iTransportUid) |
180 if (aTransport != iTransportUid) |
172 { |
181 { |
175 User::Leave(KErrNotSupported); |
184 User::Leave(KErrNotSupported); |
176 } |
185 } |
177 else |
186 else |
178 { |
187 { |
179 __FLOG_1(_L8("Relaunch the transport 0x%X"), iTransportUid.iUid); |
188 __FLOG_1(_L8("Relaunch the transport 0x%X"), iTransportUid.iUid); |
180 if(aTransport.iUid == bluetoothUid) |
189 if(aTransport.iUid == KMTPBTTransportUid) |
181 { |
190 { |
182 iTransport->Stop(*this); |
191 iTransport->Stop(*this); |
183 delete iTransport; |
192 delete iTransport; |
184 iTransportCount--; |
193 iTransportCount--; |
185 iTransport = CMTPTransportPlugin::NewL(aTransport, aParameter); |
194 iTransport = CMTPTransportPlugin::NewL(aTransport, aParameter); |
270 { |
279 { |
271 __FLOG(_L8("StopTransport - Entry")); |
280 __FLOG(_L8("StopTransport - Entry")); |
272 |
281 |
273 |
282 |
274 __FLOG_1(_L8("aTransport is 0x%X"), aTransport.iUid); |
283 __FLOG_1(_L8("aTransport is 0x%X"), aTransport.iUid); |
275 __FLOG_1(_L8("iTransportUid is 0x%X"), aTransport.iUid); |
284 __FLOG_1(_L8("iTransportUid is 0x%X"), iTransportUid.iUid); |
|
285 |
|
286 TInt transportId = iTransportUid.iUid; |
276 |
287 |
277 if ( aByBearer ) |
288 if ( aByBearer ) |
278 { |
289 { |
279 UnsuspendTransport( aTransport ); |
290 UnsuspendTransport( aTransport ); |
280 } |
291 } |
288 iTransport->Stop(*this); |
299 iTransport->Stop(*this); |
289 delete iTransport; |
300 delete iTransport; |
290 iTransport = NULL; |
301 iTransport = NULL; |
291 iTransportUid = KNullUid; |
302 iTransportUid = KNullUid; |
292 iTransportCount--; |
303 iTransportCount--; |
|
304 //To be sure Resume is done after StopTransport |
|
305 if( transportId == KMTPUsbTransportUid && iResumeCalled) |
|
306 { |
|
307 ResumeSuspendedTransport(); |
|
308 iResumeCalled = EFalse; |
|
309 } |
|
310 |
293 } |
311 } |
294 |
312 |
295 __FLOG(_L8("StopTransport - Exit")); |
313 __FLOG(_L8("StopTransport - Exit")); |
296 } |
314 } |
297 |
315 |
388 iTransportUid(KNullUid) |
406 iTransportUid(KNullUid) |
389 { |
407 { |
390 __FLOG_OPEN(KMTPSubsystem, KComponent); |
408 __FLOG_OPEN(KMTPSubsystem, KComponent); |
391 iRemoteDevice.iDeviceAddr = 0; |
409 iRemoteDevice.iDeviceAddr = 0; |
392 iRemoteDevice.iDeviceServicePort = 0; |
410 iRemoteDevice.iDeviceServicePort = 0; |
|
411 iResumeCalled = EFalse; |
393 } |
412 } |
394 |
413 |
395 /** |
414 /** |
396 Provides the connections table index of the connection with the specified |
415 Provides the connections table index of the connection with the specified |
397 connection identifier. |
416 connection identifier. |
469 __FLOG( _L8("+ResumeSuspendedTransport") ); |
488 __FLOG( _L8("+ResumeSuspendedTransport") ); |
470 const TInt count = iSuspendedTransports.Count(); |
489 const TInt count = iSuspendedTransports.Count(); |
471 __FLOG_1(_L8("The count number is %d"), count); |
490 __FLOG_1(_L8("The count number is %d"), count); |
472 __FLOG_1(_L8("The transportport id is 0x%X"), iTransportUid.iUid); |
491 __FLOG_1(_L8("The transportport id is 0x%X"), iTransportUid.iUid); |
473 |
492 |
474 TInt32 bluetoothUid = 0x10286FCB; |
|
475 |
|
476 if ( ( count > 0 ) |
493 if ( ( count > 0 ) |
477 // If the transport was just switched and suspended, it shouldn't be resumed. |
494 // If the transport was just switched and suspended, it shouldn't be resumed. |
478 && (( iTransportUid != iSuspendedTransports[count-1] ) || iTransportUid.iUid == bluetoothUid)) |
495 && (( iTransportUid != iSuspendedTransports[count-1] ) || iTransportUid.iUid == KMTPBTTransportUid)) |
479 { |
496 { |
480 __FLOG( _L8("Found suspended transport(s).") ); |
497 __FLOG( _L8("Found suspended transport(s).") ); |
481 if ( !iTransportTrigger ) |
498 if ( !iTransportTrigger ) |
482 { |
499 { |
483 iTransportTrigger = new( ELeave ) CAsyncCallBack( CActive::EPriorityStandard ); |
500 iTransportTrigger = new( ELeave ) CAsyncCallBack( CActive::EPriorityStandard ); |
484 } |
501 } |
485 __ASSERT_DEBUG( ( !iTransportTrigger->IsActive() ), User::Invariant() ); |
502 |
486 TCallBack callback( CMTPConnectionMgr::DoResumeSuspendedTransport, this ); |
503 if ( !iTransportTrigger->IsActive()) |
487 iTransportTrigger->Set( callback ); |
504 { |
488 iTransportTrigger->CallBack(); |
505 __FLOG( _L8("Set call back function!") ); |
|
506 TCallBack callback( CMTPConnectionMgr::DoResumeSuspendedTransport, this ); |
|
507 iTransportTrigger->Set( callback ); |
|
508 iTransportTrigger->CallBack(); |
|
509 } |
|
510 else |
|
511 { |
|
512 __FLOG( _L8("Call back has been set!") ); |
|
513 } |
|
514 |
489 } |
515 } |
490 __FLOG( _L8("-ResumeSuspendedTransport") ); |
516 __FLOG( _L8("-ResumeSuspendedTransport") ); |
491 } |
517 } |
492 |
518 |
493 /** |
519 /** |