Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
audacity::cloud::audiocom::sync::DataUploader::UploadOperation Struct Referencefinal
Inheritance diagram for audacity::cloud::audiocom::sync::DataUploader::UploadOperation:
[legend]
Collaboration diagram for audacity::cloud::audiocom::sync::DataUploader::UploadOperation:
[legend]

Public Member Functions

 UploadOperation (DataUploader &uploader, CancellationContextPtr cancellationContex, const UploadUrls &target, UploadData data, std::string mimeType, std::function< void(ResponseResult)> callback, std::function< void(double)> progressCallback)
 
void PerformUpload (int retriesLeft)
 
void ConfirmUpload (int retriesLeft)
 
void FailUpload (int retriesLeft)
 
void CleanUp ()
 

Public Attributes

DataUploaderUploader
 
UploadUrls Target
 
std::function< void(ResponseResult)> Callback
 
std::function< void(double)> ProgressCallback
 
std::string MimeType
 
UploadData Data
 
ResponseResult CurrentResult
 
CancellationContextPtr CancelContext
 
std::atomic< bool > UploadFailed { false }
 

Detailed Description

Definition at line 36 of file DataUploader.cpp.

Constructor & Destructor Documentation

◆ UploadOperation()

audacity::cloud::audiocom::sync::DataUploader::UploadOperation::UploadOperation ( DataUploader uploader,
CancellationContextPtr  cancellationContex,
const UploadUrls target,
UploadData  data,
std::string  mimeType,
std::function< void(ResponseResult)>  callback,
std::function< void(double)>  progressCallback 
)
inline

Definition at line 52 of file DataUploader.cpp.

57 : Uploader { uploader }
58 , Target { target }
59 , Callback { std::move(callback) }
60 , ProgressCallback { std::move(progressCallback) }
61 , MimeType { std::move(mimeType) }
62 , Data { std::move(data) }
63 , CancelContext { std::move(cancellationContex) }
64 {
65 }

Member Function Documentation

◆ CleanUp()

void audacity::cloud::audiocom::sync::DataUploader::UploadOperation::CleanUp ( )
inline

Definition at line 199 of file DataUploader.cpp.

200 {
201 BasicUI::CallAfter([this]() { Uploader.RemoveResponse(*this); });
202 }
void RemoveResponse(UploadOperation &response)
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214

References BasicUI::CallAfter(), audacity::cloud::audiocom::sync::DataUploader::RemoveResponse(), and Uploader.

Referenced by ConfirmUpload(), and FailUpload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConfirmUpload()

void audacity::cloud::audiocom::sync::DataUploader::UploadOperation::ConfirmUpload ( int  retriesLeft)
inline

Definition at line 128 of file DataUploader.cpp.

129 {
130 Data = {};
131 Request request { Target.SuccessUrl };
132
133 auto networkResponse =
134 NetworkManager::GetInstance().doPost(request, nullptr, 0);
135 CancelContext->OnCancelled(networkResponse);
136
137 networkResponse->setRequestFinishedCallback(
138 [this, retriesLeft, networkResponse, operation = weak_from_this()](auto)
139 {
140 auto strongThis = operation.lock();
141 if (!strongThis)
142 return;
143
144 CurrentResult = GetResponseResult(*networkResponse, false);
145
147 {
148 Callback(ResponseResult { SyncResultCode::Success, {} });
149 CleanUp();
150 }
151 else if (
153 retriesLeft > 0)
154 {
155 ConfirmUpload(retriesLeft - 1);
156 }
157 else
158 {
160 }
161 });
162 }
ResponsePtr doPost(const Request &request, const void *data, size_t size)
ResponseResult GetResponseResult(IResponse &response, bool readBody)

