DownloadResult -> DataTransferResult

This commit is contained in:
Nikola Knezevic 2020-04-06 15:18:51 +02:00
parent e5cc53beec
commit 142ed7fe45
5 changed files with 19 additions and 19 deletions

View file

@ -50,10 +50,10 @@ struct CurlDownloader : public Downloader
{
CurlDownloader & downloader;
DataTransferRequest request;
DownloadResult result;
DataTransferResult result;
Activity act;
bool done = false; // whether either the success or failure function has been called
Callback<DownloadResult> callback;
Callback<DataTransferResult> callback;
CURL * req = 0;
bool active = false; // whether the handle has been added to the multi object
std::string status;
@ -74,7 +74,7 @@ struct CurlDownloader : public Downloader
DownloadItem(CurlDownloader & downloader,
const DataTransferRequest & request,
Callback<DownloadResult> && callback)
Callback<DataTransferResult> && callback)
: downloader(downloader)
, request(request)
, act(*logger, lvlTalkative, actDownload,
@ -642,7 +642,7 @@ struct CurlDownloader : public Downloader
#endif
void enqueueDownload(const DataTransferRequest & request,
Callback<DownloadResult> callback) override
Callback<DataTransferResult> callback) override
{
/* Ugly hack to support s3:// URIs. */
if (hasPrefix(request.uri, "s3://")) {
@ -660,7 +660,7 @@ struct CurlDownloader : public Downloader
// FIXME: implement ETag
auto s3Res = s3Helper.getObject(bucketName, key);
DownloadResult res;
DataTransferResult res;
if (!s3Res.data)
throw DownloadError(NotFound, fmt("S3 object '%s' does not exist", request.uri));
res.data = s3Res.data;
@ -687,11 +687,11 @@ ref<Downloader> makeDownloader()
return make_ref<CurlDownloader>();
}
std::future<DownloadResult> Downloader::enqueueDownload(const DataTransferRequest & request)
std::future<DataTransferResult> Downloader::enqueueDownload(const DataTransferRequest & request)
{
auto promise = std::make_shared<std::promise<DownloadResult>>();
auto promise = std::make_shared<std::promise<DataTransferResult>>();
enqueueDownload(request,
{[promise](std::future<DownloadResult> fut) {
{[promise](std::future<DataTransferResult> fut) {
try {
promise->set_value(fut.get());
} catch (...) {
@ -701,7 +701,7 @@ std::future<DownloadResult> Downloader::enqueueDownload(const DataTransferReques
return promise->get_future();
}
DownloadResult Downloader::download(const DataTransferRequest & request)
DataTransferResult Downloader::download(const DataTransferRequest & request)
{
return enqueueDownload(request).get();
}
@ -756,7 +756,7 @@ void Downloader::download(DataTransferRequest && request, Sink & sink)
};
enqueueDownload(request,
{[_state](std::future<DownloadResult> fut) {
{[_state](std::future<DataTransferResult> fut) {
auto state(_state->lock());
state->quit = true;
try {

View file

@ -56,7 +56,7 @@ struct DataTransferRequest
}
};
struct DownloadResult
struct DataTransferResult
{
bool cached = false;
std::string etag;
@ -75,12 +75,12 @@ struct Downloader
the download. The future may throw a DownloadError
exception. */
virtual void enqueueDownload(const DataTransferRequest & request,
Callback<DownloadResult> callback) = 0;
Callback<DataTransferResult> callback) = 0;
std::future<DownloadResult> enqueueDownload(const DataTransferRequest & request);
std::future<DataTransferResult> enqueueDownload(const DataTransferRequest & request);
/* Synchronously download a file. */
DownloadResult download(const DataTransferRequest & request);
DataTransferResult download(const DataTransferRequest & request);
/* Download a file, writing its data to a sink. The sink will be
invoked on the thread of the caller. */

View file

@ -143,7 +143,7 @@ protected:
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
getDownloader()->enqueueDownload(request,
{[callbackPtr, this](std::future<DownloadResult> result) {
{[callbackPtr, this](std::future<DataTransferResult> result) {
try {
(*callbackPtr)(result.get().data);
} catch (DownloadError & e) {

View file

@ -132,7 +132,7 @@ ref<Aws::Client::ClientConfiguration> S3Helper::makeConfig(const string & region
return res;
}
S3Helper::DownloadResult S3Helper::getObject(
S3Helper::DataTransferResult S3Helper::getObject(
const std::string & bucketName, const std::string & key)
{
debug("fetching 's3://%s/%s'...", bucketName, key);
@ -146,7 +146,7 @@ S3Helper::DownloadResult S3Helper::getObject(
return Aws::New<std::stringstream>("STRINGSTREAM");
});
DownloadResult res;
DataTransferResult res;
auto now1 = std::chrono::steady_clock::now();

View file

@ -18,13 +18,13 @@ struct S3Helper
ref<Aws::Client::ClientConfiguration> makeConfig(const std::string & region, const std::string & scheme, const std::string & endpoint);
struct DownloadResult
struct DataTransferResult
{
std::shared_ptr<std::string> data;
unsigned int durationMs;
};
DownloadResult getObject(
DataTransferResult getObject(
const std::string & bucketName, const std::string & key);
};