Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
DownloadQueue Class Reference
Collaboration diagram for DownloadQueue:
Collaboration graph
[legend]

Public Member Functions

void downloadAdd (DownloadOperation *download)
 add a new download operation More...
 
void downloadCancel (DownloadOperation *download)
 cancel a download operation More...
 
int process ()
 process finished and queued downloads More...
 

Static Public Member Functions

static void init ()
 
static void quit ()
 

Static Public Attributes

static DownloadQueuedownloadQueue = NULL
 

Detailed Description

Definition at line 39 of file DownloadQueue.hpp.

Constructor & Destructor Documentation

◆ DownloadQueue()

DownloadQueue::DownloadQueue ( )

Definition at line 61 of file DownloadQueue.cpp.

62{
63#ifndef NETWORK_MOCK
64 cm = curl_multi_init();
65 curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, MAX_PARALLEL_DOWNLOADS);
66#endif
67}

◆ ~DownloadQueue()

DownloadQueue::~DownloadQueue ( )

Definition at line 69 of file DownloadQueue.cpp.

70{
71#ifndef NETWORK_MOCK
72 curl_multi_cleanup(cm);
73 cm = NULL;
74#endif
75}

Member Function Documentation

◆ downloadAdd()

void DownloadQueue::downloadAdd ( DownloadOperation download)

add a new download operation

Definition at line 78 of file DownloadQueue.cpp.

79{
80 download->status = DownloadStatus::QUEUED;
81 queue.push_back(download);
82}

Referenced by NetImageElement::fetch().

◆ downloadCancel()

void DownloadQueue::downloadCancel ( DownloadOperation download)

cancel a download operation

Definition at line 85 of file DownloadQueue.cpp.

86{
87 if (download->status == DownloadStatus::DOWNLOADING)
88 transferFinish(download);
89 else if (download->status == DownloadStatus::QUEUED && queue.size() > 0)
90 queue.remove(download);
91}

◆ init()

void DownloadQueue::init ( )
static

Definition at line 44 of file DownloadQueue.cpp.

45{
46 downloadQueue = new DownloadQueue();
47}

◆ process()

int DownloadQueue::process ( )

process finished and queued downloads

Definition at line 153 of file DownloadQueue.cpp.

154{
155#ifndef NETWORK_MOCK
156 DownloadOperation *download;
157 int still_alive = 1;
158 int msgs_left = -1;
159
160 CURLMsg *msg;
161
162 curl_multi_perform(cm, &still_alive);
163
164 // handle completed or failed downloads
165 while(msg = curl_multi_info_read(cm, &msgs_left))
166 {
167 long response_code = 404;
168
169 if (msg->msg != CURLMSG_DONE)
170 continue;
171
172 curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &download);
173 curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &response_code);
174
175 transferFinish(download);
176 startTransfersFromQueue();
177
178 if (response_code == 200)
179 download->status = DownloadStatus::COMPLETE;
180 else
181 download->status = DownloadStatus::FAILED;
182
183 download->cb(download);
184 }
185
186 startTransfersFromQueue();
187
188 return ((still_alive) || (msgs_left > 0) || (queue.size() > 0));
189#else
190 return false;
191#endif
192}

◆ quit()

void DownloadQueue::quit ( )
static

Definition at line 49 of file DownloadQueue.cpp.

50{
51 delete downloadQueue;
52}

Member Data Documentation

◆ downloadQueue

DownloadQueue * DownloadQueue::downloadQueue = NULL
static

Definition at line 57 of file DownloadQueue.hpp.


The documentation for this class was generated from the following files: