Audacity 3.2.0
Functions
audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp} Namespace Reference

Functions

std::mutex & GetResponsesMutex ()
 
std::vector< std::shared_ptr< audacity::network_manager::IResponse > > & GetPendingRequests ()
 
void RemovePendingRequest (audacity::network_manager::IResponse *request)
 
void PerformProjectGetRequest (OAuthService &oAuthService, std::string url, std::function< void(ResponseResult)> dataCallback)
 
void GetProjectInfo (OAuthService &oAuthService, const ServiceConfig &serviceConfig, std::string projectId, std::function< void(sync::ProjectInfo, ResponseResult)> callback)
 
void GetSnapshotInfo (OAuthService &oAuthService, const ServiceConfig &serviceConfig, std::string projectId, std::string snapshotId, std::function< void(sync::SnapshotInfo, ResponseResult result)> callback)
 
void GetSnapshotInfo (OAuthService &oAuthService, const ServiceConfig &serviceConfig, std::string projectId, std::string snapshotId, std::function< void(sync::ProjectInfo, sync::SnapshotInfo, ResponseResult result)> callback)
 
bool HasAutosave (const std::string &path)
 
bool DropAutosave (const std::string &path)
 

Function Documentation

◆ DropAutosave()

bool audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::DropAutosave ( const std::string &  path)

Definition at line 257 of file CloudSyncService.cpp.

258{
259 auto connection =
260 sqlite::Connection::Open(path, sqlite::OpenMode::ReadWrite);
261
262 if (!connection)
263 return false;
264
265 if (!connection->CheckTableExists("autosave"))
266 return false;
267
268 auto statement = connection->CreateStatement("DELETE FROM autosave");
269
270 if (!statement)
271 return false;
272
273 auto result = statement->Prepare().Run();
274
275 return result.IsOk();
276}

Referenced by audacity::cloud::audiocom::CloudSyncService::SyncCloudSnapshot().

Here is the caller graph for this function:

◆ GetPendingRequests()

std::vector< std::shared_ptr< audacity::network_manager::IResponse > > & audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::GetPendingRequests ( )

Definition at line 53 of file CloudSyncService.cpp.

54{
55 static std::vector<std::shared_ptr<audacity::network_manager::IResponse>>
56 requests;
57
58 return requests;
59}

Referenced by PerformProjectGetRequest(), and RemovePendingRequest().

Here is the caller graph for this function:

◆ GetProjectInfo()

void audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::GetProjectInfo ( OAuthService oAuthService,
const ServiceConfig serviceConfig,
std::string  projectId,
std::function< void(sync::ProjectInfo, ResponseResult)>  callback 
)

Definition at line 117 of file CloudSyncService.cpp.

121{
122 assert(callback);
123
125 oAuthService, serviceConfig.GetProjectInfoUrl(projectId),
126 [callback = std::move(callback)](ResponseResult result)
127 {
128 if (result.Code != SyncResultCode::Success)
129 {
130 callback(sync::ProjectInfo {}, std::move(result));
131 return;
132 }
133
134 auto projectInfo = sync::DeserializeProjectInfo(result.Content);
135
136 if (!projectInfo)
137 {
138 callback(
139 {}, { SyncResultCode::UnexpectedResponse,
140 std::move(result.Content) });
141 return;
142 }
143
144 callback(std::move(*projectInfo), std::move(result));
145 });
146}
std::string GetProjectInfoUrl(std::string_view projectId) const
void PerformProjectGetRequest(OAuthService &oAuthService, std::string url, std::function< void(ResponseResult)> dataCallback)
std::optional< ProjectInfo > DeserializeProjectInfo(const std::string &data)

References audacity::cloud::audiocom::ResponseResult::Content, audacity::cloud::audiocom::sync::DeserializeProjectInfo(), audacity::cloud::audiocom::ServiceConfig::GetProjectInfoUrl(), PerformProjectGetRequest(), and audacity::cloud::audiocom::UnexpectedResponse.

Referenced by audacity::cloud::audiocom::CloudSyncService::GetHeadSnapshotID(), GetSnapshotInfo(), and audacity::cloud::audiocom::CloudSyncService::SyncProject().

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

