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.

This commit is contained in:
yellows8 2019-11-18 10:52:46 -05:00
parent d4c0c2dfeb
commit 70ddae58ff
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
7 changed files with 34 additions and 86 deletions

View File

@ -11,10 +11,9 @@
#define ACC_USER_LIST_SIZE 8 #define ACC_USER_LIST_SIZE 8
typedef enum { typedef enum {
AccountServiceType_NotInitialized = 0, ///< Same as ::AccountServiceType_Application during \ref accountInitialize. AccountServiceType_Application = 0, ///< Initializes acc:u0.
AccountServiceType_Application = 1, ///< Initializes acc:u0. AccountServiceType_System = 1, ///< Initializes acc:u1.
AccountServiceType_System = 2, ///< Initializes acc:u1. AccountServiceType_Administrator = 2, ///< Initializes acc:su.
AccountServiceType_Administrator = 3, ///< Initializes acc:su.
} AccountServiceType; } AccountServiceType;
/// Profile /// Profile
@ -49,14 +48,8 @@ typedef struct {
u64 id; ///< Id. u64 id; ///< Id.
} AccountNetworkServiceAccountId; } 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. /// Initialize account.
Result accountInitialize(void); Result accountInitialize(AccountServiceType service_type);
/// Exit account. /// Exit account.
void accountExit(void); void accountExit(void);

View File

