homesync/contentmanager/cmserver/cmfillmanager/src/cmfmfilldrivemngr.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2008 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:  Fill drive handling 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 #include "cmcommon.h"
       
    21 #include "cmdriveinfo.h"
       
    22 #include "cmfmfilldrivemngr.h"
       
    23 #include "msdebug.h"    
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CCmFmFillDriveMngr::NewL
       
    27 // ---------------------------------------------------------------------------
       
    28 // 
       
    29 CCmFmFillDriveMngr* CCmFmFillDriveMngr::NewL( RFs& aFs, 
       
    30     RPointerArray<CCmDriveInfo>& aDrives )
       
    31     {
       
    32     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::NewL() start"));    
       
    33     CCmFmFillDriveMngr* self = CCmFmFillDriveMngr::NewLC( aFs, aDrives );
       
    34     CleanupStack::Pop( self );
       
    35     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::NewL() end"));
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CCmFmFillDriveMngr::NewLC
       
    41 // ---------------------------------------------------------------------------
       
    42 //    
       
    43 CCmFmFillDriveMngr* CCmFmFillDriveMngr::NewLC( RFs& aFs, 
       
    44     RPointerArray<CCmDriveInfo>& aDrives )
       
    45     {
       
    46     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::NewLC() start"));    
       
    47     CCmFmFillDriveMngr* self = new ( ELeave ) CCmFmFillDriveMngr( aFs, aDrives );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::NewLC() end"));
       
    51     return self;  
       
    52     }    
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CCmFmFillDriveMngr::~CCmFmFillDriveMngr
       
    56 // ---------------------------------------------------------------------------
       
    57 // 
       
    58 CCmFmFillDriveMngr::~CCmFmFillDriveMngr()
       
    59     {
       
    60     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::~CCmFmFillDriveMngr()"));
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CCmFmFillDriveMngr::CCmFmFillDriveMngr
       
    65 // ---------------------------------------------------------------------------
       
    66 // 
       
    67 CCmFmFillDriveMngr::CCmFmFillDriveMngr( RFs& aFs, 
       
    68     RPointerArray<CCmDriveInfo>& aDrives )
       
    69     : iFsSession( aFs ), iDrives( aDrives )
       
    70     {
       
    71     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::CCmFmFillDriveMngr()"));
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CCmFmFillDriveMngr::ConstructL
       
    76 // ---------------------------------------------------------------------------
       
    77 //     
       
    78 void CCmFmFillDriveMngr::ConstructL()
       
    79     {
       
    80     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::ConstructL()"));    
       
    81     }    
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CCmFmFillDriveMngr::CheckDriveId
       
    85 // ---------------------------------------------------------------------------
       
    86 // 
       
    87 TCmFmStatus CCmFmFillDriveMngr::CheckDriveId()
       
    88     {
       
    89     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::CheckDriveId()"));
       
    90     
       
    91     TCmFmStatus status(ECmFmMMCCheckFailed);
       
    92     TVolumeInfo volInfo;    
       
    93     for( TInt i = iDrives.Count() - 1; i >= 0; i-- )
       
    94         {
       
    95         DoMountFileSystem( iFsSession, volInfo, iDrives[i]->DriveNumber() );
       
    96         if( volInfo.iUniqueID != iDrives[i]->DriveId() )
       
    97             {
       
    98             delete iDrives[i];
       
    99             iDrives.Remove(i);
       
   100             }
       
   101         }
       
   102     if( iDrives.Count() )
       
   103         {
       
   104         status = ECmFmMMCOk;
       
   105         }
       
   106     
       
   107     return status;       
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCmFmFillDriveMngr::CheckFreeDiscSpace
       
   112 // ---------------------------------------------------------------------------
       
   113 // 
       
   114 TInt CCmFmFillDriveMngr::CheckFreeDiscSpace( TUint32 aFileSize,
       
   115                                              TUint& aDriveId, 
       
   116                                              TInt& aDriveNumber )
       
   117     {
       
   118     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::CheckFreeDiscSpace()"));    
       
   119     
       
   120     aDriveNumber = KErrNotFound;
       
   121     TInt64 totalSize( 0 );
       
   122     TInt64 quota( 0 );
       
   123     TInt driveIndex( 0 );
       
   124     
       
   125     for( TInt i = 0; i < iDrives.Count(); i++ )
       
   126         {
       
   127         totalSize = iDrives[i]->UsedDriveQuota() + aFileSize;
       
   128         quota = iDrives[i]->DriveQuota();
       
   129         TRACE(Print(_L("[FILL MNGR]\t CCmFmFillDriveMngr Quota = \
       
   130             : %ld"), quota ));         
       
   131         if( totalSize >= quota )
       
   132             {
       
   133             TRACE(Print(_L("[FILL MNGR]\t QUOTA FULL drive number = %d"),
       
   134                 iDrives[i]->DriveNumber()));
       
   135             }
       
   136         else
       
   137             {
       
   138             TInt error( KErrNone );
       
   139             TVolumeInfo volInfo;        
       
   140             TInt64 freespace( 0 );        
       
   141             
       
   142             error = DoMountFileSystem( iFsSession, volInfo, 
       
   143                 iDrives[i]->DriveNumber() );
       
   144             
       
   145             if ( !error )
       
   146                 {            
       
   147                 freespace = volInfo.iFree;
       
   148                 TRACE(Print(_L("[FILL MNGR]\t CCmFmFillDriveMngr freespace \
       
   149                     : %ld"), freespace ));
       
   150                 if( freespace < ( KCmMmcLowMemory + aFileSize ) )
       
   151                     {
       
   152                     TRACE(Print(_L("[FILL MNGR]\t Disc full!!")));
       
   153                     }
       
   154                 else
       
   155                     {
       
   156                     TRACE(Print(_L("[FILL MNGR]\t Drive number of the drive \
       
   157                     where to fill = %d"), iDrives[i]->DriveNumber() ));
       
   158                     aDriveNumber = iDrives[i]->DriveNumber();
       
   159                     aDriveId = iDrives[i]->DriveId();                    
       
   160                     driveIndex = i;
       
   161                     i = iDrives.Count();
       
   162                     }    
       
   163                 }
       
   164             else
       
   165                 {
       
   166                 // Disc is not ready => Do not fill
       
   167                 TRACE(Print(_L("[FILL MNGR]\t Disc is not ready!!")));
       
   168                 }              
       
   169             }                    
       
   170         }
       
   171         
       
   172     return driveIndex;
       
   173     }       
       
   174     
       
   175 // ---------------------------------------------------------------------------
       
   176 // CCmFmFillDriveMngr::DoMountFileSystem
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 TInt CCmFmFillDriveMngr::DoMountFileSystem( RFs& aFileServer, 
       
   180                                             TVolumeInfo& aVolInfo, 
       
   181                                             TInt aDriveNumber )
       
   182     {
       
   183     LOG(_L("[FILL MNGR]\t CCmFmFillDriveMngr::CheckFreeDiscSpace()")); 
       
   184     
       
   185     TInt error( KErrNone );
       
   186     TFullName fsname;  
       
   187     error = aFileServer.FileSystemName( fsname, aDriveNumber );
       
   188     
       
   189     TRACE(Print(_L("[FILL MNGR]\t FileSystemName %d, %S"), 
       
   190         error, &fsname ));                    
       
   191 
       
   192     error = aFileServer.FileSystemName( fsname, aDriveNumber );
       
   193     
       
   194     TRACE(Print(_L("[FILL MNGR]\t FileSystemName %d, %S"), 
       
   195         error, &fsname ));
       
   196 
       
   197     error = aFileServer.Volume( aVolInfo, aDriveNumber );       
       
   198 
       
   199     TRACE(Print(_L("[FILL MNGR]\t CCmFmFillDriveMngr::volinfo error = %d"), 
       
   200         error )); 
       
   201 
       
   202     return error;
       
   203     }
       
   204         
       
   205 // End of file
       
   206 
       
   207