mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 13:02:38 +02:00
Added timeSetCurrentTime() and attempt to initialize time-serv with 'time:s' first.
This commit is contained in:
parent
0dcaeec959
commit
d61154f0e5
@ -9,6 +9,7 @@
|
|||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "../services/sm.h"
|
#include "../services/sm.h"
|
||||||
|
|
||||||
|
/// Time clock type.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TimeType_UserSystemClock,
|
TimeType_UserSystemClock,
|
||||||
TimeType_NetworkSystemClock,
|
TimeType_NetworkSystemClock,
|
||||||
@ -22,3 +23,11 @@ void timeExit(void);
|
|||||||
Service* timeGetSessionService(void);
|
Service* timeGetSessionService(void);
|
||||||
|
|
||||||
Result timeGetCurrentTime(TimeType type, u64 *timestamp);
|
Result timeGetCurrentTime(TimeType type, u64 *timestamp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the time for the specified clock.
|
||||||
|
* @param[in] type Clock to use.
|
||||||
|
* @param[in] timestamp POSIX UTC timestamp.
|
||||||
|
* @return Result code.
|
||||||
|
*/
|
||||||
|
Result timeSetCurrentTime(TimeType type, u64 timestamp);
|
||||||
|
@ -20,7 +20,10 @@ Result timeInitialize(void)
|
|||||||
|
|
||||||
Result rc;
|
Result rc;
|
||||||
|
|
||||||
|
rc = smGetService(&g_timeSrv, "time:s");
|
||||||
|
if (R_FAILED(rc))
|
||||||
rc = smGetService(&g_timeSrv, "time:u");
|
rc = smGetService(&g_timeSrv, "time:u");
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@ -92,21 +95,26 @@ static Result _timeGetSession(Service* srv_out, u64 cmd_id) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result timeGetCurrentTime(TimeType type, u64 *timestamp) {
|
static Service* _timeGetClockSession(TimeType type) {
|
||||||
Service *srv = NULL;
|
|
||||||
|
|
||||||
if (type==TimeType_UserSystemClock) {
|
if (type==TimeType_UserSystemClock) {
|
||||||
srv = &g_timeUserSystemClock;
|
return &g_timeUserSystemClock;
|
||||||
}
|
}
|
||||||
else if (type==TimeType_NetworkSystemClock) {
|
else if (type==TimeType_NetworkSystemClock) {
|
||||||
srv = &g_timeNetworkSystemClock;
|
return &g_timeNetworkSystemClock;
|
||||||
}
|
}
|
||||||
else if (type==TimeType_LocalSystemClock) {
|
else if (type==TimeType_LocalSystemClock) {
|
||||||
srv = &g_timeLocalSystemClock;
|
return &g_timeLocalSystemClock;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result timeGetCurrentTime(TimeType type, u64 *timestamp) {
|
||||||
|
Service *srv = _timeGetClockSession(type);
|
||||||
|
|
||||||
|
if (srv==NULL)
|
||||||
|
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||||
|
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
@ -141,3 +149,41 @@ Result timeGetCurrentTime(TimeType type, u64 *timestamp) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result timeSetCurrentTime(TimeType type, u64 timestamp) {
|
||||||
|
Service *srv = _timeGetClockSession(type);
|
||||||
|
|
||||||
|
if (srv==NULL)
|
||||||
|
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||||
|
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u64 timestamp;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 1;
|
||||||
|
raw->timestamp = timestamp;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(srv);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user