@ -11,17 +11,15 @@
/// NfpServiceType /// NfpServiceType
typedef enum { typedef enum {
NfpServiceType_NotInitialized = 0, ///< Same as ::NfpServiceType_User during \ref nfpInitialize. NfpServiceType_User = 0, ///< Initializes nfp:user.
NfpServiceType_User = 1, ///< Initializes nfp:user. NfpServiceType_Debug = 1, ///< Initializes nfp:dbg.
NfpServiceType_Debug = 2, ///< Initializes nfp:dbg. NfpServiceType_System = 2, ///< Initializes nfp:sys.
NfpServiceType_System = 3, ///< Initializes nfp:sys.
} NfpServiceType; } NfpServiceType;
/// NfcServiceType /// NfcServiceType
typedef enum { typedef enum {
NfcServiceType_NotInitialized = 0, ///< Same as ::NfcServiceType_User during \ref nfcInitialize. NfcServiceType_User = 0, ///< Initializes nfc:user.
NfcServiceType_User = 1, ///< Initializes nfc:user. NfcServiceType_System = 1, ///< Initializes nfc:sys.
NfcServiceType_System = 3, ///< Initializes nfc:sys.
} NfcServiceType; } NfcServiceType;
typedef enum { typedef enum {
@ -146,26 +144,14 @@ typedef struct {
u8 handle[0x8]; ///< Handle. u8 handle[0x8]; ///< Handle.
} NfcDeviceHandle; } 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:*. /// Initialize nfp:*.
Result nfpInitialize(void); Result nfpInitialize(NfpServiceType service_type);
/// Exit nfp:*. /// Exit nfp:*.
void nfpExit(void); void nfpExit(void);
/// Initialize nfc:*. /// Initialize nfc:*.
Result nfcInitialize(void); Result nfcInitialize(NfcServiceType service_type);
/// Exit nfc:*. /// Exit nfc:*.
void nfcExit(void); void nfcExit(void);

View File

@ -10,10 +10,9 @@
#include "../sf/service.h" #include "../sf/service.h"
typedef enum { typedef enum {
NifmServiceType_NotInitialized = 0, ///< Initializes nifm:u. NifmServiceType_User = 0, ///< Initializes nifm:u.
NifmServiceType_User = 1, ///< Initializes nifm:u. NifmServiceType_System = 1, ///< Initializes nifm:s.
NifmServiceType_System = 2, ///< Initializes nifm:s. NifmServiceType_Admin = 2, ///< Initializes nifm:a.
NifmServiceType_Admin = 3, ///< Initializes nifm:a.
} NifmServiceType; } NifmServiceType;
typedef enum { typedef enum {
@ -29,16 +28,10 @@ typedef enum {
NifmInternetConnectionStatus_Connected = 4, ///< Internet is connected. NifmInternetConnectionStatus_Connected = 4, ///< Internet is connected.
} NifmInternetConnectionStatus; } NifmInternetConnectionStatus;
/** /// Initialize nifm. This is used automatically by gethostid().
* @brief Sets the \ref NifmServiceType for initialization. Call this function before \ref nifmInitialize. Result nifmInitialize(NifmServiceType service_type);
* @note By default nifm:u will be used.
*/
void nifmSetServiceType(NifmServiceType serviceType);
/// Initialize nifm. This is used automatically by \ref socketInitialize. /// Exit nifm. This is used automatically by gethostid().
Result nifmInitialize(void);
/// Exit nifm. This is used automatically by \ref socketExit.
void nifmExit(void); void nifmExit(void);
/// Gets the Service object for the actual nifm:* service session. /// Gets the Service object for the actual nifm:* service session.

View File

@ -584,7 +584,7 @@ int getnameinfo(const struct sockaddr *sa, socklen_t salen,
long gethostid(void) { long gethostid(void) {
u32 id = INADDR_LOOPBACK; u32 id = INADDR_LOOPBACK;
Result rc = nifmInitialize(); Result rc = nifmInitialize(NifmServiceType_User);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
rc = nifmGetCurrentIpAddress(&id); rc = nifmGetCurrentIpAddress(&id);
nifmExit(); nifmExit();

View File

@ -6,7 +6,7 @@
#include "runtime/env.h" #include "runtime/env.h"
#include "runtime/hosversion.h" #include "runtime/hosversion.h"
static AccountServiceType g_accServiceType = AccountServiceType_NotInitialized; static AccountServiceType g_accServiceType;
static Service g_accSrv; static Service g_accSrv;
static AccountUid g_accPreselectedUserID; static AccountUid g_accPreselectedUserID;
static bool g_accPreselectedUserInitialized; static bool g_accPreselectedUserInitialized;
@ -15,21 +15,16 @@ static Result _accountInitializeApplicationInfo(void);
static Result _accountGetPreselectedUser(AccountUid *uid); 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) { Result _accountInitialize(AccountServiceType service_type) {
g_accServiceType = serviceType;
}
Result _accountInitialize(void) {
Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
Result rc2=0; Result rc2=0;
AccountUid *userIdEnv = envGetUserIdStorage(); AccountUid *userIdEnv = envGetUserIdStorage();
g_accServiceType = service_type;
switch (g_accServiceType) { switch (g_accServiceType) {
case AccountServiceType_NotInitialized:
case AccountServiceType_Application: case AccountServiceType_Application:
g_accServiceType = AccountServiceType_Application;
rc = smGetService(&g_accSrv, "acc:u0"); rc = smGetService(&g_accSrv, "acc:u0");
if (R_SUCCEEDED(rc)) rc = _accountInitializeApplicationInfo(); if (R_SUCCEEDED(rc)) rc = _accountInitializeApplicationInfo();
break; break;
@ -58,7 +53,6 @@ Result _accountInitialize(void) {
void _accountCleanup(void) { void _accountCleanup(void) {
serviceClose(&g_accSrv); serviceClose(&g_accSrv);
g_accServiceType = AccountServiceType_NotInitialized;
} }
Service* accountGetServiceSession(void) { Service* accountGetServiceSession(void) {

View File

@ -4,8 +4,8 @@
#include "services/applet.h" #include "services/applet.h"
#include "services/nfc.h" #include "services/nfc.h"
static NfpServiceType g_nfpServiceType = NfpServiceType_NotInitialized; static NfpServiceType g_nfpServiceType;
static NfcServiceType g_nfcServiceType = NfcServiceType_NotInitialized; static NfcServiceType g_nfcServiceType;
static Service g_nfpSrv; static Service g_nfpSrv;
static Service g_nfpInterface; static Service g_nfpInterface;
static Service g_nfcSrv; 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 _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); 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) { Result _nfpInitialize(NfpServiceType service_type) {
g_nfpServiceType = serviceType;
}
void nfcSetServiceType(NfcServiceType serviceType) {
g_nfcServiceType = serviceType;
}
Result _nfpInitialize(void) {
Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
u64 aruid = 0; u64 aruid = 0;
// If this fails (for example because we're a sysmodule) aruid stays zero // If this fails (for example because we're a sysmodule) aruid stays zero
appletGetAppletResourceUserId(&aruid); appletGetAppletResourceUserId(&aruid);
g_nfpServiceType = service_type;
switch (g_nfpServiceType) { switch (g_nfpServiceType) {
case NfpServiceType_NotInitialized:
case NfpServiceType_User: case NfpServiceType_User:
g_nfpServiceType = NfpServiceType_User;
rc = smGetService(&g_nfpSrv, "nfp:user"); rc = smGetService(&g_nfpSrv, "nfp:user");
break; break;
case NfpServiceType_Debug: case NfpServiceType_Debug:
@ -77,22 +68,20 @@ void _nfpCleanup(void) {
_nfcCmdNoIO(&g_nfpInterface, 1); // Finalize _nfcCmdNoIO(&g_nfpInterface, 1); // Finalize
serviceClose(&g_nfpInterface); serviceClose(&g_nfpInterface);
serviceClose(&g_nfpSrv); 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; Result rc=0;
u64 aruid = 0; u64 aruid = 0;
// If this fails (for example because we're a sysmodule) aruid stays zero // If this fails (for example because we're a sysmodule) aruid stays zero
appletGetAppletResourceUserId(&aruid); appletGetAppletResourceUserId(&aruid);
g_nfcServiceType = service_type;
switch (g_nfcServiceType) { switch (g_nfcServiceType) {
case NfcServiceType_NotInitialized:
case NfcServiceType_User: case NfcServiceType_User:
g_nfcServiceType = NfcServiceType_User;
rc = smGetService(&g_nfcSrv, "nfc:user"); rc = smGetService(&g_nfcSrv, "nfc:user");
break; break;
case NfcServiceType_System: case NfcServiceType_System:
@ -116,7 +105,6 @@ void _nfcCleanup(void) {
_nfcCmdNoIO(&g_nfcInterface, hosversionBefore(4,0,0) ? 1 : 401); // Finalize _nfcCmdNoIO(&g_nfcInterface, hosversionBefore(4,0,0) ? 1 : 401); // Finalize
serviceClose(&g_nfcInterface); serviceClose(&g_nfcInterface);
serviceClose(&g_nfcSrv); serviceClose(&g_nfcSrv);
g_nfcServiceType = NfcServiceType_NotInitialized;
} }
Service* nfpGetServiceSession(void) { Service* nfpGetServiceSession(void) {

View File

@ -2,7 +2,7 @@
#include "services/nifm.h" #include "services/nifm.h"
#include "runtime/hosversion.h" #include "runtime/hosversion.h"
static NifmServiceType g_nifmServiceType = NifmServiceType_NotInitialized; static NifmServiceType g_nifmServiceType;
static Service g_nifmSrv; static Service g_nifmSrv;
static Service g_nifmIGS; static Service g_nifmIGS;
@ -10,18 +10,13 @@ static Service g_nifmIGS;
static Result _nifmCreateGeneralService(Service* srv_out); static Result _nifmCreateGeneralService(Service* srv_out);
static Result _nifmCreateGeneralServiceOld(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) { Result _nifmInitialize(NifmServiceType service_type) {
g_nifmServiceType = serviceType;
}
Result _nifmInitialize(void) {
Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
g_nifmServiceType = service_type;
switch (g_nifmServiceType) { switch (g_nifmServiceType) {
case NifmServiceType_NotInitialized:
case NifmServiceType_User: case NifmServiceType_User:
g_nifmServiceType = NifmServiceType_User;
rc = smGetService(&g_nifmSrv, "nifm:u"); rc = smGetService(&g_nifmSrv, "nifm:u");
break; break;
case NifmServiceType_System: case NifmServiceType_System:
@ -47,7 +42,6 @@ Result _nifmInitialize(void) {
void _nifmCleanup(void) { void _nifmCleanup(void) {
serviceClose(&g_nifmIGS); serviceClose(&g_nifmIGS);
serviceClose(&g_nifmSrv); serviceClose(&g_nifmSrv);
g_nifmServiceType = NifmServiceType_NotInitialized;
} }
Service* nifmGetServiceSession_StaticService(void) { Service* nifmGetServiceSession_StaticService(void) {