From fadcee14f8fca1b76b4ea48b1cfd136ccae8d182 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Tue, 28 Sep 2021 23:42:50 -0400 Subject: service: Replace service event creation with ServiceContext::CreateEvent The service context helps to manage all created events and allows us to close them upon destruction. --- src/core/hle/service/friend/friend.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/core/hle/service/friend') diff --git a/src/core/hle/service/friend/friend.cpp b/src/core/hle/service/friend/friend.cpp index b58c152ce..68c9240ae 100644 --- a/src/core/hle/service/friend/friend.cpp +++ b/src/core/hle/service/friend/friend.cpp @@ -8,11 +8,10 @@ #include "core/core.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" -#include "core/hle/kernel/k_readable_event.h" -#include "core/hle/kernel/k_writable_event.h" #include "core/hle/service/friend/errors.h" #include "core/hle/service/friend/friend.h" #include "core/hle/service/friend/friend_interface.h" +#include "core/hle/service/kernel_helpers.h" namespace Service::Friend { @@ -184,9 +183,9 @@ private: class INotificationService final : public ServiceFramework { public: - explicit INotificationService(Common::UUID uuid_, Core::System& system_) - : ServiceFramework{system_, "INotificationService"}, uuid{uuid_}, notification_event{ - system.Kernel()} { + explicit INotificationService(Core::System& system_, Common::UUID uuid_) + : ServiceFramework{system_, "INotificationService"}, uuid{uuid_}, + service_context{system_, "INotificationService"} { // clang-format off static const FunctionInfo functions[] = { {0, &INotificationService::GetEvent, "GetEvent"}, @@ -197,8 +196,11 @@ public: RegisterHandlers(functions); - Kernel::KAutoObject::Create(std::addressof(notification_event)); - notification_event.Initialize("INotificationService:NotifyEvent"); + notification_event = service_context.CreateEvent("INotificationService:NotifyEvent"); + } + + ~INotificationService() override { + service_context.CloseEvent(notification_event); } private: @@ -207,7 +209,7 @@ private: IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(ResultSuccess); - rb.PushCopyObjects(notification_event.GetReadableEvent()); + rb.PushCopyObjects(notification_event->GetReadableEvent()); } void Clear(Kernel::HLERequestContext& ctx) { @@ -272,8 +274,10 @@ private: bool has_received_friend_request; }; - Common::UUID uuid{Common::INVALID_UUID}; - Kernel::KEvent notification_event; + Common::UUID uuid; + KernelHelpers::ServiceContext service_context; + + Kernel::KEvent* notification_event; std::queue notifications; States states{}; }; @@ -293,7 +297,7 @@ void Module::Interface::CreateNotificationService(Kernel::HLERequestContext& ctx IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface(uuid, system); + rb.PushIpcInterface(system, uuid); } Module::Interface::Interface(std::shared_ptr module_, Core::System& system_, -- cgit v1.2.3