◆ GetResponsesMutex()

std::mutex & audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::GetResponsesMutex ( )

Definition at line 46 of file CloudSyncService.cpp.

47{
48 static std::mutex mutex;
49 return mutex;
50}

Referenced by PerformProjectGetRequest(), and RemovePendingRequest().

Here is the caller graph for this function:

◆ GetSnapshotInfo() [1/2]

void audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::GetSnapshotInfo ( OAuthService oAuthService,
const ServiceConfig serviceConfig,
std::string  projectId,
std::string  snapshotId,
std::function< void(sync::ProjectInfo, sync::SnapshotInfo, ResponseResult result)>  callback 
)

Definition at line 179 of file CloudSyncService.cpp.

185{
186 assert(callback);
187
189 oAuthService, serviceConfig, projectId,
190 [callback = std::move(callback), projectId,
191 snapshotId = std::move(snapshotId), &oAuthService,
192 &serviceConfig](sync::ProjectInfo projectInfo, ResponseResult result)
193 {
194 if (result.Code != SyncResultCode::Success)
195 {
196 callback({}, {}, std::move(result));
197 return;
198 }
199
200 const auto id = !snapshotId.empty() ?
201 snapshotId :
202 (projectInfo.HeadSnapshot.Synced > 0 ?
203 projectInfo.HeadSnapshot.Id :
204 projectInfo.LastSyncedSnapshotId);
205
206 if (id.empty())
207 {
208 callback(
209 std::move(projectInfo), sync::SnapshotInfo {},
210 { SyncResultCode::Success });
211 return;
212 }
213
215 oAuthService, serviceConfig, projectId, id,
216 [callback = std::move(callback),
217 projectInfo = std::move(projectInfo)](
218 sync::SnapshotInfo snapshotInfo, ResponseResult result)
219 {
220 callback(
221 std::move(projectInfo), std::move(snapshotInfo),
222 std::move(result));
223 });
224 });
225}
void GetProjectInfo(OAuthService &oAuthService, const ServiceConfig &serviceConfig, std::string projectId, std::function< void(sync::ProjectInfo, ResponseResult)> callback)
void GetSnapshotInfo(OAuthService &oAuthService, const ServiceConfig &serviceConfig, std::string projectId, std::string snapshotId, std::function< void(sync::ProjectInfo, sync::SnapshotInfo, ResponseResult result)> callback)

References audacity::cloud::audiocom::ResponseResult::Code, GetProjectInfo(), GetSnapshotInfo(), audacity::cloud::audiocom::sync::ProjectInfo::HeadSnapshot, audacity::cloud::audiocom::sync::SnapshotInfo::Id, audacity::cloud::audiocom::sync::ProjectInfo::LastSyncedSnapshotId, and audacity::cloud::audiocom::sync::SnapshotInfo::Synced.

Referenced by GetSnapshotInfo(), and audacity::cloud::audiocom::CloudSyncService::OpenFromCloud().

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

◆ GetSnapshotInfo() [2/2]

void audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::GetSnapshotInfo ( OAuthService oAuthService,
const ServiceConfig serviceConfig,
std::string  projectId,
std::string  snapshotId,
std::function< void(sync::SnapshotInfo, ResponseResult result)>  callback 
)

Definition at line 148 of file CloudSyncService.cpp.

152{
153 assert(callback);
154
156 oAuthService, serviceConfig.GetSnapshotInfoUrl(projectId, snapshotId),
157 [callback = std::move(callback)](ResponseResult result)
158 {
159 if (result.Code != SyncResultCode::Success)
160 {
161 callback({}, std::move(result));
162 return;
163 }
164
165 auto snapshotInfo = sync::DeserializeSnapshotInfo(result.Content);
166
167 if (!snapshotInfo)
168 {
169 callback(
170 {}, { SyncResultCode::UnexpectedResponse,
171 std::move(result.Content) });
172 return;
173 }
174
175 callback(std::move(*snapshotInfo), std::move(result));
176 });
177}
std::string GetSnapshotInfoUrl(std::string_view projectId, std::string_view snapshotId) const
std::optional< SnapshotInfo > DeserializeSnapshotInfo(const std::string &data)

