resource_manager.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-3.0-or-later
  3. #pragma once
  4. #include "core/hle/service/kernel_helpers.h"
  5. #include "core/hle/service/service.h"
  6. namespace Core {
  7. class System;
  8. }
  9. namespace Core::Timing {
  10. struct EventType;
  11. }
  12. namespace Kernel {
  13. class KSharedMemory;
  14. }
  15. namespace Service::HID {
  16. class AppletResource;
  17. class Controller_Stubbed;
  18. class ConsoleSixAxis;
  19. class DebugPad;
  20. class Gesture;
  21. class Keyboard;
  22. class Mouse;
  23. class NPad;
  24. class Palma;
  25. class SevenSixAxis;
  26. class SixAxis;
  27. class TouchScreen;
  28. class XPad;
  29. using CaptureButton = Controller_Stubbed;
  30. using DebugMouse = Controller_Stubbed;
  31. using HomeButton = Controller_Stubbed;
  32. using SleepButton = Controller_Stubbed;
  33. using UniquePad = Controller_Stubbed;
  34. class ResourceManager {
  35. public:
  36. explicit ResourceManager(Core::System& system_);
  37. ~ResourceManager();
  38. void Initialize();
  39. std::shared_ptr<AppletResource> GetAppletResource() const;
  40. std::shared_ptr<CaptureButton> GetCaptureButton() const;
  41. std::shared_ptr<ConsoleSixAxis> GetConsoleSixAxis() const;
  42. std::shared_ptr<DebugMouse> GetDebugMouse() const;
  43. std::shared_ptr<DebugPad> GetDebugPad() const;
  44. std::shared_ptr<Gesture> GetGesture() const;
  45. std::shared_ptr<HomeButton> GetHomeButton() const;
  46. std::shared_ptr<Keyboard> GetKeyboard() const;
  47. std::shared_ptr<Mouse> GetMouse() const;
  48. std::shared_ptr<NPad> GetNpad() const;
  49. std::shared_ptr<Palma> GetPalma() const;
  50. std::shared_ptr<SevenSixAxis> GetSevenSixAxis() const;
  51. std::shared_ptr<SixAxis> GetSixAxis() const;
  52. std::shared_ptr<SleepButton> GetSleepButton() const;
  53. std::shared_ptr<TouchScreen> GetTouchScreen() const;
  54. std::shared_ptr<UniquePad> GetUniquePad() const;
  55. Result CreateAppletResource(u64 aruid);
  56. Result RegisterCoreAppletResource();
  57. Result UnregisterCoreAppletResource();
  58. Result RegisterAppletResourceUserId(u64 aruid, bool bool_value);
  59. void UnregisterAppletResourceUserId(u64 aruid);
  60. Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
  61. void FreeAppletResourceId(u64 aruid);
  62. void EnableInput(u64 aruid, bool is_enabled);
  63. void EnableSixAxisSensor(u64 aruid, bool is_enabled);
  64. void EnablePadInput(u64 aruid, bool is_enabled);
  65. void EnableTouchScreen(u64 aruid, bool is_enabled);
  66. void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
  67. void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
  68. void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
  69. void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
  70. private:
  71. Result CreateAppletResourceImpl(u64 aruid);
  72. bool is_initialized{false};
  73. mutable std::mutex shared_mutex;
  74. std::shared_ptr<AppletResource> applet_resource = nullptr;
  75. std::shared_ptr<CaptureButton> capture_button = nullptr;
  76. std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
  77. std::shared_ptr<DebugMouse> debug_mouse = nullptr;
  78. std::shared_ptr<DebugPad> debug_pad = nullptr;
  79. std::shared_ptr<Gesture> gesture = nullptr;
  80. std::shared_ptr<HomeButton> home_button = nullptr;
  81. std::shared_ptr<Keyboard> keyboard = nullptr;
  82. std::shared_ptr<Mouse> mouse = nullptr;
  83. std::shared_ptr<NPad> npad = nullptr;
  84. std::shared_ptr<Palma> palma = nullptr;
  85. std::shared_ptr<SevenSixAxis> seven_six_axis = nullptr;
  86. std::shared_ptr<SixAxis> six_axis = nullptr;
  87. std::shared_ptr<SleepButton> sleep_button = nullptr;
  88. std::shared_ptr<TouchScreen> touch_screen = nullptr;
  89. std::shared_ptr<UniquePad> unique_pad = nullptr;
  90. std::shared_ptr<XPad> xpad = nullptr;
  91. // TODO: Create these resources
  92. // std::shared_ptr<AudioControl> audio_control = nullptr;
  93. // std::shared_ptr<ButtonConfig> button_config = nullptr;
  94. // std::shared_ptr<Config> config = nullptr;
  95. // std::shared_ptr<Connection> connection = nullptr;
  96. // std::shared_ptr<CustomConfig> custom_config = nullptr;
  97. // std::shared_ptr<Digitizer> digitizer = nullptr;
  98. // std::shared_ptr<Hdls> hdls = nullptr;
  99. // std::shared_ptr<PlayReport> play_report = nullptr;
  100. // std::shared_ptr<Rail> rail = nullptr;
  101. Core::System& system;
  102. KernelHelpers::ServiceContext service_context;
  103. };
  104. class IAppletResource final : public ServiceFramework<IAppletResource> {
  105. public:
  106. explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
  107. u64 applet_resource_user_id);
  108. ~IAppletResource() override;
  109. private:
  110. void GetSharedMemoryHandle(HLERequestContext& ctx);
  111. std::shared_ptr<Core::Timing::EventType> npad_update_event;
  112. std::shared_ptr<Core::Timing::EventType> default_update_event;
  113. std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
  114. std::shared_ptr<Core::Timing::EventType> motion_update_event;
  115. u64 aruid;
  116. std::shared_ptr<ResourceManager> resource_manager;
  117. };
  118. } // namespace Service::HID