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
Chesto::DownloadQueue Class Reference
Collaboration diagram for Chesto::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 41 of file DownloadQueue.hpp.

Constructor & Destructor Documentation

◆ DownloadQueue()

Chesto::DownloadQueue::DownloadQueue ( )

Definition at line 63 of file DownloadQueue.cpp.

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

◆ ~DownloadQueue()

Chesto::DownloadQueue::~DownloadQueue ( )

Definition at line 71 of file DownloadQueue.cpp.

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

Member Function Documentation

◆ downloadAdd()

void Chesto::DownloadQueue::downloadAdd ( DownloadOperation download)

add a new download operation

Definition at line 80 of file DownloadQueue.cpp.

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

◆ downloadCancel()

void Chesto::DownloadQueue::downloadCancel ( DownloadOperation download)

cancel a download operation

Definition at line 87 of file DownloadQueue.cpp.

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

◆ init()

void Chesto::DownloadQueue::init ( )
static

Definition at line 46 of file DownloadQueue.cpp.

47{
48 downloadQueue = new DownloadQueue();
49}

◆ process()

int Chesto::DownloadQueue::process ( )

process finished and queued downloads

Definition at line 158 of file DownloadQueue.cpp.

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

◆ quit()

void Chesto::DownloadQueue::quit ( )
static

Definition at line 51 of file DownloadQueue.cpp.

52{
53 delete downloadQueue;
54}

Member Data Documentation

◆ downloadQueue

DownloadQueue * Chesto::DownloadQueue::downloadQueue = NULL
static

Definition at line 59 of file DownloadQueue.hpp.


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