mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-01 21:34:17 +01:00
Refactor HID services
Use the new service naming convention. Tidy up some unused includes. Move constants to service namespace.
This commit is contained in:
parent
f4620dd992
commit
524cd26649
@ -61,7 +61,8 @@ add_library(skyline SHARED
|
|||||||
${source_DIR}/skyline/services/apm/apm.cpp
|
${source_DIR}/skyline/services/apm/apm.cpp
|
||||||
${source_DIR}/skyline/services/am/applet.cpp
|
${source_DIR}/skyline/services/am/applet.cpp
|
||||||
${source_DIR}/skyline/services/am/appletController.cpp
|
${source_DIR}/skyline/services/am/appletController.cpp
|
||||||
${source_DIR}/skyline/services/hid/hid.cpp
|
${source_DIR}/skyline/services/hid/IHidServer.cpp
|
||||||
|
${source_DIR}/skyline/services/hid/IAppletResource.cpp
|
||||||
${source_DIR}/skyline/services/timesrv/IStaticService.cpp
|
${source_DIR}/skyline/services/timesrv/IStaticService.cpp
|
||||||
${source_DIR}/skyline/services/timesrv/ISystemClock.cpp
|
${source_DIR}/skyline/services/timesrv/ISystemClock.cpp
|
||||||
${source_DIR}/skyline/services/timesrv/ITimeZoneService.cpp
|
${source_DIR}/skyline/services/timesrv/ITimeZoneService.cpp
|
||||||
|
@ -42,7 +42,7 @@ namespace skyline::service {
|
|||||||
audout_IAudioOut,
|
audout_IAudioOut,
|
||||||
IAudioRendererManager,
|
IAudioRendererManager,
|
||||||
IAudioRenderer,
|
IAudioRenderer,
|
||||||
hid,
|
hid_IHidServer,
|
||||||
hid_IAppletResource,
|
hid_IAppletResource,
|
||||||
timesrv_IStaticService,
|
timesrv_IStaticService,
|
||||||
timesrv_ISystemClock,
|
timesrv_ISystemClock,
|
||||||
@ -68,7 +68,7 @@ namespace skyline::service {
|
|||||||
{"appletAE", Service::am_appletAE},
|
{"appletAE", Service::am_appletAE},
|
||||||
{"audout:u", Service::audout_u},
|
{"audout:u", Service::audout_u},
|
||||||
{"audren:u", Service::IAudioRendererManager},
|
{"audren:u", Service::IAudioRendererManager},
|
||||||
{"hid", Service::hid},
|
{"hid", Service::hid_IHidServer},
|
||||||
{"time:s", Service::timesrv_IStaticService},
|
{"time:s", Service::timesrv_IStaticService},
|
||||||
{"time:a", Service::timesrv_IStaticService},
|
{"time:a", Service::timesrv_IStaticService},
|
||||||
{"time:u", Service::timesrv_IStaticService},
|
{"time:u", Service::timesrv_IStaticService},
|
||||||
|
14
app/src/main/cpp/skyline/services/hid/IAppletResource.cpp
Normal file
14
app/src/main/cpp/skyline/services/hid/IAppletResource.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "IAppletResource.h"
|
||||||
|
|
||||||
|
namespace skyline::service::hid {
|
||||||
|
IAppletResource::IAppletResource(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hid_IAppletResource, "hid:IAppletResource", {
|
||||||
|
{0x0, SFUNC(IAppletResource::GetSharedMemoryHandle)}
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
void IAppletResource::GetSharedMemoryHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
hidSharedMemory = std::make_shared<kernel::type::KSharedMemory>(state, NULL, constant::hidSharedMemSize, memory::Permission{true, false, false});
|
||||||
|
auto handle = state.process->InsertItem<type::KSharedMemory>(hidSharedMemory);
|
||||||
|
state.logger->Debug("HID Shared Memory Handle: 0x{:X}", handle);
|
||||||
|
response.copyHandles.push_back(handle);
|
||||||
|
}
|
||||||
|
}
|
26
app/src/main/cpp/skyline/services/hid/IAppletResource.h
Normal file
26
app/src/main/cpp/skyline/services/hid/IAppletResource.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <kernel/types/KProcess.h>
|
||||||
|
#include <services/base_service.h>
|
||||||
|
#include <services/serviceman.h>
|
||||||
|
|
||||||
|
namespace skyline::service::hid {
|
||||||
|
namespace constant {
|
||||||
|
constexpr size_t hidSharedMemSize = 0x40000; //!< The size of HID Shared Memory (https://switchbrew.org/wiki/HID_Shared_Memory)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief IAppletResource is used to get a handle to the HID shared memory (https://switchbrew.org/wiki/HID_services#IAppletResource)
|
||||||
|
*/
|
||||||
|
class IAppletResource : public BaseService {
|
||||||
|
public:
|
||||||
|
std::shared_ptr <type::KSharedMemory> hidSharedMemory; //!< A pointer to HID shared memory
|
||||||
|
|
||||||
|
IAppletResource(const DeviceState &state, ServiceManager &manager);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This opens a handle to HID shared memory (https://switchbrew.org/wiki/HID_services#GetSharedMemoryHandle)
|
||||||
|
*/
|
||||||
|
void GetSharedMemoryHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
|
||||||
|
};
|
||||||
|
}
|
57
app/src/main/cpp/skyline/services/hid/IHidServer.cpp
Normal file
57
app/src/main/cpp/skyline/services/hid/IHidServer.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#include "IHidServer.h"
|
||||||
|
|
||||||
|
namespace skyline::service::hid {
|
||||||
|
IHidServer::IHidServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hid_IHidServer, "hid:IHidServer", {
|
||||||
|
{0x0, SFUNC(IHidServer::CreateAppletResource)},
|
||||||
|
{0x64, SFUNC(IHidServer::SetSupportedNpadStyleSet)},
|
||||||
|
{0x66, SFUNC(IHidServer::SetSupportedNpadIdType)},
|
||||||
|
{0x67, SFUNC(IHidServer::ActivateNpad)},
|
||||||
|
{0x78, SFUNC(IHidServer::SetNpadJoyHoldType)},
|
||||||
|
{0x7A, SFUNC(IHidServer::SetNpadJoyAssignmentModeSingleByDefault)},
|
||||||
|
{0x7B, SFUNC(IHidServer::SetNpadJoyAssignmentModeSingle)},
|
||||||
|
{0x7C, SFUNC(IHidServer::SetNpadJoyAssignmentModeDual)}
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
void IHidServer::CreateAppletResource(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
resource = std::make_shared<IAppletResource>(state, manager);
|
||||||
|
manager.RegisterService(resource, session, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidServer::SetSupportedNpadStyleSet(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
auto styleSet = request.Pop<StyleSet>();
|
||||||
|
state.logger->Debug("Controller Support:\nPro-Controller: {}\nJoy-Con: Handheld: {}, Dual: {}, L: {}, R: {}\nGameCube: {}\nPokeBall: {}\nNES: {}, NES Handheld: {}, SNES: {}", static_cast<bool>(styleSet.proController), static_cast<bool>(styleSet.joyconHandheld), static_cast<bool>(styleSet.joyconDual), static_cast<bool>(styleSet.joyconLeft), static_cast<bool>
|
||||||
|
(styleSet.joyconRight), static_cast<bool>(styleSet.gamecube), static_cast<bool>(styleSet.pokeball), static_cast<bool>(styleSet.nes), static_cast<bool>(styleSet.nesHandheld), static_cast<bool>(styleSet.snes));
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidServer::SetSupportedNpadIdType(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
const auto &buffer = request.inputBuf.at(0);
|
||||||
|
size_t numId = buffer.size / sizeof(NpadId);
|
||||||
|
u64 address = buffer.address;
|
||||||
|
for (size_t i = 0; i < numId; i++) {
|
||||||
|
auto id = state.process->GetObject<NpadId>(address);
|
||||||
|
deviceMap[id] = JoyConDevice(id);
|
||||||
|
address += sizeof(NpadId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidServer::ActivateNpad(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {}
|
||||||
|
|
||||||
|
void IHidServer::SetNpadJoyHoldType(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
deviceMap[request.Pop<NpadId>()].assignment = JoyConAssignment::Single;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
orientation = request.Pop<JoyConOrientation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidServer::SetNpadJoyAssignmentModeSingle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
auto controllerId = request.Pop<NpadId>();
|
||||||
|
auto appletUserId = request.Pop<u64>();
|
||||||
|
deviceMap[controllerId].assignment = JoyConAssignment::Single;
|
||||||
|
deviceMap[controllerId].side = request.Pop<JoyConSide>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidServer::SetNpadJoyAssignmentModeDual(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
||||||
|
deviceMap[request.Pop<NpadId>()].assignment = JoyConAssignment::Dual;
|
||||||
|
}
|
||||||
|
}
|
@ -2,32 +2,13 @@
|
|||||||
|
|
||||||
#include <services/base_service.h>
|
#include <services/base_service.h>
|
||||||
#include <services/serviceman.h>
|
#include <services/serviceman.h>
|
||||||
#include <kernel/types/KProcess.h>
|
#include "IAppletResource.h"
|
||||||
|
|
||||||
namespace skyline::constant {
|
|
||||||
constexpr size_t hidSharedMemSize = 0x40000; //!< The size of HID Shared Memory (https://switchbrew.org/wiki/HID_Shared_Memory)
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace skyline::service::hid {
|
namespace skyline::service::hid {
|
||||||
/**
|
/**
|
||||||
* @brief IAppletResource is used to get the handle to the HID shared memory (https://switchbrew.org/wiki/HID_services#IAppletResource)
|
* @brief IHidServer or hid service is used to access input devices (https://switchbrew.org/wiki/HID_services#hid)
|
||||||
*/
|
*/
|
||||||
class IAppletResource : public BaseService {
|
class IHidServer : public BaseService {
|
||||||
public:
|
|
||||||
IAppletResource(const DeviceState &state, ServiceManager &manager);
|
|
||||||
|
|
||||||
std::shared_ptr<type::KSharedMemory> hidSharedMemory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This opens a handle to HID shared memory (https://switchbrew.org/wiki/HID_services#GetSharedMemoryHandle)
|
|
||||||
*/
|
|
||||||
void GetSharedMemoryHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief hid or Human Interface Device service is used to access input devices (https://switchbrew.org/wiki/HID_services#hid)
|
|
||||||
*/
|
|
||||||
class hid : public BaseService {
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief This holds the controller styles supported by an application
|
* @brief This holds the controller styles supported by an application
|
||||||
@ -43,7 +24,7 @@ namespace skyline::service::hid {
|
|||||||
bool nes : 1; //!< NES controller
|
bool nes : 1; //!< NES controller
|
||||||
bool nesHandheld : 1; //!< NES controller in handheld mode
|
bool nesHandheld : 1; //!< NES controller in handheld mode
|
||||||
bool snes : 1; //!< SNES controller
|
bool snes : 1; //!< SNES controller
|
||||||
u32 : 22;
|
u32 _pad0_ : 22;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(StyleSet) == 4);
|
static_assert(sizeof(StyleSet) == 4);
|
||||||
|
|
||||||
@ -105,13 +86,13 @@ namespace skyline::service::hid {
|
|||||||
JoyConDevice(const NpadId &id) : id(id) {}
|
JoyConDevice(const NpadId &id) : id(id) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<IAppletResource> resource{}; //!< A shared pointer to the applet resource
|
std::shared_ptr <IAppletResource> resource{}; //!< A shared pointer to the applet resource
|
||||||
std::optional<StyleSet> styleSet; //!< The controller styles supported by the application
|
std::optional <StyleSet> styleSet; //!< The controller styles supported by the application
|
||||||
std::unordered_map<NpadId, JoyConDevice> deviceMap; //!< Mapping from a controller's ID to it's corresponding JoyConDevice
|
std::unordered_map <NpadId, JoyConDevice> deviceMap; //!< Mapping from a controller's ID to it's corresponding JoyConDevice
|
||||||
JoyConOrientation orientation{JoyConOrientation::Unset}; //!< The Orientation of the Joy-Con(s)
|
JoyConOrientation orientation{JoyConOrientation::Unset}; //!< The Orientation of the Joy-Con(s)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
hid(const DeviceState &state, ServiceManager &manager);
|
IHidServer(const DeviceState &state, ServiceManager &manager);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This returns an IAppletResource (https://switchbrew.org/wiki/HID_services#CreateAppletResource)
|
* @brief This returns an IAppletResource (https://switchbrew.org/wiki/HID_services#CreateAppletResource)
|
@ -1,69 +0,0 @@
|
|||||||
#include "hid.h"
|
|
||||||
#include <os.h>
|
|
||||||
|
|
||||||
namespace skyline::service::hid {
|
|
||||||
IAppletResource::IAppletResource(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hid_IAppletResource, "hid:IAppletResource", {
|
|
||||||
{0x0, SFUNC(IAppletResource::GetSharedMemoryHandle)}
|
|
||||||
}) {}
|
|
||||||
|
|
||||||
void IAppletResource::GetSharedMemoryHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
hidSharedMemory = std::make_shared<kernel::type::KSharedMemory>(state, NULL, constant::hidSharedMemSize, memory::Permission{true, false, false});
|
|
||||||
auto handle = state.process->InsertItem<type::KSharedMemory>(hidSharedMemory);
|
|
||||||
state.logger->Debug("HID Shared Memory Handle: 0x{:X}", handle);
|
|
||||||
response.copyHandles.push_back(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
hid::hid(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hid, "hid", {
|
|
||||||
{0x0, SFUNC(hid::CreateAppletResource)},
|
|
||||||
{0x64, SFUNC(hid::SetSupportedNpadStyleSet)},
|
|
||||||
{0x66, SFUNC(hid::SetSupportedNpadIdType)},
|
|
||||||
{0x67, SFUNC(hid::ActivateNpad)},
|
|
||||||
{0x78, SFUNC(hid::SetNpadJoyHoldType)},
|
|
||||||
{0x7A, SFUNC(hid::SetNpadJoyAssignmentModeSingleByDefault)},
|
|
||||||
{0x7B, SFUNC(hid::SetNpadJoyAssignmentModeSingle)},
|
|
||||||
{0x7C, SFUNC(hid::SetNpadJoyAssignmentModeDual)}
|
|
||||||
}) {}
|
|
||||||
|
|
||||||
void hid::CreateAppletResource(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
resource = std::make_shared<IAppletResource>(state, manager);
|
|
||||||
manager.RegisterService(resource, session, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid::SetSupportedNpadStyleSet(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
auto styleSet = request.Pop<StyleSet>();
|
|
||||||
state.logger->Debug("Controller Support:\nPro-Controller: {}\nJoy-Con: Handheld: {}, Dual: {}, L: {}, R: {}\nGameCube: {}\nPokeBall: {}\nNES: {}, NES Handheld: {}, SNES: {}", static_cast<bool>(styleSet.proController), static_cast<bool>(styleSet.joyconHandheld), static_cast<bool>(styleSet.joyconDual), static_cast<bool>(styleSet.joyconLeft), static_cast<bool>
|
|
||||||
(styleSet.joyconRight), static_cast<bool>(styleSet.gamecube), static_cast<bool>(styleSet.pokeball), static_cast<bool>(styleSet.nes), static_cast<bool>(styleSet.nesHandheld), static_cast<bool>(styleSet.snes));
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid::SetSupportedNpadIdType(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
const auto &buffer = request.inputBuf.at(0);
|
|
||||||
size_t numId = buffer.size / sizeof(NpadId);
|
|
||||||
u64 address = buffer.address;
|
|
||||||
for (size_t i = 0; i < numId; i++) {
|
|
||||||
auto id = state.process->GetObject<NpadId>(address);
|
|
||||||
deviceMap[id] = JoyConDevice(id);
|
|
||||||
address += sizeof(NpadId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid::ActivateNpad(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {}
|
|
||||||
|
|
||||||
void hid::SetNpadJoyHoldType(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
deviceMap[request.Pop<NpadId>()].assignment = JoyConAssignment::Single;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid::SetNpadJoyAssignmentModeSingleByDefault(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
orientation = request.Pop<JoyConOrientation>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid::SetNpadJoyAssignmentModeSingle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
auto controllerId = request.Pop<NpadId>();
|
|
||||||
auto appletUserId = request.Pop<u64>();
|
|
||||||
deviceMap[controllerId].assignment = JoyConAssignment::Single;
|
|
||||||
deviceMap[controllerId].side = request.Pop<JoyConSide>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid::SetNpadJoyAssignmentModeDual(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
||||||
deviceMap[request.Pop<NpadId>()].assignment = JoyConAssignment::Dual;
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,7 @@
|
|||||||
#include "am/appletController.h"
|
#include "am/appletController.h"
|
||||||
#include "audout/audout.h"
|
#include "audout/audout.h"
|
||||||
#include "fatal/fatal.h"
|
#include "fatal/fatal.h"
|
||||||
#include "hid/hid.h"
|
#include "hid/IHidServer.h"
|
||||||
#include "timesrv/IStaticService.h"
|
#include "timesrv/IStaticService.h"
|
||||||
#include "fs/fs.h"
|
#include "fs/fs.h"
|
||||||
#include "nvdrv/nvdrv.h"
|
#include "nvdrv/nvdrv.h"
|
||||||
@ -47,8 +47,8 @@ namespace skyline::service {
|
|||||||
case Service::IAudioRendererManager:
|
case Service::IAudioRendererManager:
|
||||||
serviceObj = std::make_shared<audren::IAudioRendererManager>(state, *this);
|
serviceObj = std::make_shared<audren::IAudioRendererManager>(state, *this);
|
||||||
break;
|
break;
|
||||||
case Service::hid:
|
case Service::hid_IHidServer:
|
||||||
serviceObj = std::make_shared<hid::hid>(state, *this);
|
serviceObj = std::make_shared<hid::IHidServer>(state, *this);
|
||||||
break;
|
break;
|
||||||
case Service::timesrv_IStaticService:
|
case Service::timesrv_IStaticService:
|
||||||
serviceObj = std::make_shared<timesrv::IStaticService>(state, *this);
|
serviceObj = std::make_shared<timesrv::IStaticService>(state, *this);
|
||||||
|
Loading…
Reference in New Issue
Block a user