applets.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include "common/assert.h"
  6. #include "core/core.h"
  7. #include "core/hle/kernel/readable_event.h"
  8. #include "core/hle/kernel/server_port.h"
  9. #include "core/hle/kernel/writable_event.h"
  10. #include "core/hle/service/am/am.h"
  11. #include "core/hle/service/am/applets/applets.h"
  12. namespace Service::AM::Applets {
  13. AppletDataBroker::AppletDataBroker() {
  14. auto& kernel = Core::System::GetInstance().Kernel();
  15. state_changed_event = Kernel::WritableEvent::CreateEventPair(
  16. kernel, Kernel::ResetType::Sticky, "ILibraryAppletAccessor:StateChangedEvent");
  17. pop_out_data_event = Kernel::WritableEvent::CreateEventPair(
  18. kernel, Kernel::ResetType::Sticky, "ILibraryAppletAccessor:PopDataOutEvent");
  19. pop_interactive_out_data_event = Kernel::WritableEvent::CreateEventPair(
  20. kernel, Kernel::ResetType::Sticky, "ILibraryAppletAccessor:PopInteractiveDataOutEvent");
  21. }
  22. AppletDataBroker::~AppletDataBroker() = default;
  23. std::unique_ptr<IStorage> AppletDataBroker::PopNormalDataToGame() {
  24. if (out_channel.empty())
  25. return nullptr;
  26. auto out = std::move(out_channel.front());
  27. out_channel.pop();
  28. return out;
  29. }
  30. std::unique_ptr<IStorage> AppletDataBroker::PopNormalDataToApplet() {
  31. if (in_channel.empty())
  32. return nullptr;
  33. auto out = std::move(in_channel.front());
  34. in_channel.pop();
  35. return out;
  36. }
  37. std::unique_ptr<IStorage> AppletDataBroker::PopInteractiveDataToGame() {
  38. if (out_interactive_channel.empty())
  39. return nullptr;
  40. auto out = std::move(out_interactive_channel.front());
  41. out_interactive_channel.pop();
  42. return out;
  43. }
  44. std::unique_ptr<IStorage> AppletDataBroker::PopInteractiveDataToApplet() {
  45. if (in_interactive_channel.empty())
  46. return nullptr;
  47. auto out = std::move(in_interactive_channel.front());
  48. in_interactive_channel.pop();
  49. return out;
  50. }
  51. void AppletDataBroker::PushNormalDataFromGame(IStorage storage) {
  52. in_channel.push(std::make_unique<IStorage>(storage));
  53. }
  54. void AppletDataBroker::PushNormalDataFromApplet(IStorage storage) {
  55. out_channel.push(std::make_unique<IStorage>(storage));
  56. pop_out_data_event.writable->Signal();
  57. }
  58. void AppletDataBroker::PushInteractiveDataFromGame(IStorage storage) {
  59. in_interactive_channel.push(std::make_unique<IStorage>(storage));
  60. }
  61. void AppletDataBroker::PushInteractiveDataFromApplet(IStorage storage) {
  62. out_interactive_channel.push(std::make_unique<IStorage>(storage));
  63. pop_interactive_out_data_event.writable->Signal();
  64. }
  65. void AppletDataBroker::SignalStateChanged() const {
  66. state_changed_event.writable->Signal();
  67. }
  68. Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetNormalDataEvent() const {
  69. return pop_out_data_event.readable;
  70. }
  71. Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetInteractiveDataEvent() const {
  72. return pop_interactive_out_data_event.readable;
  73. }
  74. Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetStateChangedEvent() const {
  75. return state_changed_event.readable;
  76. }
  77. Applet::Applet() = default;
  78. Applet::~Applet() = default;
  79. void Applet::Initialize() {
  80. const auto common = broker.PopNormalDataToApplet();
  81. ASSERT(common != nullptr);
  82. const auto common_data = common->GetData();
  83. ASSERT(common_data.size() >= sizeof(CommonArguments));
  84. std::memcpy(&common_args, common_data.data(), sizeof(CommonArguments));
  85. initialized = true;
  86. }
  87. } // namespace Service::AM::Applets