References Callback, CancelContext, CleanUp(), audacity::cloud::audiocom::ResponseResult::Code, ConfirmUpload(), audacity::cloud::audiocom::ConnectionFailed, CurrentResult, Data, audacity::network_manager::NetworkManager::doPost(), FailUpload(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::GetResponseResult(), audacity::cloud::audiocom::sync::RetriesCount, audacity::cloud::audiocom::Success, audacity::cloud::audiocom::sync::UploadUrls::SuccessUrl, and Target.

Referenced by ConfirmUpload(), and PerformUpload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FailUpload()

void audacity::cloud::audiocom::sync::DataUploader::UploadOperation::FailUpload ( int  retriesLeft)
inline

Definition at line 164 of file DataUploader.cpp.

165 {
166 if (!UploadFailed.exchange(true))
167 {
168 Data = {};
170 }
171
172 Request request { Target.FailUrl };
173
174 auto networkResponse =
175 NetworkManager::GetInstance().doPost(request, nullptr, 0);
176 CancelContext->OnCancelled(networkResponse);
177
178 networkResponse->setRequestFinishedCallback(
179 [this, retriesLeft, networkResponse, operation = weak_from_this()](auto)
180 {
181 auto strongThis = operation.lock();
182 if (!strongThis)
183 return;
184
185 const auto result = GetResponseResult(*networkResponse, false);
186
187 if (
188 result.Code == SyncResultCode::ConnectionFailed &&
189 retriesLeft > 0)
190 FailUpload(retriesLeft - 1);
191 else
192 CleanUp();
193
194 // Ignore other errors, server will collect garbage
195 // and delete the file eventually
196 });
197 }

References Callback, CancelContext, CleanUp(), audacity::cloud::audiocom::ConnectionFailed, CurrentResult, Data, audacity::network_manager::NetworkManager::doPost(), FailUpload(), audacity::cloud::audiocom::sync::UploadUrls::FailUrl, audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::GetResponseResult(), Target, and UploadFailed.

Referenced by ConfirmUpload(), FailUpload(), and PerformUpload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PerformUpload()

void audacity::cloud::audiocom::sync::DataUploader::UploadOperation::PerformUpload ( int  retriesLeft)
inline

Definition at line 67 of file DataUploader.cpp.

68 {
69 Request request { Target.UploadUrl };
70 request.setHeader(common_headers::ContentType, MimeType);
71
72 ResponsePtr networkResponse;
73
74 if (std::holds_alternative<std::vector<uint8_t>>(Data))
75 {
76 auto data = *std::get_if<std::vector<uint8_t>>(&Data);
77
78 networkResponse = NetworkManager::GetInstance().doPut(
79 request, data.data(), data.size());
80 }
81 else
82 {
83 auto filePath = *std::get_if<std::string>(&Data);
84
85 networkResponse = NetworkManager::GetInstance().doPut(
86 request, CreateRequestPayloadStream(filePath));
87 }
88
89 CancelContext->OnCancelled(networkResponse);
90
91 networkResponse->setRequestFinishedCallback(
92 [this, retriesLeft, networkResponse, operation = weak_from_this()](auto)
93 {
94 auto strongThis = operation.lock();
95 if (!strongThis)
96 return;
97
98 CurrentResult = GetResponseResult(*networkResponse, false);
99
102 else if (
104 retriesLeft > 0)
105 PerformUpload(retriesLeft - 1);
106 else
108 });
109
110 networkResponse->setUploadProgressCallback(
111 [this, operation = weak_from_this()](
112 int64_t current, int64_t total)
113 {
114 auto strongThis = operation.lock();
115 if (!strongThis)
116 return;
117
118 if (total <= 0)
119 {
120 total = 1;
121 current = 0;
122 }
123
124 ProgressCallback(static_cast<double>(current) / total);
125 });
126 }
ResponsePtr doPut(const Request &request, const void *data, size_t size)
std::shared_ptr< IResponse > ResponsePtr
RequestPayloadStreamPtr CreateRequestPayloadStream(const void *data, int64_t size, bool copyData)

References CancelContext, audacity::cloud::audiocom::ResponseResult::Code, ConfirmUpload(), audacity::cloud::audiocom::ConnectionFailed, audacity::network_manager::common_headers::ContentType, audacity::network_manager::CreateRequestPayloadStream(), CurrentResult, Data, audacity::network_manager::NetworkManager::doPut(), FailUpload(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::GetResponseResult(), MimeType, PerformUpload(), ProgressCallback, audacity::cloud::audiocom::sync::RetriesCount, audacity::cloud::audiocom::Success, Target, and audacity::cloud::audiocom::sync::UploadUrls::UploadUrl.

Referenced by PerformUpload().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Callback

std::function<void(ResponseResult)> audacity::cloud::audiocom::sync::DataUploader::UploadOperation::Callback

Definition at line 41 of file DataUploader.cpp.

Referenced by ConfirmUpload(), and FailUpload().

◆ CancelContext

CancellationContextPtr audacity::cloud::audiocom::sync::DataUploader::UploadOperation::CancelContext

Definition at line 48 of file DataUploader.cpp.

Referenced by ConfirmUpload(), FailUpload(), and PerformUpload().

◆ CurrentResult

ResponseResult audacity::cloud::audiocom::sync::DataUploader::UploadOperation::CurrentResult

Definition at line 47 of file DataUploader.cpp.

Referenced by ConfirmUpload(), FailUpload(), and PerformUpload().

◆ Data

UploadData audacity::cloud::audiocom::sync::DataUploader::UploadOperation::Data

Definition at line 45 of file DataUploader.cpp.

Referenced by ConfirmUpload(), FailUpload(), and PerformUpload().

◆ MimeType

std::string audacity::cloud::audiocom::sync::DataUploader::UploadOperation::MimeType

Definition at line 44 of file DataUploader.cpp.

Referenced by PerformUpload().

◆ ProgressCallback

std::function<void(double)> audacity::cloud::audiocom::sync::DataUploader::UploadOperation::ProgressCallback

Definition at line 42 of file DataUploader.cpp.

Referenced by PerformUpload().

◆ Target

UploadUrls audacity::cloud::audiocom::sync::DataUploader::UploadOperation::Target

Definition at line 40 of file DataUploader.cpp.

Referenced by ConfirmUpload(), FailUpload(), and PerformUpload().

◆ Uploader

DataUploader& audacity::cloud::audiocom::sync::DataUploader::UploadOperation::Uploader

Definition at line 39 of file DataUploader.cpp.

Referenced by CleanUp().

◆ UploadFailed

std::atomic<bool> audacity::cloud::audiocom::sync::DataUploader::UploadOperation::UploadFailed { false }

Definition at line 50 of file DataUploader.cpp.

Referenced by FailUpload().


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