|
1 /* |
|
2 * Copyright (c) 2009-2010 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: |
|
15 * Declares DownloadHandler class for application. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef __ADMDOWNLOADHANDLER_H__ |
|
22 #define __ADMDOWNLOADHANDLER_H__ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <downloadmgrclient.h> |
|
26 #include "globals.h" |
|
27 #include "networkstatusobserver.h" |
|
28 |
|
29 // Forward declarations |
|
30 class CADMAppUi; |
|
31 class CNetworkStatusListener; |
|
32 class RFileLogger; |
|
33 |
|
34 class CDownloadHandler : public CBase, |
|
35 public MHttpDownloadMgrObserver, |
|
36 public MNetworkStatusObserver |
|
37 { |
|
38 public: |
|
39 class MDownloadClient |
|
40 { |
|
41 public: |
|
42 virtual void HandleIapChanged( const TUint32 aIAP ) = 0; |
|
43 virtual void HandleHttpFetchCompleted( const TDesC& aDlFilename, const TInt aDownloadType, const TInt32 aBytesDownloaded, const TReal32 aAvgDlSpeed, const TInt64 aDlTime ) = 0; |
|
44 virtual void HandleHttpFetchInProgress( const TInt32 aDownloaded, const TInt32 aTotalDownloadSize, const TReal32 aAvgDlSpeed ) = 0; |
|
45 virtual void HandleHttpFetchFailure( const TDesC& aDlFilename, const TInt aGlobalErrorId, const TInt aErrorId, const TInt aFetchType ) = 0; |
|
46 virtual void HandleDownloadDeleting() = 0; |
|
47 }; |
|
48 |
|
49 #ifdef USE_LOGFILE |
|
50 public: |
|
51 static CDownloadHandler* NewL(MDownloadClient* aDlClient, RFileLogger& aLogger, const TBool aMasterInstance); |
|
52 void Log(TRefByValue<const TDesC16> aFmt, ...); |
|
53 |
|
54 private: |
|
55 CDownloadHandler( MDownloadClient* aDlClient, RFileLogger& aLogger, const TBool aMasterInstance ); |
|
56 |
|
57 private: |
|
58 RFileLogger& iLog; ///< Not Owned |
|
59 |
|
60 #else |
|
61 public: |
|
62 static CDownloadHandler* NewL(MDownloadClient* aDlClient, const TBool aMasterInstance); |
|
63 static CDownloadHandler* NewLC(MDownloadClient* aDlClient, const TBool aMasterInstance); |
|
64 |
|
65 private: |
|
66 CDownloadHandler( MDownloadClient* aDlClient, const TBool aMasterInstance ); |
|
67 #endif |
|
68 |
|
69 public: |
|
70 ~CDownloadHandler(); |
|
71 |
|
72 public: |
|
73 void HandleDMgrEventL( RHttpDownload& aDownload, THttpDownloadEvent aEvent ); |
|
74 void StartDownloadL( const TDesC8& aDepUrl, const TDesC& aFileName, const TDesC& aDownloadPath, const TInt aFetchType ); |
|
75 void CancelAllDownloads(); |
|
76 void SetIAP( TUint32 aIAP ); |
|
77 |
|
78 inline EDownloadError GetDownloadError() const |
|
79 { |
|
80 return iDownloadError; |
|
81 } |
|
82 |
|
83 //From MNetworkStatusObserver |
|
84 void HandleNetworkStatusChangedL( const TInt aStatus ); |
|
85 |
|
86 private: |
|
87 void ConstructL(); |
|
88 TBool ProcessDlErrors(const TInt32 aGlErrId, const TInt32 aErrId, EDownloadError& aDownloadError); |
|
89 TInt64 UpdateDownloadSpeed(const TInt32 aBytesDownloaded); |
|
90 void DoHandleHttpFetchFailure(const TDesC& aDlFilename, const TInt aGlobalErrorId, const TInt aErrorId); |
|
91 |
|
92 private: |
|
93 MDownloadClient* iDlClient; |
|
94 CNetworkStatusListener* iNetworkStatusListener; |
|
95 TInt iFetchType; |
|
96 TBool iMasterInstance; |
|
97 TBool iNetworkLost; // ETrue, if used network connection is lost during download |
|
98 TBool iCancelled; // ETrue, if called HandleHttpFailure() |
|
99 HBufC8* iUrl; |
|
100 TPtrC8 iPtrToUrl; //to avoid a temporary TPtrC8 being passed by IPC |
|
101 HBufC* iResponseBodyFileName; |
|
102 TPtr iPtrToResponseBodyFileName; |
|
103 RHttpDownloadMgr iDownloadManager; |
|
104 TInt32 iIAP; |
|
105 TInt iConnectionAttempt; |
|
106 EDownloadError iDownloadError; |
|
107 TInt iDownloadState; |
|
108 TInt iProgressState; |
|
109 TTime iDlStartTime; |
|
110 TReal32 iDlAvgSpeed; |
|
111 }; |
|
112 |
|
113 #endif //__ADMDOWNLOADHANDLER_H__ |