References audacity::cloud::audiocom::ResponseResult::Content, audacity::cloud::audiocom::sync::DeserializeSnapshotInfo(), audacity::cloud::audiocom::ServiceConfig::GetSnapshotInfoUrl(), PerformProjectGetRequest(), and audacity::cloud::audiocom::UnexpectedResponse.

Here is the call graph for this function:

◆ HasAutosave()

bool audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::HasAutosave ( const std::string &  path)

Definition at line 227 of file CloudSyncService.cpp.

228{
229 auto connection = sqlite::Connection::Open(path, sqlite::OpenMode::ReadOnly);
230
231 if (!connection)
232 return false;
233
234 if (!connection->CheckTableExists("autosave"))
235 return false;
236
237 auto statement =
238 connection->CreateStatement("SELECT COUNT(1) FROM autosave");
239
240 if (!statement)
241 return false;
242
243 auto result = statement->Prepare().Run();
244
245 if (!result.IsOk())
246 return false;
247
248 for (const auto& row : result)
249 {
250 if (row.GetOr(0, 0) > 0)
251 return true;
252 }
253
254 return false;
255}

Referenced by audacity::cloud::audiocom::CloudSyncService::SyncCloudSnapshot().

Here is the caller graph for this function:

◆ PerformProjectGetRequest()

void audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::PerformProjectGetRequest ( OAuthService oAuthService,
std::string  url,
std::function< void(ResponseResult)>  dataCallback 
)

Definition at line 74 of file CloudSyncService.cpp.

77{
78 assert(oAuthService.HasAccessToken());
79
80 if (!oAuthService.HasAccessToken())
81 {
82 dataCallback({ SyncResultCode::Unauthorized });
83 return;
84 }
85
86 using namespace audacity::network_manager;
87
88 auto request = Request(std::move(url));
89
90 request.setHeader(
92
93 request.setHeader(
95
96 SetCommonHeaders(request);
97
98 auto response = NetworkManager::GetInstance().doGet(request);
99
100 response->setRequestFinishedCallback(
101 [dataCallback = std::move(dataCallback)](auto response)
102 {
104 [dataCallback = std::move(dataCallback), response]
105 {
106 auto removeRequest =
107 finally([response] { RemovePendingRequest(response); });
108
109 dataCallback(GetResponseResult(*response, true));
110 });
111 });
112
113 std::lock_guard lock { GetResponsesMutex() };
114 GetPendingRequests().emplace_back(std::move(response));
115}
bool HasAccessToken() const
Indicates, that service has a valid access token, i. e. that the user is authorized.
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214
FrameStatistics & GetInstance() noexcept
std::vector< std::shared_ptr< audacity::network_manager::IResponse > > & GetPendingRequests()
void RemovePendingRequest(audacity::network_manager::IResponse *request)
void SetCommonHeaders(Request &request)
ResponseResult GetResponseResult(IResponse &response, bool readBody)

References audacity::network_manager::common_headers::Accept, audacity::network_manager::common_content_types::ApplicationJson, BasicUI::CallAfter(), audacity::network_manager::common_headers::ContentType, audacity::network_manager::NetworkManager::doGet(), audacity::network_manager::NetworkManager::GetInstance(), GetPendingRequests(), audacity::cloud::audiocom::GetResponseResult(), GetResponsesMutex(), audacity::cloud::audiocom::OAuthService::HasAccessToken(), RemovePendingRequest(), audacity::cloud::audiocom::SetCommonHeaders(), and audacity::cloud::audiocom::Unauthorized.

Referenced by GetProjectInfo(), and GetSnapshotInfo().

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

◆ RemovePendingRequest()

void audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::RemovePendingRequest ( audacity::network_manager::IResponse request)

Definition at line 61 of file CloudSyncService.cpp.

62{
63 std::lock_guard lock { GetResponsesMutex() };
64
65 auto& requests = GetPendingRequests();
66
67 requests.erase(
68 std::remove_if(
69 requests.begin(), requests.end(),
70 [request](const auto& r) { return r.get() == request; }),
71 requests.end());
72}

References GetPendingRequests(), and GetResponsesMutex().

Referenced by PerformProjectGetRequest().

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