videofeeds/vcnsuiengine/src/vcxnsdownloadupdater.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "IptvDebug.h"
       
    22 #include <mpxmedia.h>
       
    23 #include <vcxmyvideosdefs.h>
       
    24 #include <mpxmediageneraldefs.h>
       
    25 
       
    26 #include "vcxnsdownloadupdater.h"
       
    27 #include "vcxnscontent.h"
       
    28 
       
    29 const TInt KUpdateDelay = 3000000; // 3 seconds
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // 
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CVcxNsDownloadUpdater::CVcxNsDownloadUpdater( MVcxNsDownloadUpdaterObserver* aObserver ):
       
    38     iObserver( aObserver )
       
    39     {
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // 
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 void CVcxNsDownloadUpdater::ConstructL()
       
    47     {
       
    48     iTimer = CPeriodic::NewL( EPriorityNormal );
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CVcxNsDownloadUpdater* CVcxNsDownloadUpdater::NewL( MVcxNsDownloadUpdaterObserver* aObserver )
       
    56     {
       
    57     CVcxNsDownloadUpdater* self = new( ELeave ) CVcxNsDownloadUpdater( aObserver );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // 
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CVcxNsDownloadUpdater::~CVcxNsDownloadUpdater()
       
    69     {
       
    70     if( iTimer )
       
    71         {
       
    72         iTimer->Cancel();
       
    73         }
       
    74     
       
    75     delete iTimer;
       
    76     
       
    77     iDownloadArray.Close();
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // 
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CVcxNsDownloadUpdater::AddDownload( CVcxNsContent* aContent )
       
    85     {
       
    86     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::AddDownload IN");
       
    87     
       
    88     if ( !aContent )
       
    89         {
       
    90         return;
       
    91         }
       
    92     
       
    93     CMPXMedia* media = aContent->GetMpxMedia();
       
    94     
       
    95     if( !media )
       
    96         {
       
    97         IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::AddDownload OUT, media == NULL");
       
    98         return;
       
    99         }
       
   100 
       
   101     TInt index( KErrNotFound );
       
   102     
       
   103     if( !FindDownload( aContent, &index ) )
       
   104         {
       
   105         TDownloadItem item;
       
   106         item.iContent = aContent;
       
   107         
       
   108         TUint32 status = media->ValueTObjectL<TUint8>( KVcxMediaMyVideosDownloadState );
       
   109         TInt8 progress = media->ValueTObjectL<TInt8>( KVcxMediaMyVideosDownloadProgress );
       
   110 
       
   111         item.iProgress = progress;
       
   112         item.iState = status;
       
   113         
       
   114         iDownloadArray.Append( item );
       
   115         }
       
   116     
       
   117     if( !iTimer->IsActive() )
       
   118         {
       
   119         TCallBack callback = TCallBack( Callback, this );
       
   120         const TTimeIntervalMicroSeconds32 KUpdateInterval( KUpdateDelay );
       
   121         iTimer->Start( KUpdateInterval, KUpdateInterval, callback );
       
   122         }
       
   123     
       
   124     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::AddDownload OUT");
       
   125     }
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CVcxNsDownloadUpdater::RemoveDownload( CVcxNsContent* aContent )
       
   131     {
       
   132     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::RemoveDownload IN");
       
   133 
       
   134     if ( !aContent )
       
   135         {
       
   136         return;
       
   137         }
       
   138     
       
   139     TInt index( KErrNotFound );
       
   140     
       
   141     if( FindDownload( aContent, &index ) )
       
   142         {
       
   143         iDownloadArray.Remove( index );
       
   144         }
       
   145     
       
   146     if( iDownloadArray.Count() < 1 )
       
   147         {
       
   148         iTimer->Cancel();        
       
   149         } 
       
   150 
       
   151     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::RemoveDownload OUT");
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CVcxNsDownloadUpdater::RemoveAllDownloads()
       
   159     {
       
   160     iDownloadArray.Reset();
       
   161     
       
   162     iTimer->Cancel(); 
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 TInt CVcxNsDownloadUpdater::Callback( TAny *aPtr )
       
   170     {
       
   171     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::Callback IN");
       
   172     
       
   173     CVcxNsDownloadUpdater* ptr = static_cast<CVcxNsDownloadUpdater*>( aPtr );
       
   174     
       
   175     TInt err ( KErrNotFound );
       
   176     
       
   177     if ( ptr )
       
   178         {
       
   179         TRAP( err, ptr->UpdateDownloadsL() ); 
       
   180         }
       
   181 
       
   182 #ifdef _DEBUG
       
   183     if( err )
       
   184         {
       
   185         IPTVLOGSTRING2_LOW_LEVEL("CVcxNsDownloadUpdater::Callback leaved with %d", err);
       
   186         }
       
   187 #endif // _DEBUG
       
   188     
       
   189     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::Callback OUT");
       
   190     
       
   191     return 0;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // 
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CVcxNsDownloadUpdater::UpdateDownloadsL()
       
   199     {
       
   200     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::UpdateDownloadsL IN");
       
   201     
       
   202     for ( TInt i = 0; i < iDownloadArray.Count(); i++ )
       
   203         {
       
   204         UpdateDownloadL( iDownloadArray[i] );
       
   205         }
       
   206     
       
   207     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::UpdateDownloadsL OUT");
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // 
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CVcxNsDownloadUpdater::UpdateDownloadL( TDownloadItem& aDownload )
       
   215     {
       
   216     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::UpdateDownloadL IN");
       
   217     
       
   218     CMPXMedia* media = aDownload.iContent->GetMpxMedia();
       
   219     
       
   220     if ( !media )
       
   221         {
       
   222         return;
       
   223         }
       
   224     
       
   225     TUint32 status = media->ValueTObjectL<TUint8>( KVcxMediaMyVideosDownloadState );
       
   226     TInt8 progress = media->ValueTObjectL<TInt8>( KVcxMediaMyVideosDownloadProgress );
       
   227     TUint32 mpxId  = media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ).iId1;
       
   228 
       
   229     if ( progress == 0 && aDownload.iProgress > 0 )
       
   230         {
       
   231         IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::UpdateDownloadL: Resume started from beginning.");
       
   232         iObserver->ResumeStartedFromBeginningL( mpxId );
       
   233         }
       
   234     if ( progress != aDownload.iProgress || status != aDownload.iState )
       
   235         {
       
   236         IPTVLOGSTRING2_LOW_LEVEL("CVcxNsDownloadUpdater:: dl state    = %d", status );
       
   237         IPTVLOGSTRING2_LOW_LEVEL("CVcxNsDownloadUpdater:: dl progress = %d", progress );
       
   238         
       
   239         IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::UpdateDownloadL: updating video");
       
   240         aDownload.iProgress = progress;
       
   241         aDownload.iState = status;        
       
   242 
       
   243         iObserver->UpdateVideoObject( mpxId );
       
   244         }
       
   245 
       
   246     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::UpdateDownloadL OUT");
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // 
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 TBool CVcxNsDownloadUpdater::FindDownload( CVcxNsContent* aContent, TInt* aIndex )
       
   254     {
       
   255     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::FindDownload IN");
       
   256     
       
   257     for ( TInt i = iDownloadArray.Count()-1; i >= 0; i-- )
       
   258         {
       
   259         if ( iDownloadArray[i].iContent == aContent )
       
   260             {
       
   261             *aIndex = i;
       
   262             
       
   263             IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::FindDownload OUT: found");
       
   264             
       
   265             return ETrue;
       
   266             }
       
   267         }
       
   268     
       
   269     IPTVLOGSTRING_LOW_LEVEL("CVcxNsDownloadUpdater::FindDownload OUT: NOT found");
       
   270     
       
   271     return EFalse;
       
   272     }