upnpsharing/applicationengine/src/upnpprogresswatcher.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2007 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 "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:      CUpnpProgressWatcher class implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 //  Include Files
       
    25 #include <e32property.h>
       
    26 #include <e32debug.h>
       
    27 #include <upnpstring.h>
       
    28 #include "upnpprogresswatcher.h"
       
    29 #include "upnpfilesharingengine.h"
       
    30 
       
    31 _LIT( KComponentLogfile, "applicationengine.txt");
       
    32 #include "upnplog.h"
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 // The maximum numbers of sharingrequests that can be currently received
       
    37 const TInt KMaxSharingReqs = 2;
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ============================
       
    40 
       
    41 // --------------------------------------------------------------------------
       
    42 // CUpnpProgressWatcher::CUpnpProgressWatcher
       
    43 // C++ default constructor can NOT contain any code, that
       
    44 // might leave.
       
    45 // --------------------------------------------------------------------------
       
    46 //
       
    47 CUpnpProgressWatcher::CUpnpProgressWatcher( CUPnPFileSharingEngine& aEngine )
       
    48     : CActive(CActive::EPriorityStandard),
       
    49       iEngine( aEngine )
       
    50     {
       
    51     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::CUpnpProgressWatcher");
       
    52     }
       
    53 
       
    54 // --------------------------------------------------------------------------
       
    55 // CUpnpProgressWatcher::NewL
       
    56 // Two-phased constructor.
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 CUpnpProgressWatcher* CUpnpProgressWatcher::NewL( 
       
    60     CUPnPFileSharingEngine& aEngine )
       
    61     {
       
    62     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::NewL");
       
    63     CUpnpProgressWatcher* self = 
       
    64         new ( ELeave ) CUpnpProgressWatcher( aEngine );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // --------------------------------------------------------------------------
       
    72 // CUpnpProgressWatcher::ConstructL
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 void CUpnpProgressWatcher::ConstructL()
       
    77     {
       
    78     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::ConstructL");
       
    79 
       
    80     User::LeaveIfError( 
       
    81         iProgressInfo.Attach( KUpnpContentServerCat, ESharingProgress ) );
       
    82     CActiveScheduler::Add(this);
       
    83     }
       
    84 
       
    85 // --------------------------------------------------------------------------
       
    86 // CUpnpProgressWatcher::~CUpnpProgressWatcher
       
    87 // Destructor
       
    88 // --------------------------------------------------------------------------
       
    89 //
       
    90 CUpnpProgressWatcher::~CUpnpProgressWatcher()
       
    91     {
       
    92     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::~CUpnpProgressWatcher");
       
    93 
       
    94     Cancel();
       
    95     iProgressInfo.Close();
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // CUpnpProgressWatcher::StartL
       
   100 // Starts active object
       
   101 // --------------------------------------------------------------------------
       
   102 //
       
   103 void CUpnpProgressWatcher::StartL()
       
   104     {
       
   105     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::StartL begin");
       
   106 
       
   107     TUpnpProgress totalProgress;
       
   108     TPckgBuf<TUpnpProgress> progressBuf( totalProgress );
       
   109     TInt pubErr = iProgressInfo.Get( progressBuf );
       
   110     iEngine.SetShareFileComplete( EFalse );
       
   111     if ( !pubErr )
       
   112         {
       
   113         Mem::Copy( &totalProgress, 
       
   114                    progressBuf.Ptr(), sizeof( TUpnpProgress ) );
       
   115 
       
   116         // update UI
       
   117         SetShowCompleteNote( totalProgress );
       
   118         TProgressInfos progressArr( KMaxSharingReqs );
       
   119         progressArr.Append( totalProgress.iImageVideoProgress );
       
   120         progressArr.Append( totalProgress.iMusicProgress );
       
   121         CleanupClosePushL( progressArr );
       
   122         if ( iEngine.Observer() )
       
   123             {
       
   124             iEngine.Observer()->HandleSharingProgress( 
       
   125                 iEngine, progressArr );
       
   126             }
       
   127         CleanupStack::PopAndDestroy( &progressArr );
       
   128         }
       
   129 
       
   130     if ( !IsActive() && SharingOngoing( totalProgress ) )
       
   131         {
       
   132         // start periodical reporting of progress
       
   133         RunL();
       
   134         }
       
   135 
       
   136     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::StartL end");
       
   137     }
       
   138 
       
   139 // --------------------------------------------------------------------------
       
   140 // CUpnpProgressWatcher::Stop
       
   141 // Stops active object
       
   142 // --------------------------------------------------------------------------
       
   143 //
       
   144 void CUpnpProgressWatcher::Stop()
       
   145     {
       
   146     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::Stop");
       
   147     Cancel();
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // CUpnpProgressWatcher::RunL
       
   152 // Called when asyncronous request is ready
       
   153 // --------------------------------------------------------------------------
       
   154 //
       
   155 void CUpnpProgressWatcher::RunL()
       
   156     {
       
   157     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::RunL");
       
   158 
       
   159     // resubscribe before processing new value to prevent missing updates
       
   160     iProgressInfo.Subscribe( iStatus );
       
   161     SetActive();
       
   162 
       
   163     TUpnpProgress totalProgress;
       
   164     TPckgBuf< TUpnpProgress > paramspkg( totalProgress );
       
   165 
       
   166 
       
   167     // get value
       
   168     if ( iProgressInfo.Get(
       
   169              KUpnpContentServerCat, 
       
   170              ESharingProgress, 
       
   171              paramspkg ) == KErrNotFound )
       
   172         {
       
   173         // property deleted, do necessary actions here...
       
   174         }
       
   175     else
       
   176         {
       
   177         Mem::Copy( &totalProgress, paramspkg.Ptr(), sizeof( TUpnpProgress ) );
       
   178 
       
   179 
       
   180         TProgressInfos progressArr( KMaxSharingReqs );
       
   181 
       
   182         progressArr.Append( totalProgress.iImageVideoProgress );
       
   183         progressArr.Append( totalProgress.iMusicProgress );
       
   184 
       
   185         CleanupClosePushL( progressArr );
       
   186         if ( totalProgress.iError )
       
   187             {
       
   188             HandleErrorL( totalProgress );
       
   189             }
       
   190         else
       
   191             {
       
   192             if ( iEngine.Observer() )
       
   193                 {
       
   194                 // update UI
       
   195                 iEngine.Observer()->HandleSharingProgress( 
       
   196                     iEngine, progressArr );
       
   197                 }
       
   198             if ( progressArr.Count() )
       
   199                 {
       
   200                 __LOG2( "ProgressCallbackL: cout:%d progress:%d\n",
       
   201                     progressArr.Count(), 
       
   202                     progressArr[0].iProgress );
       
   203                 }
       
   204             else
       
   205                 {
       
   206                 __LOG( "progressArr empty" );
       
   207                 }
       
   208 
       
   209             SetShowCompleteNote( totalProgress );
       
   210 
       
   211             if ( iShowCompleteNote && !SharingOngoing( totalProgress ) )
       
   212                 {
       
   213                 // no sharing operations ongoing, stop query
       
   214                 Cancel();
       
   215                 // inform UI to show final note
       
   216                 if ( iEngine.Observer() && iShowCompleteNote )
       
   217                     {
       
   218                     iShowCompleteNote = EFalse;
       
   219                     iEngine.Observer()->HandleSharingDone( 
       
   220                         iEngine, KErrNone );
       
   221                     }
       
   222                 }
       
   223             }
       
   224         CleanupStack::PopAndDestroy( &progressArr );
       
   225         }
       
   226     }
       
   227 
       
   228 // --------------------------------------------------------------------------
       
   229 // CUpnpProgressWatcher::DoCancel
       
   230 // Cancels active object
       
   231 // --------------------------------------------------------------------------
       
   232 //
       
   233 void CUpnpProgressWatcher::DoCancel()
       
   234     {
       
   235     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::DoCancel");
       
   236     iEngine.SetShareFileComplete( ETrue );
       
   237     iProgressInfo.Cancel();
       
   238     }
       
   239 
       
   240 // --------------------------------------------------------------------------
       
   241 // CUpnpProgressWatcher::SetShowCompleteNote
       
   242 // determine need to show complete note, handle errors
       
   243 // --------------------------------------------------------------------------
       
   244 //
       
   245 void CUpnpProgressWatcher::SetShowCompleteNote( 
       
   246     const TUpnpProgress& aProgress )
       
   247     {
       
   248     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::SetShowCompleteNote");
       
   249 
       
   250     if( !iShowCompleteNote )
       
   251         {
       
   252         if( aProgress.iImageVideoProgress.iProgressType != 
       
   253             TUpnpProgressInfo::EVisualStatus ||
       
   254             aProgress.iMusicProgress.iProgressType != 
       
   255             TUpnpProgressInfo::EVisualStatus)
       
   256             {
       
   257             iShowCompleteNote = ETrue;
       
   258             }
       
   259         }
       
   260     }
       
   261 
       
   262 // --------------------------------------------------------------------------
       
   263 // CUpnpProgressWatcher::SharingOngoing
       
   264 // determine need to show complete note, handle errors
       
   265 // --------------------------------------------------------------------------
       
   266 //
       
   267 TBool CUpnpProgressWatcher::SharingOngoing( const TUpnpProgress& aProgress )
       
   268     {
       
   269     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::SharingOngoing");
       
   270     TBool ret( EFalse );
       
   271 
       
   272     if( aProgress.iImageVideoProgress.iProgressType != 
       
   273         TUpnpProgressInfo::EVisualStatus ||
       
   274         aProgress.iMusicProgress.iProgressType !=
       
   275         TUpnpProgressInfo::EVisualStatus)
       
   276         {
       
   277         ret = ETrue;
       
   278         }
       
   279     return ret;
       
   280     }
       
   281 
       
   282 // --------------------------------------------------------------------------
       
   283 // CUpnpProgressWatcher::HandleErrorL
       
   284 // determine need to show complete note, handle errors
       
   285 // --------------------------------------------------------------------------
       
   286 //
       
   287 void CUpnpProgressWatcher::HandleErrorL( const TUpnpProgress& aProgress )
       
   288     {
       
   289     __LOG("[UPNP_ENGINE]\t CUpnpProgressWatcher::HandleIfErrorL");
       
   290     Cancel();
       
   291     if( aProgress.iError == KErrNoMemory || 
       
   292         aProgress.iError == KErrDiskFull )
       
   293         {
       
   294         // update UI
       
   295         TProgressInfos progressArr( KMaxSharingReqs );
       
   296         CleanupClosePushL( progressArr );
       
   297         progressArr.Append( aProgress.iImageVideoProgress );
       
   298         progressArr.Append( aProgress.iMusicProgress );
       
   299         
       
   300         if ( iEngine.Observer() )
       
   301             {
       
   302             iEngine.Observer()->HandleSharingProgress( 
       
   303                 iEngine, progressArr );
       
   304             }
       
   305         CleanupStack::PopAndDestroy( &progressArr );
       
   306         iShowCompleteNote = EFalse;
       
   307         User::Leave( aProgress.iError );
       
   308         }
       
   309     }
       
   310 
       
   311 // End of file