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

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

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

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

132{
133 return Get(const_cast<AudacityProject&>(project));
134}
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 628 of file ProjectCloudExtension.cpp.

629{
630 auto& oauthService = GetOAuthService();
631 auto& serviceConfig = GetServiceConfig();
632
633 auto userId = audacity::ToUTF8(GetUserService().GetUserId());
634
635 const auto projectId =
637
638 const auto userSlug =
640
641 auto projectPage = serviceConfig.GetProjectPagePath(userSlug, projectId, trace);
642 auto url = oauthService.MakeAudioComAuthorizeURL(userId, projectPage);
643 return url;
644}
std::string GetProjectUserSlug(std::string_view projectId)
UserService & GetUserService()
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.
std::string ToUTF8(const std::wstring &wstr)

References BasicUI::Get(), audacity::cloud::audiocom::GetOAuthService(), audacity::cloud::audiocom::GetServiceConfig(), audacity::cloud::audiocom::GetUserService(), audacity::ToUTF8(), and audacity::cloud::audiocom::anonymous_namespace{UserService.cpp}::userId.

Here is the call graph for this function:

◆ GetCurrentSyncStatus()

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

Definition at line 660 of file ProjectCloudExtension.cpp.

◆ GetProject()

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

Definition at line 453 of file ProjectCloudExtension.cpp.

454{
455 return mProject.weak_from_this();
456}

◆ GetSavesCount()

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

Definition at line 458 of file ProjectCloudExtension.cpp.

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

References BasicUI::Get().

Here is the call graph for this function:

◆ GetSnapshotId()

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

Definition at line 392 of file ProjectCloudExtension.cpp.

393{
394 auto lock = std::lock_guard { mIdentifiersMutex };
395
396 return mSnapshotId;
397}

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

647{
648 // Try load the project info first based on the
649 // file path
650 const_cast<ProjectCloudExtension*>(this)->OnLoad();
651
652 const auto projectId = GetCloudProjectId();
653
654 if (projectId.empty())
655 return false;
656
657 return CloudProjectsDatabase::Get().IsProjectBlockLocked(projectId, blockID);
658}
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 669 of file ProjectCloudExtension.cpp.

670{
671 auto lock = std::lock_guard { mIdentifiersMutex };
672
673 if (mProjectId.empty())
674 return false;
675
677}
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 378 of file ProjectCloudExtension.cpp.

379{
380 auto lock = std::lock_guard { mStatusMutex };
381
383}

◆ MarkProjectSynced()

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

Definition at line 565 of file ProjectCloudExtension.cpp.

566{
567 auto& cloudDatabase = CloudProjectsDatabase::Get();
568
569 const auto projectFilePath =
571
572 auto previousDbData = cloudDatabase.GetProjectDataForPath(projectFilePath);
573
574 DBProjectData dbData;
575
576 if (previousDbData)
577 dbData = *previousDbData;
578
579 dbData.LastModified = wxDateTime::Now().GetTicks();
580 dbData.LastRead = dbData.LastModified;
581 dbData.SyncStatus = success ? DBProjectData::SyncStatusSynced :
583
584 cloudDatabase.UpdateProjectData(dbData);
585}

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

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

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

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

143{
145}

◆ OnProjectDataUploaded()

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

This method is called from the network thread.

Definition at line 256 of file ProjectCloudExtension.cpp.

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

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

608{
609 bool wasCloudProject = false;
610
611 {
612 auto lock = std::lock_guard { mIdentifiersMutex };
613
614 wasCloudProject = !mProjectId.empty();
615
616 mProjectId.clear();
617 mSnapshotId.clear();
618 }
619
620 // This will set the status to cloud if the project is a cloud project
622
623 if (mProjectId.empty() && wasCloudProject)
625}
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 209 of file ProjectCloudExtension.cpp.

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

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

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

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

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

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

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

400{
401 auto lock = std::lock_guard { mUploadQueueMutex };
402
403 if (mUploadQueue.empty())
404 return;
405
406 const size_t dictSize = serializer.GetDict().GetSize();
407 const size_t projectSize = serializer.GetData().GetSize();
408
409 std::vector<uint8_t> data;
410 data.resize(projectSize + dictSize + sizeof(uint64_t));
411
412 const uint64_t dictSizeData =
413 IsLittleEndian() ? dictSize : SwapIntBytes(dictSize);
414
415 std::memcpy(data.data(), &dictSizeData, sizeof(uint64_t));
416
417 uint64_t offset = sizeof(uint64_t);
418
419 for (const auto [chunkData, size] : serializer.GetDict())
420 {
421 std::memcpy(data.data() + offset, chunkData, size);
422 offset += size;
423 }
424
425 for (const auto [chunkData, size] : serializer.GetData())
426 {
427 std::memcpy(data.data() + offset, chunkData, size);
428 offset += size;
429 }
430
431 mUploadQueue.back()->Data.ProjectSnapshot = std::move(data);
432
433 if (mUploadQueue.back()->Operation)
434 {
435 mUploadQueue.back()->Operation->SetUploadData(mUploadQueue.back()->Data);
436
438
439 if (dbData)
440 {
441 dbData->LocalPath =
444 }
445 }
446 else
447 Publish(
448 { AudiocomTrace::ignore, // TODO Is this correct ?
450 false);
451}
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 183 of file ProjectCloudExtension.cpp.

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

◆ Publish()

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

Definition at line 536 of file ProjectCloudExtension.cpp.

538{
539 {
540 auto lock = std::lock_guard { mStatusMutex };
541 mLastStatus = cloudStatus;
542 }
543
544 mAsyncStateNotifier->Enqueue(cloudStatus, canMerge);
545 mUIStateNotifier->Enqueue(cloudStatus, canMerge);
546
547 mAsyncStateNotifier->PublishSafe();
548
550 {
551 mUINotificationPending.store(false);
552 mUIStateNotifier->PublishSafe();
553 }
554 else if (!mUINotificationPending.exchange(true))
555 {
557 [this]
558 {
559 if (mUINotificationPending.exchange(false))
560 mUIStateNotifier->PublishSafe();
561 });
562 }
563}
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 679 of file ProjectCloudExtension.cpp.

680{
681 auto lock = std::lock_guard { mIdentifiersMutex };
682
683 if (mProjectId.empty())
684 return;
685
687}
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 474 of file ProjectCloudExtension.cpp.

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

◆ UnsafeFindUploadQueueElement() [1/2]

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

Definition at line 588 of file ProjectCloudExtension.cpp.

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

◆ UnsafeFindUploadQueueElement() [2/2]

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

Definition at line 600 of file ProjectCloudExtension.cpp.

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

◆ UnsafeUpdateProgress()

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

Definition at line 512 of file ProjectCloudExtension.cpp.

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

References ignore.

◆ UpdateIdFromDatabase()

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

Definition at line 482 of file ProjectCloudExtension.cpp.

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

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: