-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDownloadManager.cpp
87 lines (65 loc) · 1.45 KB
/
DownloadManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
This file is part of swan2 project.
Copyright (C) 2013 by Nick Sharmanzhinov
except134@gmail.com
*/
#include "PCH.h"
using namespace swan2;
using namespace swan2::lib;
using namespace swan2::lib::core;
DownloadManager::DownloadManager()
{
}
DownloadManager::~DownloadManager()
{
}
void DownloadManager::Create()
{
}
HTTPDownloader* DownloadManager::CreateDownload()
{
HTTPDownloader* pDL=new HTTPDownloader;
downloadList.push_back(pDL);
pDL->Create(this);
return pDL;
}
void DownloadManager::RemoveDownload(HTTPDownloader* pDownload)
{
auto it=std::find(downloadList.begin(),downloadList.end(),pDownload);
if(it!=downloadList.end()) {
downloadList.erase(it);
}
}
void DownloadManager::Update()
{
auto it=downloadList.begin();
while(it!=downloadList.end()) {
HTTPDownloader* pDL=*it;
switch(pDL->GetState()) {
case HTTP_STATE_NONE:
case HTTP_STATE_WORKING:
++it;
continue;
case HTTP_STATE_COMPLETE:
pDL->OnComplete();
break;
case HTTP_STATE_ERROR:
pDL->OnError();
break;
case HTTP_STATE_CANCELED:
pDL->OnCancel();
break;
}
it=downloadList.erase(it);
pDL->Release();
}
}
void DownloadManager::Release()
{
for(std::list<HTTPDownloader*>::iterator it=downloadList.begin();it!=downloadList.end();) {
HTTPDownloader* pDL=*it;
it=downloadList.erase(it);
pDL->Release();
}
delete this;
}