applets.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 Core::Frontend {
  12. class ErrorApplet;
  13. class PhotoViewerApplet;
  14. class ProfileSelectApplet;
  15. class SoftwareKeyboardApplet;
  16. class WebBrowserApplet;
  17. } // namespace Core::Frontend
  18. namespace Service::AM {
  19. class IStorage;
  20. namespace Applets {
  21. enum class AppletId : u32 {
  22. OverlayDisplay = 0x02,
  23. QLaunch = 0x03,
  24. Starter = 0x04,
  25. Auth = 0x0A,
  26. Cabinet = 0x0B,
  27. Controller = 0x0C,
  28. DataErase = 0x0D,
  29. Error = 0x0E,
  30. NetConnect = 0x0F,
  31. ProfileSelect = 0x10,
  32. SoftwareKeyboard = 0x11,
  33. MiiEdit = 0x12,
  34. LibAppletWeb = 0x13,
  35. LibAppletShop = 0x14,
  36. PhotoViewer = 0x15,
  37. Settings = 0x16,
  38. LibAppletOff = 0x17,
  39. LibAppletWhitelisted = 0x18,
  40. LibAppletAuth = 0x19,
  41. MyPage = 0x1A,
  42. };
  43. class AppletDataBroker final {
  44. public:
  45. AppletDataBroker();
  46. ~AppletDataBroker();
  47. struct RawChannelData {
  48. std::vector<std::vector<u8>> normal;
  49. std::vector<std::vector<u8>> interactive;
  50. };
  51. // Retrieves but does not pop the data sent to applet.
  52. RawChannelData PeekDataToAppletForDebug() const;
  53. std::unique_ptr<IStorage> PopNormalDataToGame();
  54. std::unique_ptr<IStorage> PopNormalDataToApplet();
  55. std::unique_ptr<IStorage> PopInteractiveDataToGame();
  56. std::unique_ptr<IStorage> PopInteractiveDataToApplet();
  57. void PushNormalDataFromGame(IStorage storage);
  58. void PushNormalDataFromApplet(IStorage storage);
  59. void PushInteractiveDataFromGame(IStorage storage);
  60. void PushInteractiveDataFromApplet(IStorage storage);
  61. void SignalStateChanged() const;
  62. Kernel::SharedPtr<Kernel::ReadableEvent> GetNormalDataEvent() const;
  63. Kernel::SharedPtr<Kernel::ReadableEvent> GetInteractiveDataEvent() const;
  64. Kernel::SharedPtr<Kernel::ReadableEvent> GetStateChangedEvent() const;
  65. private:
  66. // Queues are named from applet's perspective
  67. // PopNormalDataToApplet and PushNormalDataFromGame
  68. std::deque<std::unique_ptr<IStorage>> in_channel;
  69. // PopNormalDataToGame and PushNormalDataFromApplet
  70. std::deque<std::unique_ptr<IStorage>> out_channel;
  71. // PopInteractiveDataToApplet and PushInteractiveDataFromGame
  72. std::deque<std::unique_ptr<IStorage>> in_interactive_channel;
  73. // PopInteractiveDataToGame and PushInteractiveDataFromApplet
  74. std::deque<std::unique_ptr<IStorage>> out_interactive_channel;
  75. Kernel::EventPair state_changed_event;
  76. // Signaled on PushNormalDataFromApplet
  77. Kernel::EventPair pop_out_data_event;
  78. // Signaled on PushInteractiveDataFromApplet
  79. Kernel::EventPair pop_interactive_out_data_event;
  80. };
  81. class Applet {
  82. public:
  83. Applet();
  84. virtual ~Applet();
  85. virtual void Initialize();
  86. virtual bool TransactionComplete() const = 0;
  87. virtual ResultCode GetStatus() const = 0;
  88. virtual void ExecuteInteractive() = 0;
  89. virtual void Execute() = 0;
  90. bool IsInitialized() const {
  91. return initialized;
  92. }
  93. AppletDataBroker& GetBroker() {
  94. return broker;
  95. }
  96. const AppletDataBroker& GetBroker() const {
  97. return broker;
  98. }
  99. protected:
  100. struct CommonArguments {
  101. u32_le arguments_version;
  102. u32_le size;
  103. u32_le library_version;
  104. u32_le theme_color;
  105. u8 play_startup_sound;
  106. u64_le system_tick;
  107. };
  108. static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size.");
  109. CommonArguments common_args{};
  110. AppletDataBroker broker;
  111. bool initialized = false;
  112. };
  113. struct AppletFrontendSet {
  114. using ErrorApplet = std::unique_ptr<Core::Frontend::ErrorApplet>;
  115. using PhotoViewer = std::unique_ptr<Core::Frontend::PhotoViewerApplet>;
  116. using ProfileSelect = std::unique_ptr<Core::Frontend::ProfileSelectApplet>;
  117. using SoftwareKeyboard = std::unique_ptr<Core::Frontend::SoftwareKeyboardApplet>;
  118. using WebBrowser = std::unique_ptr<Core::Frontend::WebBrowserApplet>;
  119. AppletFrontendSet();
  120. AppletFrontendSet(ErrorApplet error, PhotoViewer photo_viewer, ProfileSelect profile_select,
  121. SoftwareKeyboard software_keyboard, WebBrowser web_browser);
  122. ~AppletFrontendSet();
  123. AppletFrontendSet(const AppletFrontendSet&) = delete;
  124. AppletFrontendSet& operator=(const AppletFrontendSet&) = delete;
  125. AppletFrontendSet(AppletFrontendSet&&) noexcept;
  126. AppletFrontendSet& operator=(AppletFrontendSet&&) noexcept;
  127. ErrorApplet error;
  128. PhotoViewer photo_viewer;
  129. ProfileSelect profile_select;
  130. SoftwareKeyboard software_keyboard;
  131. WebBrowser web_browser;
  132. };
  133. class AppletManager {
  134. public:
  135. AppletManager();
  136. ~AppletManager();
  137. void SetAppletFrontendSet(AppletFrontendSet set);
  138. void SetDefaultAppletFrontendSet();
  139. void SetDefaultAppletsIfMissing();
  140. void ClearAll();
  141. std::shared_ptr<Applet> GetApplet(AppletId id) const;
  142. private:
  143. AppletFrontendSet frontend;
  144. };
  145. } // namespace Applets
  146. } // namespace Service::AM