applets.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <queue>
  7. #include "common/swap.h"
  8. #include "core/hle/kernel/object.h"
  9. #include "core/hle/kernel/writable_event.h"
  10. union ResultCode;
  11. namespace Service::AM {
  12. class IStorage;
  13. namespace Applets {
  14. class AppletDataBroker final {
  15. public:
  16. AppletDataBroker();
  17. ~AppletDataBroker();
  18. std::unique_ptr<IStorage> PopNormalDataToGame();
  19. std::unique_ptr<IStorage> PopNormalDataToApplet();
  20. std::unique_ptr<IStorage> PopInteractiveDataToGame();
  21. std::unique_ptr<IStorage> PopInteractiveDataToApplet();
  22. void PushNormalDataFromGame(IStorage storage);
  23. void PushNormalDataFromApplet(IStorage storage);
  24. void PushInteractiveDataFromGame(IStorage storage);
  25. void PushInteractiveDataFromApplet(IStorage storage);
  26. void SignalStateChanged() const;
  27. Kernel::SharedPtr<Kernel::ReadableEvent> GetNormalDataEvent() const;
  28. Kernel::SharedPtr<Kernel::ReadableEvent> GetInteractiveDataEvent() const;
  29. Kernel::SharedPtr<Kernel::ReadableEvent> GetStateChangedEvent() const;
  30. private:
  31. // Queues are named from applet's perspective
  32. // PopNormalDataToApplet and PushNormalDataFromGame
  33. std::queue<std::unique_ptr<IStorage>> in_channel;
  34. // PopNormalDataToGame and PushNormalDataFromApplet
  35. std::queue<std::unique_ptr<IStorage>> out_channel;
  36. // PopInteractiveDataToApplet and PushInteractiveDataFromGame
  37. std::queue<std::unique_ptr<IStorage>> in_interactive_channel;
  38. // PopInteractiveDataToGame and PushInteractiveDataFromApplet
  39. std::queue<std::unique_ptr<IStorage>> out_interactive_channel;
  40. Kernel::EventPair state_changed_event;
  41. // Signaled on PushNormalDataFromApplet
  42. Kernel::EventPair pop_out_data_event;
  43. // Signaled on PushInteractiveDataFromApplet
  44. Kernel::EventPair pop_interactive_out_data_event;
  45. };
  46. class Applet {
  47. public:
  48. Applet();
  49. virtual ~Applet();
  50. virtual void Initialize();
  51. virtual bool TransactionComplete() const = 0;
  52. virtual ResultCode GetStatus() const = 0;
  53. virtual void ExecuteInteractive() = 0;
  54. virtual void Execute() = 0;
  55. bool IsInitialized() const {
  56. return initialized;
  57. }
  58. AppletDataBroker& GetBroker() {
  59. return broker;
  60. }
  61. const AppletDataBroker& GetBroker() const {
  62. return broker;
  63. }
  64. protected:
  65. struct CommonArguments {
  66. u32_le arguments_version;
  67. u32_le size;
  68. u32_le library_version;
  69. u32_le theme_color;
  70. u8 play_startup_sound;
  71. u64_le system_tick;
  72. };
  73. static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size.");
  74. CommonArguments common_args{};
  75. AppletDataBroker broker;
  76. bool initialized = false;
  77. };
  78. } // namespace Applets
  79. } // namespace Service::AM