##// END OF EJS Templates
Fixed tests due to async var creation, plus minor stuff...
Fixed tests due to async var creation, plus minor stuff A variable is created synchronously but its data is get in background so tests have now to wait until the variable is ready before checking its state. VC should have a [] operator, it's a model feature. The new data provider interface implies that each call only ask for one range, this has been reflected in its parameters. Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r0:86b06c4cec3c
r30:02d2d8643fcb
Show More
Downloader.h
72 lines | 2.0 KiB | text/x-c | ObjectiveCLexer
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include "CoreGlobal.h"
#include "Response.h"
#include <Common/MetaTypes.h>
#include <Common/spimpl.h>
#include <functional>
#include <QString>
#include <QByteArray>
#include <QUuid>
/**
* @brief The Downloader handles all data donwloads in SciQLOP.
*
* Simple synchronous GET example:
* @code{.cpp}
* auto response = Downloader::get("http://example.com")
* std::cout << "Status code: " << response.status_code() << std::endl << "Data: " << response.data().toStdString() << std::endl;
* @endcode
*
* @note
* This is a quick and KISS implementation using QNetworkAccessManager isolating from Qt stuff (Signal/slots).
* This could be impemented with a different backend in the future.
*
* @sa Response
*/
class SCIQLOP_CORE_EXPORT Downloader{
public:
/**
* @brief does a synchronous GET request on the given url
* @param url
* @param user
* @param passwd
* @return Response object containing request data and http status code
* @sa Downloader::getAsync
*/
static Response get(const QString& url, const QString& user="", const QString& passwd="");
/**
* @brief does an asynchronous GET request on the given url
* @param url
* @param callback
* @param user
* @param passwd
* @return QUuid an unique identifier associated to this request
* @sa Downloader::get, Downloader::downloadFinished
*/
static QUuid getAsync(const QString& url, std::function<void (QUuid, Response)> callback, const QString& user="", const QString& passwd="");
/**
* @brief downloadFinished
* @param uuid
* @return true if the request associated to this uuid is complete
*/
static bool downloadFinished(QUuid uuid);
static Downloader& instance()
{
static Downloader inst;
return inst;
}
private:
class p_Downloader;
explicit Downloader();
spimpl::unique_impl_ptr<Downloader::p_Downloader> impl;
};
#endif // DOWNLOADER_H