Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
audacity::cloud::audiocom::sync::ProjectCloudExtension Class Referencefinal

#include <ProjectCloudExtension.h>

Inheritance diagram for audacity::cloud::audiocom::sync::ProjectCloudExtension:
[legend]
Collaboration diagram for audacity::cloud::audiocom::sync::ProjectCloudExtension:
[legend]

Classes

struct  CloudStatusChangedNotifier
 
struct  UploadQueueElement
 

Public Member Functions

 ProjectCloudExtension (AudacityProject &project)
 
 ~ProjectCloudExtension () override
 
bool IsCloudProject () const
 
void OnLoad ()
 
void OnSyncStarted ()
 This method is called from the UI thread. More...
 
void OnSyncResumed (std::shared_ptr< ProjectUploadOperation > uploadOperation, int64_t missingBlocksCount, bool needsProjectUpload)
 This method is called from the UI thread. More...
 
void OnUploadOperationCreated (std::shared_ptr< ProjectUploadOperation > uploadOperation)
 This method is called from the UI thread. More...
 
void OnBlocksHashed (ProjectUploadOperation &uploadOperation)
 This method is called not from the UI thread. More...
 
void OnSnapshotCreated (const ProjectUploadOperation &uploadOperation, const CreateSnapshotResponse &response)
 This method is called from the network thread. More...
 
void OnProjectDataUploaded (const ProjectUploadOperation &uploadOperation)
 This method is called from the network thread. More...
 
void OnBlockUploaded (const ProjectUploadOperation &uploadOperation, std::string_view blockID, bool successful)
 This method is called from the network thread. More...
 
void OnSyncCompleted (const ProjectUploadOperation *uploadOperation, std::optional< CloudSyncError > error, AudiocomTrace trace)
 This method is called from any thread. More...
 
void AbortLastUploadOperation ()
 
void CancelSync ()
 
bool IsSyncing () const
 
std::string GetCloudProjectId () const
 
std::string GetSnapshotId () const
 
void OnUpdateSaved (const ProjectSerializer &serializer)
 
std::weak_ptr< AudacityProjectGetProject () const
 
int64_t GetSavesCount () const
 
Observer::Subscription SubscribeStatusChanged (std::function< void(const CloudStatusChangedMessage &)> callback, bool onUIThread)
 
std::string GetCloudProjectPage (AudiocomTrace) const
 
bool IsBlockLocked (int64_t blockID) const
 
ProjectSyncStatus GetCurrentSyncStatus () const
 
bool IsFirstSyncDialogShown () const
 
void SetFirstSyncDialogShown (bool shown=true)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 

Static Public Member Functions

static ProjectCloudExtensionGet (AudacityProject &project)
 
static const ProjectCloudExtensionGet (const AudacityProject &project)
 

Private Member Functions

void UpdateIdFromDatabase ()
 
void UnsafeUpdateProgress ()
 
void Publish (CloudStatusChangedMessage cloudStatus, bool canMerge)
 
void MarkProjectSynced (bool success)
 
UploadQueueElementUnsafeFindUploadQueueElement (const ProjectUploadOperation &uploadOperation)
 
const UploadQueueElementUnsafeFindUploadQueueElement (const ProjectUploadOperation &uploadOperation) const
 
void OnProjectPathChanged ()
 

Private Attributes

AudacityProjectmProject
 
Observer::Subscription mProjectPathChangedSubscription
 
std::mutex mIdentifiersMutex
 
std::string mProjectId
 
std::string mSnapshotId
 
std::mutex mUploadQueueMutex
 
std::vector< std::shared_ptr< UploadQueueElement > > mUploadQueue
 
std::mutex mStatusMutex
 
CloudStatusChangedMessage mLastStatus
 
std::unique_ptr< CloudStatusChangedNotifiermAsyncStateNotifier
 
std::unique_ptr< CloudStatusChangedNotifiermUIStateNotifier
 
std::atomic< bool > mUINotificationPending { false }
 

Detailed Description

Definition at line 58 of file ProjectCloudExtension.h.

Constructor & Destructor Documentation

