19 #ifndef HEADER_SUPERTUX_ADDON_DOWNLOADER_HPP 20 #define HEADER_SUPERTUX_ADDON_DOWNLOADER_HPP 23 #include <curl/curl.h> 24 #include <curl/easy.h> 31 #include "addon/downloader_defines.hpp" 33 typedef int TransferId;
43 const std::string file;
44 std::vector<std::function<void (bool)> > callbacks;
51 std::string error_msg;
58 const std::string& url);
63 void then(
const std::function<
void (
bool)>& callback)
65 callbacks.push_back(callback);
78 std::vector<TransferStatusPtr> m_transfer_statuses;
79 int m_successful_count;
80 std::vector<std::function<void (bool)> > m_callbacks;
82 std::string m_error_msg;
91 void push(TransferStatusPtr status);
92 void push(TransferStatusListPtr statuses);
94 void then(
const std::function<
void (
bool)>& callback)
96 m_callbacks.push_back(callback);
99 int get_download_now()
const;
100 int get_download_total()
const;
101 const std::string& get_error()
const {
return m_error_msg; }
103 bool is_active()
const;
107 void on_transfer_complete(TransferStatusPtr this_status,
bool successful);
122 CURLM* m_multi_handle;
124 std::map<TransferId, std::unique_ptr<Transfer> > m_transfers;
125 int m_next_transfer_id;
127 float m_last_update_time;
134 std::string download(
const std::string& url);
137 void download(
const std::string& url,
const std::string& filename);
139 void download(
const std::string& url,
140 size_t (*write_func)(
void* ptr,
size_t size,
size_t nmemb,
void* userdata),
145 TransferStatusPtr request_download(
const std::string& url,
const std::string& filename);
146 void abort(TransferId
id);
149 void onDownloadProgress(
int id,
int loaded,
int total);
150 void onDownloadFinished(
int id);
151 void onDownloadError(
int id);
152 void onDownloadAborted(
int id);
Definition: downloader.hpp:118
Definition: downloader.hpp:35
Definition: downloader.hpp:73
Definition: downloader.cpp:235