Audacity 3.2.0
ProjectCloudExtension.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 CloudProjectExtension.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <atomic>
14#include <cstdint>
15#include <functional>
16#include <memory>
17#include <mutex>
18#include <optional>
19#include <string>
20#include <string_view>
21#include <vector>
22
23#include "ClientData.h"
24#include "Observer.h"
25
26#include "CloudSyncError.h"
27#include "CloudSyncDTO.h"
29
30class AudacityProject;
32
33enum class AudiocomTrace;
34
36{
37class ProjectUploadOperation;
38
40{
41 Local,
43 Synced,
44 Failed,
46};
47
48struct CLOUD_AUDIOCOM_API CloudStatusChangedMessage final
49{
52 double Progress {};
53 std::optional<CloudSyncError> Error {};
54
55 bool IsSyncing() const noexcept;
56};
57
58class CLOUD_AUDIOCOM_API ProjectCloudExtension final : public ClientData::Base
59{
60public:
63
65 static const ProjectCloudExtension& Get(const AudacityProject& project);
66
67 bool IsCloudProject() const;
68
69 void OnLoad();
70
72 void OnSyncStarted();
74 void OnSyncResumed(
75 std::shared_ptr<ProjectUploadOperation> uploadOperation,
76 int64_t missingBlocksCount, bool needsProjectUpload);
78 void OnUploadOperationCreated(
79 std::shared_ptr<ProjectUploadOperation> uploadOperation);
81 void OnBlocksHashed(ProjectUploadOperation& uploadOperation);
83 void OnSnapshotCreated(
84 const ProjectUploadOperation& uploadOperation,
85 const CreateSnapshotResponse& response);
87 void OnProjectDataUploaded(const ProjectUploadOperation& uploadOperation);
89 void OnBlockUploaded(
90 const ProjectUploadOperation& uploadOperation, std::string_view blockID,
91 bool successful);
93 void OnSyncCompleted(
94 const ProjectUploadOperation* uploadOperation,
95 std::optional<CloudSyncError> error, AudiocomTrace trace);
96
98
99 void CancelSync();
100
101 bool IsSyncing() const;
102
103 std::string GetCloudProjectId() const;
104 std::string GetSnapshotId() const;
105
106 void OnUpdateSaved(const ProjectSerializer& serializer);
107
108 std::weak_ptr<AudacityProject> GetProject() const;
109
110 int64_t GetSavesCount() const;
111
112 Observer::Subscription SubscribeStatusChanged(
113 std::function<void(const CloudStatusChangedMessage&)> callback,
114 bool onUIThread);
115
116 std::string GetCloudProjectPage(AudiocomTrace) const;
117
118 bool IsBlockLocked(int64_t blockID) const;
119
120 ProjectSyncStatus GetCurrentSyncStatus() const;
121
122 bool IsFirstSyncDialogShown() const;
123 void SetFirstSyncDialogShown(bool shown = true);
124
125private:
126 struct UploadQueueElement;
128
129 void UpdateIdFromDatabase();
130
131 void UnsafeUpdateProgress();
132 void Publish(CloudStatusChangedMessage cloudStatus, bool canMerge);
133
134 void MarkProjectSynced(bool success);
135
137 UnsafeFindUploadQueueElement(const ProjectUploadOperation& uploadOperation);
138 const UploadQueueElement* UnsafeFindUploadQueueElement(
139 const ProjectUploadOperation& uploadOperation) const;
140
141 void OnProjectPathChanged();
142
144
146
147 mutable std::mutex mIdentifiersMutex;
148 std::string mProjectId;
149 std::string mSnapshotId;
150
152 std::vector<std::shared_ptr<UploadQueueElement>> mUploadQueue;
153
154 mutable std::mutex mStatusMutex;
156
157 std::unique_ptr<CloudStatusChangedNotifier> mAsyncStateNotifier;
158 std::unique_ptr<CloudStatusChangedNotifier> mUIStateNotifier;
159 std::atomic<bool> mUINotificationPending { false };
160}; // class ProjectCloudExtension
161
162} // namespace audacity::cloud::audiocom::sync
Utility ClientData::Site to register hooks into a host class that attach client data.
AudiocomTrace
Definition: ExportUtils.h:27
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
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
a class used to (de)serialize the project catalog
std::unique_ptr< CloudStatusChangedNotifier > mUIStateNotifier
std::unique_ptr< CloudStatusChangedNotifier > mAsyncStateNotifier
std::vector< std::shared_ptr< UploadQueueElement > > mUploadQueue
Utility ClientData::Site to register hooks into a host class that attach client data.
Definition: ClientData.h:25
const AudacityProject & GetProject(const Track &track)
Definition: TrackArt.cpp:479