◆ ProjectCloudExtension()

audacity::cloud::audiocom::sync::ProjectCloudExtension::ProjectCloudExtension ( AudacityProject project)
explicit

Definition at line 106 of file ProjectCloudExtension.cpp.

107 : mProject { project }
109 [this](auto message)
110 {
113 }) }
114 , mAsyncStateNotifier { std::make_unique<CloudStatusChangedNotifier>() }
115 , mUIStateNotifier { std::make_unique<CloudStatusChangedNotifier>() }
116{
117 if (!ProjectFileIO::Get(project).IsTemporary())
119}
@ ProjectFilePathChange
A normal occurrence.
const auto project
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static ProjectFileIO & Get(AudacityProject &project)
std::unique_ptr< CloudStatusChangedNotifier > mUIStateNotifier
std::unique_ptr< CloudStatusChangedNotifier > mAsyncStateNotifier

References OnProjectPathChanged(), and ProjectFilePathChange.

Here is the call graph for this function:

◆ ~ProjectCloudExtension()

audacity::cloud::audiocom::sync::ProjectCloudExtension::~ProjectCloudExtension ( )
overridedefault

Member Function Documentation

◆ AbortLastUploadOperation()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::AbortLastUploadOperation ( )

◆ CancelSync()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::CancelSync ( )

Definition at line 355 of file ProjectCloudExtension.cpp.

356{
357 std::vector<std::shared_ptr<UploadQueueElement>> queue;
358
359 {
360 auto lock = std::lock_guard { mUploadQueueMutex };
361 std::swap(queue, mUploadQueue);
362 }
363
364 if (queue.empty())
365 return;
366
367 for (auto& item : queue)
368 {
369 if (!item->Operation)
370 continue;
371
372 item->Operation->Cancel();
373 }
374}
std::vector< std::shared_ptr< UploadQueueElement > > mUploadQueue
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:628

References anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ Get() [1/2]

ProjectCloudExtension & audacity::cloud::audiocom::sync::ProjectCloudExtension::Get ( AudacityProject project)
static

◆ Get() [2/2]

const ProjectCloudExtension & audacity::cloud::audiocom::sync::ProjectCloudExtension::Get ( const AudacityProject project)
static

Definition at line 129 of file ProjectCloudExtension.cpp.

130{
131 return Get(const_cast<AudacityProject&>(project));
132}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static ProjectCloudExtension & Get(AudacityProject &project)

References project.

◆ GetCloudProjectId()

std::string audacity::cloud::audiocom::sync::ProjectCloudExtension::GetCloudProjectId ( ) const

◆ GetCloudProjectPage()

std::string audacity::cloud::audiocom::sync::ProjectCloudExtension::GetCloudProjectPage ( AudiocomTrace  trace) const

Definition at line 626 of file ProjectCloudExtension.cpp.

627{
628 const auto projectId =
630
631 const auto userSlug =
633
634 return GetServiceConfig().GetProjectPageUrl(userSlug, projectId, trace);
635}
std::string GetProjectPageUrl(std::string_view userId, std::string_view projectId, AudiocomTrace) const
std::string GetProjectUserSlug(std::string_view projectId)
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.

References BasicUI::Get(), audacity::cloud::audiocom::ServiceConfig::GetProjectPageUrl(), and audacity::cloud::audiocom::GetServiceConfig().

Here is the call graph for this function:

◆ GetCurrentSyncStatus()

ProjectSyncStatus audacity::cloud::audiocom::sync::ProjectCloudExtension::GetCurrentSyncStatus ( ) const

Definition at line 651 of file ProjectCloudExtension.cpp.

◆ GetProject()

std::weak_ptr< AudacityProject > audacity::cloud::audiocom::sync::ProjectCloudExtension::GetProject ( ) const

Definition at line 451 of file ProjectCloudExtension.cpp.

452{
453 return mProject.weak_from_this();
454}

◆ GetSavesCount()

int64_t audacity::cloud::audiocom::sync::ProjectCloudExtension::GetSavesCount ( ) const

Definition at line 456 of file ProjectCloudExtension.cpp.

