videocollection/mpxmyvideoscollection/src/vcxmyvideosdownloadcache.cpp
branchRCL_3
changeset 16 67eb01668b0e
parent 15 8f0df5c82986
child 18 baf439b22ddd
equal deleted inserted replaced
15:8f0df5c82986 16:67eb01668b0e
     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 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:    Download list cache. Circular buffer made for speeding up*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <mpxlog.h>
       
    22 #include <mpxmedia.h>
       
    23 #include <mpxmediaarray.h>
       
    24 #include <mpxmediageneraldefs.h>
       
    25 #include <mpxmediacontainerdefs.h>
       
    26 #include <vcxmyvideosdefs.h>
       
    27 #include <centralrepository.h>
       
    28 #include <collate.h>
       
    29 #include "vcxmyvideosdownloadcache.h"
       
    30 #include "vcxmyvideoscollectionplugin.h"
       
    31 #include "vcxmyvideosdownloadutil.h"
       
    32 #include "vcxmyvideoscollectionutil.h"
       
    33 #include "vcxmyvideoscategories.h"
       
    34 
       
    35 const TInt KVcxMvDownloadFindCacheSize = 20;
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ==============================
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // Two-phased constructor.
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 CVcxMyVideosDownloadCache* CVcxMyVideosDownloadCache::NewL()
       
    44     {
       
    45     CVcxMyVideosDownloadCache* self = new (ELeave) CVcxMyVideosDownloadCache();
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop(self);
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // Destructor.
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CVcxMyVideosDownloadCache::~CVcxMyVideosDownloadCache()
       
    57     {
       
    58     MPX_FUNC("CVcxMyVideosDownloadCache::~CVcxMyVideosDownloadCache");
       
    59     
       
    60     iDownloadId.Close();
       
    61     iMedia.Close(); // pointers are not own
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // Constructor.
       
    66 // ----------------------------------------------------------------------------
       
    67 //
       
    68 CVcxMyVideosDownloadCache::CVcxMyVideosDownloadCache()
       
    69     {
       
    70     MPX_FUNC("CVcxMyVideosDownloadCache::CVcxMyVideosDownloadCache");
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // Symbian 2nd phase constructor can leave.
       
    75 // ----------------------------------------------------------------------------
       
    76 //
       
    77 void CVcxMyVideosDownloadCache::ConstructL ()
       
    78     {
       
    79     iDownloadId.Reset();
       
    80     iMedia.Reset();
       
    81     for ( TInt i = 0; i < KVcxMvDownloadFindCacheSize; i++ )
       
    82         {
       
    83         iDownloadId.Append( 0 );
       
    84         iMedia.Append( NULL );
       
    85         }
       
    86     }
       
    87     
       
    88 // ----------------------------------------------------------------------------
       
    89 // CVcxMyVideosDownloadCache::Get
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 CMPXMedia* CVcxMyVideosDownloadCache::Get( TUint32 aDownloadId )
       
    93     {
       
    94     for ( TInt i = 0; i < KVcxMvDownloadFindCacheSize; i++ )
       
    95         {
       
    96         if ( iDownloadId[i] == aDownloadId )
       
    97             {
       
    98             return iMedia[i];
       
    99             }
       
   100         }
       
   101     return NULL;
       
   102     }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CVcxMyVideosDownloadCache::Add
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 void CVcxMyVideosDownloadCache::Add( TUint32 aDownloadId, CMPXMedia* aVideo )
       
   109     {
       
   110     iPos++;
       
   111     iPos %= KVcxMvDownloadFindCacheSize;
       
   112     iDownloadId[iPos] = aDownloadId;
       
   113     iMedia[iPos]      = aVideo;    
       
   114     }
       
   115 
       
   116 // ----------------------------------------------------------------------------
       
   117 // CVcxMyVideosDownloadCache::Delete
       
   118 // ----------------------------------------------------------------------------
       
   119 //
       
   120 void CVcxMyVideosDownloadCache::Delete( CMPXMedia* aVideo )
       
   121     {
       
   122     for ( TInt i = 0; i < KVcxMvDownloadFindCacheSize; i++ )
       
   123         {
       
   124         if ( iMedia[i] == aVideo )
       
   125             {
       
   126             iDownloadId[i] = 0;
       
   127             iMedia[i]      = NULL;
       
   128             }
       
   129         }
       
   130     }
       
   131 
       
   132 // End of file
       
   133