Gin
Classes | Public Member Functions | List of all members
DownloadManager Class Reference

Downloads files to a memory block and then calls a lambda on the message thread with the results. More...

Classes

struct  DownloadResult
 

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. More...
 
void setConnectTimeout (int timeout)
 How long connecting is given before it times out. More...
 
void setRetryLimit (int limit)
 If a download fails, how long many times it should retry. More...
 
void setRetryDelay (double seconds)
 If a download fails, how long to wait until trying again. More...
 
void setConcurrentDownloadLimit (int l)
 Maximum number of downloads to allow at once. More...
 
int getNumberOfDownloads ()
 Number of items in download queue. More...
 
void setThreadPriority (juce::Thread::Priority p)
 Set download thread priority. More...
 
void setProgressInterval (int ms)
 Sets minimum time between download progress callbacks in milliseconds. More...
 
void setDownloadBlockSize (int bs)
 Sets the block size of chunks to download. More...
 
int getNumDownloadsInQueue ()
 
void enableGzipDeflate (bool e)
 If enabled, will request the server sends the data compressed This only has effect on windows. More...
 
void pauseDownloads (bool)
 Pause / resume all downloads. More...
 
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. More...
 
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. More...
 
void cancelDownload (int downloadId)
 Cancels a download with a given id. More...
 
DownloadResult blockingDownload (juce::String url, juce::String postData, juce::String extraHeaders={})
 
DownloadResult blockingDownload (juce::URL url, juce::String extraHeaders={})
 

Detailed Description

Downloads files to a memory block and then calls a lambda on the message thread with the results.

Does not block the message thread while establishing the HTTP connect like URL::downloadToFile

Constructor & Destructor Documentation

◆ DownloadManager()

DownloadManager::DownloadManager ( int  connectTimeout = 30 *1000,
int  shutdownTimeout = 30 *1000 
)

◆ ~DownloadManager()

DownloadManager::~DownloadManager ( )

Member Function Documentation

◆ setQueueFinishedCallback()

void DownloadManager::setQueueFinishedCallback ( std::function< void()>  callback)

This callback is called every time all downloads are finished.

◆ setConnectTimeout()

void DownloadManager::setConnectTimeout ( int  timeout)

How long connecting is given before it times out.

◆ setRetryLimit()

void DownloadManager::setRetryLimit ( int  limit)

If a download fails, how long many times it should retry.

◆ setRetryDelay()

void DownloadManager::setRetryDelay ( double  seconds)

If a download fails, how long to wait until trying again.

◆ setConcurrentDownloadLimit()

void DownloadManager::setConcurrentDownloadLimit ( int  l)

Maximum number of downloads to allow at once.

◆ getNumberOfDownloads()

int DownloadManager::getNumberOfDownloads ( )

Number of items in download queue.

◆ setThreadPriority()

void DownloadManager::setThreadPriority ( juce::Thread::Priority  p)

Set download thread priority.

Does not affect priority of already running threads

◆ setProgressInterval()

void DownloadManager::setProgressInterval ( int  ms)

Sets minimum time between download progress callbacks in milliseconds.

References math::max().

◆ setDownloadBlockSize()

void DownloadManager::setDownloadBlockSize ( int  bs)

Sets the block size of chunks to download.

Progress callbacks and cancelling downloads can only happen between these blocks. Max size is 128 KB

◆ getNumDownloadsInQueue()

int DownloadManager::getNumDownloadsInQueue ( )

◆ enableGzipDeflate()

void DownloadManager::enableGzipDeflate ( bool  e)

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.

◆ pauseDownloads()

void DownloadManager::pauseDownloads ( bool  )

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.

◆ startAsyncDownload() [1/2]

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.

◆ startAsyncDownload() [2/2]

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 = {} 
)

◆ cancelAllDownloads()

void DownloadManager::cancelAllDownloads ( )

Cancels all downloads.

◆ cancelDownload()

void DownloadManager::cancelDownload ( int  downloadId)

Cancels a download with a given id.

◆ blockingDownload() [1/2]

DownloadResult DownloadManager::blockingDownload ( juce::String  url,
juce::String  postData,
juce::String  extraHeaders = {} 
)

◆ blockingDownload() [2/2]

DownloadResult DownloadManager::blockingDownload ( juce::URL  url,
juce::String  extraHeaders = {} 
)

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