457{
458 auto lock = std::lock_guard { mIdentifiersMutex };
459
460 if (mProjectId.empty())
461 return 0;
462
463 auto& cloudDatabase = CloudProjectsDatabase::Get();
464 auto dbData = cloudDatabase.GetProjectData(mProjectId);
465
466 if (!dbData)
467 return 0;
468
469 return dbData->SavesCount;
470}

References BasicUI::Get().

Here is the call graph for this function:

◆ GetSnapshotId()

std::string audacity::cloud::audiocom::sync::ProjectCloudExtension::GetSnapshotId ( ) const

Definition at line 390 of file ProjectCloudExtension.cpp.

391{
392 auto lock = std::lock_guard { mIdentifiersMutex };
393
394 return mSnapshotId;
395}

Referenced by audacity::cloud::audiocom::sync::OpenProjectFromCloud(), and audacity::cloud::audiocom::sync::LocalProjectSnapshot::UpdateProjectSnapshot().

Here is the caller graph for this function:

◆ IsBlockLocked()

bool audacity::cloud::audiocom::sync::ProjectCloudExtension::IsBlockLocked ( int64_t  blockID) const

Definition at line 637 of file ProjectCloudExtension.cpp.

638{
639 // Try load the project info first based on the
640 // file path
641 const_cast<ProjectCloudExtension*>(this)->OnLoad();
642
643 const auto projectId = GetCloudProjectId();
644
645 if (projectId.empty())
646 return false;
647
648 return CloudProjectsDatabase::Get().IsProjectBlockLocked(projectId, blockID);
649}
bool IsProjectBlockLocked(std::string_view projectId, int64_t blockId) const

References BasicUI::Get().

Here is the call graph for this function:

◆ IsCloudProject()

bool audacity::cloud::audiocom::sync::ProjectCloudExtension::IsCloudProject ( ) const

◆ IsFirstSyncDialogShown()

bool audacity::cloud::audiocom::sync::ProjectCloudExtension::IsFirstSyncDialogShown ( ) const

Definition at line 660 of file ProjectCloudExtension.cpp.

661{
662 auto lock = std::lock_guard { mIdentifiersMutex };
663
664 if (mProjectId.empty())
665 return false;
666
668}
bool IsFirstSyncDialogShown(std::string_view projectId) const

References BasicUI::Get().

Here is the call graph for this function:

◆ IsSyncing()

bool audacity::cloud::audiocom::sync::ProjectCloudExtension::IsSyncing ( ) const

Definition at line 376 of file ProjectCloudExtension.cpp.

377{
378 auto lock = std::lock_guard { mStatusMutex };
379
381}

◆ MarkProjectSynced()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::MarkProjectSynced ( bool  success)
private

Definition at line 563 of file ProjectCloudExtension.cpp.

564{
565 auto& cloudDatabase = CloudProjectsDatabase::Get();
566
567 const auto projectFilePath =
569
570 auto previousDbData = cloudDatabase.GetProjectDataForPath(projectFilePath);
571
572 DBProjectData dbData;
573
574 if (previousDbData)
575 dbData = *previousDbData;
576
577 dbData.LastModified = wxDateTime::Now().GetTicks();
578 dbData.LastRead = dbData.LastModified;
579 dbData.SyncStatus = success ? DBProjectData::SyncStatusSynced :
581
582 cloudDatabase.UpdateProjectData(dbData);
583}
std::string ToUTF8(const std::wstring &wstr)

References BasicUI::Get(), ProjectFileIO::Get(), audacity::cloud::audiocom::sync::DBProjectData::LastModified, audacity::cloud::audiocom::sync::DBProjectData::LastRead, audacity::cloud::audiocom::sync::DBProjectData::SyncStatus, and audacity::ToUTF8().

Here is the call graph for this function:

◆ OnBlocksHashed()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnBlocksHashed ( ProjectUploadOperation uploadOperation)

This method is called not from the UI thread.

Definition at line 194 of file ProjectCloudExtension.cpp.

