browserutilities/downloadmgr/DownloadMgrClntSrv/src/DownloadMgrCod.cpp
changeset 0 dd21522fd290
child 10 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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 the License "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: 
       
    15 *     This file contains the declaration of transaction observer of Download Mgr Server.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "DownloadMgrClient.h"
       
    22 #include "DownloadMgrCod.h"
       
    23 #include "DownloadMgrLogger.h"
       
    24 #include <apgtask.h>
       
    25 #include <eikenv.h>
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KBrowserAppUid = 0x10008D39;
       
    29 // Enough data retrieved for recogntion of internal type in case of DRM
       
    30 const TInt KRespSizeForRecognition = 1024;  //for THttpProgressState EHttpContTypeRecognitionAvail
       
    31 
       
    32 const TInt KDefaultCodDownloadLength = -1;
       
    33 
       
    34 // GLOBAL FUNCTIONS
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // CCodObserver::NewL
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 CCodObserver* CCodObserver::NewL( RHttpDownloadMgr* aDownloadMgr )
       
    43     {
       
    44     CLOG_ENTERFN_NULL("CCodObserver::NewL");
       
    45     
       
    46     CCodObserver* self = new( ELeave ) CCodObserver( aDownloadMgr );
       
    47     
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop();
       
    51 
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // CCodObserver::CCodObserver
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 CCodObserver::CCodObserver( RHttpDownloadMgr* aDownloadMgr )
       
    60     {
       
    61     CLOG_CREATE;
       
    62     CLOG_ENTERFN("CCodObserver::CCodObserver");
       
    63     
       
    64     iDownloadMgr = aDownloadMgr;
       
    65     
       
    66     iCodLength = KDefaultCodDownloadLength;
       
    67     iReadyForPD = EFalse;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CCodObserver::ConstructL
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 void CCodObserver::ConstructL()
       
    75     {
       
    76     CLOG_ENTERFN("CCodObserver::ConstructL");
       
    77     iFilename  = HBufC::NewMaxL( KMaxPath );
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CCodObserver::CCodObserver
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CCodObserver::~CCodObserver()
       
    85     {
       
    86     CLOG_ENTERFN("CCodObserver::~CCodObserver");
       
    87     
       
    88     delete iFilename;
       
    89     
       
    90     CLOG_CLOSE;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CCodObserver::CodEventL
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 void CCodObserver::CodEventL( CCodDownload& aDownload, TEvent aEvent )
       
    98     {
       
    99     CLOG_ENTERFN("CCodObserver::CodEventL");
       
   100 
       
   101     TInt handle =
       
   102         ( (SDMgrCodUserData*)( aDownload.UserData() ) )->iHandle;
       
   103     RHttpDownload* download = NULL;
       
   104     // This leaves when there is no download assotiated with handle   
       
   105     TRAPD( err, download = &iDownloadMgr->DownloadFromHandleL( handle ) );
       
   106     if( err )
       
   107         {
       
   108         return;
       
   109         }
       
   110     
       
   111     const TCodDownloadProgress& progress = aDownload.Progress();
       
   112     SDMgrCodUserData* ptr =(SDMgrCodUserData*)( aDownload.UserData() );
       
   113     ptr->iPrevCodEvent = aEvent;
       
   114 
       
   115     switch( aEvent )
       
   116     	{
       
   117     	case EStart:
       
   118     		{
       
   119     		CLOG_WRITE( "TEvent EStart");
       
   120             download->SetCodInProgress( RHttpDownload::EInProgress );
       
   121 			}
       
   122     		break;
       
   123     		
       
   124     	case ENameChanged:
       
   125     		{
       
   126     		CLOG_WRITE( "TEvent ENameChanged");
       
   127     		
       
   128     		TPtrC ptr = aDownload.Name();
       
   129     		download->SetStringAttribute( EDlAttrName, ptr );
       
   130     		}
       
   131     		break;
       
   132     		
       
   133     	case ETypeChanged:
       
   134     		{
       
   135     		CLOG_WRITE( "TEvent ETypeChanged");
       
   136     		
       
   137     		TPtrC8 ptr = aDownload.Type();
       
   138     		download->SetStringAttribute( EDlAttrContentType, ptr );
       
   139     		}
       
   140     		break;
       
   141     		
       
   142     	case EProgressUpdate:
       
   143     		{
       
   144             CLOG_WRITE( "TEvent EProgressUpdate");
       
   145 
       
   146     	    
       
   147             TInt32 bytesCur = progress.iBytesCur;
       
   148             TInt32 bytesMax = progress.iBytesMax;
       
   149  
       
   150             /*
       
   151             *   Update the length and send only if it is changed
       
   152             */
       
   153             if(iCodLength != bytesMax)
       
   154     		    {
       
   155                 iCodLength = bytesMax;
       
   156                 download->SetIntAttribute( EDlAttrLength, bytesMax );
       
   157                 }
       
   158  
       
   159     		
       
   160             download->SetIntAttribute( EDlAttrDownloadedSize, bytesCur );
       
   161             
       
   162             TPtrC ptr = aDownload.GetPath();
       
   163             
       
   164             /*
       
   165             *   Store the destination file name and temprory file name so that next time send it only if it is changed
       
   166             */
       
   167             if( 0 != ptr.Compare(iFilename->Des()))
       
   168                 {
       
   169                 iFilename->Des().Copy(ptr); ;
       
   170                 download->SetStringAttribute( EDlAttrDestFilename, ptr );            
       
   171                 download->SetStringAttribute( EDlAttrLocalFileName, ptr );
       
   172                 }
       
   173             
       
   174 
       
   175             if ( iReadyForPD && iDlAttrCodPdAvailableSet && ( bytesCur >= KRespSizeForRecognition ) )
       
   176                 {
       
   177                 TInt32 numMediaObjects;
       
   178                 download->GetIntAttribute( EDlAttrNumMediaObjects,numMediaObjects );
       
   179                 if( numMediaObjects>1 )
       
   180                 	{
       
   181                 	//No progressive play for album.So don't set EDlAttrCodPdAvailable to ETrue.
       
   182                 	download->SetBoolAttribute( EDlAttrCodPdAvailable, EFalse );
       
   183                 	}
       
   184                 else
       
   185                 	{
       
   186                 	download->SetBoolAttribute( EDlAttrCodPdAvailable, ETrue );
       
   187                 	}
       
   188 
       
   189                 iDlAttrCodPdAvailableSet = EFalse;
       
   190                 }
       
   191     		}
       
   192     		break;
       
   193     		
       
   194     	case EAccept:
       
   195     	    {
       
   196     	    CLOG_WRITE( "TEvent EAccept");
       
   197     	    download->SetBoolAttribute( EDlAttrCodDescriptorAccepted, ETrue );
       
   198     	    TBool removableMedia = aDownload.RemovableMedia();
       
   199     	    download->SetBoolAttribute( EDlAttrDestRemovable, removableMedia );
       
   200     	    download->iASReady = ETrue;
       
   201     	    }
       
   202     	    break;
       
   203     	    
       
   204     	case EEndLoad:
       
   205     	    {
       
   206     	    CLOG_WRITE( "TEvent EEndLoad");
       
   207     	    download->SetBoolAttribute( EDlAttrCodLoadEnd, ETrue );
       
   208 			download->StopWaitingAS();
       
   209     	    }
       
   210     	    break;
       
   211     	
       
   212     	case EHandlePostResponse:
       
   213     		{
       
   214     		CLOG_WRITE( "TEvent EHandlePostResponse");
       
   215     		HBufC8* url8 = NULL;
       
   216 			TRAP( err, url8 = aDownload.GetPostResponseUrlL() );
       
   217 			if( ( KErrNone == err ) && ( NULL != url8 )  )
       
   218                 {
       
   219                 // Using NextUriOBserver() for initiating the PostResponseURL download	                   
       
   220              	TRAP_IGNORE( iDownloadMgr->NextUriObserver()->NextUriL( *download, *url8 ) );
       
   221                 }
       
   222     		}
       
   223     		break;
       
   224     		
       
   225     	case EDone:
       
   226     		{
       
   227     		CLOG_WRITE( "TEvent EDone");
       
   228 
       
   229             download->SetCodInProgress( RHttpDownload::ENotActive );
       
   230     		if ( download->IsDeleteCodWhenDone() )
       
   231     		    {
       
   232                 CLOG_WRITE( "COD done, delete DL");
       
   233 //    		    download->Delete();
       
   234     		    download->StopWaitingAS();
       
   235     		    }
       
   236     		else
       
   237     		    {
       
   238                 TBool doNextUrl( EFalse );
       
   239         		switch( progress.iState )
       
   240         		    {
       
   241         		    case TCodDownloadProgress::ESucceeded:
       
   242 						{
       
   243                         CLOG_WRITE( "TCodDownloadProgress::ESucceeded");
       
   244                         
       
   245                         for(TInt32 i=1; ; i++)
       
   246                             {
       
   247                             TPtrC ptr = aDownload.GetDestFilePath(i);
       
   248                             if( ptr.Length() == 0)
       
   249                                 {
       
   250                                 break;
       
   251                                 }
       
   252                             download->SetStringAttribute( EDlAttrDestFilename, i, ptr );
       
   253                             }
       
   254                         
       
   255                         doNextUrl = ETrue;
       
   256                         TBool isProgressive = EFalse;
       
   257                         download->GetBoolAttribute( EDlAttrProgressive, isProgressive );
       
   258                         // The browser client should not move the file in case of progressive download.
       
   259                         // It should be done by the MP/VP after the playback we be done.
       
   260                         if (!isProgressive)
       
   261 						    {
       
   262                             download->SetIntAttribute( EDlAttrSucceeded, 0 );
       
   263 						    }
       
   264                         else
       
   265                             {
       
   266                             download->SetIntAttribute( EDlAttrSucceeded, 1 );
       
   267                             }						    
       
   268 						}
       
   269         		        break;       		    
       
   270 
       
   271         		    case TCodDownloadProgress::EFailedTemporary:
       
   272         		    case TCodDownloadProgress::EFailedPermanent:
       
   273         		        {
       
   274                         CLOG_WRITE_FORMAT( "TCodDownloadProgress::EFailedXXX %d", progress.iError );
       
   275 
       
   276                         // bring the error message to forground
       
   277                         if( CEikonEnv::Static() )
       
   278                         {
       
   279 	                        TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
   280 	                        TApaTask task = taskList.FindApp( TUid::Uid( KBrowserAppUid ) );
       
   281 	                        if ( task.Exists() )
       
   282 	                        {
       
   283 	                            task.BringToForeground();
       
   284 	                        }
       
   285                         	
       
   286                         }
       
   287 
       
   288                         if ( progress.iError <= -1000 )
       
   289                         	{
       
   290                         	download->SetOnError( KErrGeneral, (THttpDownloadMgrError)progress.iError );
       
   291                         	}
       
   292                         else
       
   293                         	{
       
   294                         	download->SetOnError( progress.iError );
       
   295                         	}
       
   296                         	
       
   297                         doNextUrl = ETrue;
       
   298         		        }
       
   299         		        break;
       
   300         		        
       
   301         		    case TCodDownloadProgress::EPaused:
       
   302         		        {
       
   303                         CLOG_WRITE_FORMAT( "TCodDownloadProgress::EPaused %d", progress.iError );
       
   304 						download->SetCodInProgress( RHttpDownload::EPaused );
       
   305 						TInt32 dlState;
       
   306 						download->GetIntAttribute( EDlAttrState, dlState );
       
   307 						if( dlState != EHttpDlPaused)
       
   308 						    {
       
   309                             download->Pause();
       
   310 
       
   311                             if ( progress.iError <= -1000 )
       
   312                             	{
       
   313                             	download->SetOnError( KErrGeneral, (THttpDownloadMgrError)progress.iError );
       
   314                             	}
       
   315                             else
       
   316                             	{
       
   317                             	download->SetOnError( progress.iError );
       
   318                             	}
       
   319 						    }
       
   320                         doNextUrl = EFalse;
       
   321         		        }
       
   322         		        break;
       
   323     				}
       
   324                 if( doNextUrl )
       
   325                     {
       
   326                     // follow NextURL
       
   327                     if( NULL != iDownloadMgr->NextUriObserver() )
       
   328                         {
       
   329                         HBufC8* url8 = NULL;
       
   330                         TRAP( err, url8 = aDownload.NextUrlL() );
       
   331                         if( ( KErrNone == err ) && ( NULL != url8 )  )
       
   332                             {                   
       
   333                             TRAP_IGNORE( 
       
   334                                 iDownloadMgr->NextUriObserver()->NextUriL( *download, *url8 ) );
       
   335                             if( url8 )
       
   336                                 {
       
   337                                 delete url8;
       
   338                                 }                            
       
   339                             }
       
   340                         }
       
   341                     }
       
   342                 }
       
   343     		}
       
   344     		break;
       
   345 
       
   346         case EPdPlayAvailable:
       
   347 			{
       
   348               CLOG_WRITE( "TEvent EPdPlayAvailable");
       
   349               iDlAttrCodPdAvailableSet = ETrue;
       
   350 			}
       
   351             break;
       
   352 
       
   353         case EUpdatedDDURI:
       
   354 			{
       
   355             CLOG_WRITE( "TEvent EUpdatedDDURI");
       
   356             HBufC8* updatedDDUri8 = NULL;
       
   357             TRAP( err, updatedDDUri8 = aDownload.UpdatedDDUriL() );              
       
   358             download->SetBoolAttribute( EDlAttrDownloadUpdatedDDUri, ETrue );
       
   359             download->SetStringAttribute( EDlAttrUpdatedDDUri, *updatedDDUri8 );
       
   360             download->SetBoolAttribute ( EDlAttrCodDownload , EFalse);
       
   361             download->Start();
       
   362 			}
       
   363             break;
       
   364             
       
   365         case EResumed:
       
   366     		{
       
   367     		iReadyForPD = ETrue;
       
   368     		iDlAttrCodPdAvailableSet = ETrue;
       
   369     		}
       
   370     		break;
       
   371     		
       
   372         case EDownloadPausable:
       
   373     		{
       
   374             download->SetBoolAttribute ( EDlAttrCodPausable , ETrue);
       
   375     		}
       
   376     		break;    		
       
   377 
       
   378     	case EDownloadNonPausable:
       
   379     		{
       
   380             download->SetBoolAttribute ( EDlAttrCodPausable , EFalse);
       
   381     		}
       
   382     		break;    		
       
   383     		
       
   384     	case EUpdatedMediaInfo:
       
   385     	    {
       
   386     	    HBufC8* mediaInfo8 = NULL;
       
   387     	    TRAP( err, mediaInfo8 = aDownload.UpdatedDownloadDataL() );
       
   388     	    if (mediaInfo8)
       
   389     	        {
       
   390     	        download->SetDownloadDataAttribute(*mediaInfo8);
       
   391     	        delete mediaInfo8;
       
   392     	        }
       
   393     	    }
       
   394     	    break;
       
   395     	    
       
   396 	    case ESetActiveDownload:
       
   397 	        {
       
   398             download->SetIntAttribute ( EDlAttrActiveDownload , aDownload.ActiveDownload());	        
       
   399 	        }
       
   400 	    break;
       
   401 	    
       
   402     	case EUpdatedTrackInfo:
       
   403     		{
       
   404     		HBufC8* trackInfo8 = NULL;
       
   405     		TInt trackIndex = 0;
       
   406     	    TRAP( err, trackInfo8 = aDownload.UpdatedTrackDataL(trackIndex) );
       
   407     	    if (trackInfo8)
       
   408     	        {
       
   409     	        download->SetTrackDataAttribute(trackIndex, *trackInfo8);
       
   410     	        delete trackInfo8;
       
   411     	        }
       
   412     	    }
       
   413     		break;
       
   414         default:
       
   415          	{
       
   416          	__ASSERT_DEBUG( EFalse , User::Panic( _L( "DMgrServer" ), KErrNotFound ) );
       
   417          	}
       
   418     	}    
       
   419     }