applets.h 6.2 KB

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