Deglobalize System: Hid

This commit is contained in:
David Marcec 2019-09-21 18:43:43 +10:00
parent a9e9570d84
commit 28181919a6
20 changed files with 44 additions and 37 deletions

View File

@ -9,12 +9,12 @@ namespace Service::HID {
ControllerBase::ControllerBase() = default;
ControllerBase::~ControllerBase() = default;
void ControllerBase::ActivateController() {
void ControllerBase::ActivateController(Core::System& system) {
if (is_activated) {
OnRelease();
}
is_activated = true;
OnInit();
OnInit(system);
}
void ControllerBase::DeactivateController() {

View File

@ -11,6 +11,10 @@ namespace Core::Timing {
class CoreTiming;
}
namespace Core {
class System;
}
namespace Service::HID {
class ControllerBase {
public:
@ -18,7 +22,7 @@ public:
virtual ~ControllerBase();
// Called when the controller is initialized
virtual void OnInit() = 0;
virtual void OnInit(Core::System& system) = 0;
// When the controller is released
virtual void OnRelease() = 0;
@ -30,7 +34,7 @@ public:
// Called when input devices should be loaded
virtual void OnLoadInputDevices() = 0;
void ActivateController();
void ActivateController(Core::System& system);
void DeactivateController();

View File

@ -17,7 +17,7 @@ enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right };
Controller_DebugPad::Controller_DebugPad() = default;
Controller_DebugPad::~Controller_DebugPad() = default;
void Controller_DebugPad::OnInit() {}
void Controller_DebugPad::OnInit(Core::System& system) {}
void Controller_DebugPad::OnRelease() {}

View File

@ -20,7 +20,7 @@ public:
~Controller_DebugPad() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -13,7 +13,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00;
Controller_Gesture::Controller_Gesture() = default;
Controller_Gesture::~Controller_Gesture() = default;
void Controller_Gesture::OnInit() {}
void Controller_Gesture::OnInit(Core::System& system) {}
void Controller_Gesture::OnRelease() {}

View File

@ -16,7 +16,7 @@ public:
~Controller_Gesture() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -15,7 +15,7 @@ constexpr u8 KEYS_PER_BYTE = 8;
Controller_Keyboard::Controller_Keyboard() = default;
Controller_Keyboard::~Controller_Keyboard() = default;
void Controller_Keyboard::OnInit() {}
void Controller_Keyboard::OnInit(Core::System& system) {}
void Controller_Keyboard::OnRelease() {}

View File

@ -19,7 +19,7 @@ public:
~Controller_Keyboard() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -14,7 +14,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400;
Controller_Mouse::Controller_Mouse() = default;
Controller_Mouse::~Controller_Mouse() = default;
void Controller_Mouse::OnInit() {}
void Controller_Mouse::OnInit(Core::System& system) {}
void Controller_Mouse::OnRelease() {}
void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,

View File

@ -18,7 +18,7 @@ public:
~Controller_Mouse() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -167,8 +167,8 @@ void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) {
controller.battery_level[2] = BATTERY_FULL;
}
void Controller_NPad::OnInit() {
auto& kernel = Core::System::GetInstance().Kernel();
void Controller_NPad::OnInit(Core::System& system) {
auto& kernel = system.Kernel();
styleset_changed_event = Kernel::WritableEvent::CreateEventPair(
kernel, Kernel::ResetType::Automatic, "npad:NpadStyleSetChanged");

View File

@ -24,7 +24,7 @@ public:
~Controller_NPad() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -12,7 +12,7 @@ namespace Service::HID {
Controller_Stubbed::Controller_Stubbed() = default;
Controller_Stubbed::~Controller_Stubbed() = default;
void Controller_Stubbed::OnInit() {}
void Controller_Stubbed::OnInit(Core::System& system) {}
void Controller_Stubbed::OnRelease() {}

View File

@ -14,7 +14,7 @@ public:
~Controller_Stubbed() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -16,7 +16,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400;
Controller_Touchscreen::Controller_Touchscreen() = default;
Controller_Touchscreen::~Controller_Touchscreen() = default;
void Controller_Touchscreen::OnInit() {}
void Controller_Touchscreen::OnInit(Core::System& system) {}
void Controller_Touchscreen::OnRelease() {}

View File

@ -18,7 +18,7 @@ public:
~Controller_Touchscreen() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -13,7 +13,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00;
Controller_XPad::Controller_XPad() = default;
Controller_XPad::~Controller_XPad() = default;
void Controller_XPad::OnInit() {}
void Controller_XPad::OnInit(Core::System& system) {}
void Controller_XPad::OnRelease() {}

View File

@ -16,7 +16,7 @@ public:
~Controller_XPad() override;
// Called when the controller is initialized
void OnInit() override;
void OnInit(Core::System& system) override;
// When the controller is released
void OnRelease() override;

View File

@ -42,13 +42,14 @@ constexpr s64 accelerometer_update_ticks = static_cast<s64>(Core::Timing::BASE_C
constexpr s64 gyroscope_update_ticks = static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 100);
constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000;
IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") {
IAppletResource::IAppletResource(Core::System& system)
: ServiceFramework("IAppletResource"), system(system) {
static const FunctionInfo functions[] = {
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
};
RegisterHandlers(functions);
auto& kernel = Core::System::GetInstance().Kernel();
auto& kernel = system.Kernel();
shared_mem = Kernel::SharedMemory::Create(
kernel, nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite,
Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory");
@ -66,15 +67,15 @@ IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") {
MakeController<Controller_Gesture>(HidController::Gesture);
// Homebrew doesn't try to activate some controllers, so we activate them by default
GetController<Controller_NPad>(HidController::NPad).ActivateController();
GetController<Controller_Touchscreen>(HidController::Touchscreen).ActivateController();
GetController<Controller_NPad>(HidController::NPad).ActivateController(system);
GetController<Controller_Touchscreen>(HidController::Touchscreen).ActivateController(system);
GetController<Controller_Stubbed>(HidController::Unknown1).SetCommonHeaderOffset(0x4c00);
GetController<Controller_Stubbed>(HidController::Unknown2).SetCommonHeaderOffset(0x4e00);
GetController<Controller_Stubbed>(HidController::Unknown3).SetCommonHeaderOffset(0x5000);
// Register update callbacks
auto& core_timing = Core::System::GetInstance().CoreTiming();
auto& core_timing = system.CoreTiming();
pad_update_event =
core_timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
UpdateControllers(userdata, cycles_late);
@ -88,7 +89,7 @@ IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") {
}
void IAppletResource::ActivateController(HidController controller) {
controllers[static_cast<size_t>(controller)]->ActivateController();
controllers[static_cast<size_t>(controller)]->ActivateController(system);
}
void IAppletResource::DeactivateController(HidController controller) {
@ -96,7 +97,7 @@ void IAppletResource::DeactivateController(HidController controller) {
}
IAppletResource ::~IAppletResource() {
Core::System::GetInstance().CoreTiming().UnscheduleEvent(pad_update_event, 0);
system.CoreTiming().UnscheduleEvent(pad_update_event, 0);
}
void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
@ -108,7 +109,7 @@ void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
}
void IAppletResource::UpdateControllers(u64 userdata, s64 cycles_late) {
auto& core_timing = Core::System::GetInstance().CoreTiming();
auto& core_timing = system.CoreTiming();
const bool should_reload = Settings::values.is_device_reload_pending.exchange(false);
for (const auto& controller : controllers) {
@ -141,13 +142,13 @@ private:
std::shared_ptr<IAppletResource> Hid::GetAppletResource() {
if (applet_resource == nullptr) {
applet_resource = std::make_shared<IAppletResource>();
applet_resource = std::make_shared<IAppletResource>(system);
}
return applet_resource;
}
Hid::Hid() : ServiceFramework("hid") {
Hid::Hid(Core::System& system) : ServiceFramework("hid"), system(system) {
// clang-format off
static const FunctionInfo functions[] = {
{0, &Hid::CreateAppletResource, "CreateAppletResource"},
@ -286,7 +287,7 @@ void Hid::CreateAppletResource(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
if (applet_resource == nullptr) {
applet_resource = std::make_shared<IAppletResource>();
applet_resource = std::make_shared<IAppletResource>(system);
}
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
@ -1053,8 +1054,8 @@ void ReloadInputDevices() {
Settings::values.is_device_reload_pending.store(true);
}
void InstallInterfaces(SM::ServiceManager& service_manager) {
std::make_shared<Hid>()->InstallAsService(service_manager);
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
std::make_shared<Hid>(system)->InstallAsService(service_manager);
std::make_shared<HidBus>()->InstallAsService(service_manager);
std::make_shared<HidDbg>()->InstallAsService(service_manager);
std::make_shared<HidSys>()->InstallAsService(service_manager);

View File

@ -42,7 +42,7 @@ enum class HidController : std::size_t {
class IAppletResource final : public ServiceFramework<IAppletResource> {
public:
IAppletResource();
IAppletResource(Core::System& system);
~IAppletResource() override;
void ActivateController(HidController controller);
@ -70,6 +70,7 @@ private:
Kernel::SharedPtr<Kernel::SharedMemory> shared_mem;
Core::Timing::EventType* pad_update_event;
Core::System& system;
std::array<std::unique_ptr<ControllerBase>, static_cast<size_t>(HidController::MaxControllers)>
controllers{};
@ -77,7 +78,7 @@ private:
class Hid final : public ServiceFramework<Hid> {
public:
Hid();
Hid(Core::System& system);
~Hid() override;
std::shared_ptr<IAppletResource> GetAppletResource();
@ -126,12 +127,13 @@ private:
void SwapNpadAssignment(Kernel::HLERequestContext& ctx);
std::shared_ptr<IAppletResource> applet_resource;
Core::System& system;
};
/// Reload input devices. Used when input configuration changed
void ReloadInputDevices();
/// Registers all HID services with the specified service manager.
void InstallInterfaces(SM::ServiceManager& service_manager);
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system);
} // namespace Service::HID