diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp index 6595e34edb..7a8f59725e 100644 --- a/src/core/hle/service/nfc/nfc.cpp +++ b/src/core/hle/service/nfc/nfc.cpp @@ -8,12 +8,83 @@ #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/mifare_user.h" #include "core/hle/service/nfc/nfc.h" -#include "core/hle/service/nfc/nfc_user.h" +#include "core/hle/service/nfc/nfc_interface.h" #include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::NFC { +class IUser final : public Interface { +public: + explicit IUser(Core::System& system_) : Interface(system_, "IUser") { + // clang-format off + static const FunctionInfo functions[] = { + {0, &Interface::Initialize, "InitializeOld"}, + {1, &Interface::Finalize, "FinalizeOld"}, + {2, &Interface::GetState, "GetStateOld"}, + {3, &Interface::IsNfcEnabled, "IsNfcEnabledOld"}, + {400, &Interface::Initialize, "Initialize"}, + {401, &Interface::Finalize, "Finalize"}, + {402, &Interface::GetState, "GetState"}, + {403, &Interface::IsNfcEnabled, "IsNfcEnabled"}, + {404, &Interface::ListDevices, "ListDevices"}, + {405, &Interface::GetDeviceState, "GetDeviceState"}, + {406, &Interface::GetNpadId, "GetNpadId"}, + {407, &Interface::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, + {408, &Interface::StartDetection, "StartDetection"}, + {409, &Interface::StopDetection, "StopDetection"}, + {410, &Interface::GetTagInfo, "GetTagInfo"}, + {411, &Interface::AttachActivateEvent, "AttachActivateEvent"}, + {412, &Interface::AttachDeactivateEvent, "AttachDeactivateEvent"}, + {1000, nullptr, "ReadMifare"}, + {1001, nullptr, "WriteMifare"}, + {1300, &Interface::SendCommandByPassThrough, "SendCommandByPassThrough"}, + {1301, nullptr, "KeepPassThroughSession"}, + {1302, nullptr, "ReleasePassThroughSession"}, + }; + // clang-format on + + RegisterHandlers(functions); + } +}; + +class ISystem final : public Interface { +public: + explicit ISystem(Core::System& system_) : Interface{system_, "ISystem"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, &Interface::Initialize, "InitializeOld"}, + {1, &Interface::Finalize, "FinalizeOld"}, + {2, &Interface::GetState, "GetStateOld"}, + {3, &Interface::IsNfcEnabled, "IsNfcEnabledOld"}, + {100, nullptr, "SetNfcEnabledOld"}, + {400, &Interface::Initialize, "Initialize"}, + {401, &Interface::Finalize, "Finalize"}, + {402, &Interface::GetState, "GetState"}, + {403, &Interface::IsNfcEnabled, "IsNfcEnabled"}, + {404, &Interface::ListDevices, "ListDevices"}, + {405, &Interface::GetDeviceState, "GetDeviceState"}, + {406, &Interface::GetNpadId, "GetNpadId"}, + {407, &Interface::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, + {408, &Interface::StartDetection, "StartDetection"}, + {409, &Interface::StopDetection, "StopDetection"}, + {410, &Interface::GetTagInfo, "GetTagInfo"}, + {411, &Interface::AttachActivateEvent, "AttachActivateEvent"}, + {412, &Interface::AttachDeactivateEvent, "AttachDeactivateEvent"}, + {500, nullptr, "SetNfcEnabled"}, + {510, nullptr, "OutputTestWave"}, + {1000, nullptr, "ReadMifare"}, + {1001, nullptr, "WriteMifare"}, + {1300, &Interface::SendCommandByPassThrough, "SendCommandByPassThrough"}, + {1301, nullptr, "KeepPassThroughSession"}, + {1302, nullptr, "ReleasePassThroughSession"}, + }; + // clang-format on + + RegisterHandlers(functions); + } +}; + class IAm final : public ServiceFramework { public: explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} { @@ -95,43 +166,6 @@ private: } }; -class ISystem final : public ServiceFramework { -public: - explicit ISystem(Core::System& system_) : ServiceFramework{system_, "ISystem"} { - // clang-format off - static const FunctionInfo functions[] = { - {0, nullptr, "Initialize"}, - {1, nullptr, "Finalize"}, - {2, nullptr, "GetStateOld"}, - {3, nullptr, "IsNfcEnabledOld"}, - {100, nullptr, "SetNfcEnabledOld"}, - {400, nullptr, "InitializeSystem"}, - {401, nullptr, "FinalizeSystem"}, - {402, nullptr, "GetState"}, - {403, nullptr, "IsNfcEnabled"}, - {404, nullptr, "ListDevices"}, - {405, nullptr, "GetDeviceState"}, - {406, nullptr, "GetNpadId"}, - {407, nullptr, "AttachAvailabilityChangeEvent"}, - {408, nullptr, "StartDetection"}, - {409, nullptr, "StopDetection"}, - {410, nullptr, "GetTagInfo"}, - {411, nullptr, "AttachActivateEvent"}, - {412, nullptr, "AttachDeactivateEvent"}, - {500, nullptr, "SetNfcEnabled"}, - {510, nullptr, "OutputTestWave"}, - {1000, nullptr, "ReadMifare"}, - {1001, nullptr, "WriteMifare"}, - {1300, nullptr, "SendCommandByPassThrough"}, - {1301, nullptr, "KeepPassThroughSession"}, - {1302, nullptr, "ReleasePassThroughSession"}, - }; - // clang-format on - - RegisterHandlers(functions); - } -}; - class NFC_SYS final : public ServiceFramework { public: explicit NFC_SYS(Core::System& system_) : ServiceFramework{system_, "nfc:sys"} { diff --git a/src/core/hle/service/nfc/nfc_device.cpp b/src/core/hle/service/nfc/nfc_device.cpp index c7db74d14f..47bc1a05dc 100644 --- a/src/core/hle/service/nfc/nfc_device.cpp +++ b/src/core/hle/service/nfc/nfc_device.cpp @@ -11,7 +11,6 @@ #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/nfc_device.h" #include "core/hle/service/nfc/nfc_result.h" -#include "core/hle/service/nfc/nfc_user.h" namespace Service::NFC { NfcDevice::NfcDevice(Core::HID::NpadIdType npad_id_, Core::System& system_, diff --git a/src/core/hle/service/nfc/nfc_user.cpp b/src/core/hle/service/nfc/nfc_interface.cpp similarity index 77% rename from src/core/hle/service/nfc/nfc_user.cpp rename to src/core/hle/service/nfc/nfc_interface.cpp index 7c162a4f31..be96d0cbc6 100644 --- a/src/core/hle/service/nfc/nfc_user.cpp +++ b/src/core/hle/service/nfc/nfc_interface.cpp @@ -7,41 +7,15 @@ #include "core/hle/kernel/k_event.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/nfc_device.h" +#include "core/hle/service/nfc/nfc_interface.h" #include "core/hle/service/nfc/nfc_result.h" -#include "core/hle/service/nfc/nfc_user.h" #include "core/hle/service/time/clock_types.h" namespace Service::NFC { -IUser::IUser(Core::System& system_) - : ServiceFramework{system_, "NFC::IUser"}, service_context{system_, service_name} { - static const FunctionInfo functions[] = { - {0, &IUser::Initialize, "InitializeOld"}, - {1, &IUser::Finalize, "FinalizeOld"}, - {2, &IUser::GetState, "GetStateOld"}, - {3, &IUser::IsNfcEnabled, "IsNfcEnabledOld"}, - {400, &IUser::Initialize, "Initialize"}, - {401, &IUser::Finalize, "Finalize"}, - {402, &IUser::GetState, "GetState"}, - {403, &IUser::IsNfcEnabled, "IsNfcEnabled"}, - {404, &IUser::ListDevices, "ListDevices"}, - {405, &IUser::GetDeviceState, "GetDeviceState"}, - {406, &IUser::GetNpadId, "GetNpadId"}, - {407, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, - {408, &IUser::StartDetection, "StartDetection"}, - {409, &IUser::StopDetection, "StopDetection"}, - {410, &IUser::GetTagInfo, "GetTagInfo"}, - {411, &IUser::AttachActivateEvent, "AttachActivateEvent"}, - {412, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"}, - {1000, nullptr, "ReadMifare"}, - {1001, nullptr, "WriteMifare"}, - {1300, &IUser::SendCommandByPassThrough, "SendCommandByPassThrough"}, - {1301, nullptr, "KeepPassThroughSession"}, - {1302, nullptr, "ReleasePassThroughSession"}, - }; - RegisterHandlers(functions); - - availability_change_event = service_context.CreateEvent("IUser:AvailabilityChangeEvent"); +Interface::Interface(Core::System& system_, const char* name) + : ServiceFramework{system_, name}, service_context{system_, service_name} { + availability_change_event = service_context.CreateEvent("Interface:AvailabilityChangeEvent"); for (u32 device_index = 0; device_index < 10; device_index++) { devices[device_index] = @@ -50,11 +24,11 @@ IUser::IUser(Core::System& system_) } } -IUser ::~IUser() { +Interface ::~Interface() { availability_change_event->Close(); } -void IUser::Initialize(HLERequestContext& ctx) { +void Interface::Initialize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::Initialized; @@ -67,7 +41,7 @@ void IUser::Initialize(HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IUser::Finalize(HLERequestContext& ctx) { +void Interface::Finalize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::NonInitialized; @@ -80,7 +54,7 @@ void IUser::Finalize(HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IUser::GetState(HLERequestContext& ctx) { +void Interface::GetState(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -88,7 +62,7 @@ void IUser::GetState(HLERequestContext& ctx) { rb.PushEnum(state); } -void IUser::IsNfcEnabled(HLERequestContext& ctx) { +void Interface::IsNfcEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -96,7 +70,7 @@ void IUser::IsNfcEnabled(HLERequestContext& ctx) { rb.Push(state != State::NonInitialized); } -void IUser::ListDevices(HLERequestContext& ctx) { +void Interface::ListDevices(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); if (state == State::NonInitialized) { @@ -142,7 +116,7 @@ void IUser::ListDevices(HLERequestContext& ctx) { rb.Push(static_cast(nfp_devices.size())); } -void IUser::GetDeviceState(HLERequestContext& ctx) { +void Interface::GetDeviceState(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -160,7 +134,7 @@ void IUser::GetDeviceState(HLERequestContext& ctx) { rb.PushEnum(device.value()->GetCurrentState()); } -void IUser::GetNpadId(HLERequestContext& ctx) { +void Interface::GetNpadId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -184,7 +158,7 @@ void IUser::GetNpadId(HLERequestContext& ctx) { rb.PushEnum(device.value()->GetNpadId()); } -void IUser::AttachAvailabilityChangeEvent(HLERequestContext& ctx) { +void Interface::AttachAvailabilityChangeEvent(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); if (state == State::NonInitialized) { @@ -198,7 +172,7 @@ void IUser::AttachAvailabilityChangeEvent(HLERequestContext& ctx) { rb.PushCopyObjects(availability_change_event->GetReadableEvent()); } -void IUser::StartDetection(HLERequestContext& ctx) { +void Interface::StartDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto nfp_protocol{rp.PopEnum()}; @@ -223,7 +197,7 @@ void IUser::StartDetection(HLERequestContext& ctx) { rb.Push(result); } -void IUser::StopDetection(HLERequestContext& ctx) { +void Interface::StopDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -247,7 +221,7 @@ void IUser::StopDetection(HLERequestContext& ctx) { rb.Push(result); } -void IUser::GetTagInfo(HLERequestContext& ctx) { +void Interface::GetTagInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -273,7 +247,7 @@ void IUser::GetTagInfo(HLERequestContext& ctx) { rb.Push(result); } -void IUser::AttachActivateEvent(HLERequestContext& ctx) { +void Interface::AttachActivateEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -297,7 +271,7 @@ void IUser::AttachActivateEvent(HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetActivateEvent()); } -void IUser::AttachDeactivateEvent(HLERequestContext& ctx) { +void Interface::AttachDeactivateEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -321,7 +295,7 @@ void IUser::AttachDeactivateEvent(HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetDeactivateEvent()); } -void IUser::SendCommandByPassThrough(HLERequestContext& ctx) { +void Interface::SendCommandByPassThrough(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto timeout{rp.PopRaw()}; @@ -353,7 +327,7 @@ void IUser::SendCommandByPassThrough(HLERequestContext& ctx) { rb.Push(static_cast(out_data.size())); } -std::optional> IUser::GetNfcDevice(u64 handle) { +std::optional> Interface::GetNfcDevice(u64 handle) { for (auto& device : devices) { if (device->GetHandle() == handle) { return device; diff --git a/src/core/hle/service/nfc/nfc_user.h b/src/core/hle/service/nfc/nfc_interface.h similarity index 91% rename from src/core/hle/service/nfc/nfc_user.h rename to src/core/hle/service/nfc/nfc_interface.h index aee046ae85..8c1bf5a599 100644 --- a/src/core/hle/service/nfc/nfc_user.h +++ b/src/core/hle/service/nfc/nfc_interface.h @@ -13,16 +13,10 @@ namespace Service::NFC { class NfcDevice; -class IUser final : public ServiceFramework { +class Interface : public ServiceFramework { public: - explicit IUser(Core::System& system_); - ~IUser(); - -private: - enum class State : u32 { - NonInitialized, - Initialized, - }; + explicit Interface(Core::System& system_, const char* name); + ~Interface(); void Initialize(HLERequestContext& ctx); void Finalize(HLERequestContext& ctx); @@ -39,6 +33,12 @@ private: void AttachDeactivateEvent(HLERequestContext& ctx); void SendCommandByPassThrough(HLERequestContext& ctx); +private: + enum class State : u32 { + NonInitialized, + Initialized, + }; + std::optional> GetNfcDevice(u64 handle); KernelHelpers::ServiceContext service_context; diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 2714f4bea0..2559fe5982 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -152,16 +152,10 @@ private: void CreateUserInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFP, "called"); - if (user_interface == nullptr) { - user_interface = std::make_shared(system); - } - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface(user_interface); + rb.PushIpcInterface(system); } - - std::shared_ptr user_interface; }; class ISystemManager final : public ServiceFramework { @@ -180,16 +174,10 @@ private: void CreateSystemInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFP, "called"); - if (system_interface == nullptr) { - system_interface = std::make_shared(system); - } - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface(system_interface); + rb.PushIpcInterface(system); } - - std::shared_ptr system_interface; }; class IDebugManager final : public ServiceFramework { @@ -208,16 +196,10 @@ private: void CreateDebugInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFP, "called"); - if (system_interface == nullptr) { - system_interface = std::make_shared(system); - } - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface(system_interface); + rb.PushIpcInterface(system); } - - std::shared_ptr system_interface; }; void LoopProcess(Core::System& system) {