196{
197 auto lock = std::lock_guard { mUploadQueueMutex };
198 auto element = UnsafeFindUploadQueueElement(uploadOperation);
199
200 if (!element)
201 return;
202
203 element->ReadyForUpload = true;
204 uploadOperation.Start();
205}
UploadQueueElement * UnsafeFindUploadQueueElement(const ProjectUploadOperation &uploadOperation)

References audacity::cloud::audiocom::sync::ProjectUploadOperation::Start().

Here is the call graph for this function:

◆ OnBlockUploaded()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnBlockUploaded ( const ProjectUploadOperation uploadOperation,
std::string_view  blockID,
bool  successful 
)

This method is called from the network thread.

Definition at line 268 of file ProjectCloudExtension.cpp.

271{
272 auto lock = std::lock_guard { mUploadQueueMutex };
273 auto element = UnsafeFindUploadQueueElement(uploadOperation);
274
275 if (!element)
276 return;
277
278 element->BlocksHandled++;
279
281}

Referenced by audacity::cloud::audiocom::sync::LocalProjectSnapshot::OnSnapshotCreated().

Here is the caller graph for this function:

◆ OnLoad()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnLoad ( )

Definition at line 140 of file ProjectCloudExtension.cpp.

141{
143}

◆ OnProjectDataUploaded()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnProjectDataUploaded ( const ProjectUploadOperation uploadOperation)

This method is called from the network thread.

Definition at line 254 of file ProjectCloudExtension.cpp.

256{
257 auto lock = std::lock_guard { mUploadQueueMutex };
258 auto element = UnsafeFindUploadQueueElement(uploadOperation);
259
260 if (!element)
261 return;
262
263 element->ProjectDataUploaded = true;
264
266}

Referenced by audacity::cloud::audiocom::sync::LocalProjectSnapshot::OnSnapshotCreated().

Here is the caller graph for this function:

◆ OnProjectPathChanged()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnProjectPathChanged ( )
private

Definition at line 605 of file ProjectCloudExtension.cpp.

606{
607 bool wasCloudProject = false;
608
609 {
610 auto lock = std::lock_guard { mIdentifiersMutex };
611
612 wasCloudProject = !mProjectId.empty();
613
614 mProjectId.clear();
615 mSnapshotId.clear();
616 }
617
618 // This will set the status to cloud if the project is a cloud project
620
621 if (mProjectId.empty() && wasCloudProject)
623}
void Publish(CloudStatusChangedMessage cloudStatus, bool canMerge)

References ignore.

Referenced by ProjectCloudExtension().

Here is the caller graph for this function:

◆ OnSnapshotCreated()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnSnapshotCreated ( const ProjectUploadOperation uploadOperation,
const CreateSnapshotResponse response 
)

This method is called from the network thread.

Definition at line 207 of file ProjectCloudExtension.cpp.

210{
211 auto& cloudDatabase = CloudProjectsDatabase::Get();
212
213 const auto projectFilePath =
215
216 auto previousDbData = cloudDatabase.GetProjectDataForPath(projectFilePath);
217
218 DBProjectData dbData;
219
220 if (previousDbData)
221 dbData = *previousDbData;
222
223 dbData.ProjectId = response.Project.Id;
224 dbData.SnapshotId = response.Snapshot.Id;
225 dbData.LocalPath = projectFilePath;
226 dbData.LastModified = wxDateTime::Now().GetTicks();
227 dbData.LastRead = dbData.LastModified;
228 dbData.SyncStatus = DBProjectData::SyncStatusUploading;
229 dbData.SavesCount++;
230
231 cloudDatabase.UpdateProjectData(dbData);
232 cloudDatabase.SetProjectUserSlug(
233 response.Project.Id, response.Project.Username);
234
235 {
236 auto lock = std::lock_guard { mIdentifiersMutex };
237
238 mProjectId = response.Project.Id;
239 mSnapshotId = response.Snapshot.Id;
240 }
241
242 auto lock = std::lock_guard { mUploadQueueMutex };
243 auto element = UnsafeFindUploadQueueElement(uploadOperation);
244
245 if (!element)
246 return;
247
248 element->BlocksTotal = response.SyncState.MissingBlocks.size();
249 element->SnapshotResponse = response;
250
252}

