|
1 /* |
|
2 * Copyright (c) 2007 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: server impl. of session against media server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 // System |
|
25 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
26 |
|
27 // upnp stack api |
|
28 #include <upnpitem.h> |
|
29 #include <upnpattribute.h> |
|
30 #include <upnpstring.h> |
|
31 #include <upnpdlnaprotocolinfo.h> |
|
32 #include <upnpavcontrolpoint.h> |
|
33 |
|
34 // upnpframework / avcontroller helper api |
|
35 #include "upnpconstantdefs.h" // for upnp-specific stuff |
|
36 #include "upnpitemutility.h" // FindElementByNameL, GetResElements |
|
37 |
|
38 // upnpframework / xmlparser api |
|
39 #include "upnpxmlparser.h" |
|
40 |
|
41 // upnpframework / internal api's |
|
42 #include "upnpcdsreselementutility.h" |
|
43 #include "httpuploader.h" |
|
44 #include "upnpmetadatafetcher.h" |
|
45 #include "upnpcommonutils.h" |
|
46 |
|
47 // INTERNAL INCLUDES |
|
48 #include "upnpuploadsession.h" |
|
49 #include "upnpfiletransferitem.h" |
|
50 #include "upnpavcontrollerserver.h" |
|
51 #include "upnpfiletransferitem.h" |
|
52 #include "upnpavdeviceextended.h" |
|
53 #include "upnpavdispatcher.h" |
|
54 #include "upnpaverrorhandler.h" |
|
55 #include "upnpresourcehelper.h" |
|
56 |
|
57 _LIT( KComponentLogfile, "upnpavcontrollerserver.txt"); |
|
58 #include "upnplog.h" |
|
59 |
|
60 // CONSTANTS |
|
61 _LIT8( KImportUri, "importUri" ); |
|
62 _LIT8( KAsterisk, "*" ); |
|
63 const TUint32 KBufferSize = 0x40000; // 256K |
|
64 const TInt KParallerTransfers = 1; |
|
65 |
|
66 // ======== MEMBER FUNCTIONS ======== |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CUPnPUploadSession::NewL |
|
70 // See upnpuploadsession.h |
|
71 // -------------------------------------------------------------------------- |
|
72 CUPnPUploadSession* CUPnPUploadSession::NewL( CUpnpAVControllerServer& |
|
73 aServer, TInt aSessionId, const TDesC8& aUuid ) |
|
74 { |
|
75 CUPnPUploadSession* self = new (ELeave) CUPnPUploadSession( |
|
76 aServer, aSessionId ); |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL( aUuid ); |
|
79 CleanupStack::Pop( self ); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // -------------------------------------------------------------------------- |
|
84 // CUPnPUploadSession::CUPnPUploadSession |
|
85 // See upnpuploadsession.h |
|
86 // -------------------------------------------------------------------------- |
|
87 CUPnPUploadSession::CUPnPUploadSession( CUpnpAVControllerServer& aServer, |
|
88 TInt aSessionId ) : |
|
89 CUPnPFileTransferSessionBase( aServer, aSessionId ), |
|
90 iResourceIndex( KErrNotFound ), |
|
91 iAsyncError( KErrNone ), |
|
92 iIPSessionId( KErrNotFound ), |
|
93 iSchedulerStopped( ETrue ) |
|
94 { |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CUPnPUploadSession::~CUPnPUploadSession |
|
99 // See upnpuploadsession.h |
|
100 // -------------------------------------------------------------------------- |
|
101 CUPnPUploadSession::~CUPnPUploadSession() |
|
102 { |
|
103 __LOG( "CUPnPUploadSession::~CUPnPUploadSession" ); |
|
104 |
|
105 delete iUploader; |
|
106 iResources.ResetAndDestroy(); |
|
107 |
|
108 __LOG( "CUPnPUploadSession::~CUPnPUploadSession - end" ); |
|
109 } |
|
110 |
|
111 // -------------------------------------------------------------------------- |
|
112 // CUPnPUploadSession::ConstructL |
|
113 // See upnpuploadsession.h |
|
114 // -------------------------------------------------------------------------- |
|
115 void CUPnPUploadSession::ConstructL( const TDesC8& aUuid ) |
|
116 { |
|
117 __LOG( "CUPnPUploadSession::ConstructL" ); |
|
118 |
|
119 CUPnPFileTransferSessionBase::ConstructL( aUuid ); |
|
120 |
|
121 iUploader = CHttpUploader::NewL( *this, (TUint32)iServer.IAP(), |
|
122 KBufferSize, KParallerTransfers ); |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // CUPnPDownloadSession::TransferProgress |
|
127 // See upnpdownloadsession.h |
|
128 // -------------------------------------------------------------------------- |
|
129 void CUPnPUploadSession::TransferProgress( TAny* aKey, TInt aBytes, |
|
130 TInt aTotalBytes ) |
|
131 { |
|
132 __LOG( "CUPnPUploadSession::TransferProgress" ); |
|
133 |
|
134 if( iProgressTrackingEnabled ) |
|
135 { |
|
136 TUpnpFileTransferEvent item; |
|
137 TInt err = FindItemByKey( item, (TInt)aKey ); |
|
138 if( err == KErrNone ) |
|
139 { |
|
140 item.iStatus = KErrNone; |
|
141 item.iParam2 = aTotalBytes; |
|
142 item.iParam1 = aBytes; |
|
143 item.iEvent = TUpnpFileTransferEvent::ETransferProgress; |
|
144 |
|
145 Complete( item ); |
|
146 } |
|
147 else |
|
148 { |
|
149 __LOG( "TransferProgress - Not enabled!" ); |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 // -------------------------------------------------------------------------- |
|
155 // CUPnPUploadSession::ReadyForTransfer |
|
156 // See upnpdownloadsession.h |
|
157 // -------------------------------------------------------------------------- |
|
158 void CUPnPUploadSession::ReadyForTransferL( TAny* aKey ) |
|
159 { |
|
160 __LOG( "CUPnPUploadSession::ReadyForTransferL" ); |
|
161 |
|
162 TUpnpFileTransferEvent event; |
|
163 if( FindItemByKey( event, (TInt)aKey, iResourceIndex ) == KErrNone ) |
|
164 { |
|
165 ReadyForTransferL( event ); |
|
166 |
|
167 event.iEvent = TUpnpFileTransferEvent::ETransferStarted; |
|
168 Complete( event ); |
|
169 } |
|
170 else |
|
171 { |
|
172 __LOG( "ReadyForTransfer - Key not found" ); |
|
173 |
|
174 // Not found |
|
175 event.iStatus = KErrGeneral; |
|
176 event.iParam2 = 0; |
|
177 event.iEvent = TUpnpFileTransferEvent::ETransferCompleted; |
|
178 |
|
179 Complete( event ); |
|
180 } |
|
181 } |
|
182 |
|
183 // -------------------------------------------------------------------------- |
|
184 // CUPnPUploadSession::TransferCompleted |
|
185 // See upnpdownloadsession.h |
|
186 // -------------------------------------------------------------------------- |
|
187 void CUPnPUploadSession::TransferCompleted( TAny* aKey, TInt aStatus ) |
|
188 { |
|
189 __LOG2( "CUPnPUploadSession::TransferCompleted, key = %d, status = %d", |
|
190 (TInt)aKey, aStatus ); |
|
191 |
|
192 TUpnpFileTransferEvent item; |
|
193 TInt index; |
|
194 TInt err = FindItemByKey( item, (TInt)aKey, index ); |
|
195 if( err == KErrNone ) |
|
196 { |
|
197 item.iStatus = UPnPAVErrorHandler::ConvertToSymbianErrorCode( aStatus, |
|
198 EUPnPHTTPError ); |
|
199 |
|
200 item.iEvent = TUpnpFileTransferEvent::ETransferCompleted; |
|
201 Complete( item ); |
|
202 |
|
203 iTransferItems.Remove( index ); |
|
204 delete iResources[ index ]; |
|
205 iResources.Remove( index ); |
|
206 } |
|
207 else |
|
208 { |
|
209 __LOG( "TransferCompleted - Key not found" ); |
|
210 |
|
211 // Not found |
|
212 if( aStatus == KErrCancel ) |
|
213 { |
|
214 item.iStatus = aStatus; |
|
215 } |
|
216 else |
|
217 { |
|
218 item.iStatus = KErrGeneral; |
|
219 } |
|
220 |
|
221 item.iParam2 = 0; |
|
222 item.iEvent = TUpnpFileTransferEvent::ETransferCompleted; |
|
223 |
|
224 Complete( item ); |
|
225 } |
|
226 |
|
227 if( aStatus == KErrDisconnected ) |
|
228 { |
|
229 __LOG( "TransferCompleted - Target device lost" ); |
|
230 |
|
231 TInt count = iTransferItems.Count(); |
|
232 for( TInt i = 0; i < count; i++ ) |
|
233 { |
|
234 iUploader->CancelTransfer( (TAny*)iTransferItems[i].iKey ); |
|
235 |
|
236 if( iResources[ i ]->ItemId() ) |
|
237 { |
|
238 // Send destroyobject |
|
239 __LOG( "CancelAllUploadsL - sending destroyobject" ); |
|
240 TRAP_IGNORE( iServer.ControlPoint().CdsDestroyObjectActionL( |
|
241 iDevice->Uuid(), *iResources[ i ]->ItemId() ) ); |
|
242 } |
|
243 } |
|
244 iResources.ResetAndDestroy(); |
|
245 iTransferItems.Reset(); |
|
246 } |
|
247 } |
|
248 |
|
249 // -------------------------------------------------------------------------- |
|
250 // CUPnPUploadSession::CdsCreateObjectResponse |
|
251 // See upnpbrowsingsession.h |
|
252 // -------------------------------------------------------------------------- |
|
253 void CUPnPUploadSession::CdsCreateObjectResponse( |
|
254 const TDesC8& /*aUuid*/, |
|
255 TInt aSessionId, |
|
256 TInt aErr, |
|
257 const TDesC8& /*aContainerID*/, |
|
258 const TDesC8& /*aElements*/, |
|
259 const TDesC8& aObjectID, |
|
260 const TDesC8& aResult ) |
|
261 { |
|
262 __LOG1( "CUPnPUploadSession::CdsCreateObjectResponse: %d" , aErr ); |
|
263 |
|
264 __ASSERTD( iIPSessionId == aSessionId, __FILE__, __LINE__ ); |
|
265 |
|
266 __ASSERTD( iTransferItems.Count() == iResources.Count(), __FILE__, |
|
267 __LINE__ ); |
|
268 |
|
269 iServer.Dispatcher().UnRegister( iIPSessionId ); |
|
270 iIPSessionId = KErrNotFound; |
|
271 |
|
272 aErr = UPnPAVErrorHandler::ConvertToSymbianErrorCode( aErr, |
|
273 EUPnPContentDirectoryError ); |
|
274 |
|
275 if( aErr == KErrNone ) |
|
276 { |
|
277 TRAP( aErr, HandleObjectResponseL( aObjectID, aResult ) ); |
|
278 } |
|
279 |
|
280 iAsyncError = aErr; |
|
281 StopWait(); |
|
282 } |
|
283 |
|
284 // -------------------------------------------------------------------------- |
|
285 // CUPnPUploadSession::StartUploadL |
|
286 // See upnpbrowsingsession.h |
|
287 // -------------------------------------------------------------------------- |
|
288 void CUPnPUploadSession::StartUploadL( const RMessage2& aMessage ) |
|
289 { |
|
290 __LOG( "CUPnPUploadSession::StartUploadL" ); |
|
291 |
|
292 __ASSERTD( iTransferItems.Count() == iResources.Count(), __FILE__, |
|
293 __LINE__ ); |
|
294 |
|
295 CUpnpFileTransferItem* tmpTransferItem = CUpnpFileTransferItem::NewLC(); |
|
296 |
|
297 ReadTransferItemFromMessageL( aMessage, 1 ,tmpTransferItem ); |
|
298 |
|
299 if( CheckIfKeyExists( tmpTransferItem->Key() ) ) |
|
300 { |
|
301 User::Leave( KErrInUse ); |
|
302 } |
|
303 |
|
304 TUpnpFileTransferEvent transferItem; |
|
305 transferItem.iKey = tmpTransferItem->Key(); |
|
306 |
|
307 CUpnpItem* tmpUpnpItem = UPnPMetadataFetcher::CreateItemFromFileLC( |
|
308 tmpTransferItem->Path() ); |
|
309 |
|
310 tmpUpnpItem->SetIdL( KNullDesC8 ); |
|
311 tmpUpnpItem->SetParentIdL( KContainerIdAny ); |
|
312 tmpUpnpItem->SetRestricted( EFalse ); |
|
313 |
|
314 const CUpnpElement& resEl = UPnPItemUtility::FindElementByNameL( |
|
315 *tmpUpnpItem, KElementRes ); |
|
316 |
|
317 const CUpnpAttribute* pInfo = UPnPItemUtility::FindAttributeByName( |
|
318 resEl, KAttributeProtocolInfo ); |
|
319 |
|
320 if( iDevice->DlnaCompatible() ) |
|
321 { |
|
322 // Dlna device, additional checks required |
|
323 __LOG( "StartUploadL - DLNA device" ); |
|
324 |
|
325 TPtrC8 objectClass = tmpUpnpItem->ObjectClass(); |
|
326 if( objectClass.Find( KClassAudio ) != KErrNotFound && |
|
327 iDevice->AudioUpload() ) |
|
328 { |
|
329 // Trying to upload audio and it's supported |
|
330 } |
|
331 else if( objectClass.Find( KClassImage ) != KErrNotFound && |
|
332 iDevice->ImageUpload() ) |
|
333 { |
|
334 // Trying to upload images and it's supported |
|
335 } |
|
336 else if( objectClass.Find( KClassVideo ) != KErrNotFound && |
|
337 iDevice->VideoUpload() ) |
|
338 { |
|
339 // Trying to upload video and it's supported |
|
340 } |
|
341 else |
|
342 { |
|
343 // Unknown media type, or copy not supported |
|
344 __LOG( "StartUploadL - Unknown media type, or copy not \ |
|
345 supported" ); |
|
346 User::Leave( KErrNotSupported ); |
|
347 } |
|
348 |
|
349 if( iDevice->ValidateTransfer( pInfo->Value() ) ) |
|
350 { |
|
351 __LOG( "StartUploadL - Match by protocolInfo succeeded" ); |
|
352 // Continue with DLNA upload |
|
353 // ProtocolInfo is in DLNA format |
|
354 } |
|
355 else |
|
356 { |
|
357 __LOG( "StartUploadL - Match by protocolInfo failed, upload \ |
|
358 as UPnP content" ); |
|
359 // Continue with UPnP upload |
|
360 // Check the protocolInfo |
|
361 ProtocolInfoToUPnPL( pInfo ); |
|
362 } |
|
363 } |
|
364 else |
|
365 { |
|
366 __LOG( "StartUploadL - UPnP Device -> UPnP upload" ); |
|
367 // Continue with UPnP upload |
|
368 // Check the protocolInfo |
|
369 ProtocolInfoToUPnPL( pInfo ); |
|
370 } |
|
371 |
|
372 iUploader->InsertFileIntoWaitQueueL( (TAny*)transferItem.iKey, |
|
373 tmpTransferItem->Path(), KNullDesC8 ); |
|
374 |
|
375 SetHeadersL( pInfo->Value(), (TAny*)transferItem.iKey ); |
|
376 |
|
377 iTransferItems.Append( transferItem ); |
|
378 |
|
379 CUPnPResourceHelper* helper = CUPnPResourceHelper::NewL(); |
|
380 CleanupStack::Pop( tmpUpnpItem ); |
|
381 helper->SetItem( tmpUpnpItem ); // Transfer ownership |
|
382 iResources.Append( helper ); |
|
383 |
|
384 iUploader->MoveToTransferQueueL( (TAny*)transferItem.iKey ); |
|
385 |
|
386 CleanupStack::PopAndDestroy( tmpTransferItem ); |
|
387 |
|
388 aMessage.Complete( KErrNone ); |
|
389 |
|
390 __LOG( "CUPnPUploadSession::StartUploadL - end " ); |
|
391 } |
|
392 |
|
393 // -------------------------------------------------------------------------- |
|
394 // CUPnPUploadSession::CancelUploadL |
|
395 // See upnpbrowsingsession.h |
|
396 // -------------------------------------------------------------------------- |
|
397 void CUPnPUploadSession::CancelUploadL( const RMessage2& aMessage ) |
|
398 { |
|
399 __LOG( "CUPnPUploadSession::CancelUploadL" ); |
|
400 |
|
401 __ASSERTD( iTransferItems.Count() == iResources.Count(), __FILE__, |
|
402 __LINE__ ); |
|
403 |
|
404 TInt key = aMessage.Int1(); |
|
405 |
|
406 TInt index; |
|
407 if( CheckIfKeyExists( key, index ) ) |
|
408 { |
|
409 iUploader->CancelTransfer( (TAny*)key ); |
|
410 aMessage.Complete( KErrNone ); |
|
411 iTransferItems.Remove( index ); |
|
412 if( iResources[ index ]->ItemId() ) |
|
413 { |
|
414 // Send destroyobject |
|
415 iServer.ControlPoint().CdsDestroyObjectActionL( iDevice->Uuid(), |
|
416 *iResources[ index ]->ItemId() ); |
|
417 } |
|
418 delete iResources[index ]; |
|
419 iResources.Remove( index ); |
|
420 } |
|
421 else |
|
422 { |
|
423 aMessage.Complete( KErrNotFound ); |
|
424 } |
|
425 |
|
426 __LOG( "CUPnPUploadSession::CancelUploadL - end" ); |
|
427 } |
|
428 |
|
429 // -------------------------------------------------------------------------- |
|
430 // CUPnPUploadSession::CancelAllUploadsL |
|
431 // See upnpbrowsingsession.h |
|
432 // -------------------------------------------------------------------------- |
|
433 void CUPnPUploadSession::CancelAllUploadsL( const RMessage2& aMessage ) |
|
434 { |
|
435 __LOG( "CUPnPUploadSession::CancelAllUploadsL" ); |
|
436 |
|
437 __ASSERTD( iTransferItems.Count() == iResources.Count(), __FILE__, |
|
438 __LINE__ ); |
|
439 |
|
440 TInt count = iTransferItems.Count(); |
|
441 for( TInt i = 0; i < count; i++ ) |
|
442 { |
|
443 iUploader->CancelTransfer( (TAny*)iTransferItems[i].iKey ); |
|
444 |
|
445 if( iResources[ i ]->ItemId() ) |
|
446 { |
|
447 // Send destroyobject |
|
448 __LOG( "CancelAllUploadsL - sending destroyobject" ); |
|
449 iServer.ControlPoint().CdsDestroyObjectActionL( iDevice->Uuid(), |
|
450 *iResources[ i ]->ItemId() ); |
|
451 } |
|
452 } |
|
453 iResources.ResetAndDestroy(); |
|
454 iTransferItems.Reset(); |
|
455 iEventQueu.Reset(); |
|
456 |
|
457 // Scheduler loop started, stop it and ignore createobject-resp |
|
458 __LOG( "CancelAllUploadsL - Un register" ); |
|
459 iServer.Dispatcher().UnRegister( iIPSessionId ); |
|
460 iIPSessionId = KErrNotFound; |
|
461 iAsyncError = KErrCancel; |
|
462 |
|
463 __LOG( "CancelAllUploadsL - Stop scheduler loop" ); |
|
464 StopWait(); |
|
465 |
|
466 aMessage.Complete( KErrNone ); |
|
467 |
|
468 __LOG( "CUPnPUploadSession::CancelAllUploadsL - end" ); |
|
469 } |
|
470 |
|
471 // -------------------------------------------------------------------------- |
|
472 // CUPnPUploadSession::StartTrackingUploadProgressL |
|
473 // See upnpbrowsingsession.h |
|
474 // -------------------------------------------------------------------------- |
|
475 void CUPnPUploadSession::StartTrackingUploadProgressL( const RMessage2& |
|
476 aMessage ) |
|
477 { |
|
478 __LOG( "CUPnPUploadSession::StartTrackingUploadProgressL" ); |
|
479 |
|
480 TInt key = aMessage.Int1(); |
|
481 if( CheckIfKeyExists( key ) ) |
|
482 { |
|
483 iUploader->TrackProgress( (TAny*)key, ETrue ); |
|
484 iProgressTrackingEnabled = ETrue; |
|
485 aMessage.Complete( KErrNone ); |
|
486 } |
|
487 else |
|
488 { |
|
489 aMessage.Complete( KErrNotFound ); |
|
490 } |
|
491 } |
|
492 |
|
493 // -------------------------------------------------------------------------- |
|
494 // CUPnPUploadSession::StopTrackingUploadProgressL |
|
495 // See upnpbrowsingsession.h |
|
496 // -------------------------------------------------------------------------- |
|
497 void CUPnPUploadSession::StopTrackingUploadProgressL( const RMessage2& |
|
498 aMessage ) |
|
499 { |
|
500 __LOG( "CUPnPUploadSession::StopTrackingUploadProgressL" ); |
|
501 |
|
502 TInt key = aMessage.Int1(); |
|
503 if( CheckIfKeyExists( key ) ) |
|
504 { |
|
505 iUploader->TrackProgress( (TAny*)key, EFalse ); |
|
506 iProgressTrackingEnabled = EFalse; |
|
507 aMessage.Complete( KErrNone ); |
|
508 } |
|
509 else |
|
510 { |
|
511 aMessage.Complete( KErrNotFound ); |
|
512 } |
|
513 } |
|
514 |
|
515 // -------------------------------------------------------------------------- |
|
516 // CUPnPUploadSession::GetUploadEventL |
|
517 // See upnpbrowsingsession.h |
|
518 // -------------------------------------------------------------------------- |
|
519 void CUPnPUploadSession::GetUploadEventL( const RMessage2& aMessage ) |
|
520 { |
|
521 __LOG( "CUPnPUploadSession::GetUploadEventL" ); |
|
522 |
|
523 if( iEventQueu.Count() ) |
|
524 { |
|
525 // There are events in the queu, write the first queued event back |
|
526 // to client |
|
527 __LOG1( "GetUploadEventL - events in queu, count = %d", |
|
528 iEventQueu.Count() ); |
|
529 TPckg<TUpnpFileTransferEvent> resp1( iEventQueu[0] ); |
|
530 aMessage.Write( 1, resp1 ); // Write response using slot 1 |
|
531 aMessage.Complete( KErrNone ); |
|
532 |
|
533 iEventQueu.Remove( 0 ); |
|
534 } |
|
535 else |
|
536 { |
|
537 __ASSERTD( !iEventMsg, __FILE__, __LINE__ ); |
|
538 __LOG( "GetUploadEventL - Store msg" ); |
|
539 iEventMsg = new (ELeave) RMessage2( aMessage ); |
|
540 } |
|
541 __LOG( "CUPnPUploadSession::GetUploadEventL - end" ); |
|
542 } |
|
543 |
|
544 // -------------------------------------------------------------------------- |
|
545 // CUPnPUploadSession::CancelGetUploadEventL |
|
546 // See upnpbrowsingsession.h |
|
547 // -------------------------------------------------------------------------- |
|
548 void CUPnPUploadSession::CancelGetUploadEventL( const RMessage2& aMessage ) |
|
549 { |
|
550 __LOG( "CUPnPUploadSession::CancelGetUploadEventL" ); |
|
551 |
|
552 if( iEventMsg ) |
|
553 { |
|
554 iEventMsg->Complete( KErrCancel ); |
|
555 delete iEventMsg; iEventMsg = NULL; |
|
556 } |
|
557 aMessage.Complete( KErrNone ); |
|
558 } |
|
559 |
|
560 // -------------------------------------------------------------------------- |
|
561 // CUPnPUploadSession::DeviceDisappearedL |
|
562 // See upnpbrowsingsession.h |
|
563 // -------------------------------------------------------------------------- |
|
564 void CUPnPUploadSession::DeviceDisappearedL( |
|
565 CUpnpAVDeviceExtended& aDevice ) |
|
566 { |
|
567 __LOG( "CUPnPUploadSession::DeviceDisappearedL" ); |
|
568 |
|
569 if( aDevice.Uuid().Compare( iDevice->Uuid() ) == 0 ) |
|
570 { |
|
571 TUpnpFileTransferEvent event; |
|
572 event.iEvent = TUpnpFileTransferEvent::EDeviceDisconnected; |
|
573 |
|
574 Complete( event ); |
|
575 } |
|
576 } |
|
577 |
|
578 // -------------------------------------------------------------------------- |
|
579 // CUPnPUploadSession::SetHeadersL |
|
580 // See upnpbrowsingsession.h |
|
581 // -------------------------------------------------------------------------- |
|
582 void CUPnPUploadSession::SetHeadersL( const TDesC8& aInfo, TAny* aKey ) |
|
583 { |
|
584 CUpnpDlnaProtocolInfo* tmpInfo = CUpnpDlnaProtocolInfo::NewL( aInfo ); |
|
585 CleanupStack::PushL( tmpInfo ); |
|
586 |
|
587 // Set the content-type header |
|
588 iUploader->SetHeaderL( aKey, KContentType, |
|
589 tmpInfo->ThirdField() ); |
|
590 |
|
591 // Set the expect header |
|
592 iUploader->SetHeaderL( aKey, KExpectHeader, K100Continue ); |
|
593 |
|
594 CleanupStack::PopAndDestroy( tmpInfo ); |
|
595 } |
|
596 |
|
597 // -------------------------------------------------------------------------- |
|
598 // CUPnPUploadSession::ReadyForTransferL |
|
599 // See upnpbrowsingsession.h |
|
600 // -------------------------------------------------------------------------- |
|
601 void CUPnPUploadSession::ReadyForTransferL( TUpnpFileTransferEvent& aEvent ) |
|
602 { |
|
603 __LOG( "CUPnPUploadSession::ReadyForTransferL" ); |
|
604 |
|
605 if ( !iSchedulerStopped || iWait.IsStarted() ) |
|
606 { |
|
607 __LOG1( "CUPnPUploadSession::ReadyForTransferL\ |
|
608 IsStarted = %d", (TInt)iWait.IsStarted() ); |
|
609 __LOG1( "CUPnPUploadSession::ReadyForTransferL\ |
|
610 iSchedulerStopped = %d", (TInt)iSchedulerStopped ); |
|
611 User::Leave( KErrNotReady ); |
|
612 } |
|
613 |
|
614 __ASSERTD( iTransferItems.Count() == iResources.Count(), __FILE__, |
|
615 __LINE__ ); |
|
616 |
|
617 CUpnpItem* tmpUpnpItem = iResources[ iResourceIndex ]->Item(); |
|
618 if( !tmpUpnpItem ) |
|
619 { |
|
620 User::Leave( KErrCorrupt ); |
|
621 } |
|
622 |
|
623 HBufC8* xmlDoc = CUPnPXMLParser::XmlForCreateObjectLC( |
|
624 *tmpUpnpItem ); |
|
625 |
|
626 iIPSessionId = iServer.ControlPoint().CdsCreateObjectActionL( |
|
627 iDevice->Uuid(), KContainerIdAny, *xmlDoc ); |
|
628 |
|
629 if( iIPSessionId > 0 ) |
|
630 { |
|
631 // Register |
|
632 iServer.Dispatcher().RegisterL( iIPSessionId, *this ); |
|
633 } |
|
634 else |
|
635 { |
|
636 User::Leave( iIPSessionId ); |
|
637 } |
|
638 |
|
639 CleanupStack::PopAndDestroy( xmlDoc ); |
|
640 |
|
641 iWait.Start(); |
|
642 |
|
643 __LOG1( "CUPnPUploadSession::ReadyForTransferL\ |
|
644 iAsyncError = %d", iAsyncError ); |
|
645 |
|
646 User::LeaveIfError( iAsyncError ); |
|
647 |
|
648 const CUpnpElement& resEl = UPnPItemUtility::FindElementByNameL( |
|
649 *iResources[ iResourceIndex ]->Item(), KElementRes ); |
|
650 |
|
651 const CUpnpAttribute* pInfo = UPnPItemUtility::FindAttributeByName( |
|
652 resEl, KAttributeProtocolInfo ); |
|
653 |
|
654 CUpnpDlnaProtocolInfo* tmpInfo = CUpnpDlnaProtocolInfo::NewL( |
|
655 pInfo->Value() ); |
|
656 CleanupStack::PushL( tmpInfo ); |
|
657 |
|
658 // Set DLNA specific headers |
|
659 if( tmpInfo->PnParameter().Length() ) |
|
660 { |
|
661 // DLNA content, set the content-features header |
|
662 iUploader->SetHeaderL( (TAny*)aEvent.iKey, KContentFeatures, |
|
663 tmpInfo->FourthField() ); |
|
664 |
|
665 // Check if background mode is available and use it if it is |
|
666 if( tmpInfo->DlnaFlag( UpnpDlnaProtocolInfo::TM_B_FLAG ) ) |
|
667 { |
|
668 __LOG( "ReadyForTransferL - Use background mode" ); |
|
669 |
|
670 iUploader->SetHeaderL( (TAny*)aEvent.iKey, KTransferMode, |
|
671 KBackgroundMode ); |
|
672 } |
|
673 else |
|
674 { |
|
675 // Background is not available for some reason. |
|
676 // Check if media specific transfer mode is available |
|
677 if( UPnPCommonUtils::IsImageSupported( tmpInfo->ProtocolInfoL() ) ) |
|
678 { |
|
679 // Uploading image, alternative for background is interactive |
|
680 if( tmpInfo->DlnaFlag( UpnpDlnaProtocolInfo::TM_I_FLAG ) ) |
|
681 { |
|
682 __LOG( "ReadyForTransferL - Use interactive mode" ); |
|
683 iUploader->SetHeaderL( (TAny*)aEvent.iKey, KTransferMode, |
|
684 KInteractiveMode ); |
|
685 } |
|
686 else |
|
687 { |
|
688 // Target DMS does not support appropriate transfer mode |
|
689 __LOG( "ReadyForTransferL - No appropriate mode" ); |
|
690 // Still, give a try and use background |
|
691 iUploader->SetHeaderL( (TAny*)aEvent.iKey, KTransferMode, |
|
692 KBackgroundMode ); |
|
693 } |
|
694 } |
|
695 else if( UPnPCommonUtils::IsAudioSupported( |
|
696 tmpInfo->ProtocolInfoL() ) || |
|
697 UPnPCommonUtils::IsVideoSupported( |
|
698 tmpInfo->ProtocolInfoL() ) ) |
|
699 { |
|
700 // Uploading A/V, alternative for background is streaming |
|
701 if( tmpInfo->DlnaFlag( UpnpDlnaProtocolInfo::TM_S_FLAG ) ) |
|
702 { |
|
703 __LOG( "ReadyForTransferL - Use streaming mode" ); |
|
704 iUploader->SetHeaderL( (TAny*)aEvent.iKey, KTransferMode, |
|
705 KStreamingMode ); |
|
706 } |
|
707 else |
|
708 { |
|
709 // Target DMS does not support appropriate transfer mode |
|
710 __LOG( "ReadyForTransferL - No appropriate mode" ); |
|
711 // Still, give a try and use background |
|
712 iUploader->SetHeaderL( (TAny*)aEvent.iKey, KTransferMode, |
|
713 KBackgroundMode ); |
|
714 } |
|
715 } |
|
716 else |
|
717 { |
|
718 __LOG( "ReadyForTransferL - Unknown media type" ); |
|
719 } |
|
720 |
|
721 } |
|
722 |
|
723 } |
|
724 |
|
725 CleanupStack::PopAndDestroy( tmpInfo ); |
|
726 |
|
727 iUploader->SetPropertyL( (TAny*)aEvent.iKey, |
|
728 CHttpTransferBase::ETargetURI, |
|
729 *iResources[ iResourceIndex ]->Resource() ); |
|
730 |
|
731 iUploader->StartTransferL( (TAny*)aEvent.iKey ); |
|
732 |
|
733 __LOG( "CUPnPUploadSession::ReadyForTransferL - end" ); |
|
734 } |
|
735 |
|
736 // -------------------------------------------------------------------------- |
|
737 // CUPnPUploadSession::ParseCreateObjectResponseL |
|
738 // See upnpbrowsingsession.h |
|
739 // -------------------------------------------------------------------------- |
|
740 void CUPnPUploadSession::HandleObjectResponseL( const TDesC8& aObjectID, |
|
741 const TDesC8& aResult ) |
|
742 { |
|
743 __LOG( "CUPnPUploadSession::HandleObjectResponseL" ); |
|
744 |
|
745 HBufC8* importUri = ParseCreateObjectResponseL( aResult ); |
|
746 CleanupStack::PushL( importUri ); |
|
747 |
|
748 HBufC8* tmpUri = UpnpString::EncodeXmlStringL( importUri ); |
|
749 CleanupStack::PopAndDestroy( importUri ); |
|
750 CleanupStack::PushL( tmpUri ); |
|
751 |
|
752 HBufC* tmpUri16 = UpnpString::ToUnicodeL( *tmpUri ); |
|
753 CleanupStack::PopAndDestroy( tmpUri ); |
|
754 |
|
755 iResources[ iResourceIndex ]->SetResource( tmpUri16 ); |
|
756 |
|
757 HBufC8* tmpID = aObjectID.AllocL(); |
|
758 iResources[ iResourceIndex ]->SetItemId( tmpID ); |
|
759 } |
|
760 |
|
761 // -------------------------------------------------------------------------- |
|
762 // CUPnPUploadSession::ParseCreateObjectResponseL |
|
763 // See upnpbrowsingsession.h |
|
764 // -------------------------------------------------------------------------- |
|
765 HBufC8* CUPnPUploadSession::ParseCreateObjectResponseL( |
|
766 const TDesC8& aResponse ) |
|
767 { |
|
768 __LOG( "CUPnPUploadSession::ParseCreateObjectResponseL" ); |
|
769 |
|
770 HBufC8* importURI = NULL; |
|
771 |
|
772 CUPnPXMLParser* parser = CUPnPXMLParser::NewL(); |
|
773 CleanupStack::PushL( parser ); |
|
774 |
|
775 RPointerArray<CUpnpObject> array; |
|
776 CleanupResetAndDestroyPushL( array ); |
|
777 |
|
778 parser->ParseResultDataL( array, aResponse ); |
|
779 |
|
780 TInt count = array.Count(); |
|
781 |
|
782 // Lets find the first item with an import URI and use that |
|
783 for( TInt i = 0; i < count; i++ ) |
|
784 { |
|
785 importURI = ImportURIFromItemL( *array[ i ] ); |
|
786 if( importURI ) |
|
787 { |
|
788 // Transfer ownership, casting is safe |
|
789 // (array[ 0 ]->ObjectType() == EUPnPItem) |
|
790 CUpnpItem* item = static_cast<CUpnpItem*>( array[ i ] ); |
|
791 iResources[ iResourceIndex ]->SetItem( item ); |
|
792 array.Remove( i ); |
|
793 i = count; |
|
794 } |
|
795 } |
|
796 if( !importURI ) // no suitable items, leave |
|
797 { |
|
798 User::Leave( KErrGeneral ); |
|
799 } |
|
800 |
|
801 CleanupStack::PopAndDestroy( &array ); |
|
802 CleanupStack::PopAndDestroy( parser ); |
|
803 |
|
804 if( !UpnpCdsResElementUtility::IsUriAbsolute( *importURI ) ) |
|
805 { |
|
806 // Import uri is not absolute, upload not supported. leave. |
|
807 delete importURI; importURI = NULL; |
|
808 User::Leave( KErrGeneral ); |
|
809 } |
|
810 |
|
811 return importURI; |
|
812 } |
|
813 |
|
814 // -------------------------------------------------------------------------- |
|
815 // CUPnPUploadSession::ImportURIFromItemL |
|
816 // See upnpbrowsingsession.h |
|
817 // -------------------------------------------------------------------------- |
|
818 HBufC8* CUPnPUploadSession::ImportURIFromItemL( const CUpnpObject& aObject ) |
|
819 { |
|
820 HBufC8* importURI = NULL; |
|
821 if( aObject.ObjectType() == EUPnPItem ) |
|
822 { |
|
823 // Get the res-elements |
|
824 RUPnPElementsArray elArray; |
|
825 CleanupClosePushL( elArray ); |
|
826 UPnPItemUtility::GetResElements( aObject, elArray ); |
|
827 |
|
828 // Find the import uri |
|
829 TInt count = elArray.Count(); |
|
830 for( TInt i = 0; i < count; i++ ) |
|
831 { |
|
832 const CUpnpAttribute* attribute = NULL; |
|
833 attribute = &UPnPItemUtility::FindAttributeByNameL( |
|
834 *elArray[ i ], KImportUri ); |
|
835 if( attribute ) |
|
836 { |
|
837 // import uri found |
|
838 i = count; |
|
839 importURI = attribute->Value().AllocL(); |
|
840 } |
|
841 } |
|
842 CleanupStack::PopAndDestroy( &elArray ); |
|
843 } |
|
844 return importURI; |
|
845 } |
|
846 |
|
847 // -------------------------------------------------------------------------- |
|
848 // CUPnPUploadSession::ProtocolInfoToUPnPL |
|
849 // See upnpbrowsingsession.h |
|
850 // -------------------------------------------------------------------------- |
|
851 void CUPnPUploadSession::ProtocolInfoToUPnPL( const CUpnpAttribute* aInfo ) |
|
852 { |
|
853 __LOG( "CUPnPUploadSession::ProtocolInfoToUPnPL" ); |
|
854 |
|
855 CUpnpDlnaProtocolInfo* destInfo = |
|
856 CUpnpDlnaProtocolInfo::NewL( aInfo->Value() ); |
|
857 CleanupStack::PushL( destInfo ); |
|
858 |
|
859 if( destInfo->PnParameter().Length() ) |
|
860 { |
|
861 __LOG( "ProtocolInfoToUPnPL - Convert to UPnP" ); |
|
862 |
|
863 CUpnpProtocolInfo* targetInfo = CUpnpProtocolInfo::NewL(); |
|
864 CleanupStack::PushL( targetInfo ); |
|
865 |
|
866 targetInfo->SetFirstFieldL( destInfo->FirstField() ); |
|
867 targetInfo->SetSecondFieldL( KAsterisk ); |
|
868 targetInfo->SetThirdFieldL( destInfo->ThirdField() ); |
|
869 targetInfo->SetFourthFieldL( KAsterisk ); |
|
870 |
|
871 // A bit dirty const cast.. but makes implementation much easier |
|
872 CUpnpAttribute* bute = const_cast<CUpnpAttribute*>( aInfo ); |
|
873 bute->SetValueL( targetInfo->ProtocolInfoL() ); |
|
874 |
|
875 CleanupStack::PopAndDestroy( targetInfo ); |
|
876 } |
|
877 else |
|
878 { |
|
879 __LOG( "ProtocolInfoToUPnPL - UPnP content -> do nothing" ); |
|
880 // Not DLNA content, do nothing |
|
881 } |
|
882 |
|
883 CleanupStack::PopAndDestroy( destInfo ); |
|
884 } |
|
885 |
|
886 //--------------------------------------------------------------------------- |
|
887 // CUPnPUploadSession::StopWait() |
|
888 // See upnpbrowsingsession.h |
|
889 //--------------------------------------------------------------------------- |
|
890 // |
|
891 void CUPnPUploadSession::StopWait() |
|
892 { |
|
893 __LOG( "ProtocolInfoToUPnPL::StopWait" ); |
|
894 if ( iWait.IsStarted() ) |
|
895 { |
|
896 if ( iWait.CanStopNow() ) |
|
897 { |
|
898 __LOG( "ProtocolInfoToUPnPL::StopWait - stop" ); |
|
899 iWait.AsyncStop(); |
|
900 iSchedulerStopped = ETrue; |
|
901 } |
|
902 else |
|
903 { |
|
904 __LOG( "CUPnPUploadSession::StopWait\ |
|
905 - not able to stop now, use callback" ); |
|
906 iSchedulerStopped = EFalse; |
|
907 iWait.AsyncStop( TCallBack( |
|
908 SchedulerStoppedCallBack, |
|
909 this ) ); |
|
910 } |
|
911 } |
|
912 } |
|
913 |
|
914 //--------------------------------------------------------------------------- |
|
915 // CUPnPUploadSession::SchedulerStoppedCallBack() |
|
916 // See upnpbrowsingsession.h |
|
917 //--------------------------------------------------------------------------- |
|
918 // |
|
919 TInt CUPnPUploadSession::SchedulerStoppedCallBack( TAny* aPtr ) |
|
920 { |
|
921 CUPnPUploadSession* self = |
|
922 static_cast<CUPnPUploadSession*>( aPtr ); |
|
923 self->DoSchedulerStoppedCallBack(); |
|
924 return 0; |
|
925 } |
|
926 |
|
927 //--------------------------------------------------------------------------- |
|
928 // CUPnPUploadSession::DoSchedulerStoppedCallBack() |
|
929 // See upnpbrowsingsession.h |
|
930 //--------------------------------------------------------------------------- |
|
931 // |
|
932 void CUPnPUploadSession::DoSchedulerStoppedCallBack() |
|
933 { |
|
934 __LOG( "ProtocolInfoToUPnPL::DoSchedulerStoppedCallBack" ); |
|
935 iSchedulerStopped = ETrue; |
|
936 } |
|
937 |
|
938 // End of file |