Rework service API to be cleaner with significantly less boilerplate

This patch reduces the burden of adding services significantly, rather
than having to create an enum entry and add strings in the constructor
it will all be determined at runtime through RTTI. A macro is also used
in the service creation case to reduce clutter.
This commit is contained in:
Billy Laws 2020-09-02 22:11:28 +01:00 committed by ◱ PixelyIon
parent 21e2c826a1
commit 74a150dff1
79 changed files with 204 additions and 338 deletions

View File

@ -588,7 +588,7 @@ namespace skyline::kernel::svc {
KHandle handle{};
if (port.compare("sm:") >= 0) {
handle = state.os->serviceManager.NewSession(service::Service::sm_IUserInterface);
handle = state.process->NewHandle<type::KSession>(std::static_pointer_cast<service::BaseService>(state.os->serviceManager.smUserInterface)).handle;
} else {
state.logger->Warn("svcConnectToNamedPort: Connecting to invalid port: '{}'", port);
state.ctx->registers.w0 = constant::status::NotFound;

View File

@ -16,7 +16,6 @@ namespace skyline::kernel::type {
std::shared_ptr<service::BaseService> serviceObject; //!< A shared pointer to the service class
std::unordered_map<KHandle, std::shared_ptr<service::BaseService>> domainTable; //!< This maps from a virtual handle to it's service
KHandle handleIndex{0x1}; //!< The currently allocated handle index
service::Service serviceType; //!< The type of the service
enum class ServiceStatus { Open, Closed } serviceStatus{ServiceStatus::Open}; //!< If the session is open or closed
bool isDomain{}; //!< Holds if this is a domain session or not
@ -24,7 +23,7 @@ namespace skyline::kernel::type {
* @param state The state of the device
* @param serviceObject A shared pointer to the service class
*/
KSession(const DeviceState &state, std::shared_ptr<service::BaseService> &serviceObject) : serviceObject(serviceObject), serviceType(serviceObject->serviceType), KSyncObject(state, KType::KSession) {}
KSession(const DeviceState &state, std::shared_ptr<service::BaseService> &serviceObject) : serviceObject(serviceObject), KSyncObject(state, KType::KSession) {}
/**
* This converts this session into a domain session (https://switchbrew.org/wiki/IPC_Marshalling#Domains)

View File

@ -7,7 +7,7 @@
#include "IAccountServiceForApplication.h"
namespace skyline::service::account {
IAccountServiceForApplication::IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::account_IAccountServiceForApplication, "account:IAccountServiceForApplication", {
IAccountServiceForApplication::IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x1, SFUNC(IAccountServiceForApplication::GetUserExistence)},
{0x2, SFUNC(IAccountServiceForApplication::ListAllUsers)},
{0x3, SFUNC(IAccountServiceForApplication::ListOpenUsers)},

View File

@ -4,6 +4,6 @@
#include "IManagerForApplication.h"
namespace skyline::service::account {
IManagerForApplication::IManagerForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::account_IManagerForApplication, "account:IManagerForApplication", {
IManagerForApplication::IManagerForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -5,7 +5,7 @@
#include "IProfile.h"
namespace skyline::service::account {
IProfile::IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId) : userId(userId), BaseService(state, manager, Service::account_IProfile, "account:IProfile", {
IProfile::IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId) : userId(userId), BaseService(state, manager, {
{0x0, SFUNC(IProfile::Get)},
{0x1, SFUNC(IProfile::GetBase)}
}) {}

View File

@ -8,7 +8,7 @@
#include "IAllSystemAppletProxiesService.h"
namespace skyline::service::am {
IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_IAllSystemAppletProxiesService, "am:IAllSystemAppletProxiesService", {
IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x64, SFUNC(IAllSystemAppletProxiesService::OpenSystemAppletProxy)},
{0xC8, SFUNC(IAllSystemAppletProxiesService::OpenLibraryAppletProxy)},
{0xC9, SFUNC(IAllSystemAppletProxiesService::OpenLibraryAppletProxy)},

View File

@ -5,7 +5,7 @@
#include "IApplicationProxyService.h"
namespace skyline::service::am {
IApplicationProxyService::IApplicationProxyService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_IApplicationProxyService, "am:IApplicationProxyService", {
IApplicationProxyService::IApplicationProxyService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IApplicationProxyService::OpenApplicationProxy)}
}) {}

View File

@ -7,7 +7,7 @@
#include "ILibraryAppletAccessor.h"
namespace skyline::service::am {
ILibraryAppletAccessor::ILibraryAppletAccessor(const DeviceState &state, ServiceManager &manager) : stateChangeEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::am_ILibraryAppletAccessor, "am:ILibraryAppletAccessor", {
ILibraryAppletAccessor::ILibraryAppletAccessor(const DeviceState &state, ServiceManager &manager) : stateChangeEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x0, SFUNC(ILibraryAppletAccessor::GetAppletStateChangedEvent)},
{0xA, SFUNC(ILibraryAppletAccessor::Start)},
{0x1E, SFUNC(ILibraryAppletAccessor::GetResult)},

View File

@ -4,6 +4,6 @@
#include "IAppletCommonFunctions.h"
namespace skyline::service::am {
IAppletCommonFunctions::IAppletCommonFunctions(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_IAppletCommonFunctions, "am:IAppletCommonFunctions", {
IAppletCommonFunctions::IAppletCommonFunctions(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -7,7 +7,7 @@
#include "IApplicationFunctions.h"
namespace skyline::service::am {
IApplicationFunctions::IApplicationFunctions(const DeviceState &state, ServiceManager &manager) : gpuErrorEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::am_IApplicationFunctions, "am:IApplicationFunctions", {
IApplicationFunctions::IApplicationFunctions(const DeviceState &state, ServiceManager &manager) : gpuErrorEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x1, SFUNC(IApplicationFunctions::PopLaunchParameter)},
{0x14, SFUNC(IApplicationFunctions::EnsureSaveData)},
{0x15, SFUNC(IApplicationFunctions::GetDesiredLanguage)},

View File

@ -4,7 +4,7 @@
#include "IAudioController.h"
namespace skyline::service::am {
IAudioController::IAudioController(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_IAudioController, "am:IAudioController", {
IAudioController::IAudioController(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IAudioController::SetExpectedMasterVolume)},
{0x1, SFUNC(IAudioController::GetMainAppletExpectedMasterVolume)},
{0x2, SFUNC(IAudioController::GetLibraryAppletExpectedMasterVolume)}

View File

@ -10,7 +10,7 @@ namespace skyline::service::am {
messageEvent->Signal();
}
ICommonStateGetter::ICommonStateGetter(const DeviceState &state, ServiceManager &manager) : messageEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::am_ICommonStateGetter, "am:ICommonStateGetter", {
ICommonStateGetter::ICommonStateGetter(const DeviceState &state, ServiceManager &manager) : messageEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x0, SFUNC(ICommonStateGetter::GetEventHandle)},
{0x1, SFUNC(ICommonStateGetter::ReceiveMessage)},
{0x5, SFUNC(ICommonStateGetter::GetOperationMode)},

View File

@ -4,6 +4,6 @@
#include "IDebugFunctions.h"
namespace skyline::service::am {
IDebugFunctions::IDebugFunctions(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_IDebugFunctions, "am:IDebugFunctions", {
IDebugFunctions::IDebugFunctions(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -4,6 +4,6 @@
#include "IDisplayController.h"
namespace skyline::service::am {
IDisplayController::IDisplayController(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_IDisplayController, "am:IDisplayController", {
IDisplayController::IDisplayController(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -6,7 +6,7 @@
#include "ILibraryAppletCreator.h"
namespace skyline::service::am {
ILibraryAppletCreator::ILibraryAppletCreator(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_ILibraryAppletCreator, "am:ILibraryAppletCreator", {
ILibraryAppletCreator::ILibraryAppletCreator(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(ILibraryAppletCreator::CreateLibraryApplet)},
{0xA, SFUNC(ILibraryAppletCreator::CreateStorage)}
}) {}

View File

@ -7,7 +7,7 @@
#include "ISelfController.h"
namespace skyline::service::am {
ISelfController::ISelfController(const DeviceState &state, ServiceManager &manager) : libraryAppletLaunchableEvent(std::make_shared<type::KEvent>(state)), accumulatedSuspendedTickChangedEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::am_ISelfController, "am:ISelfController", {
ISelfController::ISelfController(const DeviceState &state, ServiceManager &manager) : libraryAppletLaunchableEvent(std::make_shared<type::KEvent>(state)), accumulatedSuspendedTickChangedEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x1, SFUNC(ISelfController::LockExit)},
{0x2, SFUNC(ISelfController::UnlockExit)},
{0x9, SFUNC(ISelfController::GetLibraryAppletLaunchableEvent)},
@ -46,7 +46,7 @@ namespace skyline::service::am {
void ISelfController::CreateManagedDisplayLayer(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
state.logger->Debug("Creating Managed Layer on Default Display");
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv");
if (hosBinder->layerStatus != hosbinder::LayerStatus::Uninitialized)
throw exception("The application is creating more than one layer");
hosBinder->layerStatus = hosbinder::LayerStatus::Managed;

View File

@ -5,7 +5,7 @@
#include "IWindowController.h"
namespace skyline::service::am {
IWindowController::IWindowController(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::am_IWindowController, "am:IWindowController", {
IWindowController::IWindowController(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x1, SFUNC(IWindowController::GetAppletResourceUserId)},
{0xA, SFUNC(IWindowController::AcquireForegroundRights)}
}) {}

View File

@ -5,7 +5,7 @@
#include "IApplicationProxy.h"
namespace skyline::service::am {
IApplicationProxy::IApplicationProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, Service::am_IApplicationProxy, "am:IApplicationProxy", {
IApplicationProxy::IApplicationProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, {
{0x0, SFUNC(BaseProxy::GetCommonStateGetter)},
{0x1, SFUNC(BaseProxy::GetSelfController)},
{0x2, SFUNC(BaseProxy::GetWindowController)},

View File

@ -4,7 +4,7 @@
#include "ILibraryAppletProxy.h"
namespace skyline::service::am {
ILibraryAppletProxy::ILibraryAppletProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, Service::am_ILibraryAppletProxy, "am:ILibraryAppletProxy", {
ILibraryAppletProxy::ILibraryAppletProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, {
{0x0, SFUNC(BaseProxy::GetCommonStateGetter)},
{0x1, SFUNC(BaseProxy::GetSelfController)},
{0x2, SFUNC(BaseProxy::GetWindowController)},

View File

@ -4,7 +4,7 @@
#include "IOverlayAppletProxy.h"
namespace skyline::service::am {
IOverlayAppletProxy::IOverlayAppletProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, Service::am_IOverlayAppletProxy, "am:IOverlayAppletProxy", {
IOverlayAppletProxy::IOverlayAppletProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, {
{0x0, SFUNC(BaseProxy::GetCommonStateGetter)},
{0x1, SFUNC(BaseProxy::GetSelfController)},
{0x2, SFUNC(BaseProxy::GetWindowController)},

View File

@ -4,7 +4,7 @@
#include "ISystemAppletProxy.h"
namespace skyline::service::am {
ISystemAppletProxy::ISystemAppletProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, Service::am_ISystemAppletProxy, "am:ISystemAppletProxy", {
ISystemAppletProxy::ISystemAppletProxy(const DeviceState &state, ServiceManager &manager) : BaseProxy(state, manager, {
{0x0, SFUNC(BaseProxy::GetCommonStateGetter)},
{0x1, SFUNC(BaseProxy::GetSelfController)},
{0x2, SFUNC(BaseProxy::GetWindowController)},

View File

@ -12,7 +12,7 @@
#include "base_proxy.h"
namespace skyline::service::am {
BaseProxy::BaseProxy(const DeviceState &state, ServiceManager &manager, const Service serviceType, const std::string &serviceName, const std::unordered_map<u32, std::function<void(type::KSession &, ipc::IpcRequest &, ipc::IpcResponse &)>> &vTable) : BaseService(state, manager, serviceType, serviceName, vTable) {}
BaseProxy::BaseProxy(const DeviceState &state, ServiceManager &manager, const std::unordered_map<u32, std::function<void(type::KSession &, ipc::IpcRequest &, ipc::IpcResponse &)>> &vTable) : BaseService(state, manager, vTable) {}
void BaseProxy::GetCommonStateGetter(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
manager.RegisterService(SRVREG(ICommonStateGetter), session, response);

View File

@ -12,7 +12,7 @@ namespace skyline::service::am {
*/
class BaseProxy : public BaseService {
public:
BaseProxy(const DeviceState &state, ServiceManager &manager, const Service serviceType, const std::string &serviceName, const std::unordered_map<u32, std::function<void(type::KSession & , ipc::IpcRequest & , ipc::IpcResponse & )>> &vTable);
BaseProxy(const DeviceState &state, ServiceManager &manager, const std::unordered_map<u32, std::function<void(type::KSession & , ipc::IpcRequest & , ipc::IpcResponse & )>> &vTable);
/**
* @brief This returns #ICommonStateGetter (https://switchbrew.org/wiki/Applet_Manager_services#ICommonStateGetter)

View File

@ -5,7 +5,7 @@
#include "IStorage.h"
namespace skyline::service::am {
IStorage::IStorage(const DeviceState &state, ServiceManager &manager, size_t size) : content(size), BaseService(state, manager, Service::am_IStorage, "am:IStorage", {
IStorage::IStorage(const DeviceState &state, ServiceManager &manager, size_t size) : content(size), BaseService(state, manager, {
{0x0, SFUNC(IStorage::Open)}
}) {}

View File

@ -6,7 +6,7 @@
#include "IStorageAccessor.h"
namespace skyline::service::am {
IStorageAccessor::IStorageAccessor(const DeviceState &state, ServiceManager &manager, std::shared_ptr<IStorage> parent) : parent(parent), BaseService(state, manager, Service::am_IStorageAccessor, "am:IStorageAccessor", {
IStorageAccessor::IStorageAccessor(const DeviceState &state, ServiceManager &manager, std::shared_ptr<IStorage> parent) : parent(parent), BaseService(state, manager, {
{0x0, SFUNC(IStorageAccessor::GetSize)},
{0xA, SFUNC(IStorageAccessor::Write)},
{0xB, SFUNC(IStorageAccessor::Read)}

View File

@ -4,6 +4,6 @@
#include "IAddOnContentManager.h"
namespace skyline::service::aocsrv {
IAddOnContentManager::IAddOnContentManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::aocsrv_IAddOnContentManager, "aocsrv:IAddOnContentManager", {
IAddOnContentManager::IAddOnContentManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -5,7 +5,7 @@
#include "IManager.h"
namespace skyline::service::apm {
IManager::IManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::apm_IManager, "apm:IManager", {
IManager::IManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IManager::OpenSession)}
}) {}

View File

@ -4,7 +4,7 @@
#include "ISession.h"
namespace skyline::service::apm {
ISession::ISession(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::apm_ISession, "apm:ISession", {
ISession::ISession(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(ISession::SetPerformanceConfiguration)},
{0x1, SFUNC(ISession::GetPerformanceConfiguration)}
}) {}

View File

@ -6,7 +6,7 @@
#include "IAudioDevice.h"
namespace skyline::service::audio {
IAudioDevice::IAudioDevice(const DeviceState &state, ServiceManager &manager) : systemEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::audio_IAudioDevice, "audio:IAudioDevice", {
IAudioDevice::IAudioDevice(const DeviceState &state, ServiceManager &manager) : systemEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x0, SFUNC(IAudioDevice::ListAudioDeviceName)},
{0x1, SFUNC(IAudioDevice::SetAudioDeviceOutputVolume)},
{0x3, SFUNC(IAudioDevice::GetActiveAudioDeviceName)},

View File

@ -5,7 +5,7 @@
#include "IAudioOut.h"
namespace skyline::service::audio {
IAudioOut::IAudioOut(const DeviceState &state, ServiceManager &manager, u8 channelCount, u32 sampleRate) : sampleRate(sampleRate), channelCount(channelCount), releaseEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::audio_IAudioOut, "audio:IAudioOut", {
IAudioOut::IAudioOut(const DeviceState &state, ServiceManager &manager, u8 channelCount, u32 sampleRate) : sampleRate(sampleRate), channelCount(channelCount), releaseEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x0, SFUNC(IAudioOut::GetAudioOutState)},
{0x1, SFUNC(IAudioOut::StartAudioOut)},
{0x2, SFUNC(IAudioOut::StopAudioOut)},

View File

@ -6,7 +6,7 @@
#include "IAudioOut.h"
namespace skyline::service::audio {
IAudioOutManager::IAudioOutManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::audio_IAudioOutManager, "audio:IAudioOutManager", {
IAudioOutManager::IAudioOutManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IAudioOutManager::ListAudioOuts)},
{0x1, SFUNC(IAudioOutManager::OpenAudioOut)},
{0x2, SFUNC(IAudioOutManager::ListAudioOuts)},

View File

@ -6,7 +6,7 @@
namespace skyline::service::audio::IAudioRenderer {
IAudioRenderer::IAudioRenderer(const DeviceState &state, ServiceManager &manager, AudioRendererParameters &parameters)
: systemEvent(std::make_shared<type::KEvent>(state)), parameters(parameters), BaseService(state, manager, Service::audio_IAudioRenderer, "audio:IAudioRenderer", {
: systemEvent(std::make_shared<type::KEvent>(state)), parameters(parameters), BaseService(state, manager, {
{0x0, SFUNC(IAudioRenderer::GetSampleRate)},
{0x1, SFUNC(IAudioRenderer::GetSampleCount)},
{0x2, SFUNC(IAudioRenderer::GetMixBufferCount)},

View File

@ -7,7 +7,7 @@
#include "IAudioRendererManager.h"
namespace skyline::service::audio {
IAudioRendererManager::IAudioRendererManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::audio_IAudioRendererManager, "audio:IAudioRendererManager", {
IAudioRendererManager::IAudioRendererManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IAudioRendererManager::OpenAudioRenderer)},
{0x1, SFUNC(IAudioRendererManager::GetAudioRendererWorkBufferSize)},
{0x2, SFUNC(IAudioRendererManager::GetAudioDeviceService)},

View File

@ -4,6 +4,7 @@
#pragma once
#include <functional>
#include <cxxabi.h>
#include <kernel/ipc.h>
#include <common.h>
@ -16,119 +17,7 @@ namespace skyline::kernel::type {
namespace skyline::service {
using namespace kernel;
/**
* @brief This contains an enum for every service that's present
*/
enum class Service {
sm_IUserInterface,
fatalsrv_IService,
settings_ISettingsServer,
settings_ISystemSettingsServer,
apm_IManager,
apm_ISession,
am_IAllSystemAppletProxiesService,
am_IApplicationProxyService,
am_IApplicationProxy,
am_ILibraryAppletProxy,
am_ISystemAppletProxy,
am_IOverlayAppletProxy,
am_ICommonStateGetter,
am_IApplicationFunctions,
am_ISelfController,
am_IWindowController,
am_IAudioController,
am_IDisplayController,
am_ILibraryAppletCreator,
am_ILibraryAppletAccessor,
am_IDebugFunctions,
am_IAppletCommonFunctions,
am_IStorage,
am_IStorageAccessor,
audio_IAudioOutManager,
audio_IAudioOut,
audio_IAudioRendererManager,
audio_IAudioRenderer,
audio_IAudioDevice,
hid_IHidServer,
hid_IAppletResource,
hid_IActiveVibrationDeviceList,
timesrv_IStaticService,
timesrv_ISystemClock,
timesrv_ITimeZoneService,
timesrv_ISteadyClock,
fssrv_IFileSystemProxy,
fssrv_IFileSystem,
fssrv_IFile,
fssrv_IStorage,
nvdrv_INvDrvServices,
visrv_IManagerRootService,
visrv_IApplicationDisplayService,
visrv_ISystemDisplayService,
visrv_IManagerDisplayService,
hosbinder_IHOSBinderDriver,
pl_IPlatformServiceManager,
aocsrv_IAddOnContentManager,
pctl_IParentalControlServiceFactory,
pctl_IParentalControlService,
lm_ILogService,
lm_ILogger,
account_IAccountServiceForApplication,
account_IManagerForApplication,
account_IProfile,
friends_IServiceCreator,
friends_IFriendService,
friends_INotificationService,
nfp_IUserManager,
nfp_IUser,
nifm_IStaticService,
nifm_IGeneralService,
nifm_IRequest,
socket_IClient,
ssl_ISslService,
ssl_ISslContext,
prepo_IPrepoService
};
/**
* @brief A map from every service's name as a std::string to the corresponding serviceEnum
*/
const static std::unordered_map<std::string, Service> ServiceString{
{"fatal:u", Service::fatalsrv_IService},
{"set", Service::settings_ISettingsServer},
{"set:sys", Service::settings_ISystemSettingsServer},
{"apm", Service::apm_IManager},
{"appletOE", Service::am_IApplicationProxyService},
{"appletAE", Service::am_IAllSystemAppletProxiesService},
{"audout:u", Service::audio_IAudioOutManager},
{"audren:u", Service::audio_IAudioRendererManager},
{"hid", Service::hid_IHidServer},
{"time:s", Service::timesrv_IStaticService},
{"time:a", Service::timesrv_IStaticService},
{"time:u", Service::timesrv_IStaticService},
{"fsp-srv", Service::fssrv_IFileSystemProxy},
{"nvdrv", Service::nvdrv_INvDrvServices},
{"nvdrv:a", Service::nvdrv_INvDrvServices},
{"nvdrv:s", Service::nvdrv_INvDrvServices},
{"nvdrv:t", Service::nvdrv_INvDrvServices},
{"vi:m", Service::visrv_IManagerRootService},
{"vi:u", Service::visrv_IManagerRootService},
{"vi:s", Service::visrv_IManagerRootService},
{"pl:u", Service::pl_IPlatformServiceManager},
{"aoc:u", Service::aocsrv_IAddOnContentManager},
{"pctl", Service::pctl_IParentalControlServiceFactory},
{"pctl:a", Service::pctl_IParentalControlServiceFactory},
{"pctl:s", Service::pctl_IParentalControlServiceFactory},
{"pctl:r", Service::pctl_IParentalControlServiceFactory},
{"lm", Service::lm_ILogService},
{"acc:u0", Service::account_IAccountServiceForApplication},
{"friend:u", Service::friends_IServiceCreator},
{"nfp:user", Service::nfp_IUserManager},
{"nifm:u", Service::nifm_IStaticService},
{"bsd:u", Service::socket_IClient},
{"ssl", Service::ssl_ISslService},
{"prepo:u", Service::prepo_IPrepoService}
};
using ServiceName = u64; //!< Service names are a maximum of 8 bytes so we use a u64 to reference them
class ServiceManager;
@ -142,17 +31,26 @@ namespace skyline::service {
std::unordered_map<u32, std::function<void(type::KSession &, ipc::IpcRequest &, ipc::IpcResponse &)>> vTable; //!< This holds the mapping from a function's CmdId to the actual function
public:
Service serviceType; //!< The type of this service
std::string serviceName; //!< The name of this service
/**
* @param state The state of the device
* @param hasLoop If the service has a loop or not
* @param serviceType The type of the service
* @param serviceName The name of the service
* @param vTable The functions of the service
*/
BaseService(const DeviceState &state, ServiceManager &manager, Service serviceType, const std::string &serviceName, const std::unordered_map<u32, std::function<void(type::KSession &, ipc::IpcRequest &, ipc::IpcResponse &)>> &vTable) : state(state), manager(manager), serviceType(serviceType), serviceName(serviceName), vTable(vTable) {}
BaseService(const DeviceState &state, ServiceManager &manager, const std::unordered_map<u32, std::function<void(type::KSession &, ipc::IpcRequest &, ipc::IpcResponse &)>> &vTable) : state(state), manager(manager), vTable(vTable) {}
/**
* @note To be able to extract the name of the underlying class and ensure correct destruction order
*/
virtual ~BaseService() = default;
std::string GetName() {
int status{};
size_t length{};
auto mangledName{typeid(*this).name()};
std::unique_ptr<char, decltype(&std::free)> demangled{ abi::__cxa_demangle(mangledName, nullptr, &length, &status), std::free};
return (status == 0) ? std::string(demangled.get() + std::char_traits<char>::length("skyline::service::")) : mangledName;
}
/**
* @brief This handles all IPC commands with type request to a service
@ -164,14 +62,14 @@ namespace skyline::service {
try {
function = vTable.at(request.payload->value);
} catch (std::out_of_range &) {
state.logger->Warn("Cannot find function in service '{0}' (Type: {1}): 0x{2:X} ({2})", serviceName, serviceType, static_cast<u32>(request.payload->value));
state.logger->Warn("Cannot find function in service '{0}': 0x{1:X} ({1})", GetName(), static_cast<u32>(request.payload->value));
return;
}
try {
function(session, request, response);
} catch (std::exception &e) {
throw exception("{} (Service: {})", e.what(), serviceName);
throw exception("{} (Service: {})", e.what(), GetName());
}
};
};

View File

@ -4,7 +4,7 @@
#include "IService.h"
namespace skyline::service::fatalsrv {
IService::IService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::fatalsrv_IService, "fatalsrv:IService", {
IService::IService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IService::ThrowFatal)},
{0x1, SFUNC(IService::ThrowFatal)},
{0x2, SFUNC(IService::ThrowFatal)}

View File

@ -4,6 +4,6 @@
#include "IFriendService.h"
namespace skyline::service::friends {
IFriendService::IFriendService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::friends_IFriendService, "friends:IFriendService", {
IFriendService::IFriendService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -5,7 +5,7 @@
#include "INotificationService.h"
namespace skyline::service::friends {
INotificationService::INotificationService(const DeviceState &state, ServiceManager &manager) : notificationEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::friends_INotificationService, "friends:INotificationService", {
INotificationService::INotificationService(const DeviceState &state, ServiceManager &manager) : notificationEvent(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x0, SFUNC(INotificationService::GetEvent)},
}) {}

View File

@ -6,7 +6,7 @@
#include "IServiceCreator.h"
namespace skyline::service::friends {
IServiceCreator::IServiceCreator(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::friends_IServiceCreator, "friends:IServiceCreator", {
IServiceCreator::IServiceCreator(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IServiceCreator::CreateFriendService)},
{0x1, SFUNC(IServiceCreator::CreateNotificationService)},
}) {}

View File

@ -5,7 +5,7 @@
#include "IFile.h"
namespace skyline::service::fssrv {
IFile::IFile(std::shared_ptr<vfs::Backing> &backing, const DeviceState &state, ServiceManager &manager) : backing(backing), BaseService(state, manager, Service::fssrv_IFile, "fssrv:IFile", {
IFile::IFile(std::shared_ptr<vfs::Backing> &backing, const DeviceState &state, ServiceManager &manager) : backing(backing), BaseService(state, manager, {
{0x0, SFUNC(IFile::Read)},
{0x1, SFUNC(IFile::Write)},
{0x2, SFUNC(IFile::Flush)},

View File

@ -7,7 +7,7 @@
#include "IFileSystem.h"
namespace skyline::service::fssrv {
IFileSystem::IFileSystem(std::shared_ptr<vfs::FileSystem> backing, const DeviceState &state, ServiceManager &manager) : backing(backing), BaseService(state, manager, Service::fssrv_IFileSystem, "fssrv:IFileSystem", {
IFileSystem::IFileSystem(std::shared_ptr<vfs::FileSystem> backing, const DeviceState &state, ServiceManager &manager) : backing(backing), BaseService(state, manager, {
{0x0, SFUNC(IFileSystem::CreateFile)},
{0x7, SFUNC(IFileSystem::GetEntryType)},
{0x8, SFUNC(IFileSystem::OpenFile)},

View File

@ -8,7 +8,7 @@
#include "IStorage.h"
namespace skyline::service::fssrv {
IFileSystemProxy::IFileSystemProxy(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::fssrv_IFileSystemProxy, "fssrv:IFileSystemProxy", {
IFileSystemProxy::IFileSystemProxy(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x1, SFUNC(IFileSystemProxy::SetCurrentProcess)},
{0x12, SFUNC(IFileSystemProxy::OpenSdCardFileSystem)},
{0x33, SFUNC(IFileSystemProxy::OpenSaveDataFileSystem)},

View File

@ -5,7 +5,7 @@
#include "IStorage.h"
namespace skyline::service::fssrv {
IStorage::IStorage(std::shared_ptr<vfs::Backing> &backing, const DeviceState &state, ServiceManager &manager) : backing(backing), BaseService(state, manager, Service::fssrv_IStorage, "fssrv:IStorage", {
IStorage::IStorage(std::shared_ptr<vfs::Backing> &backing, const DeviceState &state, ServiceManager &manager) : backing(backing), BaseService(state, manager, {
{0x0, SFUNC(IStorage::Read)},
{0x4, SFUNC(IStorage::GetSize)}
}) {}

View File

@ -7,7 +7,7 @@
using namespace skyline::input;
namespace skyline::service::hid {
IActiveVibrationDeviceList::IActiveVibrationDeviceList(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hid_IActiveVibrationDeviceList, "hid:IActiveVibrationDeviceList", {
IActiveVibrationDeviceList::IActiveVibrationDeviceList(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IActiveVibrationDeviceList::ActivateVibrationDevice)}
}) {}

View File

@ -5,7 +5,7 @@
#include "IAppletResource.h"
namespace skyline::service::hid {
IAppletResource::IAppletResource(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hid_IAppletResource, "hid:IAppletResource", {
IAppletResource::IAppletResource(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IAppletResource::GetSharedMemoryHandle)}
}) {}

View File

@ -8,7 +8,7 @@
using namespace skyline::input;
namespace skyline::service::hid {
IHidServer::IHidServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hid_IHidServer, "hid:IHidServer", {
IHidServer::IHidServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IHidServer::CreateAppletResource)},
{0x64, SFUNC(IHidServer::SetSupportedNpadStyleSet)},
{0x64, SFUNC(IHidServer::GetSupportedNpadStyleSet)},

View File

@ -11,7 +11,7 @@
#include "display.h"
namespace skyline::service::hosbinder {
IHOSBinderDriver::IHOSBinderDriver(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::hosbinder_IHOSBinderDriver, "hosbinder_IHOSBinderDriver", {
IHOSBinderDriver::IHOSBinderDriver(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IHOSBinderDriver::TransactParcel)},
{0x1, SFUNC(IHOSBinderDriver::AdjustRefcount)},
{0x2, SFUNC(IHOSBinderDriver::GetNativeHandle)},
@ -124,7 +124,7 @@ namespace skyline::service::hosbinder {
auto gbpBuffer = reinterpret_cast<GbpBuffer *>(pointer);
std::shared_ptr<nvdrv::device::NvMap::NvMapObject> nvBuffer{};
auto nvmap = state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->GetDevice<nvdrv::device::NvMap>(nvdrv::device::NvDeviceType::nvmap);
auto nvmap = state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->GetDevice<nvdrv::device::NvMap>(nvdrv::device::NvDeviceType::nvmap);
if (gbpBuffer->nvmapHandle) {
nvBuffer = nvmap->handleTable.at(gbpBuffer->nvmapHandle);

View File

@ -5,7 +5,7 @@
#include "ILogService.h"
namespace skyline::service::lm {
ILogService::ILogService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::lm_ILogService, "lm:ILogService", {
ILogService::ILogService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(ILogService::OpenLogger)}
}) {}

View File

@ -5,7 +5,7 @@
#include "ILogger.h"
namespace skyline::service::lm {
ILogger::ILogger(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::lm_ILogger, "lm:ILogger", {
ILogger::ILogger(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(ILogger::Log)},
{0x1, SFUNC(ILogger::SetDestination)}
}) {}

View File

@ -5,7 +5,7 @@
#include "IUserManager.h"
namespace skyline::service::nfp {
IUser::IUser(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::nfp_IUser, "nfp:IUser", {
IUser::IUser(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IUser::Initialize)}
}) {}

View File

@ -5,7 +5,7 @@
#include "IUserManager.h"
namespace skyline::service::nfp {
IUserManager::IUserManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::nfp_IUserManager, "nfp:IUserManager", {
IUserManager::IUserManager(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IUserManager::CreateUserInterface)}
}) {}

View File

@ -5,7 +5,7 @@
#include "IGeneralService.h"
namespace skyline::service::nifm {
IGeneralService::IGeneralService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::nifm_IGeneralService, "nifm:IGeneralService", {
IGeneralService::IGeneralService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x4, SFUNC(IGeneralService::CreateRequest)}
}) {}

View File

@ -5,7 +5,7 @@
#include "IRequest.h"
namespace skyline::service::nifm {
IRequest::IRequest(const DeviceState &state, ServiceManager &manager) : event0(std::make_shared<type::KEvent>(state)), event1(std::make_shared<type::KEvent>(state)), BaseService(state, manager, Service::nifm_IRequest, "nifm:IRequest", {
IRequest::IRequest(const DeviceState &state, ServiceManager &manager) : event0(std::make_shared<type::KEvent>(state)), event1(std::make_shared<type::KEvent>(state)), BaseService(state, manager, {
{0x0, SFUNC(IRequest::GetRequestState)},
{0x1, SFUNC(IRequest::GetResult)},
{0x2, SFUNC(IRequest::GetSystemEventReadableHandles)},

View File

@ -5,7 +5,7 @@
#include "IStaticService.h"
namespace skyline::service::nifm {
IStaticService::IStaticService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::nifm_IStaticService, "nifm:IStaticService", {
IStaticService::IStaticService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x4, SFUNC(IStaticService::CreateGeneralService)},
{0x5, SFUNC(IStaticService::CreateGeneralService)}
}) {}

View File

@ -54,7 +54,7 @@ namespace skyline::service::nvdrv {
return fdIndex++;
}
INvDrvServices::INvDrvServices(const DeviceState &state, ServiceManager &manager) : hostSyncpoint(state), BaseService(state, manager, Service::nvdrv_INvDrvServices, "INvDrvServices", {
INvDrvServices::INvDrvServices(const DeviceState &state, ServiceManager &manager) : hostSyncpoint(state), BaseService(state, manager, {
{0x0, SFUNC(INvDrvServices::Open)},
{0x1, SFUNC(INvDrvServices::Ioctl)},
{0x2, SFUNC(INvDrvServices::Close)},

View File

@ -70,7 +70,7 @@ namespace skyline::service::nvdrv::device {
if (!region.nvmapHandle)
return;
auto nvmap = state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->GetDevice<nvdrv::device::NvMap>(nvdrv::device::NvDeviceType::nvmap)->handleTable.at(region.nvmapHandle);
auto nvmap = state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->GetDevice<nvdrv::device::NvMap>(nvdrv::device::NvDeviceType::nvmap)->handleTable.at(region.nvmapHandle);
u64 mapPhysicalAddress = region.bufferOffset + nvmap->address;
u64 mapSize = region.mappingSize ? region.mappingSize : nvmap->size;
@ -133,7 +133,7 @@ namespace skyline::service::nvdrv::device {
for (auto entry : entries) {
try {
auto nvmap = state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->GetDevice<nvdrv::device::NvMap>(nvdrv::device::NvDeviceType::nvmap)->handleTable.at(entry.nvmapHandle);
auto nvmap = state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->GetDevice<nvdrv::device::NvMap>(nvdrv::device::NvDeviceType::nvmap)->handleTable.at(entry.nvmapHandle);
u64 mapAddress = static_cast<u64>(entry.gpuOffset) << MinAlignmentShift;
u64 mapPhysicalAddress = nvmap->address + (static_cast<u64>(entry.mapOffset) << MinAlignmentShift);

View File

@ -19,7 +19,7 @@ namespace skyline::service::nvdrv::device {
{0x481A, NFUNC(NvHostChannel::AllocGpfifoEx2)},
{0x4714, NFUNC(NvHostChannel::SetUserData)},
}) {
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->hostSyncpoint;
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->hostSyncpoint;
channelFence.id = hostSyncpoint.AllocateSyncpoint(false);
channelFence.UpdateValue(hostSyncpoint);
@ -48,7 +48,7 @@ namespace skyline::service::nvdrv::device {
Fence fence;
} &args = state.process->GetReference<Data>(buffer.output.at(0).address);
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->hostSyncpoint;
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->hostSyncpoint;
if (args.flags.fenceWait) {
if (args.flags.incrementWithValue) {
@ -104,7 +104,7 @@ namespace skyline::service::nvdrv::device {
u32 reserved[3];
} &args = state.process->GetReference<Data>(buffer.input.at(0).address);
channelFence.UpdateValue(state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->hostSyncpoint);
channelFence.UpdateValue(state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->hostSyncpoint);
args.fence = channelFence;
}

View File

@ -95,7 +95,7 @@ namespace skyline::service::nvdrv::device {
return;
}
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->hostSyncpoint;
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->hostSyncpoint;
// Check if the syncpoint has already expired using the last known values
if (hostSyncpoint.HasSyncpointExpired(args.fence.id, args.fence.value)) {
@ -173,7 +173,7 @@ namespace skyline::service::nvdrv::device {
event.state = NvHostEvent::State::Cancelled;
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>(Service::nvdrv_INvDrvServices)->hostSyncpoint;
auto &hostSyncpoint = state.os->serviceManager.GetService<nvdrv::INvDrvServices>("nvdrv")->hostSyncpoint;
hostSyncpoint.UpdateMin(event.fence.id);
}

View File

@ -4,6 +4,6 @@
#include "IParentalControlService.h"
namespace skyline::service::pctl {
IParentalControlService::IParentalControlService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::pctl_IParentalControlService, "pctl:IParentalControlService", {
IParentalControlService::IParentalControlService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -5,7 +5,7 @@
#include "IParentalControlServiceFactory.h"
namespace skyline::service::pctl {
IParentalControlServiceFactory::IParentalControlServiceFactory(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::pctl_IParentalControlServiceFactory, "pctl:IParentalControlServiceFactory", {
IParentalControlServiceFactory::IParentalControlServiceFactory(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IParentalControlServiceFactory::CreateService)},
{0x1, SFUNC(IParentalControlServiceFactory::CreateService)}
}) {}

View File

@ -29,7 +29,7 @@ namespace skyline::service::pl {
{FontStandard, FontStandardLength}
}};
IPlatformServiceManager::IPlatformServiceManager(const DeviceState &state, ServiceManager &manager) : fontSharedMem(std::make_shared<kernel::type::KSharedMemory>(state, NULL, constant::FontSharedMemSize, memory::Permission{true, false, false})), BaseService(state, manager, Service::pl_IPlatformServiceManager, "pl:IPlatformServiceManager", {
IPlatformServiceManager::IPlatformServiceManager(const DeviceState &state, ServiceManager &manager) : fontSharedMem(std::make_shared<kernel::type::KSharedMemory>(state, NULL, constant::FontSharedMemSize, memory::Permission{true, false, false})), BaseService(state, manager, {
{0x1, SFUNC(IPlatformServiceManager::GetLoadState)},
{0x2, SFUNC(IPlatformServiceManager::GetSize)},
{0x3, SFUNC(IPlatformServiceManager::GetSharedMemoryAddressOffset)},

View File

@ -4,7 +4,7 @@
#include "IPrepoService.h"
namespace skyline::service::prepo {
IPrepoService::IPrepoService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::prepo_IPrepoService, "prepo:IPrepoService", {
IPrepoService::IPrepoService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x2775, SFUNC(IPrepoService::SaveReportWithUser)},
}) {}

View File

@ -29,106 +29,64 @@
#include "prepo/IPrepoService.h"
#include "serviceman.h"
namespace skyline::service {
ServiceManager::ServiceManager(const DeviceState &state) : state(state) {}
#define SERVICE_CASE(class, name) \
case util::MakeMagic<ServiceName>(name): { \
std::shared_ptr<BaseService> serviceObject = std::make_shared<class>(state, *this); \
serviceMap[util::MakeMagic<ServiceName>(name)] = serviceObject; \
return serviceObject; \
}
std::shared_ptr<BaseService> ServiceManager::CreateService(Service serviceType) {
auto serviceIter = serviceMap.find(serviceType);
namespace skyline::service {
ServiceManager::ServiceManager(const DeviceState &state) : state(state), smUserInterface(std::make_shared<sm::IUserInterface>(state, *this)) {}
std::shared_ptr<BaseService> ServiceManager::CreateService(ServiceName name) {
auto serviceIter = serviceMap.find(name);
if (serviceIter != serviceMap.end())
return (*serviceIter).second;
std::shared_ptr<BaseService> serviceObj;
switch (serviceType) {
case Service::sm_IUserInterface:
serviceObj = std::make_shared<sm::IUserInterface>(state, *this);
break;
case Service::fatalsrv_IService:
serviceObj = std::make_shared<fatalsrv::IService>(state, *this);
break;
case Service::settings_ISettingsServer:
serviceObj = std::make_shared<settings::ISettingsServer>(state, *this);
break;
case Service::settings_ISystemSettingsServer:
serviceObj = std::make_shared<settings::ISystemSettingsServer>(state, *this);
break;
case Service::apm_IManager:
serviceObj = std::make_shared<apm::IManager>(state, *this);
break;
case Service::am_IApplicationProxyService:
serviceObj = std::make_shared<am::IApplicationProxyService>(state, *this);
break;
case Service::am_IAllSystemAppletProxiesService:
serviceObj = std::make_shared<am::IAllSystemAppletProxiesService>(state, *this);
break;
case Service::audio_IAudioOutManager:
serviceObj = std::make_shared<audio::IAudioOutManager>(state, *this);
break;
case Service::audio_IAudioRendererManager:
serviceObj = std::make_shared<audio::IAudioRendererManager>(state, *this);
break;
case Service::hid_IHidServer:
serviceObj = std::make_shared<hid::IHidServer>(state, *this);
break;
case Service::timesrv_IStaticService:
serviceObj = std::make_shared<timesrv::IStaticService>(state, *this);
break;
case Service::fssrv_IFileSystemProxy:
serviceObj = std::make_shared<fssrv::IFileSystemProxy>(state, *this);
break;
case Service::nvdrv_INvDrvServices:
serviceObj = std::make_shared<nvdrv::INvDrvServices>(state, *this);
break;
case Service::visrv_IManagerRootService:
serviceObj = std::make_shared<visrv::IManagerRootService>(state, *this);
break;
case Service::pl_IPlatformServiceManager:
serviceObj = std::make_shared<pl::IPlatformServiceManager>(state, *this);
break;
case Service::aocsrv_IAddOnContentManager:
serviceObj = std::make_shared<aocsrv::IAddOnContentManager>(state, *this);
break;
case Service::pctl_IParentalControlServiceFactory:
serviceObj = std::make_shared<pctl::IParentalControlServiceFactory>(state, *this);
break;
case Service::lm_ILogService:
serviceObj = std::make_shared<lm::ILogService>(state, *this);
break;
case Service::account_IAccountServiceForApplication:
serviceObj = std::make_shared<account::IAccountServiceForApplication>(state, *this);
break;
case Service::friends_IServiceCreator:
serviceObj = std::make_shared<friends::IServiceCreator>(state, *this);
break;
case Service::nfp_IUserManager:
serviceObj = std::make_shared<nfp::IUserManager>(state, *this);
break;
case Service::nifm_IStaticService:
serviceObj = std::make_shared<nifm::IStaticService>(state, *this);
break;
case Service::socket_IClient:
serviceObj = std::make_shared<socket::IClient>(state, *this);
break;
case Service::ssl_ISslService:
serviceObj = std::make_shared<ssl::ISslService>(state, *this);
break;
case Service::prepo_IPrepoService:
serviceObj = std::make_shared<prepo::IPrepoService>(state, *this);
break;
switch (name) {
SERVICE_CASE(fatalsrv::IService, "fatal:u")
SERVICE_CASE(settings::ISettingsServer, "set")
SERVICE_CASE(settings::ISystemSettingsServer, "set:sys")
SERVICE_CASE(apm::IManager, "apm")
SERVICE_CASE(am::IApplicationProxyService, "appletOE")
SERVICE_CASE(am::IAllSystemAppletProxiesService, "appletAE")
SERVICE_CASE(audio::IAudioOutManager, "audout:u")
SERVICE_CASE(audio::IAudioRendererManager, "audren:u")
SERVICE_CASE(hid::IHidServer, "hid")
SERVICE_CASE(timesrv::IStaticService, "time:s")
SERVICE_CASE(timesrv::IStaticService, "time:a")
SERVICE_CASE(timesrv::IStaticService, "time:u")
SERVICE_CASE(fssrv::IFileSystemProxy, "fsp-srv")
SERVICE_CASE(nvdrv::INvDrvServices, "nvdrv")
SERVICE_CASE(nvdrv::INvDrvServices, "nvdrv:a")
SERVICE_CASE(nvdrv::INvDrvServices, "nvdrv:s")
SERVICE_CASE(nvdrv::INvDrvServices, "nvdrv:t")
SERVICE_CASE(visrv::IManagerRootService, "vi:m")
SERVICE_CASE(visrv::IManagerRootService, "vi:u")
SERVICE_CASE(visrv::IManagerRootService, "vi:s")
SERVICE_CASE(pl::IPlatformServiceManager, "pl:u")
SERVICE_CASE(aocsrv::IAddOnContentManager, "aoc:u")
SERVICE_CASE(pctl::IParentalControlServiceFactory, "pctl")
SERVICE_CASE(pctl::IParentalControlServiceFactory, "pctl:a")
SERVICE_CASE(pctl::IParentalControlServiceFactory, "pctl:s")
SERVICE_CASE(pctl::IParentalControlServiceFactory, "pctl:r")
SERVICE_CASE(lm::ILogService, "lm")
SERVICE_CASE(account::IAccountServiceForApplication, "acc:u0")
SERVICE_CASE(friends::IServiceCreator, "friend")
SERVICE_CASE(nfp::IUserManager, "nfp:user")
SERVICE_CASE(nifm::IStaticService, "nifm:u")
SERVICE_CASE(socket::IClient, "bsd:u")
SERVICE_CASE(ssl::ISslService, "ssl")
SERVICE_CASE(prepo::IPrepoService, "prepo:u")
default:
throw exception("CreateService called on missing object, type: {}", serviceType);
throw exception("CreateService called with an unknown service name: {}", name);
}
serviceMap[serviceType] = serviceObj;
return serviceObj;
}
KHandle ServiceManager::NewSession(Service serviceType) {
std::shared_ptr<BaseService> ServiceManager::NewService(ServiceName name, type::KSession &session, ipc::IpcResponse &response) {
std::lock_guard serviceGuard(mutex);
return state.process->NewHandle<type::KSession>(CreateService(serviceType)).handle;
}
std::shared_ptr<BaseService> ServiceManager::NewService(const std::string &serviceName, type::KSession &session, ipc::IpcResponse &response) {
std::lock_guard serviceGuard(mutex);
auto serviceObject = CreateService(ServiceString.at(serviceName));
auto serviceObject = CreateService(name);
KHandle handle{};
if (session.isDomain) {
session.domainTable[++session.handleIndex] = serviceObject;
@ -138,13 +96,14 @@ namespace skyline::service {
handle = state.process->NewHandle<type::KSession>(serviceObject).handle;
response.moveHandles.push_back(handle);
}
state.logger->Debug("Service has been created: \"{}\" (0x{:X})", serviceName, handle);
state.logger->Debug("Service has been created: \"{}\" (0x{:X})", serviceObject->GetName(), handle);
return serviceObject;
}
void ServiceManager::RegisterService(std::shared_ptr<BaseService> serviceObject, type::KSession &session, ipc::IpcResponse &response, bool submodule) { // NOLINT(performance-unnecessary-value-param)
void ServiceManager::RegisterService(std::shared_ptr<BaseService> serviceObject, type::KSession &session, ipc::IpcResponse &response, bool submodule, ServiceName name) { // NOLINT(performance-unnecessary-value-param)
std::lock_guard serviceGuard(mutex);
KHandle handle{};
if (session.isDomain) {
session.domainTable[session.handleIndex] = serviceObject;
response.domainObjects.push_back(session.handleIndex);
@ -153,9 +112,11 @@ namespace skyline::service {
handle = state.process->NewHandle<type::KSession>(serviceObject).handle;
response.moveHandles.push_back(handle);
}
if (!submodule)
serviceMap[serviceObject->serviceType] = serviceObject;
state.logger->Debug("Service has been registered: \"{}\" (0x{:X})", serviceObject->serviceName, handle);
serviceMap[name] = serviceObject;
state.logger->Debug("Service has been registered: \"{}\" (0x{:X})", serviceObject->GetName(), handle);
}
void ServiceManager::CloseSession(KHandle handle) {
@ -163,10 +124,14 @@ namespace skyline::service {
auto session = state.process->GetHandle<type::KSession>(handle);
if (session->serviceStatus == type::KSession::ServiceStatus::Open) {
if (session->isDomain) {
for (const auto &[objectId, service] : session->domainTable)
serviceMap.erase(service->serviceType);
for (const auto &domainEntry : session->domainTable)
std::erase_if(serviceMap, [domainEntry](const auto &entry) {
return entry.second == domainEntry.second;
});
} else {
serviceMap.erase(session->serviceObject->serviceType);
std::erase_if(serviceMap, [session](const auto &entry) {
return entry.second == session->serviceObject;
});
}
session->serviceStatus = type::KSession::ServiceStatus::Closed;
}
@ -192,7 +157,9 @@ namespace skyline::service {
service->HandleRequest(*session, request, response);
break;
case ipc::DomainCommand::CloseVHandle:
serviceMap.erase(service->serviceType);
std::erase_if(serviceMap, [service](const auto &entry) {
return entry.second == service;
});
session->domainTable.erase(request.domain->objectId);
break;
}

View File

@ -10,40 +10,36 @@
namespace skyline::service {
/**
* @brief The ServiceManager class manages passing IPC requests to the right Service and running event loops of Services
* @todo This implementation varies significantly from HOS, this should be rectified much later on
*/
class ServiceManager {
private:
const DeviceState &state; //!< The state of the device
std::unordered_map<Service, std::shared_ptr<BaseService>> serviceMap; //!< A mapping from a Service to the underlying object
std::unordered_map<ServiceName, std::shared_ptr<BaseService>> serviceMap; //!< A mapping from a Service to the underlying object
Mutex mutex; //!< This mutex is used to ensure concurrent access to services doesn't cause crashes
/**
* @brief Creates an instance of the service if it doesn't already exist, otherwise returns an existing instance
* @param serviceType The type of service requested
* @param name The name of the service to create
* @return A shared pointer to an instance of the service
*/
std::shared_ptr<BaseService> CreateService(Service serviceType);
std::shared_ptr<BaseService> CreateService(ServiceName name);
public:
std::shared_ptr<BaseService> smUserInterface; //!< This is used by applications to open connections to services
/**
* @param state The state of the device
*/
ServiceManager(const DeviceState &state);
/**
* @brief Creates a new service and returns it's handle
* @param serviceType The type of the service
* @return Handle to KService object of the service
*/
KHandle NewSession(Service serviceType);
/**
* @brief Creates a new service using it's type enum and writes it's handle or virtual handle (If it's a domain request) to IpcResponse
* @param serviceName The name of the service
* @param name The service's name
* @param session The session object of the command
* @param response The response object to write the handle or virtual handle to
*/
std::shared_ptr<BaseService> NewService(const std::string &serviceName, type::KSession &session, ipc::IpcResponse &response);
std::shared_ptr<BaseService> NewService(ServiceName name, type::KSession &session, ipc::IpcResponse &response);
/**
* @brief Registers a service object in the manager and writes it's handle or virtual handle (If it's a domain request) to IpcResponse
@ -51,8 +47,9 @@ namespace skyline::service {
* @param session The session object of the command
* @param response The response object to write the handle or virtual handle to
* @param submodule If the registered service is a submodule or not
* @param name The name of the service to register if it's not a submodule - it will be added to the service map
*/
void RegisterService(std::shared_ptr<BaseService> serviceObject, type::KSession &session, ipc::IpcResponse &response, bool submodule = true);
void RegisterService(std::shared_ptr<BaseService> serviceObject, type::KSession &session, ipc::IpcResponse &response, bool submodule = true, ServiceName name = {});
/**
* @param serviceType The type of the service
@ -61,8 +58,13 @@ namespace skyline::service {
* @note This only works for services created with `NewService` as sub-interfaces used with `RegisterService` can have multiple instances
*/
template<typename Type>
inline std::shared_ptr<Type> GetService(Service serviceType) {
return std::static_pointer_cast<Type>(serviceMap.at(serviceType));
std::shared_ptr<Type> GetService(ServiceName name) {
return std::static_pointer_cast<Type>(serviceMap.at(name));
}
template<typename Type>
constexpr std::shared_ptr<Type> GetService(std::string_view name) {
return GetService<Type>(util::MakeMagic<ServiceName>(name));
}
/**

View File

@ -5,7 +5,7 @@
#include "ISettingsServer.h"
namespace skyline::service::settings {
ISettingsServer::ISettingsServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::settings_ISettingsServer, "settings:ISettingsServer", {
ISettingsServer::ISettingsServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x1, SFUNC(ISettingsServer::GetAvailableLanguageCodes)},
{0x2, SFUNC(ISettingsServer::MakeLanguageCode)},
{0x5, SFUNC(ISettingsServer::GetAvailableLanguageCodes2)}

View File

@ -5,7 +5,7 @@
#include "ISystemSettingsServer.h"
namespace skyline::service::settings {
ISystemSettingsServer::ISystemSettingsServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::settings_ISystemSettingsServer, "settings:ISystemSettingsServer", {
ISystemSettingsServer::ISystemSettingsServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x3, SFUNC(ISystemSettingsServer::GetFirmwareVersion)}}) {}
void ISystemSettingsServer::GetFirmwareVersion(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {

View File

@ -4,7 +4,7 @@
#include "IUserInterface.h"
namespace skyline::service::sm {
IUserInterface::IUserInterface(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::sm_IUserInterface, "sm:IUserInterface", {
IUserInterface::IUserInterface(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IUserInterface::Initialize)},
{0x1, SFUNC(IUserInterface::GetService)}
}) {}
@ -12,18 +12,18 @@ namespace skyline::service::sm {
void IUserInterface::Initialize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {}
void IUserInterface::GetService(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
std::string serviceName(request.PopString());
serviceName.resize(std::min(8UL, serviceName.size()));
auto name = request.Pop<ServiceName>();
if (serviceName.empty()) {
response.errorCode = constant::status::ServiceInvName;
} else {
if (name) {
try {
manager.NewService(serviceName, session, response);
manager.NewService(name, session, response);
} catch (std::out_of_range &) {
response.errorCode = constant::status::ServiceNotReg;
state.logger->Warn("Service has not been implemented: \"{}\"", serviceName);
std::string_view stringName(reinterpret_cast<char *>(&name), sizeof(u64));
state.logger->Warn("Service has not been implemented: \"{}\"", stringName);
}
} else {
response.errorCode = constant::status::ServiceInvName;
}
}
}

View File

@ -4,7 +4,7 @@
#include "IClient.h"
namespace skyline::service::socket {
IClient::IClient(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::socket_IClient, "socket:IClient", {
IClient::IClient(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IClient::RegisterClient)},
{0x1, SFUNC(IClient::StartMonitoring)},
}) {}

View File

@ -4,6 +4,6 @@
#include "ISslContext.h"
namespace skyline::service::ssl {
ISslContext::ISslContext(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::ssl_ISslContext, "ssl:ISslContext", {
ISslContext::ISslContext(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
}) {}
}

View File

@ -5,7 +5,7 @@
#include "ISslService.h"
namespace skyline::service::ssl {
ISslService::ISslService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::ssl_ISslService, "ssl:ISslService", {
ISslService::ISslService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(ISslService::CreateContext)},
{0x5, SFUNC(ISslService::SetInterfaceVersion)}
}) {}

View File

@ -7,7 +7,7 @@
#include "IStaticService.h"
namespace skyline::service::timesrv {
IStaticService::IStaticService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::timesrv_IStaticService, "timesrv:IStaticService", {
IStaticService::IStaticService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(IStaticService::GetStandardUserSystemClock)},
{0x1, SFUNC(IStaticService::GetStandardNetworkSystemClock)},
{0x2, SFUNC(IStaticService::GetStandardSteadyClock)},

View File

@ -4,7 +4,7 @@
#include "ISteadyClock.h"
namespace skyline::service::timesrv {
ISteadyClock::ISteadyClock(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::timesrv_ISteadyClock, "timesrv:ISteadyClock", {
ISteadyClock::ISteadyClock(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x0, SFUNC(ISteadyClock::GetCurrentTimePoint)}
}) {}

View File

@ -5,7 +5,7 @@
#include "ISystemClock.h"
namespace skyline::service::timesrv {
ISystemClock::ISystemClock(const SystemClockType clockType, const DeviceState &state, ServiceManager &manager) : type(clockType), BaseService(state, manager, Service::timesrv_ISystemClock, "timesrv:ISystemClock", {
ISystemClock::ISystemClock(const SystemClockType clockType, const DeviceState &state, ServiceManager &manager) : type(clockType), BaseService(state, manager, {
{0x0, SFUNC(ISystemClock::GetCurrentTime)},
{0x2, SFUNC(ISystemClock::GetSystemClockContext)}
}) {}

View File

@ -4,7 +4,7 @@
#include "ITimeZoneService.h"
namespace skyline::service::timesrv {
ITimeZoneService::ITimeZoneService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::timesrv_ITimeZoneService, "timesrv:ITimeZoneService", {
ITimeZoneService::ITimeZoneService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x65, SFUNC(ITimeZoneService::ToCalendarTimeWithMyRule)}
}) {}

View File

@ -9,7 +9,7 @@
#include "IManagerDisplayService.h"
namespace skyline::service::visrv {
IApplicationDisplayService::IApplicationDisplayService(const DeviceState &state, ServiceManager &manager) : IDisplayService(state, manager, Service::visrv_IApplicationDisplayService, "visrv:IApplicationDisplayService", {
IApplicationDisplayService::IApplicationDisplayService(const DeviceState &state, ServiceManager &manager) : IDisplayService(state, manager, {
{0x64, SFUNC(IApplicationDisplayService::GetRelayService)},
{0x65, SFUNC(IApplicationDisplayService::GetSystemDisplayService)},
{0x66, SFUNC(IApplicationDisplayService::GetManagerDisplayService)},
@ -25,11 +25,11 @@ namespace skyline::service::visrv {
}) {}
void IApplicationDisplayService::GetRelayService(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
manager.RegisterService(SRVREG(hosbinder::IHOSBinderDriver), session, response, false);
manager.RegisterService(SRVREG(hosbinder::IHOSBinderDriver), session, response, false, util::MakeMagic<ServiceName>("dispdrv"));
}
void IApplicationDisplayService::GetIndirectDisplayTransactionService(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
manager.RegisterService(SRVREG(hosbinder::IHOSBinderDriver), session, response, false);
manager.RegisterService(SRVREG(hosbinder::IHOSBinderDriver), session, response, false, util::MakeMagic<ServiceName>("dispdrv"));
}
void IApplicationDisplayService::GetSystemDisplayService(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
@ -43,14 +43,14 @@ namespace skyline::service::visrv {
void IApplicationDisplayService::OpenDisplay(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
std::string displayName(request.PopString());
state.logger->Debug("Setting display as: {}", displayName);
state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver)->SetDisplay(displayName);
state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv")->SetDisplay(displayName);
response.Push<u64>(0); // There's only one display
}
void IApplicationDisplayService::CloseDisplay(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
state.logger->Debug("Closing the display");
state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver)->CloseDisplay();
state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv")->CloseDisplay();
}
void IApplicationDisplayService::OpenLayer(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
@ -80,7 +80,7 @@ namespace skyline::service::visrv {
u64 layerId = request.Pop<u64>();
state.logger->Debug("Closing Layer: {}", layerId);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv");
if (hosBinder->layerStatus == hosbinder::LayerStatus::Uninitialized)
state.logger->Warn("The application is destroying an uninitialized layer");
hosBinder->layerStatus = hosbinder::LayerStatus::Uninitialized;

View File

@ -7,7 +7,7 @@
#include "IDisplayService.h"
namespace skyline::service::visrv {
IDisplayService::IDisplayService(const DeviceState &state, ServiceManager &manager, const Service serviceType, const std::string &serviceName, const std::unordered_map<u32, std::function<void(type::KSession &, ipc::IpcRequest &, ipc::IpcResponse &)>> &vTable) : BaseService(state, manager, serviceType, serviceName, vTable) {}
IDisplayService::IDisplayService(const DeviceState &state, ServiceManager &manager, const std::unordered_map<u32, std::function<void(type::KSession &, ipc::IpcRequest &, ipc::IpcResponse &)>> &vTable) : BaseService(state, manager, vTable) {}
void IDisplayService::CreateStrayLayer(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
request.Skip<u64>();
@ -15,7 +15,7 @@ namespace skyline::service::visrv {
state.logger->Debug("Creating Stray Layer on Display: {}", displayId);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv");
if (hosBinder->layerStatus == hosbinder::LayerStatus::Stray)
throw exception("The application is creating more than one stray layer");
hosBinder->layerStatus = hosbinder::LayerStatus::Stray;
@ -37,7 +37,7 @@ namespace skyline::service::visrv {
auto layerId = request.Pop<u64>();
state.logger->Debug("Destroying Stray Layer: {}", layerId);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv");
if (hosBinder->layerStatus == hosbinder::LayerStatus::Uninitialized)
state.logger->Warn("The application is destroying an uninitialized layer");
hosBinder->layerStatus = hosbinder::LayerStatus::Uninitialized;

View File

@ -8,9 +8,9 @@
#include <services/common/parcel.h>
namespace skyline::service::visrv {
/**
* @brief This is the base class for all IDisplayService variants with common functions
*/
/**
* @brief This is the base class for all IDisplayService variants with common functions
*/
class IDisplayService : public BaseService {
protected:
/**
@ -27,7 +27,7 @@ namespace skyline::service::visrv {
static_assert(sizeof(LayerParcel) == 0x28);
public:
IDisplayService(const DeviceState &state, ServiceManager &manager, const Service serviceType, const std::string &serviceName, const std::unordered_map<u32, std::function<void(type::KSession & , ipc::IpcRequest & , ipc::IpcResponse & )>> &vTable);
IDisplayService(const DeviceState &state, ServiceManager &manager, const std::unordered_map<u32, std::function<void(type::KSession & , ipc::IpcRequest & , ipc::IpcResponse & )>> &vTable);
/**
* @brief This creates a stray layer using a display's ID and returns a layer ID and the corresponding buffer ID

View File

@ -7,7 +7,7 @@
#include "IManagerDisplayService.h"
namespace skyline::service::visrv {
IManagerDisplayService::IManagerDisplayService(const DeviceState &state, ServiceManager &manager) : IDisplayService(state, manager, Service::visrv_IManagerDisplayService, "visrv:IManagerDisplayService", {
IManagerDisplayService::IManagerDisplayService(const DeviceState &state, ServiceManager &manager) : IDisplayService(state, manager, {
{0x7DA, SFUNC(IManagerDisplayService::CreateManagedLayer)},
{0x7DB, SFUNC(IManagerDisplayService::DestroyManagedLayer)},
{0x7DC, SFUNC(IDisplayService::CreateStrayLayer)},
@ -19,7 +19,7 @@ namespace skyline::service::visrv {
auto displayId = request.Pop<u64>();
state.logger->Debug("Creating Managed Layer on Display: {}", displayId);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv");
if (hosBinder->layerStatus != hosbinder::LayerStatus::Uninitialized)
throw exception("The application is creating more than one layer");
hosBinder->layerStatus = hosbinder::LayerStatus::Managed;
@ -31,7 +31,7 @@ namespace skyline::service::visrv {
auto layerId = request.Pop<u64>();
state.logger->Debug("Destroying Managed Layer: {}", layerId);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>(Service::hosbinder_IHOSBinderDriver);
auto hosBinder = state.os->serviceManager.GetService<hosbinder::IHOSBinderDriver>("dispdrv");
if (hosBinder->layerStatus == hosbinder::LayerStatus::Uninitialized)
state.logger->Warn("The application is destroying an uninitialized layer");

View File

@ -6,7 +6,7 @@
#include "IApplicationDisplayService.h"
namespace skyline::service::visrv {
IManagerRootService::IManagerRootService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::visrv_IManagerRootService, "visrv:IManagerRootService", {
IManagerRootService::IManagerRootService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, {
{0x2, SFUNC(IManagerRootService::GetDisplayService)}
}) {}

View File

@ -4,7 +4,7 @@
#include "ISystemDisplayService.h"
namespace skyline::service::visrv {
ISystemDisplayService::ISystemDisplayService(const DeviceState &state, ServiceManager &manager) : IDisplayService(state, manager, Service::visrv_ISystemDisplayService, "visrv:ISystemDisplayService", {
ISystemDisplayService::ISystemDisplayService(const DeviceState &state, ServiceManager &manager) : IDisplayService(state, manager, {
{0x89D, SFUNC(ISystemDisplayService::SetLayerZ)},
{0x908, SFUNC(IDisplayService::CreateStrayLayer)}
}) {}