backend.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "common/hex_util.h"
  4. #include "common/logging/log.h"
  5. #include "core/core.h"
  6. #include "core/hle/kernel/k_event.h"
  7. #include "core/hle/service/bcat/backend/backend.h"
  8. namespace Service::BCAT {
  9. ProgressServiceBackend::ProgressServiceBackend(Core::System& system, std::string_view event_name)
  10. : service_context{system, "ProgressServiceBackend"} {
  11. update_event = service_context.CreateEvent("ProgressServiceBackend:UpdateEvent:" +
  12. std::string(event_name));
  13. }
  14. ProgressServiceBackend::~ProgressServiceBackend() {
  15. service_context.CloseEvent(update_event);
  16. }
  17. Kernel::KReadableEvent& ProgressServiceBackend::GetEvent() {
  18. return update_event->GetReadableEvent();
  19. }
  20. DeliveryCacheProgressImpl& ProgressServiceBackend::GetImpl() {
  21. return impl;
  22. }
  23. void ProgressServiceBackend::SetTotalSize(u64 size) {
  24. impl.total_bytes = size;
  25. SignalUpdate();
  26. }
  27. void ProgressServiceBackend::StartConnecting() {
  28. impl.status = DeliveryCacheProgressImpl::Status::Connecting;
  29. SignalUpdate();
  30. }
  31. void ProgressServiceBackend::StartProcessingDataList() {
  32. impl.status = DeliveryCacheProgressImpl::Status::ProcessingDataList;
  33. SignalUpdate();
  34. }
  35. void ProgressServiceBackend::StartDownloadingFile(std::string_view dir_name,
  36. std::string_view file_name, u64 file_size) {
  37. impl.status = DeliveryCacheProgressImpl::Status::Downloading;
  38. impl.current_downloaded_bytes = 0;
  39. impl.current_total_bytes = file_size;
  40. std::memcpy(impl.current_directory.data(), dir_name.data(),
  41. std::min<u64>(dir_name.size(), 0x31ull));
  42. std::memcpy(impl.current_file.data(), file_name.data(),
  43. std::min<u64>(file_name.size(), 0x31ull));
  44. SignalUpdate();
  45. }
  46. void ProgressServiceBackend::UpdateFileProgress(u64 downloaded) {
  47. impl.current_downloaded_bytes = downloaded;
  48. SignalUpdate();
  49. }
  50. void ProgressServiceBackend::FinishDownloadingFile() {
  51. impl.total_downloaded_bytes += impl.current_total_bytes;
  52. SignalUpdate();
  53. }
  54. void ProgressServiceBackend::CommitDirectory(std::string_view dir_name) {
  55. impl.status = DeliveryCacheProgressImpl::Status::Committing;
  56. impl.current_file.fill(0);
  57. impl.current_downloaded_bytes = 0;
  58. impl.current_total_bytes = 0;
  59. std::memcpy(impl.current_directory.data(), dir_name.data(),
  60. std::min<u64>(dir_name.size(), 0x31ull));
  61. SignalUpdate();
  62. }
  63. void ProgressServiceBackend::FinishDownload(Result result) {
  64. impl.total_downloaded_bytes = impl.total_bytes;
  65. impl.status = DeliveryCacheProgressImpl::Status::Done;
  66. impl.result = result;
  67. SignalUpdate();
  68. }
  69. void ProgressServiceBackend::SignalUpdate() {
  70. update_event->GetWritableEvent().Signal();
  71. }
  72. Backend::Backend(DirectoryGetter getter) : dir_getter(std::move(getter)) {}
  73. Backend::~Backend() = default;
  74. NullBackend::NullBackend(DirectoryGetter getter) : Backend(std::move(getter)) {}
  75. NullBackend::~NullBackend() = default;
  76. bool NullBackend::Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) {
  77. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, build_id={:016X}", title.title_id,
  78. title.build_id);
  79. progress.FinishDownload(ResultSuccess);
  80. return true;
  81. }
  82. bool NullBackend::SynchronizeDirectory(TitleIDVersion title, std::string name,
  83. ProgressServiceBackend& progress) {
  84. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, build_id={:016X}, name={}", title.title_id,
  85. title.build_id, name);
  86. progress.FinishDownload(ResultSuccess);
  87. return true;
  88. }
  89. bool NullBackend::Clear(u64 title_id) {
  90. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}", title_id);
  91. return true;
  92. }
  93. void NullBackend::SetPassphrase(u64 title_id, const Passphrase& passphrase) {
  94. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, passphrase={}", title_id,
  95. Common::HexToString(passphrase));
  96. }
  97. std::optional<std::vector<u8>> NullBackend::GetLaunchParameter(TitleIDVersion title) {
  98. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, build_id={:016X}", title.title_id,
  99. title.build_id);
  100. return std::nullopt;
  101. }
  102. } // namespace Service::BCAT