summaryrefslogtreecommitdiff
path: root/libs/JSystem/src/JHostIO/JORHostInfo.cpp
blob: 904cb27fbfc9bc7b752e0b9969b3b6736cdb82c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/JHostIO/JORHostInfo.h"
#include "JSystem/JHostIO/JORServer.h"

// End of each month in standard year
static s32 YearDays[] = {
    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
};

// End of each month in leap year
static s32 LeapYearDays[] = {
    0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335,
};

static BOOL IsLeapYear(int year) {
    return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}

BOOL JORGetYearDays(int year, int mon) {
    s32* days = IsLeapYear(year) ? LeapYearDays : YearDays;
    return days[mon];
}

bool JORGetHostInfo(u32 request_type, JORHostInfo* pHostinfo) {
    JORMContext* mctx = JORServer::getInstance()->attachMCTX(MCTX_MSG_GET_HOST_INFO);
    mctx->sendHostInfoRequest(request_type, pHostinfo);
    JORServer::getInstance()->releaseMCTX(mctx);

    while (pHostinfo->getResult() == 0) {
        JOR_MESSAGELOOP();
    }

    return pHostinfo->getResult() == 1;
}

void JORGetComputerName(char* buffer, u32 buffer_size) {
    JORHostInfo_String string;
    string.setStringBuffer(buffer);
    string.setBufferSize(buffer_size);

    JORGetHostInfo(HOSTINFO_REQ_COMPUTER_NAME, &string);
}

void JORGetUserName(char* buffer, u32 buffer_size) {
    JORHostInfo_String string;
    string.setStringBuffer(buffer);
    string.setBufferSize(buffer_size);

    JORGetHostInfo(HOSTINFO_REQ_USERNAME, &string);
}

void JORGetLocalTime(OSCalendarTime* pCalendarTime) {
    JORHostInfo_CalendarTime calendar_time;
    calendar_time.setCalendarTimeBuffer(pCalendarTime);

    JORGetHostInfo(HOSTINFO_REQ_LOCAL_TIME, &calendar_time);
}