summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-07-24 03:23:56 +0200
committerGitHub <noreply@github.com>2021-07-24 03:23:56 +0200
commit2656020608e32f1f0120dead047b61302bcb4461 (patch)
tree0f4b89d1e51ceb1232eec020d0fe22c7d8b7f930 /src/core/hle/service
parentMerge pull request #6686 from ReinUsesLisp/vk-optimal-copy (diff)
parenthle: service: kernel_helpers: Remove unnecessary pragma once. (diff)
downloadyuzu-2656020608e32f1f0120dead047b61302bcb4461.tar
yuzu-2656020608e32f1f0120dead047b61302bcb4461.tar.gz
yuzu-2656020608e32f1f0120dead047b61302bcb4461.tar.bz2
yuzu-2656020608e32f1f0120dead047b61302bcb4461.tar.lz
yuzu-2656020608e32f1f0120dead047b61302bcb4461.tar.xz
yuzu-2656020608e32f1f0120dead047b61302bcb4461.tar.zst
yuzu-2656020608e32f1f0120dead047b61302bcb4461.zip
Diffstat (limited to 'src/core/hle/service')
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp13
-rw-r--r--src/core/hle/service/hid/controllers/npad.h8
-rw-r--r--src/core/hle/service/hid/hid.cpp14
-rw-r--r--src/core/hle/service/hid/hid.h13
-rw-r--r--src/core/hle/service/kernel_helpers.cpp62
-rw-r--r--src/core/hle/service/kernel_helpers.h35
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.cpp11
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.h3
-rw-r--r--src/core/hle/service/service.cpp11
-rw-r--r--src/core/hle/service/service.h7
-rw-r--r--src/core/hle/service/sm/sm.cpp65
-rw-r--r--src/core/hle/service/sm/sm.h14
12 files changed, 189 insertions, 67 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 6ce1360e3..b7f551e40 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -18,6 +18,7 @@
#include "core/hle/kernel/k_writable_event.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/service/hid/controllers/npad.h"
+#include "core/hle/service/kernel_helpers.h"
namespace Service::HID {
constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
@@ -147,7 +148,9 @@ bool Controller_NPad::IsDeviceHandleValid(const DeviceHandle& device_handle) {
device_handle.device_index < DeviceIndex::MaxDeviceIndex;
}
-Controller_NPad::Controller_NPad(Core::System& system_) : ControllerBase{system_} {
+Controller_NPad::Controller_NPad(Core::System& system_,
+ KernelHelpers::ServiceContext& service_context_)
+ : ControllerBase{system_}, service_context{service_context_} {
latest_vibration_values.fill({DEFAULT_VIBRATION_VALUE, DEFAULT_VIBRATION_VALUE});
}
@@ -251,10 +254,9 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
}
void Controller_NPad::OnInit() {
- auto& kernel = system.Kernel();
for (std::size_t i = 0; i < styleset_changed_events.size(); ++i) {
- styleset_changed_events[i] = Kernel::KEvent::Create(kernel);
- styleset_changed_events[i]->Initialize(fmt::format("npad:NpadStyleSetChanged_{}", i));
+ styleset_changed_events[i] =
+ service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i));
}
if (!IsControllerActivated()) {
@@ -344,8 +346,7 @@ void Controller_NPad::OnRelease() {
}
for (std::size_t i = 0; i < styleset_changed_events.size(); ++i) {
- styleset_changed_events[i]->Close();
- styleset_changed_events[i] = nullptr;
+ service_context.CloseEvent(styleset_changed_events[i]);
}
}
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index 1409d82a2..4fcc6f93a 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -20,6 +20,10 @@ class KEvent;
class KReadableEvent;
} // namespace Kernel
+namespace Service::KernelHelpers {
+class ServiceContext;
+}
+
namespace Service::HID {
constexpr u32 NPAD_HANDHELD = 32;
@@ -27,7 +31,8 @@ constexpr u32 NPAD_UNKNOWN = 16; // TODO(ogniK): What is this?
class Controller_NPad final : public ControllerBase {
public:
- explicit Controller_NPad(Core::System& system_);
+ explicit Controller_NPad(Core::System& system_,
+ KernelHelpers::ServiceContext& service_context_);
~Controller_NPad() override;
// Called when the controller is initialized
@@ -566,6 +571,7 @@ private:
std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>,
10>;
+ KernelHelpers::ServiceContext& service_context;
std::mutex mutex;
ButtonArray buttons;
StickArray sticks;
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index d68b023d0..b8b80570d 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -46,8 +46,9 @@ constexpr auto pad_update_ns = std::chrono::nanoseconds{1000 * 1000}; //
constexpr auto motion_update_ns = std::chrono::nanoseconds{15 * 1000 * 1000}; // (15ms, 66.666Hz)
constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000;
-IAppletResource::IAppletResource(Core::System& system_)
- : ServiceFramework{system_, "IAppletResource"} {
+IAppletResource::IAppletResource(Core::System& system_,
+ KernelHelpers::ServiceContext& service_context_)
+ : ServiceFramework{system_, "IAppletResource"}, service_context{service_context_} {
static const FunctionInfo functions[] = {
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
};
@@ -63,7 +64,7 @@ IAppletResource::IAppletResource(Core::System& system_)
MakeController<Controller_Stubbed>(HidController::CaptureButton);
MakeController<Controller_Stubbed>(HidController::InputDetector);
MakeController<Controller_Stubbed>(HidController::UniquePad);
- MakeController<Controller_NPad>(HidController::NPad);
+ MakeControllerWithServiceContext<Controller_NPad>(HidController::NPad);
MakeController<Controller_Gesture>(HidController::Gesture);
MakeController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor);
@@ -191,13 +192,14 @@ private:
std::shared_ptr<IAppletResource> Hid::GetAppletResource() {
if (applet_resource == nullptr) {
- applet_resource = std::make_shared<IAppletResource>(system);
+ applet_resource = std::make_shared<IAppletResource>(system, service_context);
}
return applet_resource;
}
-Hid::Hid(Core::System& system_) : ServiceFramework{system_, "hid"} {
+Hid::Hid(Core::System& system_)
+ : ServiceFramework{system_, "hid"}, service_context{system_, service_name} {
// clang-format off
static const FunctionInfo functions[] = {
{0, &Hid::CreateAppletResource, "CreateAppletResource"},
@@ -347,7 +349,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>(system);
+ applet_resource = std::make_shared<IAppletResource>(system, service_context);
}
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index 83fc2ea1d..9c5c7f252 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -7,6 +7,7 @@
#include <chrono>
#include "core/hle/service/hid/controllers/controller_base.h"
+#include "core/hle/service/kernel_helpers.h"
#include "core/hle/service/service.h"
namespace Core::Timing {
@@ -39,7 +40,8 @@ enum class HidController : std::size_t {
class IAppletResource final : public ServiceFramework<IAppletResource> {
public:
- explicit IAppletResource(Core::System& system_);
+ explicit IAppletResource(Core::System& system_,
+ KernelHelpers::ServiceContext& service_context_);
~IAppletResource() override;
void ActivateController(HidController controller);
@@ -60,11 +62,18 @@ private:
void MakeController(HidController controller) {
controllers[static_cast<std::size_t>(controller)] = std::make_unique<T>(system);
}
+ template <typename T>
+ void MakeControllerWithServiceContext(HidController controller) {
+ controllers[static_cast<std::size_t>(controller)] =
+ std::make_unique<T>(system, service_context);
+ }
void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx);
void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
+ KernelHelpers::ServiceContext& service_context;
+
std::shared_ptr<Core::Timing::EventType> pad_update_event;
std::shared_ptr<Core::Timing::EventType> motion_update_event;
@@ -176,6 +185,8 @@ private:
static_assert(sizeof(VibrationDeviceInfo) == 0x8, "VibrationDeviceInfo has incorrect size.");
std::shared_ptr<IAppletResource> applet_resource;
+
+ KernelHelpers::ServiceContext service_context;
};
/// Reload input devices. Used when input configuration changed
diff --git a/src/core/hle/service/kernel_helpers.cpp b/src/core/hle/service/kernel_helpers.cpp
new file mode 100644
index 000000000..62f4cdfb2
--- /dev/null
+++ b/src/core/hle/service/kernel_helpers.cpp
@@ -0,0 +1,62 @@
+// Copyright 2021 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "core/core.h"
+#include "core/hle/kernel/k_event.h"
+#include "core/hle/kernel/k_process.h"
+#include "core/hle/kernel/k_readable_event.h"
+#include "core/hle/kernel/k_resource_limit.h"
+#include "core/hle/kernel/k_scoped_resource_reservation.h"
+#include "core/hle/kernel/k_writable_event.h"
+#include "core/hle/service/kernel_helpers.h"
+
+namespace Service::KernelHelpers {
+
+ServiceContext::ServiceContext(Core::System& system_, std::string name_)
+ : kernel(system_.Kernel()) {
+ process = Kernel::KProcess::Create(kernel);
+ ASSERT(Kernel::KProcess::Initialize(process, system_, std::move(name_),
+ Kernel::KProcess::ProcessType::Userland)
+ .IsSuccess());
+}
+
+ServiceContext::~ServiceContext() {
+ process->Close();
+ process = nullptr;
+}
+
+Kernel::KEvent* ServiceContext::CreateEvent(std::string&& name) {
+ // Reserve a new event from the process resource limit
+ Kernel::KScopedResourceReservation event_reservation(process,
+ Kernel::LimitableResource::Events);
+ if (!event_reservation.Succeeded()) {
+ LOG_CRITICAL(Service, "Resource limit reached!");
+ return {};
+ }
+
+ // Create a new event.
+ auto* event = Kernel::KEvent::Create(kernel);
+ if (!event) {
+ LOG_CRITICAL(Service, "Unable to create event!");
+ return {};
+ }
+
+ // Initialize the event.
+ event->Initialize(std::move(name));
+
+ // Commit the thread reservation.
+ event_reservation.Commit();
+
+ // Register the event.
+ Kernel::KEvent::Register(kernel, event);
+
+ return event;
+}
+
+void ServiceContext::CloseEvent(Kernel::KEvent* event) {
+ event->GetReadableEvent().Close();
+ event->GetWritableEvent().Close();
+}
+
+} // namespace Service::KernelHelpers
diff --git a/src/core/hle/service/kernel_helpers.h b/src/core/hle/service/kernel_helpers.h
new file mode 100644
index 000000000..4f3e95f67
--- /dev/null
+++ b/src/core/hle/service/kernel_helpers.h
@@ -0,0 +1,35 @@
+// Copyright 2021 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <string>
+
+namespace Core {
+class System;
+}
+
+namespace Kernel {
+class KernelCore;
+class KEvent;
+class KProcess;
+} // namespace Kernel
+
+namespace Service::KernelHelpers {
+
+class ServiceContext {
+public:
+ ServiceContext(Core::System& system_, std::string name_);
+ ~ServiceContext();
+
+ Kernel::KEvent* CreateEvent(std::string&& name);
+
+ void CloseEvent(Kernel::KEvent* event);
+
+private:
+ Kernel::KernelCore& kernel;
+ Kernel::KProcess* process{};
+};
+
+} // namespace Service::KernelHelpers
diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp
index 03992af5e..ff405099a 100644
--- a/src/core/hle/service/nvdrv/nvdrv.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv.cpp
@@ -39,11 +39,11 @@ void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger
nvflinger.SetNVDrvInstance(module_);
}
-Module::Module(Core::System& system) : syncpoint_manager{system.GPU()} {
- auto& kernel = system.Kernel();
+Module::Module(Core::System& system)
+ : syncpoint_manager{system.GPU()}, service_context{system, "nvdrv"} {
for (u32 i = 0; i < MaxNvEvents; i++) {
- events_interface.events[i].event = Kernel::KEvent::Create(kernel);
- events_interface.events[i].event->Initialize(fmt::format("NVDRV::NvEvent_{}", i));
+ events_interface.events[i].event =
+ service_context.CreateEvent(fmt::format("NVDRV::NvEvent_{}", i));
events_interface.status[i] = EventState::Free;
events_interface.registered[i] = false;
}
@@ -65,8 +65,7 @@ Module::Module(Core::System& system) : syncpoint_manager{system.GPU()} {
Module::~Module() {
for (u32 i = 0; i < MaxNvEvents; i++) {
- events_interface.events[i].event->Close();
- events_interface.events[i].event = nullptr;
+ service_context.CloseEvent(events_interface.events[i].event);
}
}
diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h
index a43ceb7ae..e2a1dde5b 100644
--- a/src/core/hle/service/nvdrv/nvdrv.h
+++ b/src/core/hle/service/nvdrv/nvdrv.h
@@ -9,6 +9,7 @@
#include <vector>
#include "common/common_types.h"
+#include "core/hle/service/kernel_helpers.h"
#include "core/hle/service/nvdrv/nvdata.h"
#include "core/hle/service/nvdrv/syncpoint_manager.h"
#include "core/hle/service/service.h"
@@ -154,6 +155,8 @@ private:
std::unordered_map<std::string, std::shared_ptr<Devices::nvdevice>> devices;
EventInterface events_interface;
+
+ KernelHelpers::ServiceContext service_context;
};
/// Registers all NVDRV services with the specified service manager.
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index e6fba88b2..b3e50433b 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -104,23 +104,22 @@ ServiceFrameworkBase::~ServiceFrameworkBase() {
void ServiceFrameworkBase::InstallAsService(SM::ServiceManager& service_manager) {
const auto guard = LockService();
- ASSERT(!port_installed);
+ ASSERT(!service_registered);
- auto port = service_manager.RegisterService(service_name, max_sessions).Unwrap();
- port->SetSessionHandler(shared_from_this());
- port_installed = true;
+ service_manager.RegisterService(service_name, max_sessions, shared_from_this());
+ service_registered = true;
}
Kernel::KClientPort& ServiceFrameworkBase::CreatePort() {
const auto guard = LockService();
- ASSERT(!port_installed);
+ ASSERT(!service_registered);
auto* port = Kernel::KPort::Create(kernel);
port->Initialize(max_sessions, false, service_name);
port->GetServerPort().SetSessionHandler(shared_from_this());
- port_installed = true;
+ service_registered = true;
return port->GetClientPort();
}
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index e078ac176..c9d6b879d 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -96,6 +96,9 @@ protected:
/// System context that the service operates under.
Core::System& system;
+ /// Identifier string used to connect to the service.
+ std::string service_name;
+
private:
template <typename T>
friend class ServiceFramework;
@@ -117,14 +120,12 @@ private:
void RegisterHandlersBaseTipc(const FunctionInfoBase* functions, std::size_t n);
void ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info);
- /// Identifier string used to connect to the service.
- std::string service_name;
/// Maximum number of concurrent sessions that this service can handle.
u32 max_sessions;
/// Flag to store if a port was already create/installed to detect multiple install attempts,
/// which is not supported.
- bool port_installed = false;
+ bool service_registered = false;
/// Function used to safely up-cast pointers to the derived class before invoking a handler.
InvokerFn* handler_invoker;
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp
index 15034abed..ae4dc4a75 100644
--- a/src/core/hle/service/sm/sm.cpp
+++ b/src/core/hle/service/sm/sm.cpp
@@ -4,6 +4,7 @@
#include <tuple>
#include "common/assert.h"
+#include "common/scope_exit.h"
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/k_client_port.h"
@@ -40,17 +41,13 @@ static ResultCode ValidateServiceName(const std::string& name) {
}
Kernel::KClientPort& ServiceManager::InterfaceFactory(ServiceManager& self, Core::System& system) {
- ASSERT(self.sm_interface.expired());
-
- auto sm = std::make_shared<SM>(self, system);
- self.sm_interface = sm;
+ self.sm_interface = std::make_shared<SM>(self, system);
self.controller_interface = std::make_unique<Controller>(system);
-
- return sm->CreatePort();
+ return self.sm_interface->CreatePort();
}
-ResultVal<Kernel::KServerPort*> ServiceManager::RegisterService(std::string name,
- u32 max_sessions) {
+ResultCode ServiceManager::RegisterService(std::string name, u32 max_sessions,
+ Kernel::SessionRequestHandlerPtr handler) {
CASCADE_CODE(ValidateServiceName(name));
@@ -59,12 +56,9 @@ ResultVal<Kernel::KServerPort*> ServiceManager::RegisterService(std::string name
return ERR_ALREADY_REGISTERED;
}
- auto* port = Kernel::KPort::Create(kernel);
- port->Initialize(max_sessions, false, name);
+ registered_services.emplace(std::move(name), handler);
- registered_services.emplace(std::move(name), port);
-
- return MakeResult(&port->GetServerPort());
+ return ResultSuccess;
}
ResultCode ServiceManager::UnregisterService(const std::string& name) {
@@ -76,14 +70,11 @@ ResultCode ServiceManager::UnregisterService(const std::string& name) {
return ERR_SERVICE_NOT_REGISTERED;
}
- iter->second->Close();
-
registered_services.erase(iter);
return ResultSuccess;
}
ResultVal<Kernel::KPort*> ServiceManager::GetServicePort(const std::string& name) {
-
CASCADE_CODE(ValidateServiceName(name));
auto it = registered_services.find(name);
if (it == registered_services.end()) {
@@ -91,10 +82,13 @@ ResultVal<Kernel::KPort*> ServiceManager::GetServicePort(const std::string& name
return ERR_SERVICE_NOT_REGISTERED;
}
- return MakeResult(it->second);
-}
+ auto* port = Kernel::KPort::Create(kernel);
+ port->Initialize(ServerSessionCountMax, false, name);
+ auto handler = it->second;
+ port->GetServerPort().SetSessionHandler(std::move(handler));
-SM::~SM() = default;
+ return MakeResult(port);
+}
/**
* SM::Initialize service function
@@ -156,11 +150,15 @@ ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(Kernel::HLERequestContext&
LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, port_result.Code().raw);
return port_result.Code();
}
- auto& port = port_result.Unwrap()->GetClientPort();
+ auto& port = port_result.Unwrap();
+ SCOPE_EXIT({ port->GetClientPort().Close(); });
+
+ server_ports.emplace_back(&port->GetServerPort());
// Create a new session.
Kernel::KClientSession* session{};
- if (const auto result = port.CreateSession(std::addressof(session)); result.IsError()) {
+ if (const auto result = port->GetClientPort().CreateSession(std::addressof(session));
+ result.IsError()) {
LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, result.raw);
return result;
}
@@ -180,20 +178,21 @@ void SM::RegisterService(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_SM, "called with name={}, max_session_count={}, is_light={}", name,
max_session_count, is_light);
- auto handle = service_manager.RegisterService(name, max_session_count);
- if (handle.Failed()) {
- LOG_ERROR(Service_SM, "failed to register service with error_code={:08X}",
- handle.Code().raw);
+ if (const auto result = service_manager.RegisterService(name, max_session_count, nullptr);
+ result.IsError()) {
+ LOG_ERROR(Service_SM, "failed to register service with error_code={:08X}", result.raw);
IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(handle.Code());
+ rb.Push(result);
return;
}
- IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
- rb.Push(handle.Code());
+ auto* port = Kernel::KPort::Create(kernel);
+ port->Initialize(ServerSessionCountMax, is_light, name);
+ SCOPE_EXIT({ port->GetClientPort().Close(); });
- auto server_port = handle.Unwrap();
- rb.PushMoveObjects(server_port);
+ IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
+ rb.Push(ResultSuccess);
+ rb.PushMoveObjects(port->GetServerPort());
}
void SM::UnregisterService(Kernel::HLERequestContext& ctx) {
@@ -225,4 +224,10 @@ SM::SM(ServiceManager& service_manager_, Core::System& system_)
});
}
+SM::~SM() {
+ for (auto& server_port : server_ports) {
+ server_port->Close();
+ }
+}
+
} // namespace Service::SM
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h
index ea37f11d4..068c78588 100644
--- a/src/core/hle/service/sm/sm.h
+++ b/src/core/hle/service/sm/sm.h
@@ -49,6 +49,7 @@ private:
ServiceManager& service_manager;
bool is_initialized{};
Kernel::KernelCore& kernel;
+ std::vector<Kernel::KServerPort*> server_ports;
};
class ServiceManager {
@@ -58,7 +59,8 @@ public:
explicit ServiceManager(Kernel::KernelCore& kernel_);
~ServiceManager();
- ResultVal<Kernel::KServerPort*> RegisterService(std::string name, u32 max_sessions);
+ ResultCode RegisterService(std::string name, u32 max_sessions,
+ Kernel::SessionRequestHandlerPtr handler);
ResultCode UnregisterService(const std::string& name);
ResultVal<Kernel::KPort*> GetServicePort(const std::string& name);
@@ -69,21 +71,17 @@ public:
LOG_DEBUG(Service, "Can't find service: {}", service_name);
return nullptr;
}
- auto* port = service->second;
- if (port == nullptr) {
- return nullptr;
- }
- return std::static_pointer_cast<T>(port->GetServerPort().GetSessionRequestHandler());
+ return std::static_pointer_cast<T>(service->second);
}
void InvokeControlRequest(Kernel::HLERequestContext& context);
private:
- std::weak_ptr<SM> sm_interface;
+ std::shared_ptr<SM> sm_interface;
std::unique_ptr<Controller> controller_interface;
/// Map of registered services, retrieved using GetServicePort.
- std::unordered_map<std::string, Kernel::KPort*> registered_services;
+ std::unordered_map<std::string, Kernel::SessionRequestHandlerPtr> registered_services;
/// Kernel context
Kernel::KernelCore& kernel;