browserutilities/downloadmgr/DownloadMgrClntSrv/src/DownloadMgrEventQueue.cpp
changeset 0 dd21522fd290
child 37 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "DownloadMgrEventQueue.h"
       
    22 #include "DownloadMgrLogger.h"
       
    23 #include <HttpDownload.h>
       
    24 
       
    25 #ifdef __DOWNLOADMGR_LOG__
       
    26 //#define __DUMP_EVENT_QUEUE
       
    27 #ifdef __DUMP_EVENT_QUEUE
       
    28 #pragma message ("Dump event queue!!!")
       
    29 #endif /* __DUMP_EVENT_QUEUE */
       
    30 #endif /*__DOWNLOADMGR_LOG__*/
       
    31 // ============================= LOCAL FUNCTIONS ===============================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CDownloadMgrEventQueue::CDownloadMgrEventQueue
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CDownloadMgrEventQueue::CDownloadMgrEventQueue()
       
    38 	{
       
    39 	__DECLARE_NAME( _S( "CDownloadMgrEventQueue" ) );
       
    40 	CLOG_CREATE;
       
    41 	}
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // CDownloadMgrEventQueue::~CDownloadMgrEventQueue
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 CDownloadMgrEventQueue::~CDownloadMgrEventQueue()
       
    48 	{
       
    49 	iEventQueue.ResetAndDestroy();
       
    50 	CLOG_CLOSE;
       
    51 	}
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CDownloadMgrEventQueue::In
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 TBool CDownloadMgrEventQueue::In( CHttpDownload* aDownload, 
       
    58                                   THttpDownloadState aDlState,
       
    59                                   THttpProgressState aProgState,
       
    60                                   TInt32 aMoIndex )
       
    61 	{
       
    62     CLOG_ENTERFN( "CDownloadMgrEventQueue::In" );
       
    63 
       
    64     if( aDlState == EHttpDlInprogress && 
       
    65         aProgState == EHttpProgResponseBodyReceived && 
       
    66         iEventQueue.Count() )
       
    67         // If EHttpDlInprogress-EHttpProgResponseBodyReceived is last
       
    68         // event in the queue, it doesn't need to be appended again.
       
    69         {
       
    70         CLOG_WRITE( "In-progress filter" );
       
    71         TInt count = iEventQueue.Count();
       
    72         TInt32 dlState;
       
    73         TInt32 progState;
       
    74         TInt32 moIndex;
       
    75 
       
    76         CEventRecord* record = iEventQueue[count-1];
       
    77         record->States( dlState, progState, moIndex );
       
    78 
       
    79         if( aDlState == dlState &&
       
    80             aProgState == progState &&
       
    81             aMoIndex == moIndex &&
       
    82             aDownload == record->Download())
       
    83             {
       
    84             CLOG_WRITE( "Event filtered" );
       
    85             return ETrue;
       
    86             }
       
    87         }
       
    88 
       
    89     CEventRecord* record = new CEventRecord( aDownload, aDlState, aProgState, aMoIndex );
       
    90     if( record == NULL )
       
    91         {
       
    92         return EFalse;
       
    93         }
       
    94         
       
    95     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::In: 0x%x", record );
       
    96         
       
    97     TInt err = iEventQueue.Append( record );
       
    98     if( KErrNone != err )
       
    99         {
       
   100         delete record;
       
   101         return EFalse;
       
   102         }
       
   103 #ifdef __DUMP_EVENT_QUEUE
       
   104     CLOG_WRITE( "=====================>>>>" );
       
   105     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::In Download: 0x%x", aDownload )
       
   106     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::In State: %d", aDlState )
       
   107     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::In Progress: %d",aProgState )
       
   108     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::In Media Index: %d",aMoIndex )
       
   109     CLOG_WRITE( "Dump event queue---------" );
       
   110     for( TInt i = 0; i < iEventQueue.Count(); i++ )
       
   111         {
       
   112         CLOG_WRITE_FORMAT( "i= %d", i )
       
   113         CEventRecord* r = iEventQueue[i];
       
   114         CLOG_WRITE_FORMAT( "Download: 0x%x", r->Download() )
       
   115         TInt32 state;
       
   116         TInt32 progress;
       
   117         TInt32 mediaIndex;
       
   118         r->States( state, progress, mediaIndex );
       
   119         CLOG_WRITE_FORMAT( "Download: 0x%x", r->Download() )
       
   120         CLOG_WRITE_FORMAT( "State: %d", state )
       
   121         CLOG_WRITE_FORMAT( "Progress: %d", progress )        
       
   122         CLOG_WRITE_FORMAT( "Media Index: %d", mediaIndex ) 
       
   123         }
       
   124     CLOG_WRITE( "=====================>>>>" );
       
   125 #endif /* __DUMP_EVENT_QUEUE */
       
   126 
       
   127     return ETrue;
       
   128 	}
       
   129 
       
   130 // ---------------------------------------------------------
       
   131 // CDownloadMgrEventQueue::Next
       
   132 // ---------------------------------------------------------
       
   133 //
       
   134 CHttpDownload* CDownloadMgrEventQueue::Next( TInt32& aDownloadState,
       
   135                                              TInt32& aProgressState,
       
   136                                              TInt32& aMoIndex )
       
   137 	{
       
   138     CLOG_ENTERFN( "CDownloadMgrEventQueue::Next" );
       
   139     CEventRecord* record = iEventQueue[ 0 ];
       
   140     record->States( aDownloadState, aProgressState, aMoIndex );
       
   141     CLOG_WRITE( "Next=====================" );
       
   142     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::Next Download: 0x%x", record->Download() )
       
   143     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::Next State: %d", aDownloadState )
       
   144     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::Next Progress: %d",aProgressState ) 
       
   145     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::Next Media Index: %d",aMoIndex ) 
       
   146 #ifdef __DUMP_EVENT_QUEUE
       
   147    
       
   148     CLOG_WRITE( "Dump event queue---------" );
       
   149     for( TInt i = 0; i < iEventQueue.Count(); i++ )
       
   150         {
       
   151         CLOG_WRITE_FORMAT( "i= %d", i )
       
   152         CEventRecord* r = iEventQueue[i];
       
   153         TInt32 dlState;
       
   154         TInt32 progState;
       
   155         TInt32 mediaIndex;
       
   156         r->States( dlState, progState, mediaIndex );
       
   157         CLOG_WRITE_FORMAT( "Download: 0x%x", r->Download() )
       
   158         CLOG_WRITE_FORMAT( "State: %d", dlState )
       
   159         CLOG_WRITE_FORMAT( "Progress: %d", progState )
       
   160         CLOG_WRITE_FORMAT( "Media Index: %d", mediaIndex )
       
   161         }
       
   162     CLOG_WRITE( "Next=====================" );    
       
   163 #endif /* __DUMP_EVENT_QUEUE */
       
   164     
       
   165 	return record->Download();
       
   166 	}
       
   167 
       
   168 // ---------------------------------------------------------
       
   169 // CDownloadMgrEventQueue::Out
       
   170 // ---------------------------------------------------------
       
   171 //
       
   172 void CDownloadMgrEventQueue::Out()
       
   173 	{
       
   174     CLOG_ENTERFN( "CDownloadMgrEventQueue::Out" );
       
   175 
       
   176     CEventRecord* record = iEventQueue[ 0 ];
       
   177     iEventQueue.Remove( 0 );
       
   178     CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::Out Download: 0x%x", record->Download() )
       
   179     delete record;
       
   180     iEventQueue.Compress();
       
   181 
       
   182 #ifdef __DUMP_EVENT_QUEUE
       
   183     CLOG_WRITE( "<<<<=====================" );
       
   184     CLOG_WRITE( "Dump event queue---------" );
       
   185     for( TInt i = 0; i < iEventQueue.Count(); i++ )
       
   186         {
       
   187         CLOG_WRITE_FORMAT( "i= %d", i )
       
   188         CEventRecord* r = iEventQueue[i];
       
   189         TInt32 dlState;
       
   190         TInt32 progState;
       
   191         r->States( dlState, progState );        
       
   192         CLOG_WRITE_FORMAT( "Download: 0x%x", r->Download() )
       
   193         CLOG_WRITE_FORMAT( "State: %d", dlState )
       
   194         CLOG_WRITE_FORMAT( "Progress: %d", progState )
       
   195         }
       
   196     CLOG_WRITE( "<<<<=====================" );
       
   197 #endif /* __DUMP_EVENT_QUEUE */
       
   198 	}
       
   199 
       
   200 // ---------------------------------------------------------
       
   201 // CDownloadMgrEventQueue::IsEmpty
       
   202 // ---------------------------------------------------------
       
   203 //	
       
   204 TBool CDownloadMgrEventQueue::IsEmpty() const
       
   205 	{
       
   206     CLOG_WRITE( "CDownloadMgrEventQueue::IsEmpty" );
       
   207     return ( iEventQueue.Count() ? EFalse : ETrue );
       
   208 	}
       
   209 
       
   210 // ---------------------------------------------------------
       
   211 // CDownloadMgrEventQueue::Remove
       
   212 // ---------------------------------------------------------
       
   213 //	
       
   214 void CDownloadMgrEventQueue::Remove( CHttpDownload* aDownload )
       
   215 	{
       
   216     CLOG_WRITE( "CDownloadMgrEventQueue::Remove" );
       
   217     for( TInt i = 0; i < iEventQueue.Count(); i++ )
       
   218         {
       
   219         if( iEventQueue[i]->IsDownload( aDownload ) )
       
   220             {
       
   221             CEventRecord* record = iEventQueue[i];
       
   222             CLOG_WRITE_FORMAT( "CDownloadMgrEventQueue::Remove Download: 0x%x", record->Download() )
       
   223             iEventQueue.Remove( i );
       
   224             delete record;
       
   225             record = NULL;
       
   226             iEventQueue.Compress();
       
   227             i--;
       
   228             }
       
   229         }
       
   230 	}
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CEventRecord::CEventRecord
       
   234 // ---------------------------------------------------------
       
   235 //
       
   236 CEventRecord::CEventRecord( CHttpDownload* aDownload, 
       
   237                             TInt32 aDownloadState,
       
   238                             TInt32 aProgressState,
       
   239                             TInt32 aMoIndex )
       
   240 :iDownloadState( aDownloadState )
       
   241 ,iProgressState( aProgressState )
       
   242 ,iMoIndex( aMoIndex )
       
   243     {
       
   244     iDownload = aDownload;
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------
       
   248 // CEventRecord::~CEventRecord
       
   249 // ---------------------------------------------------------
       
   250 //
       
   251 CEventRecord::~CEventRecord()
       
   252     {
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------
       
   256 // CEventRecord::States
       
   257 // ---------------------------------------------------------
       
   258 //
       
   259 void CEventRecord::States( TInt32& aDownloadState,
       
   260                            TInt32& aProgressState,
       
   261                            TInt32& aMoIndex )
       
   262     {
       
   263     aDownloadState = iDownloadState;
       
   264     aProgressState = iProgressState;
       
   265     aMoIndex = iMoIndex;
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------
       
   269 // CEventRecord::Download
       
   270 // ---------------------------------------------------------
       
   271 //
       
   272 CHttpDownload* CEventRecord::Download()
       
   273     {
       
   274     return iDownload;
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------
       
   278 // CEventRecord::IsDownload
       
   279 // ---------------------------------------------------------
       
   280 //
       
   281 TBool CEventRecord::IsDownload( CHttpDownload* aDownload )
       
   282     {
       
   283     return (iDownload == aDownload) ? ETrue : EFalse;
       
   284     }
       
   285 
       
   286 //  End of File