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)
 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 () 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 55 of file ProjectCloudExtension.h.

Constructor & Destructor Documentation

◆ ProjectCloudExtension()

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

Definition at line 105 of file ProjectCloudExtension.cpp.

106 : mProject { project }
108 [this](auto message)
109 {
112 }) }
113 , mAsyncStateNotifier { std::make_unique<CloudStatusChangedNotifier>() }
114 , mUIStateNotifier { std::make_unique<CloudStatusChangedNotifier>() }
115{
116 if (!ProjectFileIO::Get(project).IsTemporary())
118}
@ 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 350 of file ProjectCloudExtension.cpp.

351{
352 std::vector<std::shared_ptr<UploadQueueElement>> queue;
353
354 {
355 auto lock = std::lock_guard { mUploadQueueMutex };
356 std::swap(queue, mUploadQueue);
357 }
358
359 if (queue.empty())
360 return;
361
362 for (auto& item : queue)
363 {
364 if (!item->Operation)
365 continue;
366
367 item->Operation->Cancel();
368 }
369}
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 128 of file ProjectCloudExtension.cpp.

129{
130 return Get(const_cast<AudacityProject&>(project));
131}
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 ( ) const

Definition at line 614 of file ProjectCloudExtension.cpp.

615{
616 const auto projectId =
618
619 const auto userSlug =
621
622 return GetServiceConfig().GetProjectPageUrl(userSlug, projectId);
623}
std::string GetProjectPageUrl(std::string_view userId, std::string_view projectId) 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 639 of file ProjectCloudExtension.cpp.

◆ GetProject()

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

Definition at line 443 of file ProjectCloudExtension.cpp.

444{
445 return mProject.weak_from_this();
446}

◆ GetSavesCount()

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

Definition at line 448 of file ProjectCloudExtension.cpp.

449{
450 auto lock = std::lock_guard { mIdentifiersMutex };
451
452 if (mProjectId.empty())
453 return 0;
454
455 auto& cloudDatabase = CloudProjectsDatabase::Get();
456 auto dbData = cloudDatabase.GetProjectData(mProjectId);
457
458 if (!dbData)
459 return 0;
460
461 return dbData->SavesCount;
462}

References BasicUI::Get().

Here is the call graph for this function:

◆ GetSnapshotId()

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

Definition at line 385 of file ProjectCloudExtension.cpp.

386{
387 auto lock = std::lock_guard { mIdentifiersMutex };
388
389 return mSnapshotId;
390}

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 625 of file ProjectCloudExtension.cpp.

626{
627 // Try load the project info first based on the
628 // file path
629 const_cast<ProjectCloudExtension*>(this)->OnLoad();
630
631 const auto projectId = GetCloudProjectId();
632
633 if (projectId.empty())
634 return false;
635
636 return CloudProjectsDatabase::Get().IsProjectBlockLocked(projectId, blockID);
637}
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 648 of file ProjectCloudExtension.cpp.

649{
650 auto lock = std::lock_guard { mIdentifiersMutex };
651
652 if (mProjectId.empty())
653 return false;
654
656}
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 371 of file ProjectCloudExtension.cpp.

372{
373 auto lock = std::lock_guard { mStatusMutex };
374
376}

◆ MarkProjectSynced()

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

Definition at line 552 of file ProjectCloudExtension.cpp.

553{
554 auto& cloudDatabase = CloudProjectsDatabase::Get();
555
556 const auto projectFilePath =
558
559 auto previousDbData = cloudDatabase.GetProjectDataForPath(projectFilePath);
560
561 DBProjectData dbData;
562
563 if (previousDbData)
564 dbData = *previousDbData;
565
566 dbData.LastModified = wxDateTime::Now().GetTicks();
567 dbData.LastRead = dbData.LastModified;
568 dbData.SyncStatus = success ? DBProjectData::SyncStatusSynced :
570
571 cloudDatabase.UpdateProjectData(dbData);
572}
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 193 of file ProjectCloudExtension.cpp.

