service: hid: Move and migrate AppletResource and ActiveVibrationDevice
This commit is contained in:
parent
975d6f1ec4
commit
d08f201e0c
|
@ -666,6 +666,10 @@ add_library(core STATIC
|
||||||
hle/service/glue/time/worker.h
|
hle/service/glue/time/worker.h
|
||||||
hle/service/grc/grc.cpp
|
hle/service/grc/grc.cpp
|
||||||
hle/service/grc/grc.h
|
hle/service/grc/grc.h
|
||||||
|
hle/service/hid/active_vibration_device_list.cpp
|
||||||
|
hle/service/hid/active_vibration_device_list.h
|
||||||
|
hle/service/hid/applet_resource.cpp
|
||||||
|
hle/service/hid/applet_resource.h
|
||||||
hle/service/hid/hid.cpp
|
hle/service/hid/hid.cpp
|
||||||
hle/service/hid/hid.h
|
hle/service/hid/hid.h
|
||||||
hle/service/hid/hid_debug_server.cpp
|
hle/service/hid/hid_debug_server.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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -2,6 +2,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
@ -10,6 +11,8 @@
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
#include "core/hle/service/cmif_serialization.h"
|
#include "core/hle/service/cmif_serialization.h"
|
||||||
#include "core/hle/service/hid/hid_server.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/hle/service/ipc_helpers.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
#include "hid_core/hid_result.h"
|
#include "hid_core/hid_result.h"
|
||||||
|
@ -36,67 +39,6 @@
|
||||||
|
|
||||||
namespace Service::HID {
|
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,
|
IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> resource,
|
||||||
std::shared_ptr<HidFirmwareSettings> settings)
|
std::shared_ptr<HidFirmwareSettings> settings)
|
||||||
: ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} {
|
: ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/kernel/k_shared_memory.h"
|
|
||||||
#include "core/hle/service/ipc_helpers.h"
|
#include "core/hle/service/ipc_helpers.h"
|
||||||
#include "core/hle/service/set/system_settings_server.h"
|
#include "core/hle/service/set/system_settings_server.h"
|
||||||
#include "core/hle/service/sm/sm.h"
|
#include "core/hle/service/sm/sm.h"
|
||||||
|
@ -501,29 +500,4 @@ void ResourceManager::UpdateMotion(std::chrono::nanoseconds ns_late) {
|
||||||
console_six_axis->OnUpdate(core_timing);
|
console_six_axis->OnUpdate(core_timing);
|
||||||
}
|
}
|
||||||
|
|
||||||
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, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
|
||||||
};
|
|
||||||
RegisterHandlers(functions);
|
|
||||||
}
|
|
||||||
|
|
||||||
IAppletResource::~IAppletResource() {
|
|
||||||
resource_manager->FreeAppletResourceId(aruid);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) {
|
|
||||||
Kernel::KSharedMemory* handle;
|
|
||||||
const auto result = resource_manager->GetSharedMemoryHandle(&handle, aruid);
|
|
||||||
|
|
||||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw);
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
||||||
rb.Push(result);
|
|
||||||
rb.PushCopyObjects(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
|
|
@ -174,17 +174,4 @@ private:
|
||||||
KernelHelpers::ServiceContext service_context;
|
KernelHelpers::ServiceContext service_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
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:
|
|
||||||
void GetSharedMemoryHandle(HLERequestContext& ctx);
|
|
||||||
|
|
||||||
u64 aruid{};
|
|
||||||
std::shared_ptr<ResourceManager> resource_manager;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
|
Reference in New Issue