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