From 70ddae58ffae84eabefb90a1964c140d7a27145d Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 18 Nov 2019 10:52:46 -0500 Subject: [PATCH] acc/nfc/nifm: Removed *SetServiceType and moved the service_type param into the actual {service}Initialize() funcs. Removed *ServiceType_NotInitialized and updated the *ServiceType enum values. Minor other changes / improved nifm docs. --- nx/include/switch/services/acc.h | 15 ++++----------- nx/include/switch/services/nfc.h | 28 +++++++--------------------- nx/include/switch/services/nifm.h | 19 ++++++------------- nx/source/runtime/resolver.c | 2 +- nx/source/services/acc.c | 14 ++++---------- nx/source/services/nfc.c | 28 ++++++++-------------------- nx/source/services/nifm.c | 14 ++++---------- 7 files changed, 34 insertions(+), 86 deletions(-) diff --git a/nx/include/switch/services/acc.h b/nx/include/switch/services/acc.h index 388c327f..a41e30cb 100644 --- a/nx/include/switch/services/acc.h +++ b/nx/include/switch/services/acc.h @@ -11,10 +11,9 @@ #define ACC_USER_LIST_SIZE 8 typedef enum { - AccountServiceType_NotInitialized = 0, ///< Same as ::AccountServiceType_Application during \ref accountInitialize. - AccountServiceType_Application = 1, ///< Initializes acc:u0. - AccountServiceType_System = 2, ///< Initializes acc:u1. - AccountServiceType_Administrator = 3, ///< Initializes acc:su. + AccountServiceType_Application = 0, ///< Initializes acc:u0. + AccountServiceType_System = 1, ///< Initializes acc:u1. + AccountServiceType_Administrator = 2, ///< Initializes acc:su. } AccountServiceType; /// Profile @@ -49,14 +48,8 @@ typedef struct { u64 id; ///< Id. } AccountNetworkServiceAccountId; -/** - * @brief Sets the \ref AccountServiceType for initialization. Call this function before \ref accountInitialize, if needed. - * @note By default ::AccountServiceType_NotInitialized will be used. - */ -void accountSetServiceType(AccountServiceType serviceType); - /// Initialize account. -Result accountInitialize(void); +Result accountInitialize(AccountServiceType service_type); /// Exit account. void accountExit(void); diff --git a/nx/include/switch/services/nfc.h b/nx/include/switch/services/nfc.h index 3d0410a2..90d40012 100644 --- a/nx/include/switch/services/nfc.h +++ b/nx/include/switch/services/nfc.h @@ -11,17 +11,15 @@ /// NfpServiceType typedef enum { - NfpServiceType_NotInitialized = 0, ///< Same as ::NfpServiceType_User during \ref nfpInitialize. - NfpServiceType_User = 1, ///< Initializes nfp:user. - NfpServiceType_Debug = 2, ///< Initializes nfp:dbg. - NfpServiceType_System = 3, ///< Initializes nfp:sys. + NfpServiceType_User = 0, ///< Initializes nfp:user. + NfpServiceType_Debug = 1, ///< Initializes nfp:dbg. + NfpServiceType_System = 2, ///< Initializes nfp:sys. } NfpServiceType; /// NfcServiceType typedef enum { - NfcServiceType_NotInitialized = 0, ///< Same as ::NfcServiceType_User during \ref nfcInitialize. - NfcServiceType_User = 1, ///< Initializes nfc:user. - NfcServiceType_System = 3, ///< Initializes nfc:sys. + NfcServiceType_User = 0, ///< Initializes nfc:user. + NfcServiceType_System = 1, ///< Initializes nfc:sys. } NfcServiceType; typedef enum { @@ -146,26 +144,14 @@ typedef struct { u8 handle[0x8]; ///< Handle. } NfcDeviceHandle; -/** - * @brief Sets the \ref NfpServiceType for initialization. Call this function before \ref nfpInitialize, if needed. - * @note By default ::NfpServiceType_NotInitialized will be used. - */ -void nfpSetServiceType(NfpServiceType serviceType); - -/** - * @brief Sets the \ref NfcServiceType for initialization. Call this function before \ref nfcInitialize, if needed. - * @note By default ::NfcServiceType_NotInitialized will be used. - */ -void nfcSetServiceType(NfcServiceType serviceType); - /// Initialize nfp:*. -Result nfpInitialize(void); +Result nfpInitialize(NfpServiceType service_type); /// Exit nfp:*. void nfpExit(void); /// Initialize nfc:*. -Result nfcInitialize(void); +Result nfcInitialize(NfcServiceType service_type); /// Exit nfc:*. void nfcExit(void); diff --git a/nx/include/switch/services/nifm.h b/nx/include/switch/services/nifm.h index 1357c591..04d0cc7a 100644 --- a/nx/include/switch/services/nifm.h +++ b/nx/include/switch/services/nifm.h @@ -10,10 +10,9 @@ #include "../sf/service.h" typedef enum { - NifmServiceType_NotInitialized = 0, ///< Initializes nifm:u. - NifmServiceType_User = 1, ///< Initializes nifm:u. - NifmServiceType_System = 2, ///< Initializes nifm:s. - NifmServiceType_Admin = 3, ///< Initializes nifm:a. + NifmServiceType_User = 0, ///< Initializes nifm:u. + NifmServiceType_System = 1, ///< Initializes nifm:s. + NifmServiceType_Admin = 2, ///< Initializes nifm:a. } NifmServiceType; typedef enum { @@ -29,16 +28,10 @@ typedef enum { NifmInternetConnectionStatus_Connected = 4, ///< Internet is connected. } NifmInternetConnectionStatus; -/** - * @brief Sets the \ref NifmServiceType for initialization. Call this function before \ref nifmInitialize. - * @note By default nifm:u will be used. - */ -void nifmSetServiceType(NifmServiceType serviceType); +/// Initialize nifm. This is used automatically by gethostid(). +Result nifmInitialize(NifmServiceType service_type); -/// Initialize nifm. This is used automatically by \ref socketInitialize. -Result nifmInitialize(void); - -/// Exit nifm. This is used automatically by \ref socketExit. +/// Exit nifm. This is used automatically by gethostid(). void nifmExit(void); /// Gets the Service object for the actual nifm:* service session. diff --git a/nx/source/runtime/resolver.c b/nx/source/runtime/resolver.c index 753731eb..36728b9f 100644 --- a/nx/source/runtime/resolver.c +++ b/nx/source/runtime/resolver.c @@ -584,7 +584,7 @@ int getnameinfo(const struct sockaddr *sa, socklen_t salen, long gethostid(void) { u32 id = INADDR_LOOPBACK; - Result rc = nifmInitialize(); + Result rc = nifmInitialize(NifmServiceType_User); if (R_SUCCEEDED(rc)) { rc = nifmGetCurrentIpAddress(&id); nifmExit(); diff --git a/nx/source/services/acc.c b/nx/source/services/acc.c index e5e57117..0256a68c 100644 --- a/nx/source/services/acc.c +++ b/nx/source/services/acc.c @@ -6,7 +6,7 @@ #include "runtime/env.h" #include "runtime/hosversion.h" -static AccountServiceType g_accServiceType = AccountServiceType_NotInitialized; +static AccountServiceType g_accServiceType; static Service g_accSrv; static AccountUid g_accPreselectedUserID; static bool g_accPreselectedUserInitialized; @@ -15,21 +15,16 @@ static Result _accountInitializeApplicationInfo(void); static Result _accountGetPreselectedUser(AccountUid *uid); -NX_GENERATE_SERVICE_GUARD(account); +NX_GENERATE_SERVICE_GUARD_PARAMS(account, (AccountServiceType service_type), (service_type)); -void accountSetServiceType(AccountServiceType serviceType) { - g_accServiceType = serviceType; -} - -Result _accountInitialize(void) { +Result _accountInitialize(AccountServiceType service_type) { Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); Result rc2=0; AccountUid *userIdEnv = envGetUserIdStorage(); + g_accServiceType = service_type; switch (g_accServiceType) { - case AccountServiceType_NotInitialized: case AccountServiceType_Application: - g_accServiceType = AccountServiceType_Application; rc = smGetService(&g_accSrv, "acc:u0"); if (R_SUCCEEDED(rc)) rc = _accountInitializeApplicationInfo(); break; @@ -58,7 +53,6 @@ Result _accountInitialize(void) { void _accountCleanup(void) { serviceClose(&g_accSrv); - g_accServiceType = AccountServiceType_NotInitialized; } Service* accountGetServiceSession(void) { diff --git a/nx/source/services/nfc.c b/nx/source/services/nfc.c index 9caefe6a..062a505a 100644 --- a/nx/source/services/nfc.c +++ b/nx/source/services/nfc.c @@ -4,8 +4,8 @@ #include "services/applet.h" #include "services/nfc.h" -static NfpServiceType g_nfpServiceType = NfpServiceType_NotInitialized; -static NfcServiceType g_nfcServiceType = NfcServiceType_NotInitialized; +static NfpServiceType g_nfpServiceType; +static NfcServiceType g_nfcServiceType; static Service g_nfpSrv; static Service g_nfpInterface; static Service g_nfcSrv; @@ -30,27 +30,18 @@ static Result _nfcCmdInDevhandleNoOut(Service* srv, const NfcDeviceHandle *handl static Result _nfcCmdInDevhandleOutEvent(Service* srv, const NfcDeviceHandle *handle, Event *out_event, u32 cmd_id); static Result _nfcCmdInDevhandleOutBuffer(Service* srv, const NfcDeviceHandle *handle, void* buf, size_t buf_size, u32 cmd_id); -NX_GENERATE_SERVICE_GUARD(nfp); +NX_GENERATE_SERVICE_GUARD_PARAMS(nfp, (NfpServiceType service_type), (service_type)); -void nfpSetServiceType(NfpServiceType serviceType) { - g_nfpServiceType = serviceType; -} - -void nfcSetServiceType(NfcServiceType serviceType) { - g_nfcServiceType = serviceType; -} - -Result _nfpInitialize(void) { +Result _nfpInitialize(NfpServiceType service_type) { Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); u64 aruid = 0; // If this fails (for example because we're a sysmodule) aruid stays zero appletGetAppletResourceUserId(&aruid); + g_nfpServiceType = service_type; switch (g_nfpServiceType) { - case NfpServiceType_NotInitialized: case NfpServiceType_User: - g_nfpServiceType = NfpServiceType_User; rc = smGetService(&g_nfpSrv, "nfp:user"); break; case NfpServiceType_Debug: @@ -77,22 +68,20 @@ void _nfpCleanup(void) { _nfcCmdNoIO(&g_nfpInterface, 1); // Finalize serviceClose(&g_nfpInterface); serviceClose(&g_nfpSrv); - g_nfpServiceType = NfpServiceType_NotInitialized; } -NX_GENERATE_SERVICE_GUARD(nfc); +NX_GENERATE_SERVICE_GUARD_PARAMS(nfc, (NfcServiceType service_type), (service_type)); -Result _nfcInitialize(void) { +Result _nfcInitialize(NfcServiceType service_type) { Result rc=0; u64 aruid = 0; // If this fails (for example because we're a sysmodule) aruid stays zero appletGetAppletResourceUserId(&aruid); + g_nfcServiceType = service_type; switch (g_nfcServiceType) { - case NfcServiceType_NotInitialized: case NfcServiceType_User: - g_nfcServiceType = NfcServiceType_User; rc = smGetService(&g_nfcSrv, "nfc:user"); break; case NfcServiceType_System: @@ -116,7 +105,6 @@ void _nfcCleanup(void) { _nfcCmdNoIO(&g_nfcInterface, hosversionBefore(4,0,0) ? 1 : 401); // Finalize serviceClose(&g_nfcInterface); serviceClose(&g_nfcSrv); - g_nfcServiceType = NfcServiceType_NotInitialized; } Service* nfpGetServiceSession(void) { diff --git a/nx/source/services/nifm.c b/nx/source/services/nifm.c index c0d001df..d03cbbf0 100644 --- a/nx/source/services/nifm.c +++ b/nx/source/services/nifm.c @@ -2,7 +2,7 @@ #include "services/nifm.h" #include "runtime/hosversion.h" -static NifmServiceType g_nifmServiceType = NifmServiceType_NotInitialized; +static NifmServiceType g_nifmServiceType; static Service g_nifmSrv; static Service g_nifmIGS; @@ -10,18 +10,13 @@ static Service g_nifmIGS; static Result _nifmCreateGeneralService(Service* srv_out); static Result _nifmCreateGeneralServiceOld(Service* srv_out); -NX_GENERATE_SERVICE_GUARD(nifm); +NX_GENERATE_SERVICE_GUARD_PARAMS(nifm, (NifmServiceType service_type), (service_type)); -void nifmSetServiceType(NifmServiceType serviceType) { - g_nifmServiceType = serviceType; -} - -Result _nifmInitialize(void) { +Result _nifmInitialize(NifmServiceType service_type) { Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); + g_nifmServiceType = service_type; switch (g_nifmServiceType) { - case NifmServiceType_NotInitialized: case NifmServiceType_User: - g_nifmServiceType = NifmServiceType_User; rc = smGetService(&g_nifmSrv, "nifm:u"); break; case NifmServiceType_System: @@ -47,7 +42,6 @@ Result _nifmInitialize(void) { void _nifmCleanup(void) { serviceClose(&g_nifmIGS); serviceClose(&g_nifmSrv); - g_nifmServiceType = NifmServiceType_NotInitialized; } Service* nifmGetServiceSession_StaticService(void) {