applets.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <functional>
  6. #include <memory>
  7. #include <queue>
  8. #include "common/swap.h"
  9. #include "core/hle/kernel/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::Event> GetNormalDataEvent() const;
  28. Kernel::SharedPtr<Kernel::Event> GetInteractiveDataEvent() const;
  29. Kernel::SharedPtr<Kernel::Event> GetStateChangedEvent() const;
  30. private:
  31. // Queues are named from applet's perspective
  32. std::queue<std::unique_ptr<IStorage>>
  33. in_channel; // PopNormalDataToApplet and PushNormalDataFromGame
  34. std::queue<std::unique_ptr<IStorage>>
  35. out_channel; // PopNormalDataToGame and PushNormalDataFromApplet
  36. std::queue<std::unique_ptr<IStorage>>
  37. in_interactive_channel; // PopInteractiveDataToApplet and PushInteractiveDataFromGame
  38. std::queue<std::unique_ptr<IStorage>>
  39. out_interactive_channel; // PopInteractiveDataToGame and PushInteractiveDataFromApplet
  40. Kernel::SharedPtr<Kernel::Event> state_changed_event;
  41. Kernel::SharedPtr<Kernel::Event> pop_out_data_event; // Signaled on PushNormalDataFromApplet
  42. Kernel::SharedPtr<Kernel::Event>
  43. pop_interactive_out_data_event; // Signaled on PushInteractiveDataFromApplet
  44. };
  45. class Applet {
  46. public:
  47. Applet();
  48. virtual ~Applet();
  49. virtual void Initialize(std::shared_ptr<AppletDataBroker> broker);
  50. virtual bool TransactionComplete() const = 0;
  51. virtual ResultCode GetStatus() const = 0;
  52. virtual void ExecuteInteractive() = 0;
  53. virtual void Execute() = 0;
  54. bool IsInitialized() const {
  55. return initialized;
  56. }
  57. protected:
  58. struct CommonArguments {
  59. u32_le arguments_version;
  60. u32_le size;
  61. u32_le library_version;
  62. u32_le theme_color;
  63. u8 play_startup_sound;
  64. u64_le system_tick;
  65. };
  66. static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size.");
  67. CommonArguments common_args;
  68. std::shared_ptr<AppletDataBroker> broker;
  69. bool initialized = false;
  70. };
  71. } // namespace Applets
  72. } // namespace Service::AM