Added account. Added u128 type to types.h.

This commit is contained in:
yellows8 2017-11-29 23:31:18 -05:00
parent cb123dd579
commit a405bc4827
4 changed files with 84 additions and 4 deletions

View File

@ -25,6 +25,7 @@ extern "C" {
#include <switch/services/sm.h>
#include <switch/services/fs.h>
#include <switch/services/account.h>
#include <switch/services/applet.h>
#include <switch/services/binder.h>
#include <switch/services/bsd.h>

View File

@ -0,0 +1,6 @@
Result accountInitialize(void);
void accountExit(void);
Handle accountGetSessionService(void);
/// Get the userID for the currently active user. The output userID is only valid when the output account_selected==1, otherwise no user is currently selected.
Result accountGetActiveUser(u128 *userID, bool *account_selected);

View File

@ -18,10 +18,11 @@
#endif
#endif
typedef uint8_t u8; ///< 8-bit unsigned integer
typedef uint16_t u16; ///< 16-bit unsigned integer
typedef uint32_t u32; ///< 32-bit unsigned integer
typedef uint64_t u64; ///< 64-bit unsigned integer
typedef uint8_t u8; ///< 8-bit unsigned integer
typedef uint16_t u16; ///< 16-bit unsigned integer
typedef uint32_t u32; ///< 32-bit unsigned integer
typedef uint64_t u64; ///< 64-bit unsigned integer
typedef __uint128_t u128; ///< 128-bit unsigned integer
typedef int8_t s8; ///< 8-bit signed integer
typedef int16_t s16; ///< 16-bit signed integer

View File

@ -0,0 +1,72 @@
#include <string.h>
#include <switch.h>
static Handle g_accountServiceSession = INVALID_HANDLE;
Result accountInitialize(void) {
if (g_accountServiceSession != INVALID_HANDLE) return MAKERESULT(MODULE_LIBNX, LIBNX_ALREADYINITIALIZED);
Result rc = 0;
rc = smGetService(&g_accountServiceSession, "acc:u1");
if (R_FAILED(rc)) return rc;
return rc;
}
void accountExit(void)
{
if (g_accountServiceSession == INVALID_HANDLE) return;
if (g_accountServiceSession != INVALID_HANDLE) {
svcCloseHandle(g_accountServiceSession);
g_accountServiceSession = INVALID_HANDLE;
}
}
Handle accountGetSessionService(void) {
return g_accountServiceSession;
}
Result accountGetActiveUser(u128 *userID, bool *account_selected) {
if (g_accountServiceSession == INVALID_HANDLE) return MAKERESULT(MODULE_LIBNX, LIBNX_NOTINITIALIZED);
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
} *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 4;
Result rc = ipcDispatch(g_accountServiceSession);
if (R_SUCCEEDED(rc)) {
IpcCommandResponse r;
ipcParseResponse(&r);
struct {
u64 magic;
u64 result;
u128 userID;
} *resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && userID) {
*userID = resp->userID;
if (account_selected) {
*account_selected = 0;
if (*userID != 0) *account_selected = 1;
}
}
}
return rc;
}