applets.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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/service/kernel_helpers.h"
  9. union ResultCode;
  10. namespace Core {
  11. class System;
  12. }
  13. namespace Core::Frontend {
  14. class ControllerApplet;
  15. class ECommerceApplet;
  16. class ErrorApplet;
  17. class MiiEditApplet;
  18. class ParentalControlsApplet;
  19. class PhotoViewerApplet;
  20. class ProfileSelectApplet;
  21. class SoftwareKeyboardApplet;
  22. class WebBrowserApplet;
  23. } // namespace Core::Frontend
  24. namespace Kernel {
  25. class KernelCore;
  26. class KEvent;
  27. class KReadableEvent;
  28. } // namespace Kernel
  29. namespace Service::AM {
  30. class IStorage;
  31. namespace Applets {
  32. enum class AppletId : u32 {
  33. OverlayDisplay = 0x02,
  34. QLaunch = 0x03,
  35. Starter = 0x04,
  36. Auth = 0x0A,
  37. Cabinet = 0x0B,
  38. Controller = 0x0C,
  39. DataErase = 0x0D,
  40. Error = 0x0E,
  41. NetConnect = 0x0F,
  42. ProfileSelect = 0x10,
  43. SoftwareKeyboard = 0x11,
  44. MiiEdit = 0x12,
  45. Web = 0x13,
  46. Shop = 0x14,
  47. PhotoViewer = 0x15,
  48. Settings = 0x16,
  49. OfflineWeb = 0x17,
  50. LoginShare = 0x18,
  51. WebAuth = 0x19,
  52. MyPage = 0x1A,
  53. };
  54. enum class LibraryAppletMode : u32 {
  55. AllForeground = 0,
  56. Background = 1,
  57. NoUI = 2,
  58. BackgroundIndirectDisplay = 3,
  59. AllForegroundInitiallyHidden = 4,
  60. };
  61. class AppletDataBroker final {
  62. public:
  63. explicit AppletDataBroker(Core::System& system_, LibraryAppletMode applet_mode_);
  64. ~AppletDataBroker();
  65. struct RawChannelData {
  66. std::vector<std::vector<u8>> normal;
  67. std::vector<std::vector<u8>> interactive;
  68. };
  69. // Retrieves but does not pop the data sent to applet.
  70. RawChannelData PeekDataToAppletForDebug() const;
  71. std::shared_ptr<IStorage> PopNormalDataToGame();
  72. std::shared_ptr<IStorage> PopNormalDataToApplet();
  73. std::shared_ptr<IStorage> PopInteractiveDataToGame();
  74. std::shared_ptr<IStorage> PopInteractiveDataToApplet();
  75. void PushNormalDataFromGame(std::shared_ptr<IStorage>&& storage);
  76. void PushNormalDataFromApplet(std::shared_ptr<IStorage>&& storage);
  77. void PushInteractiveDataFromGame(std::shared_ptr<IStorage>&& storage);
  78. void PushInteractiveDataFromApplet(std::shared_ptr<IStorage>&& storage);
  79. void SignalStateChanged();
  80. Kernel::KReadableEvent& GetNormalDataEvent();
  81. Kernel::KReadableEvent& GetInteractiveDataEvent();
  82. Kernel::KReadableEvent& GetStateChangedEvent();
  83. private:
  84. Core::System& system;
  85. LibraryAppletMode applet_mode;
  86. KernelHelpers::ServiceContext service_context;
  87. // Queues are named from applet's perspective
  88. // PopNormalDataToApplet and PushNormalDataFromGame
  89. std::deque<std::shared_ptr<IStorage>> in_channel;
  90. // PopNormalDataToGame and PushNormalDataFromApplet
  91. std::deque<std::shared_ptr<IStorage>> out_channel;
  92. // PopInteractiveDataToApplet and PushInteractiveDataFromGame
  93. std::deque<std::shared_ptr<IStorage>> in_interactive_channel;
  94. // PopInteractiveDataToGame and PushInteractiveDataFromApplet
  95. std::deque<std::shared_ptr<IStorage>> out_interactive_channel;
  96. Kernel::KEvent* state_changed_event;
  97. // Signaled on PushNormalDataFromApplet
  98. Kernel::KEvent* pop_out_data_event;
  99. // Signaled on PushInteractiveDataFromApplet
  100. Kernel::KEvent* pop_interactive_out_data_event;
  101. };
  102. class Applet {
  103. public:
  104. explicit Applet(Core::System& system_, LibraryAppletMode applet_mode_);
  105. virtual ~Applet();
  106. virtual void Initialize();
  107. virtual bool TransactionComplete() const = 0;
  108. virtual ResultCode GetStatus() const = 0;
  109. virtual void ExecuteInteractive() = 0;
  110. virtual void Execute() = 0;
  111. AppletDataBroker& GetBroker() {
  112. return broker;
  113. }
  114. const AppletDataBroker& GetBroker() const {
  115. return broker;
  116. }
  117. LibraryAppletMode GetLibraryAppletMode() const {
  118. return applet_mode;
  119. }
  120. bool IsInitialized() const {
  121. return initialized;
  122. }
  123. protected:
  124. struct CommonArguments {
  125. u32_le arguments_version;
  126. u32_le size;
  127. u32_le library_version;
  128. u32_le theme_color;
  129. u8 play_startup_sound;
  130. u64_le system_tick;
  131. };
  132. static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size.");
  133. CommonArguments common_args{};
  134. AppletDataBroker broker;
  135. LibraryAppletMode applet_mode;
  136. bool initialized = false;
  137. };
  138. struct AppletFrontendSet {
  139. using ControllerApplet = std::unique_ptr<Core::Frontend::ControllerApplet>;
  140. using ErrorApplet = std::unique_ptr<Core::Frontend::ErrorApplet>;
  141. using MiiEdit = std::unique_ptr<Core::Frontend::MiiEditApplet>;
  142. using ParentalControlsApplet = std::unique_ptr<Core::Frontend::ParentalControlsApplet>;
  143. using PhotoViewer = std::unique_ptr<Core::Frontend::PhotoViewerApplet>;
  144. using ProfileSelect = std::unique_ptr<Core::Frontend::ProfileSelectApplet>;
  145. using SoftwareKeyboard = std::unique_ptr<Core::Frontend::SoftwareKeyboardApplet>;
  146. using WebBrowser = std::unique_ptr<Core::Frontend::WebBrowserApplet>;
  147. AppletFrontendSet();
  148. AppletFrontendSet(ControllerApplet controller_applet, ErrorApplet error_applet,
  149. MiiEdit mii_edit_, ParentalControlsApplet parental_controls_applet,
  150. PhotoViewer photo_viewer_, ProfileSelect profile_select_,
  151. SoftwareKeyboard software_keyboard_, WebBrowser web_browser_);
  152. ~AppletFrontendSet();
  153. AppletFrontendSet(const AppletFrontendSet&) = delete;
  154. AppletFrontendSet& operator=(const AppletFrontendSet&) = delete;
  155. AppletFrontendSet(AppletFrontendSet&&) noexcept;
  156. AppletFrontendSet& operator=(AppletFrontendSet&&) noexcept;
  157. ControllerApplet controller;
  158. ErrorApplet error;
  159. MiiEdit mii_edit;
  160. ParentalControlsApplet parental_controls;
  161. PhotoViewer photo_viewer;
  162. ProfileSelect profile_select;
  163. SoftwareKeyboard software_keyboard;
  164. WebBrowser web_browser;
  165. };
  166. class AppletManager {
  167. public:
  168. explicit AppletManager(Core::System& system_);
  169. ~AppletManager();
  170. const AppletFrontendSet& GetAppletFrontendSet() const;
  171. void SetAppletFrontendSet(AppletFrontendSet set);
  172. void SetDefaultAppletFrontendSet();
  173. void SetDefaultAppletsIfMissing();
  174. void ClearAll();
  175. std::shared_ptr<Applet> GetApplet(AppletId id, LibraryAppletMode mode) const;
  176. private:
  177. AppletFrontendSet frontend;
  178. Core::System& system;
  179. };
  180. } // namespace Applets
  181. } // namespace Service::AM