imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp
branchRCL_3
changeset 11 85a88bc05e45
parent 10 ee674526fac5
child 13 ffb2d5dd62e9
equal deleted inserted replaced
10:ee674526fac5 11:85a88bc05e45
    33 #include "thumbnailpanic.h"
    33 #include "thumbnailpanic.h"
    34 #include "thumbnailmanagerconstants.h"
    34 #include "thumbnailmanagerconstants.h"
    35 #include "thumbnailserver.h"
    35 #include "thumbnailserver.h"
    36 
    36 
    37 
    37 
    38 _LIT8( KThumbnailSqlConfig, "page_size=1024; cache_size=32;" );
    38 _LIT8( KThumbnailSqlConfig, "page_size=16384; cache_size=32;" );
    39 
    39 
    40 const TInt KStreamBufferSize = 1024 * 8;
    40 const TInt KStreamBufferSize = 1024 * 8;
    41 const TInt KMajor = 3;
    41 const TInt KMajor = 3;
    42 const TInt KMinor = 2;
    42 const TInt KMinor = 2;
    43 
    43 
    66 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    67 // RThumbnailTransaction::BeginL()
    67 // RThumbnailTransaction::BeginL()
    68 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    69 //
    69 //
    70 void RThumbnailTransaction::BeginL()
    70 void RThumbnailTransaction::BeginL()
    71     {
    71     {    
       
    72     if (iDatabase.InTransaction())
       
    73         {
       
    74         TN_DEBUG1( "RThumbnailTransaction::BeginL() - error: old transaction open!" );
       
    75         __ASSERT_DEBUG(( !iDatabase.InTransaction() ), ThumbnailPanic( EThumbnailSQLTransaction ));
       
    76         
       
    77         // old transaction already open, don't open another
       
    78         iState = EOldOpen;
       
    79         
       
    80         return;
       
    81         }
       
    82     
    72     const TInt err = iDatabase.Exec( KThumbnailBeginTransaction );
    83     const TInt err = iDatabase.Exec( KThumbnailBeginTransaction );
    73     if ( err >= 0 )
    84     if ( err >= 0 )
    74         {
    85         {
    75         iState = EOpen;
    86         iState = EOpen;
    76         }
    87         }
    89 // RThumbnailTransaction::Close()
   100 // RThumbnailTransaction::Close()
    90 // ---------------------------------------------------------------------------
   101 // ---------------------------------------------------------------------------
    91 //
   102 //
    92 void RThumbnailTransaction::Close()
   103 void RThumbnailTransaction::Close()
    93     {
   104     {
    94     if ( iState != EClosed )
   105     if ( iState != EClosed && iState != EOldOpen )
    95         {
   106         {
    96         Rollback();
   107         Rollback();
    97         }
   108         }
    98     }
   109     }
    99 
   110 
   101 // RThumbnailTransaction::CommitL()
   112 // RThumbnailTransaction::CommitL()
   102 // ---------------------------------------------------------------------------
   113 // ---------------------------------------------------------------------------
   103 //
   114 //
   104 void RThumbnailTransaction::CommitL()
   115 void RThumbnailTransaction::CommitL()
   105     {
   116     {
   106     TInt ret = iDatabase.Exec( KThumbnailCommitTransaction );
   117     if ( iState != EOldOpen )
       
   118         {
       
   119         TInt ret = iDatabase.Exec( KThumbnailCommitTransaction );
   107     
   120     
   108 #ifdef _DEBUG
   121 #ifdef _DEBUG
   109     TPtrC errorMsg = iDatabase.LastErrorMessage();
   122     TPtrC errorMsg = iDatabase.LastErrorMessage();
   110     TN_DEBUG3( "RThumbnailTransaction::CommitL() lastError %S, ret = %d" , &errorMsg, ret);
   123     TN_DEBUG3( "RThumbnailTransaction::CommitL() lastError %S, ret = %d" , &errorMsg, ret);
   111 #endif  
   124 #endif  
   112     User::LeaveIfError( ret );
   125     User::LeaveIfError( ret );
       
   126         }
   113     
   127     
   114     iState = EClosed;
   128     iState = EClosed;
   115     }
   129     }
   116 
   130 
   117 // ---------------------------------------------------------------------------
   131 // ---------------------------------------------------------------------------
   118 // RThumbnailTransaction::Rollback()
   132 // RThumbnailTransaction::Rollback()
   119 // ---------------------------------------------------------------------------
   133 // ---------------------------------------------------------------------------
   120 //
   134 //
   121 TInt RThumbnailTransaction::Rollback()
   135 TInt RThumbnailTransaction::Rollback()
   122     {
   136     {
   123     const TInt err = iDatabase.Exec( KThumbnailRollbackTransaction );
   137     if ( iState != EOldOpen )
   124     if ( err >= 0 )
   138         {
   125         {
   139         const TInt err = iDatabase.Exec( KThumbnailRollbackTransaction );
   126         iState = EClosed;
   140         if ( err >= 0 )
   127         }
   141             {
   128     return err;
   142             iState = EClosed;
       
   143             }
       
   144         
       
   145         return err;
       
   146         }
       
   147     
       
   148     iState = EClosed;
       
   149     
       
   150     return KErrNone;
   129     }
   151     }
   130 
   152 
   131 
   153 
   132 // ======== MEMBER FUNCTIONS ========
   154 // ======== MEMBER FUNCTIONS ========
   133 
   155 
  1764             rowStatus = stmt->Next();
  1786             rowStatus = stmt->Next();
  1765             }
  1787             }
  1766         
  1788         
  1767         CleanupStack::PopAndDestroy( stmt_infodata );
  1789         CleanupStack::PopAndDestroy( stmt_infodata );
  1768         CleanupStack::PopAndDestroy( stmt_info );
  1790         CleanupStack::PopAndDestroy( stmt_info );
       
  1791         CleanupStack::PopAndDestroy( stmt );
  1769         
  1792         
  1770 		//remove delete mark
  1793 		//remove delete mark
  1771         User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) );
  1794         User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) );
  1772         } 
  1795         } 
  1773     else
  1796     else
  1774         {
  1797         {
       
  1798         TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- add to Deleted" );
       
  1799     
  1775         // only add path to deleted table
  1800         // only add path to deleted table
  1776         stmt = &iStmt_KThumbnailSqlInsertDeleted;
  1801         stmt = &iStmt_KThumbnailSqlInsertDeleted;
  1777         CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
  1802         CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
  1778         
  1803         
  1779         paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
  1804         paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
  1780         User::LeaveIfError( paramIndex );
  1805         User::LeaveIfError( paramIndex );
  1781         User::LeaveIfError( stmt->BindText( paramIndex, *path ));
  1806         User::LeaveIfError( stmt->BindText( paramIndex, *path ));
  1782         
  1807         
  1783         count = stmt->Exec();
  1808         count = stmt->Exec();
  1784         }
  1809         
  1785     
  1810         CleanupStack::PopAndDestroy( stmt );
  1786     CleanupStack::PopAndDestroy( stmt );    
  1811         }    
  1787     
  1812     
  1788     if (aTransaction)
  1813     if (aTransaction)
  1789         {
  1814         {
  1790         transaction.CommitL();
  1815         transaction.CommitL();
  1791         CleanupStack::PopAndDestroy( &transaction );
  1816         CleanupStack::PopAndDestroy( &transaction );
  1909         {
  1934         {
  1910         // cache empty or db unusable
  1935         // cache empty or db unusable
  1911         return;
  1936         return;
  1912         }
  1937         }
  1913     
  1938     
  1914     if(iBatchItemCount < iBatchFlushItemCount && !aForce)
  1939     // fixed batch size if MTP sync on
       
  1940     TInt MPXHarvesting(0);
       
  1941     TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting);
       
  1942     if(ret != KErrNone)
       
  1943         {
       
  1944         TN_DEBUG2( "CThumbnailStore::FlushCacheTable() error checking MTP sync: %d", ret);
       
  1945         }
       
  1946     
       
  1947     if(MPXHarvesting && iBatchItemCount < KMaxBatchItemsMTP && !aForce)
       
  1948         {
       
  1949         TN_DEBUG1("CThumbnailStore::FlushCacheTable() MTP sync, fixed batch...");
       
  1950     
       
  1951         //some items in cache
       
  1952         StartAutoFlush();
       
  1953         return;
       
  1954         }    
       
  1955     else if(!MPXHarvesting && iBatchItemCount < iBatchFlushItemCount && !aForce)
  1915        {
  1956        {
  1916        //some items in cache
  1957        //some items in cache
  1917        StartAutoFlush();
  1958        StartAutoFlush();
  1918        return;
  1959        return;
  1919        }
  1960        }    
  1920     
       
  1921     
  1961     
  1922     iStartFlush.UniversalTime();
  1962     iStartFlush.UniversalTime();
  1923     
  1963     
  1924     // Move data from temp table to main....
  1964     // Move data from temp table to main....
  1925     TInt err_begin = iDatabase.Exec( KThumbnailBeginTransaction );
  1965     TInt err_begin = iDatabase.Exec( KThumbnailBeginTransaction );
  1970         TN_DEBUG1("CThumbnailStore::FlushCacheTable() db corrupted");
  2010         TN_DEBUG1("CThumbnailStore::FlushCacheTable() db corrupted");
  1971     
  2011     
  1972         // open new
  2012         // open new
  1973         TRAP_IGNORE(OpenDatabaseL(ETrue));
  2013         TRAP_IGNORE(OpenDatabaseL(ETrue));
  1974         }
  2014         }
  1975     
  2015    
  1976 	//adjust batch size dynamically between min and max based on read flush speed. 
       
  1977     iStopFlush.UniversalTime();
  2016     iStopFlush.UniversalTime();
  1978     TInt aFlushDelay = (TInt)iStopFlush.MicroSecondsFrom(iStartFlush).Int64()/1000;
  2017     TInt aFlushDelay = (TInt)iStopFlush.MicroSecondsFrom(iStartFlush).Int64()/1000;
       
  2018     
  1979     TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", aFlushDelay);
  2019     TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", aFlushDelay);
       
  2020     
       
  2021     //adjust batch size dynamically between min and max based on read flush speed
       
  2022     if (!MPXHarvesting)
       
  2023         {
       
  2024         //increase batch count if there room for one more item (based on average time per item)
       
  2025         if( aFlushDelay < KMaxFlushDelay && iBatchFlushItemCount < KMaxBatchItems )
       
  2026             {
       
  2027             iBatchFlushItemCount++;
       
  2028             }
       
  2029         //decrease batch count if we exeeced max time allowed in flushing the TEMP table
       
  2030         else if(aFlushDelay > KMaxFlushDelay && iBatchFlushItemCount > KMInBatchItems )
       
  2031             {
       
  2032             iBatchFlushItemCount--;
       
  2033             }
       
  2034         }
  1980     
  2035     
  1981     //cache flushed
  2036     //cache flushed
  1982     iBatchItemCount = 0;
  2037     iBatchItemCount = 0;
  1983     
       
  1984     //increase batch count if there room for one more item (based on average time per item)
       
  1985     if( aFlushDelay < KMaxFlushDelay && iBatchFlushItemCount < KMaxBatchItems )
       
  1986         {
       
  1987         iBatchFlushItemCount++;
       
  1988         }
       
  1989     //decrease batch count if we exeeced max time allowed in flushing the TEMP table
       
  1990     else if(aFlushDelay > KMaxFlushDelay && iBatchFlushItemCount > KMInBatchItems )
       
  1991         {
       
  1992         iBatchFlushItemCount--;
       
  1993         }
       
  1994 
  2038 
  1995     TN_DEBUG2("CThumbnailStore::FlushCacheTable() out iBatchFlushItemCount = %d", iBatchFlushItemCount);
  2039     TN_DEBUG2("CThumbnailStore::FlushCacheTable() out iBatchFlushItemCount = %d", iBatchFlushItemCount);
  1996     }
  2040     }
  1997 
  2041 
  1998 // -----------------------------------------------------------------------------
  2042 // -----------------------------------------------------------------------------
  2157         // next round
  2201         // next round
  2158         if (self->iIdle && ( self->iDeleteThumbs || self->iCheckFilesExist) )
  2202         if (self->iIdle && ( self->iDeleteThumbs || self->iCheckFilesExist) )
  2159             {
  2203             {
  2160             self->StartMaintenance();
  2204             self->StartMaintenance();
  2161             }  
  2205             }  
  2162         else
  2206         else if (!self->iDeleteThumbs && !self->iCheckFilesExist)
  2163             {
  2207             {
  2164             // no need to monitor activity anymore
  2208             // no need to monitor activity anymore
  2165             self->iActivityManager->Cancel();
  2209             self->iActivityManager->Cancel();
  2166             }
  2210             }
  2167         }
  2211         }