browserutilities/downloadmgr/DownloadMgrServEng/Src/HttpDownloadManagerServerEngine.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002-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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 	//User Includes
       
    23 #include "HttpDownloadManagerServerEngine.h"
       
    24 #include "HttpClientApp.h"
       
    25 #include "HttpDownloadMgrLogger.h"
       
    26 
       
    27 	//System Includes
       
    28 #include <bldvariant.hrh>
       
    29 #include <e32std.h>
       
    30 #include <centralrepository.h>
       
    31 #include <BrowserUiSDKCRKeys.h>
       
    32 #include <DocumentHandler.h>
       
    33 #include <FeatMgr.h>
       
    34 
       
    35 #ifdef RD_MULTIPLE_DRIVE
       
    36 #include <driveinfo.h>
       
    37 #endif //RD_MULTIPLE_DRIVE
       
    38 
       
    39 #ifdef __DOWNLOADMGR_CLOG__
       
    40 #pragma message ( "DMgr Engine logger enabled" )
       
    41 #endif
       
    42 
       
    43 // EXTERNAL DATA STRUCTURES
       
    44 //extern  ?external_data;
       
    45 
       
    46 // EXTERNAL FUNCTION PROTOTYPES  
       
    47 //extern ?external_function( ?arg_type,?arg_type );
       
    48 
       
    49 // CONSTANTS
       
    50 //const ?type ?constant_var = ?constant;
       
    51 _LIT( KDmDefaultDir, "c:\\system\\dmgr\\" );
       
    52 _LIT( KDefaultDriveList, "C;E" );
       
    53 #ifdef RD_MULTIPLE_DRIVE
       
    54 _LIT( KDefaultDriveListSep, ";" );
       
    55 #endif
       
    56 // TODO: Modify KGrandMasterAppUid if stand-alone DMgr app's uid is known")
       
    57 
       
    58 // MACROS
       
    59 //#define ?macro ?macro_def
       
    60 
       
    61 // LOCAL CONSTANTS AND MACROS
       
    62 //const ?type ?constant_var = ?constant;
       
    63 //#define ?macro_name ?macro_def
       
    64 
       
    65 // MODULE DATA STRUCTURES
       
    66 //enum ?declaration
       
    67 //typedef ?declaration
       
    68 
       
    69 // LOCAL FUNCTION PROTOTYPES
       
    70 //?type ?function_name( ?arg_type, ?arg_type );
       
    71 
       
    72 // FORWARD DECLARATIONS
       
    73 //class ?FORWARD_CLASSNAME;
       
    74 
       
    75 // ============================= LOCAL FUNCTIONS ===============================
       
    76 #if defined(_DEBUG)
       
    77 void DMPanic( TInt aPanicCode )
       
    78     {
       
    79     User::Panic( _L("DMEngine"), aPanicCode );
       
    80     }
       
    81 #endif
       
    82 
       
    83 // ============================ MEMBER FUNCTIONS ===============================
       
    84 
       
    85 CMMCNotifier::CMMCNotifier( RProperty* aProperty )
       
    86 	: CActive( EPriorityStandard ) 
       
    87 	,iProperty( aProperty )
       
    88 	{
       
    89     CActiveScheduler::Add( this );
       
    90 	}
       
    91 
       
    92 CMMCNotifier::~CMMCNotifier()
       
    93     {
       
    94     Cancel();
       
    95     }
       
    96     
       
    97 void CMMCNotifier::StartObserving( MMMCObserver* aObserver )
       
    98 	{
       
    99 	__ASSERT_DEBUG( !IsActive(), User::Panic( KNullDesC, KErrInUse) );
       
   100 	
       
   101 	iObserver = aObserver;
       
   102 	
       
   103 	iProperty->Subscribe( iStatus );
       
   104 	SetActive();
       
   105 	}
       
   106 	
       
   107 void CMMCNotifier::RunL()
       
   108     {
       
   109 	TInt value( 0 );
       
   110 	iProperty->Get( value);
       
   111 	
       
   112 	iObserver->MMCModeChanged( value == 1 );
       
   113 	
       
   114 	iProperty->Subscribe( iStatus );
       
   115 	SetActive();
       
   116     }
       
   117     
       
   118 void CMMCNotifier::DoCancel()
       
   119     {
       
   120     iProperty->Cancel();
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CHttpDownloadManagerServerEngine::CHttpDownloadManagerServerEngine
       
   125 // C++ default constructor can NOT contain any code, that
       
   126 // might leave.
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 CHttpDownloadManagerServerEngine::CHttpDownloadManagerServerEngine()
       
   130     : iMMCUniqueID( (TUint)KErrNotFound ),
       
   131     iFeatProgressiveDownload(EFalse)
       
   132     {
       
   133     CLOG_CREATE;
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CHttpDownloadManagerServerEngine::ConstructL
       
   138 // Symbian 2nd phase constructor can leave.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CHttpDownloadManagerServerEngine::ConstructL()
       
   142     {
       
   143     CLOG_NAME( _L("Engine") );
       
   144     LOGGER_ENTERFN( "ConstructL()" );
       
   145 
       
   146     User::LeaveIfError( iRfs.Connect() );
       
   147 	User::LeaveIfError(iRfs.ShareProtected());
       
   148 
       
   149     iDocHandler = CDocumentHandler::NewL();
       
   150     
       
   151     iFeatProgressiveDownload = FeatureManager::FeatureSupported( KFeatureIdBrowserProgressiveDownload );
       
   152     
       
   153     iProperty = new (ELeave) RProperty;
       
   154     CLOG_ATTACH( iProperty, this );
       
   155     iProperty->Attach( KPSUidUikon,KUikMMCInserted );
       
   156     
       
   157     iMMCNotifier = new (ELeave) CMMCNotifier( iProperty );
       
   158     CLOG_ATTACH( iMMCNotifier, this );
       
   159     iMMCNotifier->StartObserving( this );
       
   160 
       
   161     QueryMMCUniqueId();
       
   162 
       
   163     QueryDriveListL();
       
   164 
       
   165     iClientApps = new (ELeave) CArrayPtrFlat<CHttpClientApp>(2);
       
   166 
       
   167     // make directory for the server
       
   168     // No problem if it already exists
       
   169     TInt error = iRfs.MkDirAll( KDmDefaultDir );
       
   170     if( error != KErrNone && error != KErrAlreadyExists )
       
   171         // leave if makedir failed in some way
       
   172         // don't leave if already exists
       
   173         {
       
   174         CLOG_WRITE8_1( "MkDirAll: %d", error );
       
   175         User::Leave( error );
       
   176         }
       
   177 
       
   178     LoadClientsL();
       
   179     
       
   180     // This code generates a unique id for the next download
       
   181     // client will create. It is always the the highest unique
       
   182     // id of all downloads + 1.
       
   183     iNextDownloadId = 1;
       
   184 
       
   185     for( TInt apps = 0; apps < iClientApps->Count(); ++apps )
       
   186         {
       
   187         CArrayPtrFlat<CHttpDownload>* allDownloads = (*iClientApps)[apps]->Downloads();
       
   188 
       
   189         for( TInt i = 0; i < allDownloads->Count(); ++i )
       
   190             {
       
   191             if( iNextDownloadId <= (*allDownloads)[i]->Id() )
       
   192                 {
       
   193                 iNextDownloadId = (*allDownloads)[i]->Id() + 1;
       
   194                 }
       
   195             }
       
   196         }
       
   197     
       
   198     error = iSocketServ.Connect();
       
   199     User::LeaveIfError(error);
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CHttpDownloadManagerServerEngine::NewL
       
   204 // Two-phased constructor.
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C CHttpDownloadManagerServerEngine* 
       
   208                                     CHttpDownloadManagerServerEngine::NewL()
       
   209     {
       
   210     CHttpDownloadManagerServerEngine* self = 
       
   211                             new( ELeave ) CHttpDownloadManagerServerEngine();
       
   212 
       
   213     CleanupStack::PushL( self );
       
   214     self->ConstructL();
       
   215     CleanupStack::Pop();
       
   216 
       
   217     return self;
       
   218     }
       
   219 
       
   220     
       
   221 // Destructor
       
   222 CHttpDownloadManagerServerEngine::~CHttpDownloadManagerServerEngine()
       
   223     {
       
   224     CLOG_WRITE( "~CHttpDownloadManagerServerEngine" );
       
   225 
       
   226     CloseEngine( EFalse );
       
   227     
       
   228     CLOG_CLOSE;
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CHttpDownloadManagerServerEngine::CloseEngine
       
   233 // ?implementation_description
       
   234 // (other items were commented in a header).
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CHttpDownloadManagerServerEngine::CloseEngine( TBool /*bStore*/ )
       
   238     {
       
   239     LOGGER_ENTERFN( "CloseEngine" );
       
   240     iEngineClosing = ETrue;
       
   241 
       
   242     if( iClientApps )
       
   243         {
       
   244         iClientApps->ResetAndDestroy();
       
   245         delete iClientApps; iClientApps = NULL;
       
   246         }
       
   247 
       
   248     if( iMMCNotifier )
       
   249         {
       
   250         iMMCNotifier->Cancel();
       
   251         delete iMMCNotifier; iMMCNotifier = NULL;
       
   252         }
       
   253         
       
   254     delete iProperty; iProperty = NULL;
       
   255 
       
   256     iRfs.Close();
       
   257     iSocketServ.Close();
       
   258     
       
   259     delete iDocHandler; iDocHandler = NULL;
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CHttpDownloadManagerServerEngine::CreateNewClientAppL
       
   264 // ?implementation_description
       
   265 // (other items were commented in a header).
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 EXPORT_C CHttpClientAppInstance* 
       
   269     CHttpDownloadManagerServerEngine::CreateNewClientAppInstanceL( 
       
   270                                             TUint32 aAppUid, 
       
   271                                             MDownloadStateObserver* aObserver,
       
   272                                             TBool aMaster )
       
   273     {
       
   274     LOGGER_ENTERFN( "CreateNewClientAppInstanceL" );
       
   275 
       
   276     // clientApp is stored in iCliendApps array
       
   277     CHttpClientApp* clientApp = CreateNewClientAppL( aAppUid );
       
   278 
       
   279     CHttpClientAppInstance* instance = 
       
   280                         clientApp->CreateNewInstanceL( aObserver,
       
   281                                                        aMaster );
       
   282 
       
   283     return instance;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CHttpDownloadManagerServerEngine::CloseClientInstance
       
   288 // ?implementation_description
       
   289 // (other items were commented in a header).
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 EXPORT_C void CHttpDownloadManagerServerEngine::CloseClientInstance( 
       
   293                                               CHttpClientAppInstance* aAppInst )
       
   294     {
       
   295     LOGGER_ENTERFN( "CloseClientInstance" );
       
   296 
       
   297     if( !aAppInst )
       
   298         {
       
   299         return;
       
   300         }
       
   301 
       
   302     __ASSERT_DEBUG( aAppInst->ClientApp(), DMPanic( KErrArgument ) );
       
   303 
       
   304     aAppInst->ClientApp()->CloseInstance( aAppInst );
       
   305     }
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CHttpDownloadManagerServerEngine::ActiveDownloads
       
   309 // ?implementation_description
       
   310 // (other items were commented in a header).
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 EXPORT_C TInt CHttpDownloadManagerServerEngine::ActiveDownloads() const
       
   314     {
       
   315     LOGGER_ENTERFN( "ActiveDownloads" );
       
   316 
       
   317     TInt downloads( 0 );
       
   318 
       
   319     for( TInt apps = 0; apps < iClientApps->Count(); ++apps )
       
   320         {
       
   321         CArrayPtrFlat<CHttpDownload>* dlArray = (*iClientApps)[apps]->Downloads();
       
   322 
       
   323         for( TInt dl = 0; dl < dlArray->Count(); ++dl )
       
   324             {
       
   325             if( (*dlArray)[dl]->State() == EHttpDlInprogress )
       
   326                 {
       
   327                 ++downloads;
       
   328                 }
       
   329             }
       
   330         }
       
   331 
       
   332     return downloads;
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CHttpDownloadManagerServerEngine::AllDownloadsSizeL
       
   337 // ?implementation_description
       
   338 // (other items were commented in a header).
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 TInt CHttpDownloadManagerServerEngine::AllDownloadsSizeL(const CHttpDownload *aDownload) const
       
   342     {
       
   343     LOGGER_ENTERFN( "AllDownloadsSize" );
       
   344 
       
   345     TInt allDownloadsSize( 0 );
       
   346     TInt numClientApps = iClientApps->Count();
       
   347     for( TInt apps = 0; apps < numClientApps; ++apps )
       
   348         {
       
   349         CArrayPtrFlat<CHttpDownload>* dlArray = (*iClientApps)[apps]->Downloads();
       
   350         TInt numDownloads = dlArray->Count();
       
   351         for( TInt dl = 0; dl < numDownloads; ++dl )
       
   352             {
       
   353             if( ( aDownload != (*dlArray)[dl]) && (*dlArray)[dl]->State() != EHttpDlMultipleMOCompleted)
       
   354                 {
       
   355                 TInt32 totalSize(0);
       
   356                 TInt32 downloadedSize(0);
       
   357                 
       
   358                 (*dlArray)[dl]->GetIntAttributeL(EDlAttrMultipleMOLength, totalSize);
       
   359                 (*dlArray)[dl]->GetIntAttributeL(EDlAttrMultipleMODownloadedSize, downloadedSize);
       
   360 
       
   361                 //Do not conside the downloads with unknown size
       
   362                 if(KDefaultContentLength != totalSize)
       
   363                 	allDownloadsSize += (totalSize - downloadedSize);
       
   364                 }
       
   365             }
       
   366         }
       
   367     
       
   368     return allDownloadsSize;
       
   369     }
       
   370 
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CHttpDownloadManagerServerEngine::AllDownloadsSizeInDriveL
       
   374 // ?implementation_description
       
   375 // (other items were commented in a header).
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 TInt CHttpDownloadManagerServerEngine::AllDownloadsSizeInDriveL(const CHttpDownload *aDownload, TInt aDriveId) const
       
   379     {
       
   380     LOGGER_ENTERFN( "AllDownloadsSizeInDriveL" );
       
   381 
       
   382     TInt allDownloadsSize( 0 );
       
   383     TInt numClientApps = iClientApps->Count();
       
   384     for( TInt apps = 0; apps < numClientApps; ++apps )
       
   385         {
       
   386         CArrayPtrFlat<CHttpDownload>* dlArray = (*iClientApps)[apps]->Downloads();
       
   387         TInt numDownloads = dlArray->Count();
       
   388         for( TInt dl = 0; dl < numDownloads; ++dl )
       
   389             {
       
   390             if( ( aDownload != (*dlArray)[dl]) && (*dlArray)[dl]->State() != EHttpDlMultipleMOCompleted 
       
   391                   && aDriveId == (*dlArray)[dl]->GetDestinationDriveID())
       
   392                 {
       
   393                 TInt32 totalSize(0);
       
   394                 TInt32 downloadedSize(0);
       
   395                 
       
   396                 (*dlArray)[dl]->GetIntAttributeL(EDlAttrMultipleMOLength, totalSize);
       
   397                 (*dlArray)[dl]->GetIntAttributeL(EDlAttrMultipleMODownloadedSize, downloadedSize);
       
   398 
       
   399                 //Do not conside the downloads with unknown size
       
   400                 if(KDefaultContentLength != totalSize)
       
   401                 	allDownloadsSize += (totalSize - downloadedSize);
       
   402                 }
       
   403             }
       
   404         }
       
   405     
       
   406     return allDownloadsSize;
       
   407     }
       
   408 // -----------------------------------------------------------------------------
       
   409 // CHttpDownloadManagerServerEngine::IsDownloadAttached
       
   410 // ?implementation_description
       
   411 // (other items were commented in a header).
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 TBool CHttpDownloadManagerServerEngine::IsAttachedAlready(TInt32 aDownloadId)
       
   415 {
       
   416     LOGGER_ENTERFN( "IsAttachedAlready" );
       
   417 
       
   418     for( TInt apps = 0; apps < iClientApps->Count(); ++apps )
       
   419         {
       
   420         CArrayPtrFlat<CHttpDownload>* dlArray = (*iClientApps)[apps]->Downloads();
       
   421 
       
   422         for( TInt dl = 0; dl < dlArray->Count(); ++dl )
       
   423             {
       
   424             if( (*dlArray)[dl]->Id() == aDownloadId )
       
   425                 {
       
   426 				if ((*dlArray)[dl]->PDClientAppInstance())
       
   427 					{
       
   428 						return ETrue;
       
   429 					}
       
   430                 }
       
   431             }
       
   432         }
       
   433 
       
   434     return EFalse;
       
   435 
       
   436 }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CHttpDownloadManagerServerEngine::FindDownload
       
   440 // ?implementation_description
       
   441 // (other items were commented in a header).
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 CHttpDownload* 
       
   445     CHttpDownloadManagerServerEngine::FindDownload( TInt32 aDownloadId )
       
   446     {
       
   447     for( TInt apps = 0; apps < iClientApps->Count(); ++apps )
       
   448         {
       
   449         CArrayPtrFlat<CHttpDownload>* allDownloads = (*iClientApps)[apps]->Downloads();
       
   450 
       
   451         for( TInt i = 0; i < allDownloads->Count(); ++i )
       
   452             {
       
   453             if( (*allDownloads)[i]->Id() == aDownloadId )
       
   454                 {
       
   455                 return (*allDownloads)[i];
       
   456                 }
       
   457             }
       
   458         }
       
   459 
       
   460     return NULL;        
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CHttpDownloadManagerServerEngine::CreateNewClientAppL
       
   465 // ?implementation_description
       
   466 // (other items were commented in a header).
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 CHttpClientApp* 
       
   470     CHttpDownloadManagerServerEngine::CreateNewClientAppL( TUint32 aAppUid )
       
   471     {
       
   472     LOGGER_ENTERFN( "CreateNewClientAppL" );
       
   473     CHttpClientApp* clientApp = NULL;
       
   474 
       
   475     // Is this client app already registered?
       
   476     for( TInt index = 0; index < iClientApps->Count(); ++index )
       
   477         {
       
   478         if( (*iClientApps)[index]->AppUid() == aAppUid )
       
   479             {
       
   480             // we found it
       
   481             clientApp = (*iClientApps)[index];
       
   482             clientApp->LoadClientInfoL(KNullDesC);
       
   483             break;
       
   484             }
       
   485         }
       
   486 
       
   487     if( !clientApp )
       
   488         {
       
   489         clientApp = CHttpClientApp::NewL( aAppUid,
       
   490                                           this );
       
   491         CleanupStack::PushL( clientApp );
       
   492         iClientApps->AppendL( clientApp );
       
   493         CleanupStack::Pop( clientApp );
       
   494         }
       
   495 
       
   496     return clientApp;
       
   497     }
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // CHttpDownloadManagerServerEngine::LoadClientsL
       
   501 // ?implementation_description
       
   502 // (other items were commented in a header).
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 void CHttpDownloadManagerServerEngine::LoadClientsL()
       
   506     {
       
   507     LOGGER_ENTERFN( "LoadClientsL" );
       
   508 
       
   509     CDir* dirs = 0;
       
   510     // hidden + system + dir + only these
       
   511     TUint mask = KEntryAttMatchMask | KEntryAttMatchExclusive; 
       
   512 
       
   513     User::LeaveIfError( iRfs.GetDir( KDmDefaultDir, 
       
   514                                      mask, 
       
   515                                      EAscending | EDirsFirst, 
       
   516                                      dirs) );
       
   517     if( dirs && dirs->Count() )
       
   518         {
       
   519         CleanupStack::PushL( dirs );
       
   520 
       
   521         for( TInt ii = 0; ii < dirs->Count(); ++ii )
       
   522             {
       
   523             TEntry entry = (*dirs)[ii];
       
   524 
       
   525             CLOG_WRITE_1( "Found: %S", &entry.iName );
       
   526 
       
   527             TUint32 clientUid = CheckClientDirName( entry.iName );
       
   528             if( clientUid )
       
   529                 {
       
   530                 CreateNewClientAppL( clientUid );
       
   531                 }
       
   532             }
       
   533 
       
   534         CleanupStack::Pop( dirs );
       
   535         }
       
   536 
       
   537     delete dirs;
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CHttpDownloadManagerServerEngine::CheckClientDirName
       
   542 // ?implementation_description
       
   543 // (other items were commented in a header).
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 TUint32 CHttpDownloadManagerServerEngine::CheckClientDirName( TDesC& aClientDir )
       
   547     {
       
   548     TLex temp( aClientDir );
       
   549     TUint32 clientUid( 0 );
       
   550 
       
   551     temp.Val( clientUid, EHex );
       
   552 
       
   553     return clientUid;
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CHttpDownloadManagerServerEngine::ClientAppFolder
       
   558 // ?implementation_description
       
   559 // (other items were commented in a header).
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 void CHttpDownloadManagerServerEngine::ClientAppFolder( 
       
   563                                                     const CHttpClientApp* aClientApp, 
       
   564                                                     TDes& aFolder )
       
   565     {
       
   566     _LIT( KClientAppFolderFormat, "%S%x\\" );
       
   567 
       
   568     aFolder.Format( KClientAppFolderFormat, &KDmDefaultDir, aClientApp->AppUid() );
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // CHttpDownloadManagerServerEngine::ClientAppFolder
       
   573 // ?implementation_description
       
   574 // (other items were commented in a header).
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 void CHttpDownloadManagerServerEngine::ClientAppFolderWithoutDriveLetter( 
       
   578                                         const CHttpClientApp* aClientApp, 
       
   579                                         TDes& aFolder )
       
   580     {
       
   581     _LIT( KClientAppFolderFormat, "%s%x\\" );
       
   582 
       
   583     // [3] cut off the drive letter + ':\\' part
       
   584     aFolder.Format( KClientAppFolderFormat, 
       
   585                     &KDmDefaultDir()[3], 
       
   586                     aClientApp->AppUid() );
       
   587     }
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // CHttpDownloadManagerServerEngine::DownloadInfoFolder
       
   591 // ?implementation_description
       
   592 // (other items were commented in a header).
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 void CHttpDownloadManagerServerEngine::DownloadInfoFolder( 
       
   596                                                 const CHttpClientApp* aClientApp,  
       
   597                                                 TDes& aFolder ) const
       
   598     {
       
   599     _LIT( KDownloadFolderFormat, "%S%x\\%S\\" );
       
   600 
       
   601     aFolder.Format( KDownloadFolderFormat, 
       
   602                         &KDmDefaultDir, 
       
   603                         aClientApp->AppUid(),
       
   604                         &KInfoFilesDirName );
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CHttpDownloadManagerServerEngine::DownloadInfoFolder
       
   609 // ?implementation_description
       
   610 // (other items were commented in a header).
       
   611 // -----------------------------------------------------------------------------
       
   612 //
       
   613 void CHttpDownloadManagerServerEngine::CODDownloadInfoFolder( 
       
   614                                                 const CHttpClientApp* aClientApp,  
       
   615                                                 TDes& aFolder ) const
       
   616     {
       
   617     _LIT( KDownloadFolderFormat, "%S%x\\%S\\" );
       
   618 
       
   619     aFolder.Format( KDownloadFolderFormat, 
       
   620                         &KDmDefaultDir, 
       
   621                         aClientApp->AppUid(),
       
   622                         &KInfoFilesCodDirName );
       
   623     }
       
   624 // -----------------------------------------------------------------------------
       
   625 // CHttpDownloadManagerServerEngine::DownloadInfoFolder
       
   626 // ?implementation_description
       
   627 // (other items were commented in a header).
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 void CHttpDownloadManagerServerEngine::DownloadContentFolder( 
       
   631                                                 const CHttpClientApp* aClientApp, 
       
   632                                                 TDes& aFolder ) const
       
   633     {
       
   634     _LIT( KDownloadFolderFormat, "%S%x\\%S\\" );
       
   635 
       
   636     aFolder.Format( KDownloadFolderFormat, 
       
   637                         &KDmDefaultDir, 
       
   638                         aClientApp->AppUid(),
       
   639                         &KContentsDirName );
       
   640     }
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // CHttpDownloadManagerServerEngine::DownloadInfoFolder
       
   644 // ?implementation_description
       
   645 // (other items were commented in a header).
       
   646 // -----------------------------------------------------------------------------
       
   647 //
       
   648 void CHttpDownloadManagerServerEngine::CodFolder( 
       
   649                                                 const CHttpClientApp* aClientApp, 
       
   650                                                 TDes& aFolder ) const
       
   651     {
       
   652     _LIT( KDownloadFolderFormat, "%S%x\\%S\\" );
       
   653 
       
   654     aFolder.Format( KDownloadFolderFormat, 
       
   655                         &KDmDefaultDir, 
       
   656                         aClientApp->AppUid(),
       
   657                         &KCodsDirName );
       
   658     }
       
   659 
       
   660 #ifdef DEAD_CODE
       
   661 // -----------------------------------------------------------------------------
       
   662 // CHttpDownloadManagerServerEngine::AllDownloadsL
       
   663 // ?implementation_description
       
   664 // (other items were commented in a header).
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 CArrayPtrFlat<CHttpDownload>* 
       
   668                         CHttpDownloadManagerServerEngine::AllDownloadsL() const
       
   669     {
       
   670     CArrayPtrFlat<CHttpDownload>* downloads = 
       
   671                                     new (ELeave) CArrayPtrFlat<CHttpDownload>(2);
       
   672 
       
   673     CleanupStack::PushL( downloads );
       
   674 
       
   675     for( TInt apps = 0; apps < iClientApps->Count(); ++apps )
       
   676         {
       
   677         CArrayPtrFlat<CHttpDownload>* allDownloads = (*iClientApps)[apps]->Downloads();
       
   678 
       
   679         for( TInt i = 0; i < allDownloads->Count(); ++i )
       
   680             {
       
   681             downloads->AppendL( (*allDownloads)[i] );
       
   682             }
       
   683         }
       
   684     CleanupStack::Pop( downloads );
       
   685 
       
   686     return downloads;
       
   687     }
       
   688 #endif
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CHttpDownloadManagerServerEngine::Fs
       
   692 // ?implementation_description
       
   693 // (other items were commented in a header).
       
   694 // -----------------------------------------------------------------------------
       
   695 //
       
   696 RFs& CHttpDownloadManagerServerEngine::Fs()
       
   697     {
       
   698     return iRfs;
       
   699     }
       
   700 
       
   701 // -----------------------------------------------------------------------------
       
   702 // CHttpDownloadManagerServerEngine::SocketServ
       
   703 // ?implementation_description
       
   704 // (other items were commented in a header).
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 RSocketServ& CHttpDownloadManagerServerEngine::SocketServ()
       
   708     {
       
   709     return iSocketServ;
       
   710     }
       
   711 
       
   712 // -----------------------------------------------------------------------------
       
   713 // CHttpDownloadManagerServerEngine::NextDownloadId
       
   714 // ?implementation_description
       
   715 // (other items were commented in a header).
       
   716 // -----------------------------------------------------------------------------
       
   717 //
       
   718 TInt CHttpDownloadManagerServerEngine::NextDownloadId()
       
   719     {
       
   720     return iNextDownloadId++;
       
   721     }
       
   722 
       
   723 //------------------------------------------------------------------------
       
   724 //CHttpDownloadManagerServerEngine::MMCModeChanged
       
   725 //------------------------------------------------------------------------
       
   726 void CHttpDownloadManagerServerEngine::MMCModeChanged( TBool aMmcPresent )
       
   727     {
       
   728     for( TInt apps = 0; apps < iClientApps->Count(); ++apps )
       
   729         {
       
   730         CArrayPtrFlat<CHttpDownload>* allDownloads = (*iClientApps)[apps]->Downloads();
       
   731 
       
   732         for( TInt i = 0; i < allDownloads->Count(); ++i )
       
   733             {
       
   734             QueryMMCUniqueId();
       
   735             
       
   736             if( aMmcPresent )
       
   737                 {
       
   738                 (*allDownloads)[i]->MediaInserted( iMMCUniqueID );
       
   739                 }
       
   740             else
       
   741                 {
       
   742                 (*allDownloads)[i]->MediaRemoved( iMMCUniqueID );
       
   743                 }
       
   744             }
       
   745         }
       
   746     }
       
   747 
       
   748 //------------------------------------------------------------------------
       
   749 //CHttpDownloadManagerServerEngine::MMCModeChanged
       
   750 //------------------------------------------------------------------------
       
   751 void CHttpDownloadManagerServerEngine::QueryMMCUniqueId()
       
   752     {
       
   753     //
       
   754     // Query the MMC's or Default Removable Mass Storage unique id
       
   755     //
       
   756     TInt drive( 0 );
       
   757 #ifdef RD_MULTIPLE_DRIVE
       
   758     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
       
   759 #else
       
   760     iRfs.CharToDrive( 'E', drive );
       
   761 #endif
       
   762 
       
   763     TVolumeInfo info;
       
   764 
       
   765     if( iRfs.Volume( info, drive ) == KErrNone )
       
   766         {
       
   767         iMMCUniqueID = info.iUniqueID;
       
   768         }
       
   769     else
       
   770         {
       
   771         iMMCUniqueID = (TUint)KErrNotFound;
       
   772         }
       
   773 
       
   774 
       
   775     CLOG_WRITE_1( "MMC id: %d", iMMCUniqueID );
       
   776     }
       
   777 
       
   778 #ifdef RD_MULTIPLE_DRIVE    
       
   779 //------------------------------------------------------------------------
       
   780 //CHttpDownloadManagerServerEngine::QueryDynDriveListLC
       
   781 //------------------------------------------------------------------------
       
   782 HBufC8* CHttpDownloadManagerServerEngine::QueryDynDriveListLC()
       
   783     {
       
   784     TDriveList driveList;
       
   785     TInt driveCount( 0 );
       
   786     TInt err;
       
   787     TChar driveLetter;
       
   788     TBuf8<KMaxDriveListStrLen> driveLettersDyn;
       
   789 
       
   790     // Checking validity of drives in Cenrep List
       
   791     // drive letters are separated by semicolons
       
   792     // Destination is FFS in default
       
   793     TInt drive;
       
   794     User::LeaveIfError(
       
   795         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, drive ) );
       
   796 
       
   797     for( TInt i = 0; i < iDriveLettersCenRep.Length(); i = i + 2 )
       
   798         {
       
   799         if( iRfs.CharToDrive( iDriveLettersCenRep[i], drive ) == KErrNone )
       
   800             {
       
   801             TUint status;
       
   802             if ( DriveInfo::GetDriveStatus( iRfs, drive, status ) == KErrNone )
       
   803                 {
       
   804                 if ( ( status & ( DriveInfo::EDriveUserVisible | DriveInfo::EDrivePresent ) ) )
       
   805                     {
       
   806                     CLOG_WRITE_1( "Drive %d is present and visible", drive);
       
   807                     }
       
   808                 }
       
   809             }
       
   810         }
       
   811 
       
   812     if ( iDriveLettersCenRep.Length() > 0 )
       
   813         {
       
   814         driveLettersDyn.Append( iDriveLettersCenRep );
       
   815         if ( driveLettersDyn[driveLettersDyn.Length() - 1] != ';' )
       
   816             {
       
   817             driveLettersDyn.Append( KDefaultDriveListSep );
       
   818             }
       
   819         }
       
   820 
       
   821     // get the list of drives available in real time
       
   822     err = DriveInfo::GetUserVisibleDrives( iRfs, driveList, driveCount );
       
   823     if ( err == KErrNone )
       
   824         {
       
   825         TInt count( driveList.Length() );
       
   826         for ( TInt i( 0 ); i < count; ++i )
       
   827             {
       
   828             if ( driveList[ i ] )
       
   829                 {
       
   830                 User::LeaveIfError( iRfs.DriveToChar( i, driveLetter) );
       
   831                 TInt drivePos = driveLettersDyn.LocateF( driveLetter );
       
   832                 if ( drivePos == KErrNotFound )
       
   833                     {
       
   834                     driveLettersDyn.Append( driveLetter ); 
       
   835                     driveLettersDyn.Append( KDefaultDriveListSep ); 
       
   836                     }
       
   837                 }
       
   838             }
       
   839 
       
   840         CLOG_WRITE_1( "Pref. drive list dynamic: [%S]", &driveLettersDyn );
       
   841         }
       
   842     else
       
   843         {
       
   844         CLOG_WRITE_1( "GetUserVisibleDrives failed with %d", err );
       
   845         }
       
   846 
       
   847     HBufC8* driveLetters = HBufC8::NewLC( KMaxDriveListStrLen );
       
   848     driveLetters->Des().Copy( driveLettersDyn );
       
   849     return driveLetters;
       
   850     }
       
   851 #endif
       
   852 
       
   853 //------------------------------------------------------------------------
       
   854 //CHttpDownloadManagerServerEngine::QueryDriveList
       
   855 //------------------------------------------------------------------------
       
   856 void CHttpDownloadManagerServerEngine::QueryDriveListL()
       
   857     {
       
   858     CRepository* repository = CRepository::NewLC( KCRUidBrowser );
       
   859     
       
   860     if( repository->Get(KBrowserDrivePrefListForDownloadedContent, iDriveLettersCenRep) != KErrNone )
       
   861         {
       
   862         CLOG_WRITE( "Drive list not found" );
       
   863         iDriveLettersCenRep.Copy( KDefaultDriveList );
       
   864         }
       
   865     
       
   866     CLOG_WRITE_1( "Pref. drive list: [%S]", &iDriveLettersCenRep );
       
   867     
       
   868     CleanupStack::PopAndDestroy( repository );
       
   869     }
       
   870 
       
   871 //------------------------------------------------------------------------
       
   872 //CHttpDownloadManagerServerEngine::DocHandler
       
   873 //------------------------------------------------------------------------
       
   874 CDocumentHandler* CHttpDownloadManagerServerEngine::DocHandler() const
       
   875     {
       
   876     return iDocHandler;
       
   877     }
       
   878     
       
   879 //  End of File