// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/service.h" namespace Core { class System; } namespace Core::HID { struct FirmwareVersion; struct VibrationDeviceHandle; struct VibrationValue; struct VibrationDeviceInfo; } // namespace Core::HID namespace Core::Timing { struct EventType; } namespace Kernel { class KEvent; class KSharedMemory; } // namespace Kernel namespace Service::HID { class AppletResource; class CaptureButton; class Controller_Stubbed; class ConsoleSixAxis; class DebugMouse; class DebugPad; class Digitizer; class Gesture; class HidFirmwareSettings; class HomeButton; class Keyboard; class Mouse; class NPad; class Palma; class SevenSixAxis; class SixAxis; class SleepButton; class TouchScreen; class TouchDriver; class TouchResource; class UniquePad; class NpadVibrationBase; class NpadN64VibrationDevice; class NpadGcVibrationDevice; class NpadVibrationDevice; struct HandheldConfig; class ResourceManager { public: explicit ResourceManager(Core::System& system_, std::shared_ptr settings); ~ResourceManager(); void Initialize(); std::shared_ptr GetAppletResource() const; std::shared_ptr GetCaptureButton() const; std::shared_ptr GetConsoleSixAxis() const; std::shared_ptr GetDebugMouse() const; std::shared_ptr GetDebugPad() const; std::shared_ptr GetDigitizer() const; std::shared_ptr GetGesture() const; std::shared_ptr GetHomeButton() const; std::shared_ptr GetKeyboard() const; std::shared_ptr GetMouse() const; std::shared_ptr GetNpad() const; std::shared_ptr GetPalma() const; std::shared_ptr GetSevenSixAxis() const; std::shared_ptr GetSixAxis() const; std::shared_ptr GetSleepButton() const; std::shared_ptr GetTouchScreen() const; std::shared_ptr GetUniquePad() const; Result CreateAppletResource(u64 aruid); Result RegisterCoreAppletResource(); Result UnregisterCoreAppletResource(); Result RegisterAppletResourceUserId(u64 aruid, bool bool_value); void UnregisterAppletResourceUserId(u64 aruid); Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); void FreeAppletResourceId(u64 aruid); void EnableInput(u64 aruid, bool is_enabled); void EnableSixAxisSensor(u64 aruid, bool is_enabled); void EnablePadInput(u64 aruid, bool is_enabled); void EnableTouchScreen(u64 aruid, bool is_enabled); NpadVibrationBase* GetVibrationDevice(const Core::HID::VibrationDeviceHandle& handle); NpadN64VibrationDevice* GetN64VibrationDevice(const Core::HID::VibrationDeviceHandle& handle); NpadVibrationDevice* GetNSVibrationDevice(const Core::HID::VibrationDeviceHandle& handle); NpadGcVibrationDevice* GetGcVibrationDevice(const Core::HID::VibrationDeviceHandle& handle); Result SetAruidValidForVibration(u64 aruid, bool is_enabled); void SetForceHandheldStyleVibration(bool is_forced); Result IsVibrationAruidActive(u64 aruid, bool& is_active) const; Result GetVibrationDeviceInfo(Core::HID::VibrationDeviceInfo& device_info, const Core::HID::VibrationDeviceHandle& handle); Result SendVibrationValue(u64 aruid, const Core::HID::VibrationDeviceHandle& handle, const Core::HID::VibrationValue& value); Result GetTouchScreenFirmwareVersion(Core::HID::FirmwareVersion& firmware) const; void UpdateControllers(std::chrono::nanoseconds ns_late); void UpdateNpad(std::chrono::nanoseconds ns_late); void UpdateMouseKeyboard(std::chrono::nanoseconds ns_late); void UpdateMotion(std::chrono::nanoseconds ns_late); private: Result CreateAppletResourceImpl(u64 aruid); void InitializeHandheldConfig(); void InitializeHidCommonSampler(); void InitializeTouchScreenSampler(); void InitializeConsoleSixAxisSampler(); void InitializeAHidSampler(); bool is_initialized{false}; mutable std::recursive_mutex shared_mutex; std::shared_ptr applet_resource{nullptr}; mutable std::mutex input_mutex; Kernel::KEvent* input_event{nullptr}; std::shared_ptr handheld_config{nullptr}; std::shared_ptr firmware_settings{nullptr}; std::shared_ptr capture_button{nullptr}; std::shared_ptr console_six_axis{nullptr}; std::shared_ptr debug_mouse{nullptr}; std::shared_ptr debug_pad{nullptr}; std::shared_ptr digitizer{nullptr}; std::shared_ptr home_button{nullptr}; std::shared_ptr keyboard{nullptr}; std::shared_ptr mouse{nullptr}; std::shared_ptr npad{nullptr}; std::shared_ptr palma{nullptr}; std::shared_ptr seven_six_axis{nullptr}; std::shared_ptr six_axis{nullptr}; std::shared_ptr sleep_button{nullptr}; std::shared_ptr unique_pad{nullptr}; std::shared_ptr npad_update_event; std::shared_ptr default_update_event; std::shared_ptr mouse_keyboard_update_event; std::shared_ptr motion_update_event; // TODO: Create these resources // std::shared_ptr audio_control{nullptr}; // std::shared_ptr button_config{nullptr}; // std::shared_ptr config{nullptr}; // std::shared_ptr connection{nullptr}; // std::shared_ptr custom_config{nullptr}; // std::shared_ptr digitizer{nullptr}; // std::shared_ptr hdls{nullptr}; // std::shared_ptr play_report{nullptr}; // std::shared_ptr rail{nullptr}; // Touch Resources std::shared_ptr gesture{nullptr}; std::shared_ptr touch_screen{nullptr}; std::shared_ptr touch_resource{nullptr}; std::shared_ptr touch_driver{nullptr}; std::shared_ptr touch_update_event{nullptr}; Core::System& system; KernelHelpers::ServiceContext service_context; }; } // namespace Service::HID