|
Gin
|
Asynchronous HTTP download manager with queue and progress tracking. More...
#include <gin_downloadmanager.h>
Classes | |
| struct | DownloadResult |
| Result of a completed or failed download. More... | |
Public Member Functions | |
| DownloadManager (int connectTimeout=30 *1000, int shutdownTimeout=30 *1000) | |
| ~DownloadManager () | |
| void | setQueueFinishedCallback (std::function< void()> callback) |
| This callback is called every time all downloads are finished. | |
| void | setConnectTimeout (int timeout) |
| How long connecting is given before it times out. | |
| void | setRetryLimit (int limit) |
| If a download fails, how long many times it should retry. | |
| void | setRetryDelay (double seconds) |
| If a download fails, how long to wait until trying again. | |
| void | setConcurrentDownloadLimit (int l) |
| Maximum number of downloads to allow at once. | |
| int | getNumberOfDownloads () |
| Number of items in download queue. | |
| void | setThreadPriority (juce::Thread::Priority p) |
| Set download thread priority. | |
| void | setProgressInterval (int ms) |
| Sets minimum time between download progress callbacks in milliseconds. | |
| void | setDownloadBlockSize (int bs) |
| Sets the block size of chunks to download. | |
| int | getNumDownloadsInQueue () |
| void | enableGzipDeflate (bool e) |
| If enabled, will request the server sends the data compressed This only has effect on windows. | |
| void | pauseDownloads (bool) |
| Pause / resume all downloads. | |
| int | startAsyncDownload (juce::String url, juce::String postData, std::function< void(DownloadResult)> completionCallback, std::function< void(juce::int64, juce::int64, juce::int64)> progressCallback=nullptr, juce::String extraHeaders={}) |
| Starts a download and returns the download id which can be used to cancel the download. | |
| int | startAsyncDownload (juce::URL url, std::function< void(DownloadResult)> completionCallback, std::function< void(juce::int64, juce::int64, juce::int64)> progressCallback=nullptr, juce::String extraHeaders={}) |
| void | cancelAllDownloads () |
| Cancels all downloads. | |
| void | cancelDownload (int downloadId) |
| Cancels a download with a given id. | |
| DownloadResult | blockingDownload (juce::String url, juce::String postData, juce::String extraHeaders={}) |
| DownloadResult | blockingDownload (juce::URL url, juce::String extraHeaders={}) |
Asynchronous HTTP download manager with queue and progress tracking.
DownloadManager provides a robust system for downloading files without blocking the message thread. Unlike juce::URL::downloadToFile which blocks during HTTP connection establishment, DownloadManager performs all network operations on background threads and delivers results via callbacks on the message thread.
Key Features:
The manager maintains a queue of downloads, executes them on background threads, and calls completion callbacks on the message thread. This ensures UI remains responsive during large downloads or slow connections.
Usage:
Thread Safety:
| DownloadManager::~DownloadManager | ( | ) |
This callback is called every time all downloads are finished.
How long connecting is given before it times out.
If a download fails, how long many times it should retry.
If a download fails, how long to wait until trying again.
Maximum number of downloads to allow at once.
| int DownloadManager::getNumberOfDownloads | ( | ) |
Number of items in download queue.
| void DownloadManager::setThreadPriority | ( | juce::Thread::Priority | p | ) |
Set download thread priority.
Does not affect priority of already running threads
Sets minimum time between download progress callbacks in milliseconds.
Sets the block size of chunks to download.
Progress callbacks and cancelling downloads can only happen between these blocks. Max size is 128 KB
| int DownloadManager::getNumDownloadsInQueue | ( | ) |
If enabled, will request the server sends the data compressed This only has effect on windows.
On macOS it is handled by the system libraries and is always on.
Pause / resume all downloads.
This actually stops any running downloads and then restarts them when unpaused. You will loose some downloaded data that will need to be redownloaded.
| int DownloadManager::startAsyncDownload | ( | juce::String | url, |
| juce::String | postData, | ||
| std::function< void(DownloadResult)> | completionCallback, | ||
| std::function< void(juce::int64, juce::int64, juce::int64)> | progressCallback = nullptr, |
||
| juce::String | extraHeaders = {} |
||
| ) |
Starts a download and returns the download id which can be used to cancel the download.
progressCallback returns current amount downloaded, total amount to download, and amount downloaded since last callback. Note that for http chunk encoding total size is unknown and will be maximum int64 value.
| int DownloadManager::startAsyncDownload | ( | juce::URL | url, |
| std::function< void(DownloadResult)> | completionCallback, | ||
| std::function< void(juce::int64, juce::int64, juce::int64)> | progressCallback = nullptr, |
||
| juce::String | extraHeaders = {} |
||
| ) |
| void DownloadManager::cancelAllDownloads | ( | ) |
Cancels all downloads.
| DownloadResult DownloadManager::blockingDownload | ( | juce::String | url, |
| juce::String | postData, | ||
| juce::String | extraHeaders = {} |
||
| ) |
| DownloadResult DownloadManager::blockingDownload | ( | juce::URL | url, |
| juce::String | extraHeaders = {} |
||
| ) |