93 return iTransportUid; |
95 return iTransportUid; |
94 } |
96 } |
95 |
97 |
96 void CMTPConnectionMgr::ConnectionCloseComplete(const TUint& /*aConnUid*/) |
98 void CMTPConnectionMgr::ConnectionCloseComplete(const TUint& /*aConnUid*/) |
97 { |
99 { |
98 if (iIsTransportStopping) |
100 __FLOG(_L8("ConnectionCloseComplete - Entry")); |
99 { |
101 ResumeSuspendedTransport(); |
100 iIsTransportStopping = EFalse; |
102 __FLOG(_L8("ConnectionCloseComplete - exit")); |
101 ResumeSuspendedTransport(); |
|
102 } |
|
103 } |
103 } |
104 |
104 |
105 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport) |
105 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport) |
106 { |
106 { |
107 StartTransportL( aTransport, NULL ); |
107 |
|
108 TInt32 bluetoothUid = 0x10286FCB; |
|
109 |
|
110 RUsb usb; |
|
111 User::LeaveIfError(usb.Connect()); |
|
112 TInt usbMode; |
|
113 TUsbServiceState usbStat; |
|
114 TInt err = usb.GetCurrentPersonalityId(usbMode); |
|
115 __FLOG_1(_L8("The return value of GetCurrentPersonalityId is %d"), err); |
|
116 |
|
117 err = usb.GetServiceState(usbStat); |
|
118 __FLOG_1(_L8("The return value of GetServiceState is %d"), err); |
|
119 |
|
120 usb.Close(); |
|
121 |
|
122 __FLOG_1(_L8("The current usb mode is %d"), usbMode); |
|
123 __FLOG_1(_L8("The current usb service state is %d"), usbStat); |
|
124 |
|
125 TInt massStorageMode = 0x02; |
|
126 |
|
127 if(usbMode == massStorageMode && usbStat != EUsbServiceIdle) |
|
128 { |
|
129 __FLOG(_L8("StartTransportL without parameter!")); |
|
130 StartTransportL( aTransport, NULL ); |
|
131 return; |
|
132 } |
|
133 |
|
134 |
|
135 |
|
136 //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) |
|
138 { |
|
139 __FLOG(_L8("StartTransportL with parameter!")); |
|
140 TMTPBTRemoteDeviceBuf tmpdata(iRemoteDevice); |
|
141 StartTransportL( aTransport, &tmpdata ); |
|
142 iRemoteDevice.iDeviceAddr = 0; |
|
143 iRemoteDevice.iDeviceServicePort = 0; |
|
144 } |
|
145 else |
|
146 { |
|
147 __FLOG(_L8("StartTransportL without parameter!")); |
|
148 StartTransportL( aTransport, NULL ); |
|
149 } |
|
150 |
108 } |
151 } |
109 |
152 |
110 /** |
153 /** |
111 Loads and starts up the MTP transport plug-in with the specified |
154 Loads and starts up the MTP transport plug-in with the specified |
112 CMTPTransportPlugin interface implementation UID. Only one MTP transport |
155 CMTPTransportPlugin interface implementation UID. Only one MTP transport |
117 @leave One of the system wide error codes, if a processing failure occurs. |
160 @leave One of the system wide error codes, if a processing failure occurs. |
118 @see StopTransport |
161 @see StopTransport |
119 */ |
162 */ |
120 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport, const TAny* aParameter) |
163 EXPORT_C void CMTPConnectionMgr::StartTransportL(TUid aTransport, const TAny* aParameter) |
121 { |
164 { |
122 __FLOG(_L8("StartTransportL - Entry")); |
165 __FLOG(_L8("StartTransportL - Entry")); |
123 |
166 |
|
167 TInt32 bluetoothUid = 0x10286FCB; |
|
168 |
124 if (iTransport) |
169 if (iTransport) |
125 { |
170 { |
|
171 __FLOG(_L8("The transport is not none.")); |
126 if (aTransport != iTransportUid) |
172 if (aTransport != iTransportUid) |
127 { |
173 { |
128 // Multiple transports not currently supported. |
174 // Multiple transports not currently supported. |
|
175 __FLOG(_L8("Multiple transports are not supported now!")); |
129 User::Leave(KErrNotSupported); |
176 User::Leave(KErrNotSupported); |
130 } |
177 } |
|
178 else |
|
179 { |
|
180 __FLOG_1(_L8("Relaunch the transport 0x%X"), iTransportUid.iUid); |
|
181 if(aTransport.iUid == bluetoothUid) |
|
182 { |
|
183 iTransport->Stop(*this); |
|
184 delete iTransport; |
|
185 |
|
186 iTransport = CMTPTransportPlugin::NewL(aTransport, aParameter); |
|
187 |
|
188 TRAPD(err, iTransport->StartL(*this)); |
|
189 if (err != KErrNone) |
|
190 { |
|
191 __FLOG_VA( ( _L8("StartTransportL error, error code = %d"), err) ); |
|
192 delete iTransport; |
|
193 iTransport = NULL; |
|
194 User::Leave(err); |
|
195 } |
|
196 iTransportUid = aTransport; |
|
197 |
|
198 iTransportCount++; |
|
199 } |
|
200 |
|
201 } |
131 } |
202 } |
132 else |
203 else |
133 { |
204 { |
134 |
205 __FLOG(_L8("begin start transport.")); |
135 iTransport = CMTPTransportPlugin::NewL(aTransport, aParameter); |
206 iTransport = CMTPTransportPlugin::NewL(aTransport, aParameter); |
136 |
207 |
137 TRAPD(err, iTransport->StartL(*this)); |
208 TRAPD(err, iTransport->StartL(*this)); |
138 if (err != KErrNone) |
209 if (err != KErrNone) |
139 { |
210 { |
140 __FLOG_VA( ( _L8("StartTransportL error, error code = %d"), err) ); |
211 __FLOG_VA( ( _L8("StartTransportL error, error code = %d"), err) ); |
141 delete iTransport; |
212 delete iTransport; |
142 iTransport = NULL; |
213 iTransport = NULL; |
143 User::Leave(err); |
214 User::Leave(err); |
144 } |
215 } |
145 iTransportUid = aTransport; |
216 iTransportUid = aTransport; |
146 |
217 |
147 iTransportCount++; |
218 iTransportCount++; |
148 UnsuspendTransport( iTransportUid ); |
219 |
|
220 if(iTransportUid.iUid != bluetoothUid) |
|
221 { |
|
222 UnsuspendTransport( iTransportUid ); |
|
223 } |
|
224 else |
|
225 { |
|
226 //Suspend BT transport to handle switching with Mass Storage |
|
227 SuspendTransportL( iTransportUid); |
|
228 } |
149 } |
229 } |
150 |
230 |
151 __FLOG(_L8("StartTransportL - Exit")); |
231 __FLOG(_L8("StartTransportL - Exit")); |
152 } |
232 } |
153 |
233 |
188 */ |
268 */ |
189 EXPORT_C void CMTPConnectionMgr::StopTransport( TUid aTransport, TBool aByBearer ) |
269 EXPORT_C void CMTPConnectionMgr::StopTransport( TUid aTransport, TBool aByBearer ) |
190 { |
270 { |
191 __FLOG(_L8("StopTransport - Entry")); |
271 __FLOG(_L8("StopTransport - Entry")); |
192 |
272 |
|
273 |
|
274 __FLOG_1(_L8("aTransport is 0x%X"), aTransport.iUid); |
|
275 __FLOG_1(_L8("iTransportUid is 0x%X"), aTransport.iUid); |
|
276 |
|
277 if ( aByBearer ) |
|
278 { |
|
279 UnsuspendTransport( aTransport ); |
|
280 } |
|
281 |
193 if ( ( iTransport ) && ( aTransport == iTransportUid ) ) |
282 if ( ( iTransport ) && ( aTransport == iTransportUid ) ) |
194 { |
283 { |
195 if ( !aByBearer ) |
284 if ( !aByBearer ) |
196 { |
285 { |
197 TRAP_IGNORE( SuspendTransportL( aTransport ) ); |
286 TRAP_IGNORE( SuspendTransportL( aTransport ) ); |
198 } |
287 } |
199 iIsTransportStopping = ETrue; |
|
200 iTransport->Stop(*this); |
288 iTransport->Stop(*this); |
201 delete iTransport; |
289 delete iTransport; |
202 iTransport = NULL; |
290 iTransport = NULL; |
203 iTransportUid = KNullUid; |
291 iTransportUid = KNullUid; |
204 iTransportCount--; |
292 iTransportCount--; |
205 } |
293 } |
206 |
294 |
207 if ( aByBearer ) |
|
208 { |
|
209 UnsuspendTransport( aTransport ); |
|
210 } |
|
211 |
|
212 __FLOG(_L8("StopTransport - Exit")); |
295 __FLOG(_L8("StopTransport - Exit")); |
213 } |
296 } |
214 |
297 |
215 /** |
298 /** |
216 Shuts down and unloads all active MTP transport plug-ins. |
299 Shuts down and unloads all active MTP transport plug-ins. |
231 Returns the number of active Transports. |
314 Returns the number of active Transports. |
232 @return Number of active transports |
315 @return Number of active transports |
233 */ |
316 */ |
234 EXPORT_C TInt CMTPConnectionMgr::TransportCount() const |
317 EXPORT_C TInt CMTPConnectionMgr::TransportCount() const |
235 { |
318 { |
236 return iTransportCount; |
319 return iTransportCount; |
|
320 } |
|
321 |
|
322 /* |
|
323 Record the remote device bluetooth address when connection setup. |
|
324 */ |
|
325 EXPORT_C void CMTPConnectionMgr::SetBTResumeParameter(const TBTDevAddr& aBTAddr, const TUint16& aPSMPort) |
|
326 { |
|
327 TInt64 addr(0); |
|
328 TUint8 i(0); |
|
329 addr += aBTAddr[i++]; |
|
330 for(; i<KBTDevAddrSize; ++i) |
|
331 { |
|
332 addr <<= 8; |
|
333 addr += aBTAddr[i]; |
|
334 } |
|
335 |
|
336 iRemoteDevice.iDeviceAddr = addr; |
|
337 iRemoteDevice.iDeviceServicePort = aPSMPort; |
237 } |
338 } |
238 |
339 |
239 TBool CMTPConnectionMgr::ConnectionClosed(MMTPTransportConnection& aTransportConnection) |
340 TBool CMTPConnectionMgr::ConnectionClosed(MMTPTransportConnection& aTransportConnection) |
240 { |
341 { |
241 __FLOG(_L8("ConnectionClosed - Entry")); |
342 __FLOG(_L8("ConnectionClosed - Entry")); |
282 Constructor. |
383 Constructor. |
283 */ |
384 */ |
284 CMTPConnectionMgr::CMTPConnectionMgr() : |
385 CMTPConnectionMgr::CMTPConnectionMgr() : |
285 iConnectionOrder(ConnectionOrderCompare), |
386 iConnectionOrder(ConnectionOrderCompare), |
286 iShutdownConnectionIdx(KErrNotFound), |
387 iShutdownConnectionIdx(KErrNotFound), |
287 iTransportUid(KNullUid), |
388 iTransportUid(KNullUid) |
288 iIsTransportStopping(EFalse) |
389 { |
289 { |
390 __FLOG_OPEN(KMTPSubsystem, KComponent); |
290 __FLOG_OPEN(KMTPSubsystem, KComponent); |
391 iRemoteDevice.iDeviceAddr = 0; |
|
392 iRemoteDevice.iDeviceServicePort = 0; |
291 } |
393 } |
292 |
394 |
293 /** |
395 /** |
294 Provides the connections table index of the connection with the specified |
396 Provides the connections table index of the connection with the specified |
295 connection identifier. |
397 connection identifier. |
364 */ |
466 */ |
365 void CMTPConnectionMgr::ResumeSuspendedTransport() |
467 void CMTPConnectionMgr::ResumeSuspendedTransport() |
366 { |
468 { |
367 __FLOG( _L8("+ResumeSuspendedTransport") ); |
469 __FLOG( _L8("+ResumeSuspendedTransport") ); |
368 const TInt count = iSuspendedTransports.Count(); |
470 const TInt count = iSuspendedTransports.Count(); |
|
471 __FLOG_1(_L8("The count number is %d"), count); |
|
472 __FLOG_1(_L8("The transportport id is 0x%X"), iTransportUid.iUid); |
|
473 |
|
474 TInt32 bluetoothUid = 0x10286FCB; |
|
475 |
369 if ( ( count > 0 ) |
476 if ( ( count > 0 ) |
370 // If the transport was just switched and suspended, it shouldn't be resumed. |
477 // If the transport was just switched and suspended, it shouldn't be resumed. |
371 && ( iTransportUid != iSuspendedTransports[count-1] ) ) |
478 && (( iTransportUid != iSuspendedTransports[count-1] ) || iTransportUid.iUid == bluetoothUid)) |
372 { |
479 { |
373 __FLOG( _L8("Found suspended transport(s).") ); |
480 __FLOG( _L8("Found suspended transport(s).") ); |
374 if ( !iTransportTrigger ) |
481 if ( !iTransportTrigger ) |
375 { |
482 { |
376 iTransportTrigger = new( ELeave ) CAsyncCallBack( CActive::EPriorityStandard ); |
483 iTransportTrigger = new( ELeave ) CAsyncCallBack( CActive::EPriorityStandard ); |