195{
196 auto lock = std::lock_guard { mUploadQueueMutex };
197 auto element = UnsafeFindUploadQueueElement(uploadOperation);
198
199 if (!element)
200 return;
201
202 element->ReadyForUpload = true;
203 uploadOperation.Start();
204}
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 267 of file ProjectCloudExtension.cpp.

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

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 139 of file ProjectCloudExtension.cpp.

140{
142}

◆ OnProjectDataUploaded()

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

This method is called from the network thread.

Definition at line 253 of file ProjectCloudExtension.cpp.

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

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 594 of file ProjectCloudExtension.cpp.

595{
596 bool wasCloudProject = false;
597
598 {
599 auto lock = std::lock_guard { mIdentifiersMutex };
600
601 wasCloudProject = !mProjectId.empty();
602
603 mProjectId.clear();
604 mSnapshotId.clear();
605 }
606
607 // This will set the status to cloud if the project is a cloud project
609
610 if (mProjectId.empty() && wasCloudProject)
612}
void Publish(CloudStatusChangedMessage cloudStatus, bool canMerge)

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 206 of file ProjectCloudExtension.cpp.

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

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 
)

This method is called from any thread.

Definition at line 282 of file ProjectCloudExtension.cpp.

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

References BasicUI::Get(), ProjectFileIO::Get(), 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 162 of file ProjectCloudExtension.cpp.

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

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 144 of file ProjectCloudExtension.cpp.

145{
146 auto element = std::make_shared<UploadQueueElement>();
147
148 element->Data.Tracks = TrackList::Create(nullptr);
149
150 for (auto pTrack : TrackList::Get(mProject))
151 {
152 if (pTrack->GetId() == TrackId {})
153 // Don't copy a pending added track
154 continue;
155 element->Data.Tracks->Add(pTrack->Duplicate());
156 }
157
158 auto lock = std::lock_guard { mUploadQueueMutex };
159 mUploadQueue.push_back(std::move(element));
160}
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 392 of file ProjectCloudExtension.cpp.

393{
394 auto lock = std::lock_guard { mUploadQueueMutex };
395
396 if (mUploadQueue.empty())
397 return;
398
399 const size_t dictSize = serializer.GetDict().GetSize();
400 const size_t projectSize = serializer.GetData().GetSize();
401
402 std::vector<uint8_t> data;
403 data.resize(projectSize + dictSize + sizeof(uint64_t));
404
405 const uint64_t dictSizeData =
406 IsLittleEndian() ? dictSize : SwapIntBytes(dictSize);
407
408 std::memcpy(data.data(), &dictSizeData, sizeof(uint64_t));
409
410 uint64_t offset = sizeof(dictSize);
411
412 for (const auto [chunkData, size] : serializer.GetDict())
413 {
414 std::memcpy(data.data() + offset, chunkData, size);
415 offset += size;
416 }
417
418 for (const auto [chunkData, size] : serializer.GetData())
419 {
420 std::memcpy(data.data() + offset, chunkData, size);
421 offset += size;
422 }
423
424 mUploadQueue.back()->Data.ProjectSnapshot = std::move(data);
425
426 if (mUploadQueue.back()->Operation)
427 {
428 mUploadQueue.back()->Operation->SetUploadData(mUploadQueue.back()->Data);
429
431
432 if (dbData)
433 {
434 dbData->LocalPath =
437 }
438 }
439 else
441}
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(), 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 180 of file ProjectCloudExtension.cpp.

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

◆ Publish()

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

Definition at line 523 of file ProjectCloudExtension.cpp.

525{
526 {
527 auto lock = std::lock_guard { mStatusMutex };
528 mLastStatus = cloudStatus;
529 }
530
531 mAsyncStateNotifier->Enqueue(cloudStatus, canMerge);
532 mUIStateNotifier->Enqueue(cloudStatus, canMerge);
533
534 mAsyncStateNotifier->PublishSafe();
535
537 {
538 mUINotificationPending.store(false);
539 mUIStateNotifier->PublishSafe();
540 }
541 else if (!mUINotificationPending.exchange(true))
542 {
544 [this]
545 {
546 if (mUINotificationPending.exchange(false))
547 mUIStateNotifier->PublishSafe();
548 });
549 }
550}
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:213
bool IsUiThread()
Whether the current thread is the UI thread.
Definition: BasicUI.h:399

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 658 of file ProjectCloudExtension.cpp.

