Audacity 3.2.0
CloudSyncService.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 CloudSyncService.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <atomic>
14#include <functional>
15#include <future>
16#include <memory>
17#include <string>
18#include <string_view>
19#include <variant>
20#include <vector>
21
22#include "NetworkUtils.h"
23
25
26class AudacityProject;
27
29{
30namespace sync
31{
34class ProjectInfo;
35class SnapshotInfo;
37
39{
40 enum class StatusCode
41 {
43 Blocked,
44 Failed,
45 };
46
49 std::string ProjectPath;
51}; // struct ProjectSyncResult
52
53using ProgressCallback = std::function<bool(double)>;
54
56 std::variant<sync::PaginatedProjectsResponse, ResponseResult>;
57
58using GetHeadSnapshotIDResult = std::variant<std::string, ResponseResult>;
59} // namespace sync
60
63class CLOUD_AUDIOCOM_API CloudSyncService final
64{
65 CloudSyncService() = default;
66 ~CloudSyncService() = default;
67
72
73public:
74 static CloudSyncService& Get();
75
76 using SyncPromise = std::promise<sync::ProjectSyncResult>;
77 using SyncFuture = std::future<sync::ProjectSyncResult>;
78
79 using GetProjectsPromise = std::promise<sync::GetProjectsResult>;
80 using GetProjectsFuture = std::future<sync::GetProjectsResult>;
81
82 using GetHeadSnapshotIDPromise = std::promise<sync::GetHeadSnapshotIDResult>;
83 using GetHeadSnapshotIDFuture = std::future<sync::GetHeadSnapshotIDResult>;
84
85 enum class SyncMode
86 {
87 Normal,
88 ForceOverwrite,
89 ForceNew
90 };
91
93 GetProjectsFuture GetProjects(
94 concurrency::CancellationContextPtr context, int page, int pageSize,
95 std::string_view searchString);
96
98 [[nodiscard]] SyncFuture OpenFromCloud(
99 std::string projectId, std::string snapshotId, SyncMode mode,
100 sync::ProgressCallback callback);
101
102 [[nodiscard]] SyncFuture SyncProject(
103 AudacityProject& project, const std::string& path, bool forceSync,
104 sync::ProgressCallback callback);
105
106 static bool IsCloudProject(const std::string& path);
107
108 enum class ProjectState
109 {
110 NotAvaliable,
111 PendingSync,
112 FullySynced
113 };
114 static ProjectState GetProjectState(const std::string& projectId);
115
116 GetHeadSnapshotIDFuture GetHeadSnapshotID(std::string_view projectId);
117
118private:
119 void FailSync(ResponseResult responseResult);
120
121 void CompleteSync(std::string path);
122
123 void CompleteSync(sync::ProjectSyncResult result);
124
125 void SyncCloudSnapshot(
126 const sync::ProjectInfo& projectInfo,
127 const sync::SnapshotInfo& snapshotInfo, SyncMode mode);
128
129 void UpdateDowloadProgress(double downloadProgress);
130
131 void
132 ReportUploadStats(std::string_view projectId, const TransferStats& stats);
133
134 std::vector<std::shared_ptr<sync::LocalProjectSnapshot>> mLocalSnapshots;
135 std::shared_ptr<sync::RemoteProjectSnapshot> mRemoteSnapshot;
136
139
140 std::atomic<double> mDownloadProgress { 0.0 };
141 std::atomic<bool> mProgressUpdateQueued { false };
142
143 std::atomic<bool> mSyncInProcess { false };
144};
145} // namespace audacity::cloud::audiocom
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CloudSyncService & operator=(CloudSyncService &&)=delete
CloudSyncService & operator=(const CloudSyncService &)=delete
std::promise< sync::GetProjectsResult > GetProjectsPromise
std::future< sync::GetProjectsResult > GetProjectsFuture
std::promise< sync::ProjectSyncResult > SyncPromise
std::shared_ptr< sync::RemoteProjectSnapshot > mRemoteSnapshot
CloudSyncService(const CloudSyncService &)=delete
std::future< sync::GetHeadSnapshotIDResult > GetHeadSnapshotIDFuture
CloudSyncService(CloudSyncService &&)=delete
std::promise< sync::GetHeadSnapshotIDResult > GetHeadSnapshotIDPromise
std::vector< std::shared_ptr< sync::LocalProjectSnapshot > > mLocalSnapshots
std::future< sync::ProjectSyncResult > SyncFuture
std::variant< std::string, ResponseResult > GetHeadSnapshotIDResult
std::variant< sync::PaginatedProjectsResponse, ResponseResult > GetProjectsResult
std::function< bool(double)> ProgressCallback
std::shared_ptr< CancellationContext > CancellationContextPtr