References BasicUI::Get(), ProjectFileIO::Get(), audacity::cloud::audiocom::sync::SnapshotInfo::Id, audacity::cloud::audiocom::sync::ProjectInfo::Id, audacity::cloud::audiocom::sync::DBProjectData::LastModified, audacity::cloud::audiocom::sync::DBProjectData::LastRead, audacity::cloud::audiocom::sync::DBProjectData::LocalPath, audacity::cloud::audiocom::sync::ProjectSyncState::MissingBlocks, audacity::cloud::audiocom::sync::CreateSnapshotResponse::Project, audacity::cloud::audiocom::sync::DBProjectData::ProjectId, audacity::cloud::audiocom::sync::DBProjectData::SavesCount, audacity::cloud::audiocom::sync::CreateSnapshotResponse::Snapshot, audacity::cloud::audiocom::sync::DBProjectData::SnapshotId, audacity::cloud::audiocom::sync::CreateSnapshotResponse::SyncState, audacity::cloud::audiocom::sync::DBProjectData::SyncStatus, audacity::ToUTF8(), and audacity::cloud::audiocom::sync::ProjectInfo::Username.

Referenced by audacity::cloud::audiocom::sync::LocalProjectSnapshot::OnSnapshotCreated().

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

◆ OnSyncCompleted()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnSyncCompleted ( const ProjectUploadOperation uploadOperation,
std::optional< CloudSyncError error,
AudiocomTrace  trace 
)

This method is called from any thread.

Definition at line 283 of file ProjectCloudExtension.cpp.