659{
660 auto lock = std::lock_guard { mIdentifiersMutex };
661
662 if (mProjectId.empty())
663 return;
664
666}
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 464 of file ProjectCloudExtension.cpp.

467{
468 return onUIThread ? mUIStateNotifier->SubscribeSafe(std::move(callback)) :
469 mAsyncStateNotifier->SubscribeSafe(std::move(callback));
470}

◆ UnsafeFindUploadQueueElement() [1/2]

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

Definition at line 575 of file ProjectCloudExtension.cpp.

577{
578 auto it = std::find_if(
579 mUploadQueue.begin(), mUploadQueue.end(),
580 [&](const auto& element)
581 { return element->Operation.get() == &uploadOperation; });
582
583 return it != mUploadQueue.end() ? it->get() : nullptr;
584}

◆ UnsafeFindUploadQueueElement() [2/2]

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

Definition at line 587 of file ProjectCloudExtension.cpp.

589{
590 return const_cast<ProjectCloudExtension*>(this)
591 ->UnsafeFindUploadQueueElement(uploadOperation);
592}

◆ UnsafeUpdateProgress()

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

Definition at line 500 of file ProjectCloudExtension.cpp.

501{
502 if (mUploadQueue.empty())
503 return;
504
505 int64_t handledElements = 0;
506 int64_t totalElements = 0;
507
508 for (auto& element : mUploadQueue)
509 {
510 handledElements +=
511 element->BlocksHandled + int(element->ProjectDataUploaded);
512 totalElements += element->BlocksTotal + 1;
513 }
514
515 assert(totalElements > 0);
516
517 Publish(
519 double(handledElements) / double(totalElements) },
520 true);
521}

◆ UpdateIdFromDatabase()

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

Definition at line 472 of file ProjectCloudExtension.cpp.

473{
474 auto& projectFileIO = ProjectFileIO::Get(mProject);
475 auto& cloudDatabase = CloudProjectsDatabase::Get();
476
477 auto projectData = cloudDatabase.GetProjectDataForPath(
478 audacity::ToUTF8(projectFileIO.GetFileName()));
479
480 if (!projectData)
481 return;
482
483 {
484 auto lock = std::lock_guard { mIdentifiersMutex };
485
486 mProjectId = projectData->ProjectId;
487 mSnapshotId = projectData->SnapshotId;
488 }
489
490 Publish(
491 {
492 projectData->SyncStatus ==
493 DBProjectData::SyncStatusType::SyncStatusSynced ?
496 },
497 false);
498}

References BasicUI::Get(), ProjectFileIO::Get(), 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 154 of file ProjectCloudExtension.h.

◆ mIdentifiersMutex

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

Definition at line 144 of file ProjectCloudExtension.h.

◆ mLastStatus

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

Definition at line 152 of file ProjectCloudExtension.h.

◆ mProject

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

Definition at line 140 of file ProjectCloudExtension.h.

◆ mProjectId

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

Definition at line 145 of file ProjectCloudExtension.h.

◆ mProjectPathChangedSubscription

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

Definition at line 142 of file ProjectCloudExtension.h.

◆ mSnapshotId

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

Definition at line 146 of file ProjectCloudExtension.h.

◆ mStatusMutex

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

Definition at line 151 of file ProjectCloudExtension.h.

◆ mUINotificationPending

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

Definition at line 156 of file ProjectCloudExtension.h.

◆ mUIStateNotifier

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

Definition at line 155 of file ProjectCloudExtension.h.

◆ mUploadQueue

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

Definition at line 149 of file ProjectCloudExtension.h.

◆ mUploadQueueMutex

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

Definition at line 148 of file ProjectCloudExtension.h.


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