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() |
38 Destructor. |
41 Destructor. |
39 */ |
42 */ |
40 CMTPConnectionMgr::~CMTPConnectionMgr() |
43 CMTPConnectionMgr::~CMTPConnectionMgr() |
41 { |
44 { |
42 StopTransport( iTransportUid, ETrue ); |
45 StopTransport( iTransportUid, ETrue ); |
43 iConnections.ResetAndDestroy(); |
46 iConnections.ResetAndDestroy(); |
44 iSuspendedTransports.Reset(); |
|
45 iSuspendedTransports.Close(); |
47 iSuspendedTransports.Close(); |
46 delete iTransportTrigger; |
48 delete iTransportTrigger; |
47 __FLOG_CLOSE; |
49 __FLOG_CLOSE; |
48 } |
50 } |
49 |
51 |
96 } |
98 } |
97 |
99 |
98 void CMTPConnectionMgr::ConnectionCloseComplete(const TUint& /*aConnUid*/) |
100 void CMTPConnectionMgr::ConnectionCloseComplete(const TUint& /*aConnUid*/) |
99 { |
101 { |
100 __FLOG(_L8("ConnectionCloseComplete - Entry")); |
102 __FLOG(_L8("ConnectionCloseComplete - Entry")); |
101 ResumeSuspendedTransport(); |
103 if (iTransportUid.iUid != KMTPUsbTransportUid ) |
|
104 { |
|
105 ResumeSuspendedTransport(); |
|
106 } |
|
107 else |
|
108 { |
|
109 iResumeCalled = ETrue; |
|
110 } |
|
111 |
102 __FLOG(_L8("ConnectionCloseComplete - exit")); |
112 __FLOG(_L8("ConnectionCloseComplete - exit")); |
103 } |
113 } |
104 |
114 |
105 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport) |
115 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport) |
106 { |
116 { |
107 |
117 __FLOG(_L8("StartTransportL - Entry")); |
108 TInt32 bluetoothUid = 0x10286FCB; |
118 |
109 |
|
110 RUsb usb; |
119 RUsb usb; |
111 User::LeaveIfError(usb.Connect()); |
120 User::LeaveIfError(usb.Connect()); |
|
121 __FLOG(_L8("after connect, and before call get currentpersonalityid")); |
112 TInt usbMode; |
122 TInt usbMode; |
113 TUsbServiceState usbStat; |
123 TUsbServiceState usbStat; |
114 TInt err = usb.GetCurrentPersonalityId(usbMode); |
124 TInt err = usb.GetCurrentPersonalityId(usbMode); |
115 __FLOG_1(_L8("The return value of GetCurrentPersonalityId is %d"), err); |
125 __FLOG_1(_L8("The return value of GetCurrentPersonalityId is %d"), err); |
116 |
126 |
132 } |
142 } |
133 |
143 |
134 |
144 |
135 |
145 |
136 //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. |
137 if(aTransport.iUid == bluetoothUid && iRemoteDevice.iDeviceAddr != 0 && aTransport != iTransportUid) |
147 if(aTransport.iUid == KMTPBTTransportUid && iRemoteDevice.iDeviceAddr != 0 && aTransport != iTransportUid) |
138 { |
148 { |
139 __FLOG(_L8("StartTransportL with parameter!")); |
149 __FLOG(_L8("StartTransportL with parameter!")); |
140 TMTPBTRemoteDeviceBuf tmpdata(iRemoteDevice); |
150 TMTPBTRemoteDeviceBuf tmpdata(iRemoteDevice); |
141 StartTransportL( aTransport, &tmpdata ); |
151 StartTransportL( aTransport, &tmpdata ); |
142 iRemoteDevice.iDeviceAddr = 0; |
152 iRemoteDevice.iDeviceAddr = 0; |
145 else |
155 else |
146 { |
156 { |
147 __FLOG(_L8("StartTransportL without parameter!")); |
157 __FLOG(_L8("StartTransportL without parameter!")); |
148 StartTransportL( aTransport, NULL ); |
158 StartTransportL( aTransport, NULL ); |
149 } |
159 } |
150 |
160 __FLOG(_L8("StartTransportL - Exit")); |
151 } |
161 } |
152 |
162 |
153 /** |
163 /** |
154 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 |
155 CMTPTransportPlugin interface implementation UID. Only one MTP transport |
165 CMTPTransportPlugin interface implementation UID. Only one MTP transport |
162 */ |
172 */ |
163 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport, const TAny* aParameter) |
173 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport, const TAny* aParameter) |
164 { |
174 { |
165 __FLOG(_L8("StartTransportL - Entry")); |
175 __FLOG(_L8("StartTransportL - Entry")); |
166 |
176 |
167 TInt32 bluetoothUid = 0x10286FCB; |
|
168 |
|
169 if (iTransport) |
177 if (iTransport) |
170 { |
178 { |
171 __FLOG(_L8("The transport is not none.")); |
179 __FLOG(_L8("The transport is not none.")); |
172 if (aTransport != iTransportUid) |
180 if (aTransport != iTransportUid) |
173 { |
181 { |
176 User::Leave(KErrNotSupported); |
184 User::Leave(KErrNotSupported); |
177 } |
185 } |
178 else |
186 else |
179 { |
187 { |
180 __FLOG_1(_L8("Relaunch the transport 0x%X"), iTransportUid.iUid); |
188 __FLOG_1(_L8("Relaunch the transport 0x%X"), iTransportUid.iUid); |
181 if(aTransport.iUid == bluetoothUid) |
189 if(aTransport.iUid == KMTPBTTransportUid) |
182 { |
190 { |
183 iTransport->Stop(*this); |
191 iTransport->Stop(*this); |
184 delete iTransport; |
192 delete iTransport; |
185 |
193 iTransportCount--; |
186 iTransport = CMTPTransportPlugin::NewL(aTransport, aParameter); |
194 iTransport = CMTPTransportPlugin::NewL(aTransport, aParameter); |
187 |
195 |
188 TRAPD(err, iTransport->StartL(*this)); |
196 TRAPD(err, iTransport->StartL(*this)); |
189 if (err != KErrNone) |
197 if (err != KErrNone) |
190 { |
198 { |
191 __FLOG_VA( ( _L8("StartTransportL error, error code = %d"), err) ); |
199 __FLOG_VA( ( _L8("StartTransportL error, error code = %d"), err) ); |
192 delete iTransport; |
200 delete iTransport; |
193 iTransport = NULL; |
201 iTransport = NULL; |
|
202 |
194 User::Leave(err); |
203 User::Leave(err); |
195 } |
204 } |
|
205 iTransportCount++; |
196 iTransportUid = aTransport; |
206 iTransportUid = aTransport; |
197 |
207 |
198 iTransportCount++; |
|
199 } |
208 } |
200 |
209 |
201 } |
210 } |
202 } |
211 } |
203 else |
212 else |
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 /** |