diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2024-02-22 18:58:52 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2024-02-24 00:49:02 +0100 |
commit | d08f201e0c0e6d36176983f9673a89550705952b (patch) | |
tree | 93229a986e75f1962d0665dd05a8d2813a8c9ce7 /src/core/hle | |
parent | Merge pull request #13141 from liamwhite/swap (diff) | |
download | yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.gz yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.bz2 yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.lz yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.xz yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.zst yuzu-d08f201e0c0e6d36176983f9673a89550705952b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/hid/active_vibration_device_list.cpp | 53 | ||||
-rw-r--r-- | src/core/hle/service/hid/active_vibration_device_list.h | 39 | ||||
-rw-r--r-- | src/core/hle/service/hid/applet_resource.cpp | 34 | ||||
-rw-r--r-- | src/core/hle/service/hid/applet_resource.h | 36 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_server.cpp | 64 |
5 files changed, 165 insertions, 61 deletions
diff --git a/src/core/hle/service/hid/active_vibration_device_list.cpp b/src/core/hle/service/hid/active_vibration_device_list.cpp new file mode 100644 index 000000000..c440f8382 --- /dev/null +++ b/src/core/hle/service/hid/active_vibration_device_list.cpp @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common/logging/log.h" +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/hid/active_vibration_device_list.h" +#include "hid_core/hid_result.h" +#include "hid_core/hid_util.h" +#include "hid_core/resource_manager.h" +#include "hid_core/resources/vibration/vibration_device.h" + +namespace Service::HID { + +IActiveVibrationDeviceList::IActiveVibrationDeviceList(Core::System& system_, + std::shared_ptr<ResourceManager> resource) + : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) { + // clang-format off + static const FunctionInfo functions[] = { + {0, C<&IActiveVibrationDeviceList::ActivateVibrationDevice>, "ActivateVibrationDevice"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IActiveVibrationDeviceList::~IActiveVibrationDeviceList() = default; + +Result IActiveVibrationDeviceList::ActivateVibrationDevice( + Core::HID::VibrationDeviceHandle vibration_device_handle) { + LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index); + + std::scoped_lock lock{mutex}; + + R_TRY(IsVibrationHandleValid(vibration_device_handle)); + + for (std::size_t i = 0; i < list_size; i++) { + if (vibration_device_handle.device_index == vibration_device_list[i].device_index && + vibration_device_handle.npad_id == vibration_device_list[i].npad_id && + vibration_device_handle.npad_type == vibration_device_list[i].npad_type) { + R_SUCCEED(); + } + } + + R_UNLESS(list_size < MaxVibrationDevicesHandles, ResultVibrationDeviceIndexOutOfRange); + R_TRY(resource_manager->GetVibrationDevice(vibration_device_handle)->Activate()); + + vibration_device_list[list_size++] = vibration_device_handle; + R_SUCCEED(); +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/active_vibration_device_list.h b/src/core/hle/service/hid/active_vibration_device_list.h new file mode 100644 index 000000000..beaa44d97 --- /dev/null +++ b/src/core/hle/service/hid/active_vibration_device_list.h @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include <array> +#include <memory> +#include <mutex> + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" +#include "hid_core/hid_types.h" + +namespace Core { +class System; +} + +namespace Service::HID { +class ResourceManager; + +class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { +public: + explicit IActiveVibrationDeviceList(Core::System& system_, + std::shared_ptr<ResourceManager> resource); + ~IActiveVibrationDeviceList() override; + +private: + static constexpr std::size_t MaxVibrationDevicesHandles{0x100}; + + Result ActivateVibrationDevice(Core::HID::VibrationDeviceHandle vibration_device_handle); + + mutable std::mutex mutex; + std::size_t list_size{}; + std::array<Core::HID::VibrationDeviceHandle, MaxVibrationDevicesHandles> + vibration_device_list{}; + std::shared_ptr<ResourceManager> resource_manager; +}; + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/applet_resource.cpp b/src/core/hle/service/hid/applet_resource.cpp new file mode 100644 index 000000000..4814d7ad5 --- /dev/null +++ b/src/core/hle/service/hid/applet_resource.cpp @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common/logging/log.h" +#include "core/hle/kernel/k_shared_memory.h" +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/hid/applet_resource.h" +#include "hid_core/resource_manager.h" + +namespace Service::HID { + +IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource, + u64 applet_resource_user_id) + : ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id}, + resource_manager{resource} { + static const FunctionInfo functions[] = { + {0, C<&IAppletResource::GetSharedMemoryHandle>, "GetSharedMemoryHandle"}, + }; + RegisterHandlers(functions); +} + +IAppletResource::~IAppletResource() { + resource_manager->FreeAppletResourceId(aruid); +} + +Result IAppletResource::GetSharedMemoryHandle( + OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle) { + const auto result = resource_manager->GetSharedMemoryHandle(out_shared_memory_handle, aruid); + + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw); + R_RETURN(result); +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/applet_resource.h b/src/core/hle/service/hid/applet_resource.h new file mode 100644 index 000000000..d1e7db9b1 --- /dev/null +++ b/src/core/hle/service/hid/applet_resource.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include <memory> + +#include "common/common_types.h" +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Core { +class System; +} + +namespace Kernel { +class KSharedMemory; +} + +namespace Service::HID { +class ResourceManager; + +class IAppletResource final : public ServiceFramework<IAppletResource> { +public: + explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource, + u64 applet_resource_user_id); + ~IAppletResource() override; + +private: + Result GetSharedMemoryHandle(OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle); + + u64 aruid{}; + std::shared_ptr<ResourceManager> resource_manager; +}; + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 3603d8ccf..6942f6e82 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include <array> + #include "common/common_types.h" #include "common/logging/log.h" #include "common/settings.h" @@ -10,6 +11,8 @@ #include "core/hle/kernel/kernel.h" #include "core/hle/service/cmif_serialization.h" #include "core/hle/service/hid/hid_server.h" +#include "core/hle/service/hid/active_vibration_device_list.h" +#include "core/hle/service/hid/applet_resource.h" #include "core/hle/service/ipc_helpers.h" #include "core/memory.h" #include "hid_core/hid_result.h" @@ -36,67 +39,6 @@ namespace Service::HID { -class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { -public: - explicit IActiveVibrationDeviceList(Core::System& system_, - std::shared_ptr<ResourceManager> resource) - : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) { - // clang-format off - static const FunctionInfo functions[] = { - {0, &IActiveVibrationDeviceList::ActivateVibrationDevice, "ActivateVibrationDevice"}, - }; - // clang-format on - - RegisterHandlers(functions); - } - -private: - void ActivateVibrationDevice(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()}; - - LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", - vibration_device_handle.npad_type, vibration_device_handle.npad_id, - vibration_device_handle.device_index); - - const auto result = ActivateVibrationDeviceImpl(vibration_device_handle); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - } - - Result ActivateVibrationDeviceImpl(const Core::HID::VibrationDeviceHandle& handle) { - std::scoped_lock lock{mutex}; - - const Result is_valid = IsVibrationHandleValid(handle); - if (is_valid.IsError()) { - return is_valid; - } - - for (std::size_t i = 0; i < list_size; i++) { - if (handle.device_index == vibration_device_list[i].device_index && - handle.npad_id == vibration_device_list[i].npad_id && - handle.npad_type == vibration_device_list[i].npad_type) { - return ResultSuccess; - } - } - if (list_size == vibration_device_list.size()) { - return ResultVibrationDeviceIndexOutOfRange; - } - const Result result = resource_manager->GetVibrationDevice(handle)->Activate(); - if (result.IsError()) { - return result; - } - vibration_device_list[list_size++] = handle; - return ResultSuccess; - } - - mutable std::mutex mutex; - std::size_t list_size{}; - std::array<Core::HID::VibrationDeviceHandle, 0x100> vibration_device_list{}; - std::shared_ptr<ResourceManager> resource_manager; -}; - IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> resource, std::shared_ptr<HidFirmwareSettings> settings) : ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} { |