Initialize time by using TimeServiceType/__nx_time_service_type, with the default now being User.

This commit is contained in:
yellows8 2019-11-01 13:20:55 -04:00
parent 1f792cd92f
commit fa27331045
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
2 changed files with 36 additions and 5 deletions

View File

@ -9,6 +9,15 @@
#include "../types.h" #include "../types.h"
#include "../sf/service.h" #include "../sf/service.h"
/// Values for __nx_time_service_type.
typedef enum {
TimeServiceType_User = 0, ///< Default. Initializes time:u.
TimeServiceType_Menu = 1, ///< Initializes time:a
TimeServiceType_System = 2, ///< Initializes time:s.
TimeServiceType_Repair = 3, ///< Initializes time:r. Only available with [9.0.0+].
TimeServiceType_SystemUser = 4, ///< Initializes time:su. Only available with [9.0.0+].
} TimeServiceType;
/// Time clock type. /// Time clock type.
typedef enum { typedef enum {
TimeType_UserSystemClock, TimeType_UserSystemClock,

View File

@ -1,6 +1,9 @@
#define NX_SERVICE_ASSUME_NON_DOMAIN #define NX_SERVICE_ASSUME_NON_DOMAIN
#include "service_guard.h" #include "service_guard.h"
#include "services/time.h" #include "services/time.h"
#include "runtime/hosversion.h"
__attribute__((weak)) TimeServiceType __nx_time_service_type = TimeServiceType_User;
static Service g_timeSrv; static Service g_timeSrv;
static Service g_timeUserSystemClock; static Service g_timeUserSystemClock;
@ -13,11 +16,30 @@ static Result _timeCmdGetSession(Service* srv, Service* srv_out, u32 cmd_id);
NX_GENERATE_SERVICE_GUARD(time); NX_GENERATE_SERVICE_GUARD(time);
Result _timeInitialize(void) { Result _timeInitialize(void) {
Result rc=0; Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
switch (__nx_time_service_type) {
rc = smGetService(&g_timeSrv, "time:s"); case TimeServiceType_User:
if (R_FAILED(rc))
rc = smGetService(&g_timeSrv, "time:u"); rc = smGetService(&g_timeSrv, "time:u");
break;
case TimeServiceType_Menu:
rc = smGetService(&g_timeSrv, "time:a");
break;
case TimeServiceType_System:
rc = smGetService(&g_timeSrv, "time:s");
break;
case TimeServiceType_Repair:
if (hosversionBefore(9,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
else
rc = smGetService(&g_timeSrv, "time:r");
break;
case TimeServiceType_SystemUser:
if (hosversionBefore(9,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
else
rc = smGetService(&g_timeSrv, "time:su");
break;
}
if (R_FAILED(rc)) if (R_FAILED(rc))
return rc; return rc;