34using UploadData = std::variant<std::vector<uint8_t>, std::string>;
37 std::enable_shared_from_this<DataUploader::UploadOperation>
56 std::function<
void(
double)> progressCallback)
74 if (std::holds_alternative<std::vector<uint8_t>>(
Data))
76 auto data = *std::get_if<std::vector<uint8_t>>(&
Data);
79 request, data.data(), data.size());
83 auto filePath = *std::get_if<std::string>(&
Data);
91 networkResponse->setRequestFinishedCallback(
92 [
this, retriesLeft, networkResponse, operation = weak_from_this()](
auto)
94 auto strongThis = operation.lock();
110 networkResponse->setUploadProgressCallback(
111 [
this, operation = weak_from_this()](
112 int64_t current, int64_t total)
114 auto strongThis = operation.lock();
133 auto networkResponse =
137 networkResponse->setRequestFinishedCallback(
138 [
this, retriesLeft, networkResponse, operation = weak_from_this()](
auto)
140 auto strongThis = operation.lock();
174 auto networkResponse =
178 networkResponse->setRequestFinishedCallback(
179 [
this, retriesLeft, networkResponse, operation = weak_from_this()](
auto)
181 auto strongThis = operation.lock();
217 const UploadUrls& target, std::vector<uint8_t> data,
219 std::function<
void(
double)> progressCallback)
222 callback = [](
auto...) {};
224 if (!progressCallback)
225 progressCallback = [](
auto...) {
return true; };
227 if (!cancellationContex)
232 mResponses.emplace_back(std::make_unique<UploadOperation>(
233 *
this, cancellationContex, target, std::move(data),
235 std::move(callback), std::move(progressCallback)));
242 const UploadUrls& target, std::string filePath,
244 std::function<
void(
double)> progressCallback)
247 callback = [](
auto...) {};
249 if (!progressCallback)
250 progressCallback = [](
auto...) {
return true; };
252 if (!cancellationContex)
267 mResponses.emplace_back(std::make_shared<UploadOperation>(
268 *
this, cancellationContex, target, std::move(filePath),
270 std::move(callback), std::move(progressCallback)));
282 [&response](
const auto& item) { return item.get() == &response; }),
Toolkit-neutral facade for basic user interface services.
Declare functions to perform UTF-8 to std::wstring conversions.
Declare an interface for HTTP response.
Declare a class for performing HTTP requests.
Declare a class for constructing HTTP requests.
Declare a class for constructing HTTP requests.
Configuration for the audio.com.
static DataUploader & Get()
void Upload(CancellationContextPtr cancellationContex, const ServiceConfig &config, const UploadUrls &target, std::vector< uint8_t > data, std::function< void(ResponseResult)> callback, std::function< void(double)> progressCallback={})
std::mutex mResponseMutex
void RemoveResponse(UploadOperation &response)
static CancellationContextPtr Create()
static NetworkManager & GetInstance()
ResponsePtr doPost(const Request &request, const void *data, size_t size)
ResponsePtr doPut(const Request &request, const void *data, size_t size)
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
std::variant< std::vector< uint8_t >, std::string > UploadData
std::function< bool(double)> ProgressCallback
constexpr int RetriesCount
ResponseResult GetResponseResult(IResponse &response, bool readBody)
std::shared_ptr< CancellationContext > CancellationContextPtr
const std::string ApplicationXOctetStream
std::shared_ptr< IResponse > ResponsePtr
RequestPayloadStreamPtr CreateRequestPayloadStream(const void *data, int64_t size, bool copyData)
std::string ToUTF8(const std::wstring &wstr)
wxString ToWXString(const std::string &str)
std::function< void(double)> ProgressCallback
void PerformUpload(int retriesLeft)
void ConfirmUpload(int retriesLeft)
void FailUpload(int retriesLeft)
std::function< void(ResponseResult)> Callback
std::atomic< bool > UploadFailed
ResponseResult CurrentResult
CancellationContextPtr CancelContext
UploadOperation(DataUploader &uploader, CancellationContextPtr cancellationContex, const UploadUrls &target, UploadData data, std::string mimeType, std::function< void(ResponseResult)> callback, std::function< void(double)> progressCallback)