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
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);

View File

@ -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);

View File

@ -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.

View File

@ -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();

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {