emailservices/emailclientapi/src/emailmailboxcache.cpp
branchRCL_3
changeset 64 3533d4323edc
parent 63 d189ee25cf9d
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    21 static const TInt KCacheGranularity = 2;
    21 static const TInt KCacheGranularity = 2;
    22 
    22 
    23 // ---------------------------------------------------------------------------
    23 // ---------------------------------------------------------------------------
    24 // 
    24 // 
    25 // ---------------------------------------------------------------------------
    25 // ---------------------------------------------------------------------------
       
    26 //
    26 CEmailMailboxCache* CEmailMailboxCache::NewL()
    27 CEmailMailboxCache* CEmailMailboxCache::NewL()
    27     {
    28     {
    28     CEmailMailboxCache* cache = new ( ELeave ) CEmailMailboxCache();
    29     CEmailMailboxCache* cache = new ( ELeave ) CEmailMailboxCache();
    29     return cache;
    30     return cache;
    30     }
    31     }
    31 
    32 
    32 // ---------------------------------------------------------------------------
    33 // ---------------------------------------------------------------------------
    33 // 
    34 // 
    34 // ---------------------------------------------------------------------------
    35 // ---------------------------------------------------------------------------
       
    36 //
    35 CEmailMailboxCache::~CEmailMailboxCache()
    37 CEmailMailboxCache::~CEmailMailboxCache()
    36     {
    38     {
    37     iEntries.Close();
    39     iEntries.Close();
    38     }
    40     }
    39 
    41 
    40 // ---------------------------------------------------------------------------
    42 // ---------------------------------------------------------------------------
    41 // Start of cache transaction with clenanup support
    43 // Start of cache transaction with clenanup support
    42 // ---------------------------------------------------------------------------
    44 // ---------------------------------------------------------------------------
       
    45 //
    43 void CEmailMailboxCache::StartCachingPushL()
    46 void CEmailMailboxCache::StartCachingPushL()
    44     {
    47     {
    45     TCleanupItem item( &CEmailMailboxCache::CleanupOp, this );
    48     TCleanupItem item( &CEmailMailboxCache::CleanupOp, this );
    46     CleanupStack::PushL( item );
    49     CleanupStack::PushL( item );
    47     iState = ECaching;
    50     iState = ECaching;
    48     iEntries.Reset();
    51     iEntries.Reset();
    49     }
    52     }
    50 
    53     
    51 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    52 //  End of cache transaction
    55 //  End of cache transaction
    53 // ---------------------------------------------------------------------------
    56 // ---------------------------------------------------------------------------
       
    57 //
    54 void CEmailMailboxCache::EndCachingPop()
    58 void CEmailMailboxCache::EndCachingPop()
    55     {
    59     {
    56     iState = EComplete;
    60     iState = EComplete;
    57     CleanupStack::Pop();
    61     CleanupStack::Pop();
    58     }
    62     }
    59 
    63 
    60 // ---------------------------------------------------------------------------
    64 // ---------------------------------------------------------------------------
    61 // 
    65 // 
    62 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
       
    67 //
    63 TBool CEmailMailboxCache::IsCached() const
    68 TBool CEmailMailboxCache::IsCached() const
    64     {
    69     {
    65     return iState == EComplete;
    70     return iState == EComplete;
    66     }
    71     }
    67 
    72 
    68 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    69 // 
    74 // 
    70 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
       
    76 //
    71 void CEmailMailboxCache::AddMailboxL( 
    77 void CEmailMailboxCache::AddMailboxL( 
    72     CPluginData& aPluginData, 
    78     CPluginData& aPluginData, 
    73     const TMailboxId& aMailboxId )
    79     const TMailboxId& aMailboxId )
    74     {
    80     {
    75     if ( iState != ECaching )
    81     if ( iState != ECaching )
    84     }
    90     }
    85 
    91 
    86 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
    87 // 
    93 // 
    88 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
       
    95 //
    89 CPluginData* CEmailMailboxCache::PluginDataL( const TMailboxId& aMailboxId ) const
    96 CPluginData* CEmailMailboxCache::PluginDataL( const TMailboxId& aMailboxId ) const
    90     {
    97     {
    91     CPluginData* pdata = NULL;
    98     CPluginData* pdata = NULL;
    92     const TInt index( FindById( aMailboxId ) );
    99     const TInt index( FindById( aMailboxId ) );
    93     if ( index != KErrNotFound )
   100     if ( index != KErrNotFound )
    99     }
   106     }
   100 
   107 
   101 // ---------------------------------------------------------------------------
   108 // ---------------------------------------------------------------------------
   102 // 
   109 // 
   103 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
       
   111 //
   104 CPluginData* CEmailMailboxCache::PluginDataL( const TUid& aPluginId ) const
   112 CPluginData* CEmailMailboxCache::PluginDataL( const TUid& aPluginId ) const
   105     {
   113     {
   106     CPluginData* pdata = NULL;
   114     CPluginData* pdata = NULL;
   107     const TInt index( FindByPluginIdL( aPluginId ) );
   115     const TInt index( FindByPluginIdL( aPluginId ) );
   108     if ( index != KErrNotFound )
   116     if ( index != KErrNotFound )
   109         {
   117         {
   110         const TCacheEntry& entry = iEntries[ index ];
   118         const TCacheEntry& entry = iEntries[ index ];
   111         pdata = entry.iPluginData;
   119         pdata = entry.iPluginData;
   112         }
   120         }    
   113     return pdata;
   121     return pdata;
   114     }
   122     }
   115 
   123 
   116 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   117 // 
   125 // 
   118 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
       
   127 //
   119 void CEmailMailboxCache::GetIdsL( REmailMailboxIdArray& aIdArray ) const
   128 void CEmailMailboxCache::GetIdsL( REmailMailboxIdArray& aIdArray ) const
   120     {
   129     {
   121     if ( iState != EComplete )
   130     if ( iState != EComplete )
   122         {
   131         {
   123         // cache not up to date
   132         // cache not up to date
   131     }
   140     }
   132 
   141 
   133 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   134 // 
   143 // 
   135 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
       
   145 //
   136 TInt CEmailMailboxCache::FindById( const TMailboxId& aMailboxId ) const
   146 TInt CEmailMailboxCache::FindById( const TMailboxId& aMailboxId ) const
   137     {
   147     {
   138     TIdentityRelation<TCacheEntry> rel( CEmailMailboxCache::Equals );
   148     TIdentityRelation<TCacheEntry> rel( CEmailMailboxCache::Equals );
   139 
   149     
   140     // don't care about plugin data because this is seach key only and
   150     // don't care about plugin data because this is seach key only and
   141     // mailbox id is used for search
   151     // mailbox id is used for search
   142     TCacheEntry entry( NULL, aMailboxId );
   152     TCacheEntry entry( NULL, aMailboxId );
   143     return iEntries.Find( entry, rel );
   153     return iEntries.Find( entry, rel );
   144     }
   154     }
   145 
   155 
   146 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------
   147 // 
   157 // 
   148 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
       
   159 //
   149 TInt CEmailMailboxCache::FindByPluginIdL( const TUid& aPluginId ) const
   160 TInt CEmailMailboxCache::FindByPluginIdL( const TUid& aPluginId ) const
   150     {
   161     {
   151     TIdentityRelation<TCacheEntry> rel( CEmailMailboxCache::PluginEquals );
   162     TIdentityRelation<TCacheEntry> rel( CEmailMailboxCache::PluginEquals );
   152     CPluginData* key = new ( ELeave ) CPluginData( aPluginId );
   163     CPluginData* key = new ( ELeave ) CPluginData( aPluginId );
   153     TCacheEntry entry( key, TMailboxId() );
   164     TCacheEntry entry( key, TMailboxId() );
   157     }
   168     }
   158 
   169 
   159 // ---------------------------------------------------------------------------
   170 // ---------------------------------------------------------------------------
   160 // 
   171 // 
   161 // ---------------------------------------------------------------------------
   172 // ---------------------------------------------------------------------------
       
   173 //
   162 TBool CEmailMailboxCache::Equals( const TCacheEntry& a1, const TCacheEntry& a2 )
   174 TBool CEmailMailboxCache::Equals( const TCacheEntry& a1, const TCacheEntry& a2 )
   163     {
   175     {
   164     return ( a1.iMailboxId == a2.iMailboxId );
   176     return ( a1.iMailboxId == a2.iMailboxId );
   165     }
   177     }
   166 
   178 
   167 // ---------------------------------------------------------------------------
   179 // ---------------------------------------------------------------------------
   168 // 
   180 // 
   169 // ---------------------------------------------------------------------------
   181 // ---------------------------------------------------------------------------
       
   182 //
   170 TBool CEmailMailboxCache::PluginEquals( const TCacheEntry& a1, const TCacheEntry& a2 )
   183 TBool CEmailMailboxCache::PluginEquals( const TCacheEntry& a1, const TCacheEntry& a2 )
   171     {
   184     {
   172     return ( a1.iPluginData->Uid() == a2.iPluginData->Uid() );
   185     return ( a1.iPluginData->Uid() == a2.iPluginData->Uid() );
   173     }
   186     }
   174 
   187 
   175 // ---------------------------------------------------------------------------
   188 // ---------------------------------------------------------------------------
   176 // Cleanup 
   189 // Cleanup 
   177 // ---------------------------------------------------------------------------
   190 // ---------------------------------------------------------------------------
       
   191 //
   178 void CEmailMailboxCache::CleanupOp( TAny* aAny )
   192 void CEmailMailboxCache::CleanupOp( TAny* aAny )
   179     {
   193     {
   180     CEmailMailboxCache* cache = reinterpret_cast<CEmailMailboxCache*>( aAny );
   194     CEmailMailboxCache* cache = reinterpret_cast<CEmailMailboxCache*>( aAny );
   181     cache->iEntries.Reset();
   195     cache->iEntries.Reset();
   182     cache->iState = EEmpty;
   196     cache->iState = EEmpty;
   183     }
   197     }
   184 
   198 
   185 // ---------------------------------------------------------------------------
   199 // ---------------------------------------------------------------------------
   186 // 
   200 // 
   187 // ---------------------------------------------------------------------------
   201 // ---------------------------------------------------------------------------
       
   202 //
   188 CEmailMailboxCache::CEmailMailboxCache() : 
   203 CEmailMailboxCache::CEmailMailboxCache() : 
   189     iState( EEmpty ), 
   204     iState( EEmpty ), 
   190     iEntries( KCacheGranularity )
   205     iEntries( KCacheGranularity )
   191     {
   206     {
   192     }
   207     }
   193 
   208 
   194 // End of file
   209 // End of file.