videocollection/mpxmyvideoscollection/inc/vcxmyvideosvideocache.h
branchRCL_3
changeset 16 67eb01668b0e
parent 1 6711b85517b7
child 18 baf439b22ddd
equal deleted inserted replaced
15:8f0df5c82986 16:67eb01668b0e
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:    Contains cached MDS media items*
    14 * Description:   Contains cached MDS media items*
    15 */
    15 */
    16 
       
    17 
    16 
    18 
    17 
    19 
    18 
    20 #ifndef VCXMYVIDEOSVIDEOCACHE_H
    19 #ifndef VCXMYVIDEOSVIDEOCACHE_H
    21 #define VCXMYVIDEOSVIDEOCACHE_H
    20 #define VCXMYVIDEOSVIDEOCACHE_H
    24 #include "vcxmyvideosmdsdb.h"
    23 #include "vcxmyvideosmdsdb.h"
    25 
    24 
    26 // FORWARD DECLARATIONS
    25 // FORWARD DECLARATIONS
    27 class CVcxMyVideosCollectionPlugin;
    26 class CVcxMyVideosCollectionPlugin;
    28 class CMPXMedia;
    27 class CMPXMedia;
    29 class CVcxMyVideosDownloadCache;
       
    30 class CRepository;
    28 class CRepository;
    31 
    29 
    32 // CONSTANTS
    30 // CONSTANTS
    33 
    31 
    34 // CLASS DECLARATION
    32 // CLASS DECLARATION
       
    33 
       
    34 /**
       
    35  * Contains information about video.
       
    36  * These are stored to CVcxMyVideosVideoListIndex::iVideoArray.
       
    37  */
       
    38 NONSHARABLE_CLASS(TVcxMyVideosVideo)
       
    39     {
       
    40     public:
       
    41 
       
    42         /**
       
    43          * Constructor.
       
    44          */        
       
    45         TVcxMyVideosVideo();
       
    46         
       
    47         /**
       
    48         * = operator.
       
    49         */        
       
    50         TVcxMyVideosVideo& operator=( const TVcxMyVideosVideo& aVideo );
       
    51     public:
       
    52         
       
    53         /**
       
    54         * Set values.
       
    55         * 
       
    56         * @param aMdsId  MDS ID
       
    57         * @param aPos    Position in CVcxMyVideosVideoCache::iVideoList
       
    58         * @param aVideo  Pointer to CVcxMyVideosVideoCache::iVideoList item,
       
    59         *                ownership does not move.
       
    60         */
       
    61         void Set( TUint32 aMdsId, TInt aPos, CMPXMedia* aVideo );
       
    62 
       
    63     public:
       
    64         TUint32    iMdsId; // Video object ID in MDS.
       
    65         CMPXMedia* iVideo; // Pointer to CVcxMyVideosVideoCache::iVideoList item
       
    66         TInt       iPos;   // Items position in CVcxMyVideosVideoCache::iVideoList
       
    67     };
       
    68 
       
    69 /**
       
    70 * Used for keeping videos in MDS ID order for fast access.
       
    71 * (Indexes CVcxMyVideosVideoCache::iVideoList).
       
    72 *
       
    73 * @lib mpxmyvideoscollectionplugin.lib
       
    74 */
       
    75 NONSHARABLE_CLASS(CVcxMyVideosVideoListIndex) : public CBase
       
    76     {    
       
    77 public: // Constructors and destructor
       
    78 
       
    79     /**
       
    80     * Two-phased constructor
       
    81     * @return Object constructed
       
    82     */
       
    83     static CVcxMyVideosVideoListIndex* NewL();
       
    84     
       
    85     /**
       
    86     * Destructor
       
    87     */
       
    88     virtual ~CVcxMyVideosVideoListIndex();
       
    89 
       
    90 public:
       
    91     
       
    92     /**
       
    93      * Sets up iVideoArray from aVideoList. Sorting is also done.
       
    94      * 
       
    95      * @param aVideoList  Video list to use for constructing iVideoArray. 
       
    96      */
       
    97     void SetL( const CMPXMedia& aVideoList );
       
    98     
       
    99     /**
       
   100      * Finds video by MDS ID from the index. Uses bisection method.
       
   101      * 
       
   102      * @param aVideo  The found video data is written here.
       
   103      * @return        KErrNotFound if not found, index of the item in iVideoArray
       
   104      *                otherwise.
       
   105      */
       
   106     TInt Find( TUint32 aMdsId, TVcxMyVideosVideo& aVideo );
       
   107     
       
   108     /**
       
   109      * Removes video from index.
       
   110      * 
       
   111      * @param aMdsId     ID if the item to be removed.
       
   112      * @param aCompress  If ETrue, compresses the video array.
       
   113      * @return           KErrNotFound if not found, index of the removed item otherwise.
       
   114      */
       
   115     TInt Remove( TUint32 aMdsId, TBool aCompress = ETrue );
       
   116     
       
   117     /**
       
   118      * Adds video to index. Keeps sorting order.
       
   119      * 
       
   120      * @param aVideo  Video to be added, ownership does not move.
       
   121      * @param aPos    aVideo's position in CVcxMyVideosVideoCache::iVideoList.
       
   122      */
       
   123     void AddL( CMPXMedia* aVideo, TInt aPos );
       
   124 
       
   125 #ifdef _DEBUG
       
   126     /**
       
   127      * Returns reference to video array.
       
   128      */
       
   129     const RArray<TVcxMyVideosVideo>& VideoArray();
       
   130 #endif
       
   131     
       
   132 private:
       
   133     /**
       
   134     * Constructor
       
   135     */
       
   136     CVcxMyVideosVideoListIndex();
       
   137     
       
   138     /**
       
   139     * Symbian 2nd phase constructor.
       
   140     */
       
   141     void ConstructL ();
       
   142 
       
   143     /**
       
   144      * Sorts iVideoArray by MDS ID.
       
   145      */
       
   146     void Sort();
       
   147     
       
   148     /**
       
   149      * Used for keeping RArray<TVcxMyVideosVideo> in integer order by
       
   150      * TVcxMyVideosVideo::iMdsId.
       
   151      * 
       
   152      * @param aVideo1 Video to compare
       
   153      * @param aVideo2 Video to compare
       
   154      * @return -1 if aVideo1 is smaller than aVideo2, 1 if aVideo1 is larger than
       
   155      *         aVideo2.
       
   156      */
       
   157     static TInt CompareVideosByMdsId( const TVcxMyVideosVideo& aVideo1,
       
   158             const TVcxMyVideosVideo& aVideo2 );
       
   159 
       
   160 private:
       
   161     
       
   162     /**
       
   163      * Video array which is kept in order by MDS ID.
       
   164      */
       
   165     RArray<TVcxMyVideosVideo> iVideoArray;
       
   166     };
    35 
   167 
    36 /**
   168 /**
    37 * Used for storing MDS items to RAM for fast access.
   169 * Used for storing MDS items to RAM for fast access.
    38 *
   170 *
    39 * @lib mpxmyvideoscollectionplugin.lib
   171 * @lib mpxmyvideoscollectionplugin.lib
    53         /**
   185         /**
    54         * Destructor
   186         * Destructor
    55         */
   187         */
    56         virtual ~CVcxMyVideosVideoCache();
   188         virtual ~CVcxMyVideosVideoCache();
    57  
   189  
       
   190     public:
       
   191         
       
   192         /**
       
   193          * @return  ETrue if iVideoList is complete. (All items have
       
   194          *          been fetched from MDS.)
       
   195          */
       
   196         TBool IsComplete();
       
   197         
       
   198         /**
       
   199          * Set to ETrue when all items have been fetched from MDS.
       
   200          */
       
   201         void SetComplete( TBool aComplete );
       
   202 
    58     private:
   203     private:
    59         /**
   204         /**
    60         * Constructor
   205         * Constructor
    61         */
   206         */
    62         CVcxMyVideosVideoCache( CVcxMyVideosCollectionPlugin& aMyVideosCollectionPlugin );
   207         CVcxMyVideosVideoCache( CVcxMyVideosCollectionPlugin& aMyVideosCollectionPlugin );
   177         *
   322         *
   178         * @param aVideo  Video which position is searched.
   323         * @param aVideo  Video which position is searched.
   179         * @return        Position, KErrNotFound if item is not in iVideoList.
   324         * @return        Position, KErrNotFound if item is not in iVideoList.
   180         */
   325         */
   181         TInt PosOnVideoListL( CMPXMedia& aVideo );
   326         TInt PosOnVideoListL( CMPXMedia& aVideo );
   182                  
   327 
       
   328 #ifdef _DEBUG
       
   329         /**
       
   330          * Checks that iVideoListIndex is correctly formed.
       
   331          */
       
   332         void CheckVideoListIndexL();
       
   333 #endif
       
   334         
   183     public:            
   335     public:            
   184         /**
   336         /**
   185         * Creates filtered video list from iVideoList. This is used for
   337         * Creates filtered video list from iVideoList. This is used for
   186         * showing video categories by origin.
   338         * showing video categories by origin.
   187         *
   339         *
   223         *               Pointer ownership is not moved to the caller.
   375         *               Pointer ownership is not moved to the caller.
   224         */
   376         */
   225         CMPXMedia* FindVideoByMdsIdL( TUint32 aMdsId, TInt& aPos );
   377         CMPXMedia* FindVideoByMdsIdL( TUint32 aMdsId, TInt& aPos );
   226         
   378         
   227         /**
   379         /**
   228         * Tries to find media with matching download ID from iVideoList and iPartialVideoList.
       
   229         * If aDownloadId is 0, then NULL is returned.
       
   230         *
       
   231         * @param aDownloadId ID to compare
       
   232         * @return            Contains pointer to media if match found, NULL otherwise.
       
   233         *                    Pointer ownership is not moved to the caller.
       
   234         */
       
   235         CMPXMedia* FindVideoByDownloadIdL( TUint aDownloadId );
       
   236 
       
   237         /**
       
   238         * Gets medias from iVideoList and iPartialVideoList.
   380         * Gets medias from iVideoList and iPartialVideoList.
   239         *
   381         *
   240         * @param aMdsIds  IDs of the items to fetch.
   382         * @param aMdsIds  IDs of the items to fetch.
   241         * @return         Pointer to fetched items, KMPXMediaArrayContents
   383         * @return         Pointer to fetched items, KMPXMediaArrayContents
   242         *                 attribute contains the media items. Ownership
   384         *                 attribute contains the media items. Ownership
   243         *                 moves to caller.
   385         *                 moves to caller.
   244         */
   386         */
   245         CMPXMedia* GetVideosL( RArray<TUint32> aMdsIds );
   387         CMPXMedia* GetVideosL( RArray<TUint32>& aMdsIds );
   246 
   388 
   247         /**
   389         /**
   248         * Removes video from iVideoList (or from iPartialVideoList).
   390         * Removes video from iVideoList (or from iPartialVideoList).
   249         *
   391         *
   250         * @param aMdsId             MDS ID of the video to be removed.
   392         * @param aMdsId             MDS ID of the video to be removed.
   266         * will contain only those items which were actually added to cache.
   408         * will contain only those items which were actually added to cache.
   267         *
   409         *
   268         * @param aMdsIds                   Array containing MDS IDs of the videos to be added.
   410         * @param aMdsIds                   Array containing MDS IDs of the videos to be added.
   269         * @param aListFetchingWasCanceled  This is set to EFalse if video list fetching from mds
   411         * @param aListFetchingWasCanceled  This is set to EFalse if video list fetching from mds
   270         *                                  had to be cancelled. EFalse otherwise. 
   412         *                                  had to be cancelled. EFalse otherwise. 
   271         */
   413         * @param aNonVideoIds              If argument given then Ids which were detected to not be
   272         void AddVideosFromMdsL( RArray<TUint32>& aMdsIds, TBool& aListFetchingWasCanceled );
   414         *                                  videos are written here. Caller owns the array, ownership
       
   415         *                                  does not move.
       
   416         */
       
   417         void AddVideosFromMdsL( RArray<TUint32>& aMdsIds, TBool& aListFetchingWasCanceled,
       
   418                 RArray<TUint32>* aNonVideoIds = NULL );
   273 
   419 
   274         /**
   420         /**
   275         * Deletes old and creates new iVideoList. After the function call iVideoList exists,
   421         * Deletes old and creates new iVideoList. After the function call iVideoList exists,
   276         * but it might not contain any media items yet, only empty array.
   422         * but it might not contain any media items yet, only empty array.
   277         * Media items are added to the list asynchronoysly in
   423         * Media items are added to the list asynchronoysly in
   278         * VcxMyVideosColletionPlugin::HandleCreateVideoListResp(), called by
   424         * VcxMyVideosColletionPlugin::HandleCreateVideoListResp(), called by
   279         * VcxMyVideosMdsDb. When new items are added, they are synchronized with
   425         * VcxMyVideosMdsDb. Once iVideoList is complete, iVideoListIsPartial
   280         * Download Manager. Once iVideoList is complete, iVideoListIsPartial
       
   281         * is set to EFalse. During the video list fetching
   426         * is set to EFalse. During the video list fetching
   282         * VcxMyVideosMdsDb::iVideoListFetchingIsOngoing is ETrue.
   427         * VcxMyVideosMdsDb::iVideoListFetchingIsOngoing is ETrue.
   283         * If there is video list creation already ongoing
   428         * If there is video list creation already ongoing
   284         * and the aSortingOrder is the same, nothing is done.
   429         * and the aSortingOrder is the same, nothing is done.
   285         * During the video list fetching iPartialVideoList items are moved to
   430         * During the video list fetching iPartialVideoList items are moved to
   335         * are added here. When iVideoList instance is received from MDS, it is
   480         * are added here. When iVideoList instance is received from MDS, it is
   336         * replaced by item from iPartialVideoList and instance from iPartialVideoList
   481         * replaced by item from iPartialVideoList and instance from iPartialVideoList
   337         * is removed.
   482         * is removed.
   338         */
   483         */
   339         RArray<CMPXMedia*> iPartialVideoList;
   484         RArray<CMPXMedia*> iPartialVideoList;
   340 
       
   341         /**
       
   342         * If ETrue then iVideoList does not contain all items from MDS.
       
   343         */
       
   344         TBool iVideoListIsPartial;
       
   345                                 
   485                                 
   346         /**
   486         /**
   347         * Sorting order which was used last time when list was queryed from MDS.
   487         * Sorting order which was used last time when list was queryed from MDS.
   348         */
   488         */
   349         TVcxMyVideosSortingOrder iLastSortingOrder;
   489         TVcxMyVideosSortingOrder iLastSortingOrder;
   350         
   490         
       
   491         /**
       
   492          * Set to ETrue when doing videolist fetching.
       
   493          */
       
   494         TBool iIsFetchingVideoList;
   351     private:
   495     private:
   352         
   496 
   353         /**
   497         /**
   354         * Circular buffer containing download id and media object pointer pairs.
   498         * If ETrue then iVideoList contains all items from MDS.
   355         * Media object pointers are owned by iVideoList.
   499         */
   356         * Used to speed up access to media objects which are used regularly during the
   500         TBool iVideoListIsComplete;
   357         * download.
   501         
   358         */
       
   359         CVcxMyVideosDownloadCache* iDownloadCache;
       
   360 
       
   361         /**
   502         /**
   362         * My Videos collection plugin, owner of this object.
   503         * My Videos collection plugin, owner of this object.
   363         */
   504         */
   364         CVcxMyVideosCollectionPlugin& iCollection;        
   505         CVcxMyVideosCollectionPlugin& iCollection;
   365 
   506         
       
   507         /**
       
   508          * Index which keeps TVcxMyVidesVideo items indexed in MDS ID
       
   509          * order for fast access.
       
   510          */
       
   511         CVcxMyVideosVideoListIndex* iVideoListIndex;
       
   512         
   366         /**
   513         /**
   367         * Provides access to the sorting order key in cenrep. Own.
   514         * Provides access to the sorting order key in cenrep. Own.
   368         */
   515         */
   369         CRepository* iCenRep;
   516         CRepository* iCenRep;
   370 
   517