182 // -------------------------------------------------------------------------------------------- |
182 // -------------------------------------------------------------------------------------------- |
183 |
183 |
184 CNetConnManager::~CNetConnManager() |
184 CNetConnManager::~CNetConnManager() |
185 { |
185 { |
186 Cancel(); |
186 Cancel(); |
187 |
187 |
188 iDownloadMgr.Close(); |
188 delete iHTTPReceiver; |
189 } |
189 } |
190 |
190 |
191 // -------------------------------------------------------------------------------------------- |
191 // -------------------------------------------------------------------------------------------- |
192 |
192 |
193 void CNetConnManager::ConstructL() |
193 void CNetConnManager::ConstructL() |
199 SetActive(); |
199 SetActive(); |
200 |
200 |
201 // set the death status pointer point to the request status of this ao |
201 // set the death status pointer point to the request status of this ao |
202 iAttributes.iDeathStatus = &iStatus; |
202 iAttributes.iDeathStatus = &iStatus; |
203 |
203 |
204 // init |
204 iHTTPReceiver = CHTTPReceiver::NewL( *this ); |
205 TUid dlUid; |
|
206 dlUid.iUid = 0x00011100 + iAttributes.iId; // generate unique identifier instead of using the LoadGen uid for all instances |
|
207 iDownloadMgr.ConnectL(dlUid, *this, ETrue); |
|
208 |
205 |
209 // start timer |
206 // start timer |
210 iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
207 iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
211 iPeriodicTimer->Start(KDefaultStart, KDefaultPeriod, TCallBack(PeriodicTimerCallBack, this)); |
208 iPeriodicTimer->Start(KDefaultStart, KDefaultPeriod, TCallBack(PeriodicTimerCallBack, this)); |
212 } |
209 } |
239 |
236 |
240 // -------------------------------------------------------------------------------------------- |
237 // -------------------------------------------------------------------------------------------- |
241 |
238 |
242 void CNetConnManager::StartDownloadL() |
239 void CNetConnManager::StartDownloadL() |
243 { |
240 { |
244 iDownloadMgr.SetIntAttribute(EDlMgrExitAction, EExitPause); |
|
245 iDownloadMgr.DeleteAll(); |
|
246 |
241 |
247 // create new download |
242 // create new download |
248 TBuf8<256> url; |
243 TBuf8<256> url; |
249 url.Copy(iAttributes.iDestination); |
244 url.Copy(iAttributes.iDestination); |
250 |
245 |
251 RHttpDownload& download = iDownloadMgr.CreateDownloadL( url ); |
246 iHTTPReceiver->SendHTTPGetL( url ); |
252 |
247 } |
253 download.SetIntAttribute(EDlAttrAction, EDoNothing); // do nothing when download has finished |
248 |
254 download.SetBoolAttribute(EDlAttrHidden, ETrue); // download is hidden |
249 // -------------------------------------------------------------------------------------------- |
255 download.SetIntAttribute(EDlAttrRestartAction, ERestartForced); // force to download always ignoring cache |
250 |
256 |
251 void CNetConnManager::HTTPFileReceived( TInt aStatus ) |
257 // start the download |
252 { |
258 download.Start(); |
253 switch ( aStatus ) |
259 } |
|
260 |
|
261 // -------------------------------------------------------------------------------------------- |
|
262 |
|
263 void CNetConnManager::HandleDMgrEventL(RHttpDownload& aDownload, THttpDownloadEvent aEvent) |
|
264 { |
|
265 if (aEvent.iProgressState == EHttpContentTypeReceived) |
|
266 { |
254 { |
267 // need to start the download if already not started |
255 case 200: |
268 aDownload.Start(); |
|
269 } |
|
270 |
|
271 switch ( aEvent.iDownloadState ) |
|
272 { |
|
273 case EHttpDlPaused: |
|
274 case EHttpDlCompleted: |
|
275 case EHttpDlFailed: |
|
276 { |
256 { |
277 // assume that the download has finished in this stage |
257 // assume that the download has finished in this stage |
278 // delete download and restart |
|
279 aDownload.Delete(); |
|
280 iPeriodicTimer->Start(CLoadGenUtils::MilliSecondsToMicroSeconds(iAttributes.iIdle, iAttributes.iRandomVariance), KDefaultPeriod, TCallBack(PeriodicTimerCallBack, this)); |
258 iPeriodicTimer->Start(CLoadGenUtils::MilliSecondsToMicroSeconds(iAttributes.iIdle, iAttributes.iRandomVariance), KDefaultPeriod, TCallBack(PeriodicTimerCallBack, this)); |
281 break; |
259 break; |
282 } |
260 } |
283 |
261 |
284 default: |
262 default: |