15#include <condition_variable>
22#include <unordered_set>
70 static std::shared_ptr<RemoteProjectSnapshot>
Sync(
78 std::string_view GetProjectId()
const;
92 std::string AttachOriginalDB();
95 const std::string& dbName, std::unordered_set<std::string> blocks);
97 std::unordered_set<std::string>
98 CalculateKnownBlocks(
const std::string& attachedDbName)
const;
103 DownloadBlob(std::string url,
SuccessHandler onSuccess,
int retries = 3);
107 void OnBlockDownloaded(
113 void MarkProjectInDB(
bool successfulDownload);
115 void ReportProgress();
117 bool InProgress()
const;
118 void RequestsThread();
120 void SetState(
State state);
122 void CleanupOrphanBlocks();
132 std::atomic<State>
mState { State::Downloading };
134 using Clock = std::chrono::steady_clock;
144 std::vector<std::pair<std::string, SuccessHandler>>
mRequests;
146 int mRequestsInProgress { 0 };
147 size_t mNextRequestIndex { 0 };
150 std::vector<std::shared_ptr<audacity::network_manager::IResponse>>
154 std::atomic<int64_t> mDownloadedBlocks { 0 };
155 std::atomic<int64_t> mCopiedBlocks { 0 };
156 std::atomic<int64_t> mDownloadedBytes { 0 };
158 int64_t mMissingBlocks { 0 };
162 std::atomic<bool> mProjectDownloaded {
false };
164 bool mNothingToDo {
false };
165 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