15#include <condition_variable>
22#include <unordered_set>
69 static std::shared_ptr<RemoteProjectSnapshot>
Sync(
77 std::string_view GetProjectId()
const;
91 std::string AttachOriginalDB();
94 const std::string& dbName, std::unordered_set<std::string> blocks);
96 std::unordered_set<std::string>
97 CalculateKnownBlocks(
const std::string& attachedDbName)
const;
102 DownloadBlob(std::string url,
SuccessHandler onSuccess,
int retries = 3);
106 void OnBlockDownloaded(
112 void MarkProjectInDB(
bool successfulDownload);
114 void ReportProgress();
116 bool InProgress()
const;
117 void RequestsThread();
119 void SetState(
State state);
121 void CleanupOrphanBlocks();
131 std::atomic<State>
mState { State::Downloading };
133 using Clock = std::chrono::steady_clock;
143 std::vector<std::pair<std::string, SuccessHandler>>
mRequests;
145 int mRequestsInProgress { 0 };
146 size_t mNextRequestIndex { 0 };
149 std::vector<std::shared_ptr<audacity::network_manager::IResponse>>
153 std::atomic<int64_t> mDownloadedBlocks { 0 };
154 std::atomic<int64_t> mCopiedBlocks { 0 };
155 std::atomic<int64_t> mDownloadedBytes { 0 };
157 int64_t mMissingBlocks { 0 };
161 std::atomic<bool> mProjectDownloaded {
false };
163 bool mNothingToDo {
false };
164 const bool mDownloadDetached {
false };
std::mutex mRequestsMutex
const SnapshotInfo mSnapshotInfo
RemoteProjectSnapshot & operator=(const RemoteProjectSnapshot &)=delete
std::thread mRequestsThread
std::condition_variable mRequestsCV
std::optional< std::future< bool > > mCopyBlocksFuture
Clock::time_point TimePoint
RemoteProjectSnapshotStateCallback mCallback
RemoteProjectSnapshot(RemoteProjectSnapshot &&)=delete
RemoteProjectSnapshot & operator=(RemoteProjectSnapshot &&)=delete
std::vector< std::string > mAttachedDBNames
std::vector< std::shared_ptr< audacity::network_manager::IResponse > > mResponses
std::mutex mResponsesMutex
std::function< void(audacity::network_manager::ResponsePtr)> SuccessHandler
const std::string mSnapshotDBName
std::vector< std::pair< std::string, SuccessHandler > > mRequests
const ProjectInfo mProjectInfo
RemoteProjectSnapshot(const RemoteProjectSnapshot &)=delete
std::chrono::steady_clock Clock
std::condition_variable mResponsesEmptyCV
Interface, that provides access to the data from the HTTP response.
void Sync(const wxString &string)
std::function< void(RemoteProjectSnapshotState)> RemoteProjectSnapshotStateCallback
std::shared_ptr< IResponse > ResponsePtr
bool IsComplete() const noexcept