286{
287 auto lock = std::lock_guard { mUploadQueueMutex };
288
289 auto element = uploadOperation != nullptr ?
290 UnsafeFindUploadQueueElement(*uploadOperation) :
291 nullptr;
292
293 if (element != nullptr)
294 {
295 element->Synced = true;
296
297 if (
298 error.has_value() && error->Type == CloudSyncError::Aborted &&
299 element->SnapshotResponse)
300 {
301 auto& cloudDatabase = CloudProjectsDatabase::Get();
302
303 const auto projectFilePath =
305
306 auto previousDbData =
307 cloudDatabase.GetProjectDataForPath(projectFilePath);
308
309 DBProjectData dbData;
310
311 if (previousDbData)
312 dbData = *previousDbData;
313
314 const auto parentId = element->SnapshotResponse->Snapshot.ParentId;
315
316 dbData.SnapshotId = parentId;
317
318 cloudDatabase.UpdateProjectData(dbData);
319
320 {
321 auto lock = std::lock_guard { mIdentifiersMutex };
322 mSnapshotId = parentId;
323 }
324 }
325 }
326
327 // std::all_of returns true if the range is empty
328 if (!std::all_of(
329 mUploadQueue.begin(), mUploadQueue.end(),
330 [](auto& operation) { return operation->Synced; }))
331 {
333 return;
334 }
335
336 mUploadQueue.clear();
337
338 MarkProjectSynced(!error.has_value());
339
340 Publish(
341 { trace,
342 error.has_value() ? ProjectSyncStatus::Failed :
344 {},
345 error },
346 false);
347
348 if (!IsCloudProject())
349 Publish(
350 { AudiocomTrace::ignore, // All right
352 false);
353}

References BasicUI::Get(), ProjectFileIO::Get(), ignore, audacity::cloud::audiocom::sync::DBProjectData::SnapshotId, and audacity::ToUTF8().

Referenced by audacity::cloud::audiocom::sync::LocalProjectSnapshot::MarkSnapshotSynced(), and audacity::cloud::audiocom::sync::LocalProjectSnapshot::UploadFailed().

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

◆ OnSyncResumed()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnSyncResumed ( std::shared_ptr< ProjectUploadOperation uploadOperation,
int64_t  missingBlocksCount,
bool  needsProjectUpload 
)

This method is called from the UI thread.

Definition at line 163 of file ProjectCloudExtension.cpp.

166{
167 auto element = std::make_shared<UploadQueueElement>();
168 element->Operation = uploadOperation;
169 element->BlocksTotal = missingBlocksCount;
170 element->ProjectDataUploaded = !needsProjectUpload;
171
172 {
173 auto lock = std::lock_guard { mUploadQueueMutex };
174 mUploadQueue.push_back(element);
175 }
176
177 uploadOperation->Start();
179}

Referenced by audacity::cloud::audiocom::sync::anonymous_namespace{ResumedSnaphotUploadOperation.cpp}::ResumedSnaphotUploadOperation::Perform().

Here is the caller graph for this function:

◆ OnSyncStarted()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnSyncStarted ( )

This method is called from the UI thread.

Definition at line 145 of file ProjectCloudExtension.cpp.

146{
147 auto element = std::make_shared<UploadQueueElement>();
148
149 element->Data.Tracks = TrackList::Create(nullptr);
150
151 for (auto pTrack : TrackList::Get(mProject))
152 {
153 if (pTrack->GetId() == TrackId {})
154 // Don't copy a pending added track
155 continue;
156 element->Data.Tracks->Add(pTrack->Duplicate());
157 }
158
159 auto lock = std::lock_guard { mUploadQueueMutex };
160 mUploadQueue.push_back(std::move(element));
161}
An in-session identifier of track objects across undo states. It does not persist between sessions.
Definition: Track.h:79
static TrackListHolder Create(AudacityProject *pOwner)
Definition: Track.cpp:330
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314

References TrackList::Create(), and TrackList::Get().

Here is the call graph for this function:

◆ OnUpdateSaved()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnUpdateSaved ( const ProjectSerializer serializer)

Definition at line 397 of file ProjectCloudExtension.cpp.

398{
399 auto lock = std::lock_guard { mUploadQueueMutex };
400
401 if (mUploadQueue.empty())
402 return;
403
404 const size_t dictSize = serializer.GetDict().GetSize();
405 const size_t projectSize = serializer.GetData().GetSize();
406
407 std::vector<uint8_t> data;
408 data.resize(projectSize + dictSize + sizeof(uint64_t));
409
410 const uint64_t dictSizeData =
411 IsLittleEndian() ? dictSize : SwapIntBytes(dictSize);
412
413 std::memcpy(data.data(), &dictSizeData, sizeof(uint64_t));
414
415 uint64_t offset = sizeof(dictSize);
416
417 for (const auto [chunkData, size] : serializer.GetDict())
418 {
419 std::memcpy(data.data() + offset, chunkData, size);
420 offset += size;
421 }
422
423 for (const auto [chunkData, size] : serializer.GetData())
424 {
425 std::memcpy(data.data() + offset, chunkData, size);
426 offset += size;
427 }
428
429 mUploadQueue.back()->Data.ProjectSnapshot = std::move(data);
430
431 if (mUploadQueue.back()->Operation)
432 {
433 mUploadQueue.back()->Operation->SetUploadData(mUploadQueue.back()->Data);
434
436
437 if (dbData)
438 {
439 dbData->LocalPath =
442 }
443 }
444 else
445 Publish(
446 { AudiocomTrace::ignore, // TODO Is this correct ?
448 false);
449}
constexpr IntType SwapIntBytes(IntType value) noexcept
Swap bytes in an integer.
Definition: MemoryX.h:377
bool IsLittleEndian() noexcept
Check that machine is little-endian.
Definition: MemoryX.h:368
const size_t GetSize() const noexcept
const MemoryStream & GetData() const
const MemoryStream & GetDict() const
bool UpdateProjectData(const DBProjectData &projectData)
std::optional< DBProjectData > GetProjectData(std::string_view projectId) const

References BasicUI::Get(), ProjectFileIO::Get(), ProjectSerializer::GetData(), ProjectSerializer::GetDict(), MemoryStream::GetSize(), ignore, IsLittleEndian(), size, SwapIntBytes(), and audacity::ToUTF8().

Here is the call graph for this function:

◆ OnUploadOperationCreated()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::OnUploadOperationCreated ( std::shared_ptr< ProjectUploadOperation uploadOperation)

This method is called from the UI thread.

Definition at line 181 of file ProjectCloudExtension.cpp.

183{
184 auto lock = std::lock_guard { mUploadQueueMutex };
185 assert(mUploadQueue.size() > 0);
186
187 if (mUploadQueue.empty())
188 return;
189
190 mUploadQueue.back()->Operation = uploadOperation;
192}

◆ Publish()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::Publish ( CloudStatusChangedMessage  cloudStatus,
bool  canMerge 
)
private

Definition at line 534 of file ProjectCloudExtension.cpp.

536{
537 {
538 auto lock = std::lock_guard { mStatusMutex };
539 mLastStatus = cloudStatus;
540 }
541
542 mAsyncStateNotifier->Enqueue(cloudStatus, canMerge);
543 mUIStateNotifier->Enqueue(cloudStatus, canMerge);
544
545 mAsyncStateNotifier->PublishSafe();
546
548 {
549 mUINotificationPending.store(false);
550 mUIStateNotifier->PublishSafe();
551 }
552 else if (!mUINotificationPending.exchange(true))
553 {
555 [this]
556 {
557 if (mUINotificationPending.exchange(false))
558 mUIStateNotifier->PublishSafe();
559 });
560 }
561}
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214
bool IsUiThread()
Whether the current thread is the UI thread.
Definition: BasicUI.h:407

References BasicUI::CallAfter(), and BasicUI::IsUiThread().

Here is the call graph for this function:

◆ SetFirstSyncDialogShown()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::SetFirstSyncDialogShown ( bool  shown = true)

Definition at line 670 of file ProjectCloudExtension.cpp.

671{
672 auto lock = std::lock_guard { mIdentifiersMutex };
673
674 if (mProjectId.empty())
675 return;
676
678}
void SetFirstSyncDialogShown(std::string_view projectId, bool shown=true)

References BasicUI::Get().

Here is the call graph for this function:

◆ SubscribeStatusChanged()

Observer::Subscription audacity::cloud::audiocom::sync::ProjectCloudExtension::SubscribeStatusChanged ( std::function< void(const CloudStatusChangedMessage &)>  callback,
bool  onUIThread 
)

Definition at line 472 of file ProjectCloudExtension.cpp.

475{
476 return onUIThread ? mUIStateNotifier->SubscribeSafe(std::move(callback)) :
477 mAsyncStateNotifier->SubscribeSafe(std::move(callback));
478}

◆ UnsafeFindUploadQueueElement() [1/2]

ProjectCloudExtension::UploadQueueElement * audacity::cloud::audiocom::sync::ProjectCloudExtension::UnsafeFindUploadQueueElement ( const ProjectUploadOperation uploadOperation)
private

Definition at line 586 of file ProjectCloudExtension.cpp.

588{
589 auto it = std::find_if(
590 mUploadQueue.begin(), mUploadQueue.end(),
591 [&](const auto& element)
592 { return element->Operation.get() == &uploadOperation; });
593
594 return it != mUploadQueue.end() ? it->get() : nullptr;
595}

◆ UnsafeFindUploadQueueElement() [2/2]

const ProjectCloudExtension::UploadQueueElement * audacity::cloud::audiocom::sync::ProjectCloudExtension::UnsafeFindUploadQueueElement ( const ProjectUploadOperation uploadOperation) const
private

Definition at line 598 of file ProjectCloudExtension.cpp.

600{
601 return const_cast<ProjectCloudExtension*>(this)
602 ->UnsafeFindUploadQueueElement(uploadOperation);
603}

◆ UnsafeUpdateProgress()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::UnsafeUpdateProgress ( )
private

Definition at line 510 of file ProjectCloudExtension.cpp.

511{
512 if (mUploadQueue.empty())
513 return;
514
515 int64_t handledElements = 0;
516 int64_t totalElements = 0;
517
518 for (auto& element : mUploadQueue)
519 {
520 handledElements +=
521 element->BlocksHandled + int(element->ProjectDataUploaded);
522 totalElements += element->BlocksTotal + 1;
523 }
524
525 assert(totalElements > 0);
526
527 Publish(
528 { AudiocomTrace::ignore, // All right
530 double(handledElements) / double(totalElements) },
531 true);
532}

References ignore.

◆ UpdateIdFromDatabase()

void audacity::cloud::audiocom::sync::ProjectCloudExtension::UpdateIdFromDatabase ( )
private

Definition at line 480 of file ProjectCloudExtension.cpp.

481{
482 auto& projectFileIO = ProjectFileIO::Get(mProject);
483 auto& cloudDatabase = CloudProjectsDatabase::Get();
484
485 auto projectData = cloudDatabase.GetProjectDataForPath(
486 audacity::ToUTF8(projectFileIO.GetFileName()));
487
488 if (!projectData)
489 return;
490
491 {
492 auto lock = std::lock_guard { mIdentifiersMutex };
493
494 mProjectId = projectData->ProjectId;
495 mSnapshotId = projectData->SnapshotId;
496 }
497
498 Publish(
499 {
500 AudiocomTrace::ignore, // OK here because we're not publishing an
501 // error
502 projectData->SyncStatus ==
503 DBProjectData::SyncStatusType::SyncStatusSynced ?
506 },
507 false);
508}

References BasicUI::Get(), ProjectFileIO::Get(), ignore, and audacity::ToUTF8().

Here is the call graph for this function:

Member Data Documentation

◆ mAsyncStateNotifier

std::unique_ptr<CloudStatusChangedNotifier> audacity::cloud::audiocom::sync::ProjectCloudExtension::mAsyncStateNotifier
private

Definition at line 157 of file ProjectCloudExtension.h.

◆ mIdentifiersMutex

std::mutex audacity::cloud::audiocom::sync::ProjectCloudExtension::mIdentifiersMutex
mutableprivate

Definition at line 147 of file ProjectCloudExtension.h.

◆ mLastStatus

CloudStatusChangedMessage audacity::cloud::audiocom::sync::ProjectCloudExtension::mLastStatus
private

Definition at line 155 of file ProjectCloudExtension.h.

◆ mProject

AudacityProject& audacity::cloud::audiocom::sync::ProjectCloudExtension::mProject
private

Definition at line 143 of file ProjectCloudExtension.h.

◆ mProjectId

std::string audacity::cloud::audiocom::sync::ProjectCloudExtension::mProjectId
private

Definition at line 148 of file ProjectCloudExtension.h.

◆ mProjectPathChangedSubscription

Observer::Subscription audacity::cloud::audiocom::sync::ProjectCloudExtension::mProjectPathChangedSubscription
private

Definition at line 145 of file ProjectCloudExtension.h.

◆ mSnapshotId

std::string audacity::cloud::audiocom::sync::ProjectCloudExtension::mSnapshotId
private

Definition at line 149 of file ProjectCloudExtension.h.

◆ mStatusMutex

std::mutex audacity::cloud::audiocom::sync::ProjectCloudExtension::mStatusMutex
mutableprivate

Definition at line 154 of file ProjectCloudExtension.h.

◆ mUINotificationPending

std::atomic<bool> audacity::cloud::audiocom::sync::ProjectCloudExtension::mUINotificationPending { false }
private

Definition at line 159 of file ProjectCloudExtension.h.

◆ mUIStateNotifier

std::unique_ptr<CloudStatusChangedNotifier> audacity::cloud::audiocom::sync::ProjectCloudExtension::mUIStateNotifier
private

Definition at line 158 of file ProjectCloudExtension.h.

◆ mUploadQueue

std::vector<std::shared_ptr<UploadQueueElement> > audacity::cloud::audiocom::sync::ProjectCloudExtension::mUploadQueue
private

Definition at line 152 of file ProjectCloudExtension.h.

◆ mUploadQueueMutex

std::mutex audacity::cloud::audiocom::sync::ProjectCloudExtension::mUploadQueueMutex
private

Definition at line 151 of file ProjectCloudExtension.h.


The documentation for this class was generated from the following files: