diff options
| author | 2021-09-28 23:42:50 -0400 | |
|---|---|---|
| committer | 2021-10-01 23:38:59 -0400 | |
| commit | fadcee14f8fca1b76b4ea48b1cfd136ccae8d182 (patch) | |
| tree | a5787938bc73ff1b0b539e0945d3544d06a7d6d2 /src/core/hle/service/nfp | |
| parent | Merge pull request #7102 from Morph1984/remove-boxcat (diff) | |
| download | yuzu-fadcee14f8fca1b76b4ea48b1cfd136ccae8d182.tar.gz yuzu-fadcee14f8fca1b76b4ea48b1cfd136ccae8d182.tar.xz yuzu-fadcee14f8fca1b76b4ea48b1cfd136ccae8d182.zip | |
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.
Diffstat (limited to 'src/core/hle/service/nfp')
| -rw-r--r-- | src/core/hle/service/nfp/nfp.cpp | 49 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp.h | 11 |
2 files changed, 34 insertions, 26 deletions
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 5f1ca029d..6791f20a5 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -8,9 +8,8 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/core.h" | 9 | #include "core/core.h" |
| 10 | #include "core/hle/ipc_helpers.h" | 10 | #include "core/hle/ipc_helpers.h" |
| 11 | #include "core/hle/kernel/k_readable_event.h" | 11 | #include "core/hle/kernel/k_event.h" |
| 12 | #include "core/hle/kernel/k_thread.h" | 12 | #include "core/hle/kernel/k_thread.h" |
| 13 | #include "core/hle/kernel/k_writable_event.h" | ||
| 14 | #include "core/hle/kernel/kernel.h" | 13 | #include "core/hle/kernel/kernel.h" |
| 15 | #include "core/hle/lock.h" | 14 | #include "core/hle/lock.h" |
| 16 | #include "core/hle/service/nfp/nfp.h" | 15 | #include "core/hle/service/nfp/nfp.h" |
| @@ -23,18 +22,21 @@ constexpr ResultCode ERR_NO_APPLICATION_AREA(ErrorModule::NFP, 152); | |||
| 23 | 22 | ||
| 24 | Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_, | 23 | Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_, |
| 25 | const char* name) | 24 | const char* name) |
| 26 | : ServiceFramework{system_, name}, nfc_tag_load{system.Kernel()}, module{std::move(module_)} { | 25 | : ServiceFramework{system_, name}, module{std::move(module_)}, service_context{system_, |
| 27 | Kernel::KAutoObject::Create(std::addressof(nfc_tag_load)); | 26 | "NFP::IUser"} { |
| 28 | nfc_tag_load.Initialize("IUser:NFCTagDetected"); | 27 | nfc_tag_load = service_context.CreateEvent("NFP::IUser:NFCTagDetected"); |
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | Module::Interface::~Interface() = default; | 30 | Module::Interface::~Interface() { |
| 31 | service_context.CloseEvent(nfc_tag_load); | ||
| 32 | } | ||
| 32 | 33 | ||
| 33 | class IUser final : public ServiceFramework<IUser> { | 34 | class IUser final : public ServiceFramework<IUser> { |
| 34 | public: | 35 | public: |
| 35 | explicit IUser(Module::Interface& nfp_interface_, Core::System& system_) | 36 | explicit IUser(Module::Interface& nfp_interface_, Core::System& system_, |
| 37 | KernelHelpers::ServiceContext& service_context_) | ||
| 36 | : ServiceFramework{system_, "NFP::IUser"}, nfp_interface{nfp_interface_}, | 38 | : ServiceFramework{system_, "NFP::IUser"}, nfp_interface{nfp_interface_}, |
| 37 | deactivate_event{system.Kernel()}, availability_change_event{system.Kernel()} { | 39 | service_context{service_context_} { |
| 38 | static const FunctionInfo functions[] = { | 40 | static const FunctionInfo functions[] = { |
| 39 | {0, &IUser::Initialize, "Initialize"}, | 41 | {0, &IUser::Initialize, "Initialize"}, |
| 40 | {1, &IUser::Finalize, "Finalize"}, | 42 | {1, &IUser::Finalize, "Finalize"}, |
| @@ -64,11 +66,14 @@ public: | |||
| 64 | }; | 66 | }; |
| 65 | RegisterHandlers(functions); | 67 | RegisterHandlers(functions); |
| 66 | 68 | ||
| 67 | Kernel::KAutoObject::Create(std::addressof(deactivate_event)); | 69 | deactivate_event = service_context.CreateEvent("NFP::IUser:DeactivateEvent"); |
| 68 | Kernel::KAutoObject::Create(std::addressof(availability_change_event)); | 70 | availability_change_event = |
| 71 | service_context.CreateEvent("NFP::IUser:AvailabilityChangeEvent"); | ||
| 72 | } | ||
| 69 | 73 | ||
| 70 | deactivate_event.Initialize("IUser:DeactivateEvent"); | 74 | ~IUser() override { |
| 71 | availability_change_event.Initialize("IUser:AvailabilityChangeEvent"); | 75 | service_context.CloseEvent(deactivate_event); |
| 76 | service_context.CloseEvent(availability_change_event); | ||
| 72 | } | 77 | } |
| 73 | 78 | ||
| 74 | private: | 79 | private: |
| @@ -166,7 +171,7 @@ private: | |||
| 166 | 171 | ||
| 167 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 172 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 168 | rb.Push(ResultSuccess); | 173 | rb.Push(ResultSuccess); |
| 169 | rb.PushCopyObjects(deactivate_event.GetReadableEvent()); | 174 | rb.PushCopyObjects(deactivate_event->GetReadableEvent()); |
| 170 | } | 175 | } |
| 171 | 176 | ||
| 172 | void StopDetection(Kernel::HLERequestContext& ctx) { | 177 | void StopDetection(Kernel::HLERequestContext& ctx) { |
| @@ -175,7 +180,7 @@ private: | |||
| 175 | switch (device_state) { | 180 | switch (device_state) { |
| 176 | case DeviceState::TagFound: | 181 | case DeviceState::TagFound: |
| 177 | case DeviceState::TagNearby: | 182 | case DeviceState::TagNearby: |
| 178 | deactivate_event.GetWritableEvent().Signal(); | 183 | deactivate_event->GetWritableEvent().Signal(); |
| 179 | device_state = DeviceState::Initialized; | 184 | device_state = DeviceState::Initialized; |
| 180 | break; | 185 | break; |
| 181 | case DeviceState::SearchingForTag: | 186 | case DeviceState::SearchingForTag: |
| @@ -264,7 +269,7 @@ private: | |||
| 264 | 269 | ||
| 265 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 270 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 266 | rb.Push(ResultSuccess); | 271 | rb.Push(ResultSuccess); |
| 267 | rb.PushCopyObjects(availability_change_event.GetReadableEvent()); | 272 | rb.PushCopyObjects(availability_change_event->GetReadableEvent()); |
| 268 | } | 273 | } |
| 269 | 274 | ||
| 270 | void GetRegisterInfo(Kernel::HLERequestContext& ctx) { | 275 | void GetRegisterInfo(Kernel::HLERequestContext& ctx) { |
| @@ -313,14 +318,16 @@ private: | |||
| 313 | rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub | 318 | rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub |
| 314 | } | 319 | } |
| 315 | 320 | ||
| 321 | Module::Interface& nfp_interface; | ||
| 322 | KernelHelpers::ServiceContext& service_context; | ||
| 323 | |||
| 316 | bool has_attached_handle{}; | 324 | bool has_attached_handle{}; |
| 317 | const u64 device_handle{0}; // Npad device 1 | 325 | const u64 device_handle{0}; // Npad device 1 |
| 318 | const u32 npad_id{0}; // Player 1 controller | 326 | const u32 npad_id{0}; // Player 1 controller |
| 319 | State state{State::NonInitialized}; | 327 | State state{State::NonInitialized}; |
| 320 | DeviceState device_state{DeviceState::Initialized}; | 328 | DeviceState device_state{DeviceState::Initialized}; |
| 321 | Module::Interface& nfp_interface; | 329 | Kernel::KEvent* deactivate_event; |
| 322 | Kernel::KEvent deactivate_event; | 330 | Kernel::KEvent* availability_change_event; |
| 323 | Kernel::KEvent availability_change_event; | ||
| 324 | }; | 331 | }; |
| 325 | 332 | ||
| 326 | void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { | 333 | void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { |
| @@ -328,7 +335,7 @@ void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { | |||
| 328 | 335 | ||
| 329 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 336 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 330 | rb.Push(ResultSuccess); | 337 | rb.Push(ResultSuccess); |
| 331 | rb.PushIpcInterface<IUser>(*this, system); | 338 | rb.PushIpcInterface<IUser>(*this, system, service_context); |
| 332 | } | 339 | } |
| 333 | 340 | ||
| 334 | bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { | 341 | bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { |
| @@ -338,12 +345,12 @@ bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { | |||
| 338 | } | 345 | } |
| 339 | 346 | ||
| 340 | std::memcpy(&amiibo, buffer.data(), sizeof(amiibo)); | 347 | std::memcpy(&amiibo, buffer.data(), sizeof(amiibo)); |
| 341 | nfc_tag_load.GetWritableEvent().Signal(); | 348 | nfc_tag_load->GetWritableEvent().Signal(); |
| 342 | return true; | 349 | return true; |
| 343 | } | 350 | } |
| 344 | 351 | ||
| 345 | Kernel::KReadableEvent& Module::Interface::GetNFCEvent() { | 352 | Kernel::KReadableEvent& Module::Interface::GetNFCEvent() { |
| 346 | return nfc_tag_load.GetReadableEvent(); | 353 | return nfc_tag_load->GetReadableEvent(); |
| 347 | } | 354 | } |
| 348 | 355 | ||
| 349 | const Module::Interface::AmiiboFile& Module::Interface::GetAmiiboBuffer() const { | 356 | const Module::Interface::AmiiboFile& Module::Interface::GetAmiiboBuffer() const { |
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h index 5e4e49bc6..95c127efb 100644 --- a/src/core/hle/service/nfp/nfp.h +++ b/src/core/hle/service/nfp/nfp.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <vector> | 8 | #include <vector> |
| 9 | 9 | ||
| 10 | #include "core/hle/kernel/k_event.h" | 10 | #include "core/hle/service/kernel_helpers.h" |
| 11 | #include "core/hle/service/service.h" | 11 | #include "core/hle/service/service.h" |
| 12 | 12 | ||
| 13 | namespace Kernel { | 13 | namespace Kernel { |
| @@ -42,12 +42,13 @@ public: | |||
| 42 | Kernel::KReadableEvent& GetNFCEvent(); | 42 | Kernel::KReadableEvent& GetNFCEvent(); |
| 43 | const AmiiboFile& GetAmiiboBuffer() const; | 43 | const AmiiboFile& GetAmiiboBuffer() const; |
| 44 | 44 | ||
| 45 | private: | ||
| 46 | Kernel::KEvent nfc_tag_load; | ||
| 47 | AmiiboFile amiibo{}; | ||
| 48 | |||
| 49 | protected: | 45 | protected: |
| 50 | std::shared_ptr<Module> module; | 46 | std::shared_ptr<Module> module; |
| 47 | |||
| 48 | private: | ||
| 49 | KernelHelpers::ServiceContext service_context; | ||
| 50 | Kernel::KEvent* nfc_tag_load; | ||
| 51 | AmiiboFile amiibo{}; | ||
| 51 | }; | 52 | }; |
| 52 | }; | 53 | }; |
| 53 | 54 | ||