|
1 /** @file |
|
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: Handles uploads |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System include files |
|
20 #include <es_sock.h> |
|
21 |
|
22 // User include files |
|
23 #include "httpuploader.h" |
|
24 #include "httpuploadworker.h" |
|
25 #include "httptransferbase.h" |
|
26 #include "httptransferobserver.h" |
|
27 |
|
28 // Constants |
|
29 const TUint KMaxParallelTransfers = 5; |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // -------------------------------------------------------------------------- |
|
34 // CHttpUploader::CHttpDownloader() |
|
35 // -------------------------------------------------------------------------- |
|
36 // |
|
37 CHttpUploader::CHttpUploader( |
|
38 MHttpTransferObserver& aObserver, |
|
39 TUint aIAPId, |
|
40 TUint aBufferSize, |
|
41 TUint aParallelTransfers = KDefaultParallelTransfers ) |
|
42 { |
|
43 iObserver = &aObserver; |
|
44 iIAPId = aIAPId; |
|
45 iBufferSize = aBufferSize; |
|
46 |
|
47 if ( aParallelTransfers <= 0 ) |
|
48 { |
|
49 iParallelTransfers = KDefaultParallelTransfers; |
|
50 } |
|
51 else if ( aParallelTransfers > KMaxParallelTransfers ) |
|
52 { |
|
53 iParallelTransfers = KMaxParallelTransfers; |
|
54 } |
|
55 else |
|
56 { |
|
57 iParallelTransfers = aParallelTransfers; |
|
58 } |
|
59 } |
|
60 |
|
61 |
|
62 // -------------------------------------------------------------------------- |
|
63 // CHttpUploader::ConstructL() |
|
64 // (See comments in header file) |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 void CHttpUploader::ConstructL() |
|
68 { |
|
69 |
|
70 for ( TInt i=0; i < iParallelTransfers; i++ ) |
|
71 { |
|
72 iWorkerArray.Append( CHttpUploadWorker::NewL( *iObserver, |
|
73 iIAPId, |
|
74 iBufferSize, |
|
75 *this ) ); |
|
76 } |
|
77 } |
|
78 |
|
79 |
|
80 // -------------------------------------------------------------------------- |
|
81 // CHttpUploader::NewL() |
|
82 // (See comments in header file) |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C CHttpUploader* CHttpUploader::NewL( |
|
86 MHttpTransferObserver& aObserver, |
|
87 TUint aIAPId, |
|
88 TUint aBufferSize, |
|
89 TUint aParallelTransfers ) |
|
90 { |
|
91 CHttpUploader* self = CHttpUploader::NewLC( aObserver, |
|
92 aIAPId, |
|
93 aBufferSize, |
|
94 aParallelTransfers ); |
|
95 CleanupStack::Pop( self ); |
|
96 return self; |
|
97 } |
|
98 |
|
99 |
|
100 // -------------------------------------------------------------------------- |
|
101 // CHttpDownloader::NewLC() |
|
102 // (See comments in header file) |
|
103 // -------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C CHttpUploader* CHttpUploader::NewLC( |
|
106 MHttpTransferObserver& aObserver, |
|
107 TUint aIAPId, |
|
108 TUint aBufferSize, |
|
109 TUint aParallelTransfers ) |
|
110 { |
|
111 CHttpUploader* self = new( ELeave ) CHttpUploader( aObserver, |
|
112 aIAPId, |
|
113 aBufferSize, |
|
114 aParallelTransfers ); |
|
115 CleanupStack::PushL( self ); |
|
116 self->ConstructL(); |
|
117 return self; |
|
118 } |
|
119 |
|
120 |
|
121 // -------------------------------------------------------------------------- |
|
122 // CHttpUploader::~CHttpUploader() |
|
123 // (See comments in header file) |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 CHttpUploader::~CHttpUploader() |
|
127 { |
|
128 } |
|
129 |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CHttpUploader::UploadFileL |
|
133 // (See comments in header file) |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C void CHttpUploader::UploadFileL( const TDesC8& aUri, |
|
137 const TDesC& aTargetPath, |
|
138 TAny* aKey ) |
|
139 { |
|
140 // if aKey already exists -> leave |
|
141 for ( TInt i=0; i < iFileQueue.Count(); i++ ) |
|
142 { |
|
143 if ( iFileQueue[i]->Key() == aKey ) |
|
144 { |
|
145 User::Leave( KErrAlreadyExists ); |
|
146 } |
|
147 } |
|
148 |
|
149 // Add new CHttpFile into the iFileQueue |
|
150 CreateAndQueueHttpFileL( aUri, aTargetPath, aKey ); |
|
151 |
|
152 // Activate new request |
|
153 ActivateNewTransferRequest(); |
|
154 } |
|
155 |
|
156 |
|
157 // end of file |