erpt: reimplement the sysmodule (#875)

* erpt: reimplement the sysmodule

* fatal: update for latest bindings

* erpt: amend logic for culling orphan attachments
This commit is contained in:
SciresM 2020-04-13 17:07:37 -07:00 committed by GitHub
parent eca5ac01b8
commit 79b9e07ee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
117 changed files with 6716 additions and 59 deletions

View file

@ -20,47 +20,49 @@
#include <vapours.hpp>
/* Libstratosphere-only utility. */
#include "stratosphere/util.hpp"
#include <stratosphere/util.hpp>
/* Sadly required shims. */
#include "stratosphere/svc/svc_stratosphere_shims.hpp"
#include <stratosphere/svc/svc_stratosphere_shims.hpp>
/* Critical modules with no dependencies. */
#include "stratosphere/ams.hpp"
#include "stratosphere/os.hpp"
#include "stratosphere/dd.hpp"
#include "stratosphere/lmem.hpp"
#include "stratosphere/mem.hpp"
#include <stratosphere/ams.hpp>
#include <stratosphere/os.hpp>
#include <stratosphere/dd.hpp>
#include <stratosphere/lmem.hpp>
#include <stratosphere/mem.hpp>
/* Pull in all ID definitions from NCM. */
#include "stratosphere/ncm/ncm_ids.hpp"
#include <stratosphere/ncm/ncm_ids.hpp>
/* At this point, just include the rest alphabetically. */
/* TODO: Figure out optimal order. */
#include "stratosphere/boot2.hpp"
#include "stratosphere/cfg.hpp"
#include "stratosphere/dmnt.hpp"
#include "stratosphere/erpt.hpp"
#include "stratosphere/fatal.hpp"
#include "stratosphere/hid.hpp"
#include "stratosphere/hos.hpp"
#include "stratosphere/kvdb.hpp"
#include "stratosphere/ldr.hpp"
#include "stratosphere/lr.hpp"
#include "stratosphere/map.hpp"
#include "stratosphere/ncm.hpp"
#include "stratosphere/nim.hpp"
#include "stratosphere/patcher.hpp"
#include "stratosphere/pm.hpp"
#include "stratosphere/reg.hpp"
#include "stratosphere/ro.hpp"
#include "stratosphere/settings.hpp"
#include "stratosphere/sf.hpp"
#include "stratosphere/sm.hpp"
#include "stratosphere/spl.hpp"
#include "stratosphere/updater.hpp"
#include <stratosphere/boot2.hpp>
#include <stratosphere/cfg.hpp>
#include <stratosphere/dmnt.hpp>
#include <stratosphere/erpt.hpp>
#include <stratosphere/fatal.hpp>
#include <stratosphere/hid.hpp>
#include <stratosphere/hos.hpp>
#include <stratosphere/kvdb.hpp>
#include <stratosphere/ldr.hpp>
#include <stratosphere/lr.hpp>
#include <stratosphere/map.hpp>
#include <stratosphere/ncm.hpp>
#include <stratosphere/nim.hpp>
#include <stratosphere/patcher.hpp>
#include <stratosphere/psc.hpp>
#include <stratosphere/pm.hpp>
#include <stratosphere/reg.hpp>
#include <stratosphere/ro.hpp>
#include <stratosphere/settings.hpp>
#include <stratosphere/sf.hpp>
#include <stratosphere/sm.hpp>
#include <stratosphere/spl.hpp>
#include <stratosphere/time.hpp>
#include <stratosphere/updater.hpp>
/* Include FS last. */
#include "stratosphere/fs.hpp"
#include "stratosphere/fssrv.hpp"
#include "stratosphere/fssystem.hpp"
#include <stratosphere/fs.hpp>
#include <stratosphere/fssrv.hpp>
#include <stratosphere/fssystem.hpp>

View file

@ -17,3 +17,9 @@
#pragma once
#include <stratosphere/erpt/erpt_ids.autogen.hpp>
#include <stratosphere/erpt/erpt_types.hpp>
#include <stratosphere/erpt/erpt_multiple_category_context.hpp>
#include <stratosphere/erpt/sf/erpt_sf_i_context.hpp>
#include <stratosphere/erpt/sf/erpt_sf_i_session.hpp>
#include <stratosphere/erpt/srv/erpt_srv_types.hpp>
#include <stratosphere/erpt/srv/erpt_srv_api.hpp>

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/erpt/erpt_types.hpp>
#include <stratosphere/sf/sf_buffer_tags.hpp>
namespace ams::erpt {
constexpr inline u32 CategoriesPerMultipleCategoryContext = 0x10;
constexpr inline u32 FieldsPerMultipleCategoryContext = CategoriesPerMultipleCategoryContext * 4;
struct MultipleCategoryContextEntry : public sf::LargeData, public sf::PrefersMapAliasTransferMode {
u32 version;
u32 category_count;
CategoryId categories[CategoriesPerMultipleCategoryContext];
u32 field_counts[CategoriesPerMultipleCategoryContext];
u32 array_buf_counts[CategoriesPerMultipleCategoryContext];
FieldEntry fields[FieldsPerMultipleCategoryContext];
};
}

View file

@ -0,0 +1,234 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os.hpp>
#include <stratosphere/time/time_posix_time.hpp>
#include <stratosphere/erpt/erpt_ids.autogen.hpp>
namespace ams::erpt {
#define GENERATE_ENUM(NAME, ID, ...) NAME = ID,
enum FieldType {
AMS_ERPT_FOREACH_FIELD_TYPE(GENERATE_ENUM)
FieldType_Count,
};
#undef GENERATE_ENUM
#define GENERATE_ENUM(NAME, ID, ...) CategoryId_##NAME = ID,
enum CategoryId {
AMS_ERPT_FOREACH_CATEGORY(GENERATE_ENUM)
CategoryId_Count,
};
#undef GENERATE_ENUM
#define GENERATE_ENUM(NAME, ID, ...) FieldId_##NAME = ID,
enum FieldId {
AMS_ERPT_FOREACH_FIELD(GENERATE_ENUM)
FieldId_Count,
};
#undef GENERATE_ENUM
constexpr inline u32 ArrayBufferSizeDefault = 0x100;
constexpr inline u32 ArrayBufferSizeMax = 96_KB;
constexpr inline u32 ArrayFieldSizeMax = 16_KB - 1;
enum ReportType {
ReportType_Start = 0,
ReportType_Visible = ReportType_Start,
ReportType_Invisible = 1,
ReportType_End = 2,
ReportType_Count = ReportType_End,
ReportType_Any = ReportType_Count,
};
constexpr inline u32 ReportCountMax = 50;
constexpr inline u32 AttachmentsPerReportMax = 5;
constexpr inline u32 AttachmentCountMax = ReportCountMax * AttachmentsPerReportMax;
constexpr inline u32 ReportMetaDataSize = 0x20;
struct ReportMetaData {
u8 user_data[ReportMetaDataSize];
};
constexpr inline u32 ReportIdSize = 20;
struct ReportId {
union {
u8 id[ReportIdSize];
util::Uuid uuid;
#pragma pack(push, 1)
struct {
u32 time_low;
u16 time_mid;
u16 time_high_and_version;
u8 clock_high;
u8 clock_low;
u64 node;
} uuid_data;
#pragma pack(pop)
};
};
static_assert(sizeof(ReportId) == ReportIdSize);
inline bool operator==(const ReportId &lhs, const ReportId &rhs) {
return std::memcmp(lhs.id, rhs.id, sizeof(lhs.uuid)) == 0;
}
inline bool operator!=(const ReportId &lhs, const ReportId &rhs) {
return !(lhs == rhs);
}
struct ReportFlag {
using Transmitted = util::BitFlagSet<BITSIZEOF(u32), ReportFlag>::Flag<0>;
using HasAttachment = util::BitFlagSet<BITSIZEOF(u32), ReportFlag>::Flag<1>;
};
using ReportFlagSet = util::BitFlagSet<BITSIZEOF(u32), ReportFlag>;
static_assert(std::is_pod<ReportFlagSet>::value);
static_assert(sizeof(ReportFlagSet) == sizeof(u32));
struct ReportInfo {
ReportType type;
ReportId id;
ReportMetaData meta_data;
ReportFlagSet flags;
time::PosixTime timestamp_user;
time::PosixTime timestamp_network;
s64 report_size;
u64 reserved[3];
};
struct ReportList {
u32 report_count;
ReportInfo reports[ReportCountMax];
};
constexpr inline u32 AttachmentIdSize = 20;
struct AttachmentId {
union {
u8 id[AttachmentIdSize];
util::Uuid uuid;
};
};
static_assert(sizeof(AttachmentId) == AttachmentIdSize);
inline bool operator==(const AttachmentId &lhs, const AttachmentId &rhs) {
return std::memcmp(lhs.id, rhs.id, sizeof(lhs.uuid)) == 0;
}
inline bool operator!=(const AttachmentId &lhs, const AttachmentId &rhs) {
return !(lhs == rhs);
}
struct AttachmentFlag {
using HasOwner = util::BitFlagSet<BITSIZEOF(u32), AttachmentFlag>::Flag<1>;
};
using AttachmentFlagSet = util::BitFlagSet<BITSIZEOF(u32), AttachmentFlag>;
static_assert(std::is_pod<AttachmentFlagSet>::value);
static_assert(sizeof(AttachmentFlagSet) == sizeof(u32));
constexpr inline u32 AttachmentNameSizeMax = 0x20;
struct AttachmentInfo {
ReportId owner_report_id;
AttachmentId attachment_id;
AttachmentFlagSet flags;
s64 attachment_size;
char attachment_name[AttachmentNameSizeMax];
};
struct AttachmentList {
u32 attachment_count;
AttachmentInfo attachments[AttachmentsPerReportMax];
};
constexpr inline u32 AttachmentSizeMax = 512_KB;
struct FieldEntry {
FieldId id;
FieldType type;
union {
u64 value_u64;
u32 value_u32;
u16 value_u16;
u8 value_u8;
s64 value_i64;
s32 value_i32;
s16 value_i16;
s8 value_i8;
bool value_bool;
struct {
u32 start_idx;
u32 size;
} value_array;
};
};
constexpr inline u32 FieldsPerContext = 20;
struct ContextEntry {
u32 version;
u32 field_count;
CategoryId category;
FieldEntry fields[FieldsPerContext];
u8 *array_buffer;
u32 array_free_count;
u32 array_buffer_size;
};
struct StorageUsageStatistics {
util::Uuid journal_uuid;
u32 used_storage_size;
s64 max_report_size;
u32 report_count[ReportType_Count];
u32 transmitted_count[ReportType_Count];
u32 untransmitted_count[ReportType_Count];
};
/* https://github.com/msgpack/msgpack/blob/master/spec.md#overview */
enum class ValueTypeTag {
FixMap = 0x80,
FixArray = 0x90,
FixStr = 0xA0,
False = 0xC2,
True = 0xC3,
Bin8 = 0xC4,
Bin16 = 0xC5,
U8 = 0xCC,
U16 = 0xCD,
U32 = 0xCE,
U64 = 0xCF,
I8 = 0xD0,
I16 = 0xD1,
I32 = 0xD2,
I64 = 0xD3,
Str8 = 0xD9,
Str16 = 0xDA,
Array16 = 0xDC,
Map16 = 0xDE,
};
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/erpt/erpt_types.hpp>
namespace ams::erpt::sf {
class IAttachment : public ams::sf::IServiceObject {
protected:
enum class CommandId {
Open = 0,
Read = 1,
SetFlags = 2,
GetFlags = 3,
Close = 4,
GetSize = 5,
};
public:
/* Actual commands. */
virtual Result Open(const AttachmentId &attachment_id) = 0;
virtual Result Read(ams::sf::Out<u32> out_count, const ams::sf::OutBuffer &out_buffer) = 0;
virtual Result SetFlags(AttachmentFlagSet flags) = 0;
virtual Result GetFlags(ams::sf::Out<AttachmentFlagSet> out) = 0;
virtual Result Close() = 0;
virtual Result GetSize(ams::sf::Out<s64> out) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(Open),
MAKE_SERVICE_COMMAND_META(Read),
MAKE_SERVICE_COMMAND_META(SetFlags),
MAKE_SERVICE_COMMAND_META(GetFlags),
MAKE_SERVICE_COMMAND_META(Close),
MAKE_SERVICE_COMMAND_META(GetSize),
};
};
}

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/sf.hpp>
#include <stratosphere/erpt/erpt_types.hpp>
#include <stratosphere/erpt/erpt_multiple_category_context.hpp>
#include <stratosphere/time/time_steady_clock_time_point.hpp>
namespace ams::erpt::sf {
class IContext : public ams::sf::IServiceObject {
protected:
enum class CommandId {
SubmitContext = 0,
CreateReport = 1,
SetInitialLaunchSettingsCompletionTime = 2,
ClearInitialLaunchSettingsCompletionTime = 3,
UpdatePowerOnTime = 4,
UpdateAwakeTime = 5,
SubmitMultipleCategoryContext = 6,
UpdateApplicationLaunchTime = 7,
ClearApplicationLaunchTime = 8,
SubmitAttachment = 9,
CreateReportWithAttachments = 10,
};
public:
/* Actual commands. */
virtual Result SubmitContext(const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer) = 0;
virtual Result CreateReport(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &meta_buffer) = 0;
virtual Result SetInitialLaunchSettingsCompletionTime(const time::SteadyClockTimePoint &time_point) = 0;
virtual Result ClearInitialLaunchSettingsCompletionTime() = 0;
virtual Result UpdatePowerOnTime() = 0;
virtual Result UpdateAwakeTime() = 0;
virtual Result SubmitMultipleCategoryContext(const MultipleCategoryContextEntry &ctx_entry, const ams::sf::InBuffer &str_buffer) = 0;
virtual Result UpdateApplicationLaunchTime() = 0;
virtual Result ClearApplicationLaunchTime() = 0;
virtual Result SubmitAttachment(ams::sf::Out<AttachmentId> out, const ams::sf::InBuffer &attachment_name, const ams::sf::InBuffer &attachment_data) = 0;
virtual Result CreateReportWithAttachments(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &attachment_ids_buffer) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(SubmitContext),
MAKE_SERVICE_COMMAND_META(CreateReport),
MAKE_SERVICE_COMMAND_META(SetInitialLaunchSettingsCompletionTime, hos::Version_300),
MAKE_SERVICE_COMMAND_META(ClearInitialLaunchSettingsCompletionTime, hos::Version_300),
MAKE_SERVICE_COMMAND_META(UpdatePowerOnTime, hos::Version_300),
MAKE_SERVICE_COMMAND_META(UpdateAwakeTime, hos::Version_300),
MAKE_SERVICE_COMMAND_META(SubmitMultipleCategoryContext, hos::Version_500),
MAKE_SERVICE_COMMAND_META(UpdateApplicationLaunchTime, hos::Version_600),
MAKE_SERVICE_COMMAND_META(ClearApplicationLaunchTime, hos::Version_600),
MAKE_SERVICE_COMMAND_META(SubmitAttachment, hos::Version_800),
MAKE_SERVICE_COMMAND_META(CreateReportWithAttachments, hos::Version_800),
};
};
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/erpt/erpt_types.hpp>
namespace ams::erpt::sf {
class IManager : public ams::sf::IServiceObject {
protected:
enum class CommandId {
GetReportList = 0,
GetEvent = 1,
CleanupReports = 2,
DeleteReport = 3,
GetStorageUsageStatistics = 4,
GetAttachmentList = 5,
};
public:
/* Actual commands. */
virtual Result GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter) = 0;
virtual Result GetEvent(ams::sf::OutCopyHandle out) = 0;
virtual Result CleanupReports() = 0;
virtual Result DeleteReport(const ReportId &report_id) = 0;
virtual Result GetStorageUsageStatistics(ams::sf::Out<StorageUsageStatistics> out) = 0;
virtual Result GetAttachmentList(const ams::sf::OutBuffer &out_buf, const ReportId &report_id) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(GetReportList),
MAKE_SERVICE_COMMAND_META(GetEvent),
MAKE_SERVICE_COMMAND_META(CleanupReports, hos::Version_400),
MAKE_SERVICE_COMMAND_META(DeleteReport, hos::Version_500),
MAKE_SERVICE_COMMAND_META(GetStorageUsageStatistics, hos::Version_500),
MAKE_SERVICE_COMMAND_META(GetAttachmentList, hos::Version_800),
};
};
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/erpt/erpt_types.hpp>
namespace ams::erpt::sf {
class IReport : public ams::sf::IServiceObject {
protected:
enum class CommandId {
Open = 0,
Read = 1,
SetFlags = 2,
GetFlags = 3,
Close = 4,
GetSize = 5,
};
public:
/* Actual commands. */
virtual Result Open(const ReportId &report_id) = 0;
virtual Result Read(ams::sf::Out<u32> out_count, const ams::sf::OutBuffer &out_buffer) = 0;
virtual Result SetFlags(ReportFlagSet flags) = 0;
virtual Result GetFlags(ams::sf::Out<ReportFlagSet> out) = 0;
virtual Result Close() = 0;
virtual Result GetSize(ams::sf::Out<s64> out) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(Open),
MAKE_SERVICE_COMMAND_META(Read),
MAKE_SERVICE_COMMAND_META(SetFlags),
MAKE_SERVICE_COMMAND_META(GetFlags),
MAKE_SERVICE_COMMAND_META(Close),
MAKE_SERVICE_COMMAND_META(GetSize),
};
};
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/erpt/erpt_types.hpp>
#include <stratosphere/erpt/sf/erpt_sf_i_report.hpp>
#include <stratosphere/erpt/sf/erpt_sf_i_manager.hpp>
#include <stratosphere/erpt/sf/erpt_sf_i_attachment.hpp>
namespace ams::erpt::sf {
class ISession : public ams::sf::IServiceObject {
protected:
enum class CommandId {
OpenReport = 0,
OpenManager = 1,
OpenAttachment = 2,
};
public:
/* Actual commands. */
virtual Result OpenReport(ams::sf::Out<std::shared_ptr<erpt::sf::IReport>> out) = 0;
virtual Result OpenManager(ams::sf::Out<std::shared_ptr<erpt::sf::IManager>> out) = 0;
virtual Result OpenAttachment(ams::sf::Out<std::shared_ptr<erpt::sf::IAttachment>> out) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(OpenReport),
MAKE_SERVICE_COMMAND_META(OpenManager),
MAKE_SERVICE_COMMAND_META(OpenAttachment, hos::Version_800),
};
};
}

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::erpt::srv {
Result Initialize(u8 *mem, size_t mem_size);
Result InitializeAndStartService();
Result SetSerialNumberAndOsVersion(const char *sn, u32 sn_len, const char *os, u32 os_len, const char *os_priv, u32 os_priv_len);
Result SetProductModel(const char *model, u32 model_len);
Result SetRegionSetting(const char *region, u32 region_len);
/* Atmosphere extension. */
Result SetRedirectNewReportsToSdCard(bool redirect);
void Wait();
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os.hpp>
#include <stratosphere/erpt/erpt_ids.autogen.hpp>
namespace ams::erpt::srv {
constexpr inline const char ReportOnSdStoragePath[] = "ersd";
constexpr inline const char ReportStoragePath[] = "save";
constexpr inline const char JournalFileName[] = "save:/journal";
constexpr size_t ReportFileNameLength = 64;
constexpr size_t AttachmentFileNameLength = 64;
constexpr size_t MaxFieldStringSize = 64;
struct ReportFileName {
char name[ReportFileNameLength];
};
struct AttachmentFileName {
char name[AttachmentFileNameLength];
};
enum FieldFlag : u8 {
FieldFlag_None = 0,
FieldFlag_Encrypt = 1,
};
#define STRINGIZE_HANDLER(NAME, ...) #NAME,
constexpr inline const char * const FieldString[] = {
AMS_ERPT_FOREACH_FIELD(STRINGIZE_HANDLER)
};
constexpr inline const char * const CategoryString[] = {
AMS_ERPT_FOREACH_CATEGORY(STRINGIZE_HANDLER)
};
constexpr inline const char * const TypeString[] = {
AMS_ERPT_FOREACH_FIELD_TYPE(STRINGIZE_HANDLER)
};
#undef STRINGIZE_HANDLER
#define GET_FIELD_CATEGORY(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = CategoryId_##CATEGORY,
constexpr inline const CategoryId FieldToCategoryMap[] = {
AMS_ERPT_FOREACH_FIELD(GET_FIELD_CATEGORY)
};
#undef GET_FIELD_CATEGORY
#define GET_FIELD_TYPE(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = TYPE,
constexpr inline const FieldType FieldToTypeMap[] = {
AMS_ERPT_FOREACH_FIELD(GET_FIELD_TYPE)
};
#undef GET_FIELD_TYPE
#define GET_FIELD_FLAG(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = FLAG,
constexpr inline const FieldFlag FieldToFlagMap[] = {
AMS_ERPT_FOREACH_FIELD(GET_FIELD_FLAG)
};
#undef GET_FIELD_FLAG
constexpr inline ReportFlagSet MakeNoReportFlags() {
return util::MakeBitFlagSet<32, ReportFlag>();
}
constexpr inline AttachmentFlagSet MakeNoAttachmentFlags() {
return util::MakeBitFlagSet<32, AttachmentFlag>();
}
}

View file

@ -26,4 +26,9 @@ namespace ams::fs {
Result GetSaveDataFlags(u32 *out, SaveDataSpaceId space_id, SaveDataId id);
Result SetSaveDataFlags(SaveDataId id, SaveDataSpaceId space_id, u32 flags);
Result GetSaveDataAvailableSize(s64 *out, SaveDataId id);
Result GetSaveDataJournalSize(s64 *out, SaveDataId id);
Result ExtendSaveData(SaveDataSpaceId space_id, SaveDataId id, s64 available_size, s64 journal_size);
}

View file

@ -20,4 +20,6 @@ namespace ams::fs {
Result MountSdCard(const char *name);
Result MountSdCardErrorReportDirectoryForAtmosphere(const char *name);
}

View file

@ -14,15 +14,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "../../fs/fs_common.hpp"
#include "../../fs/fsa/fs_ifile.hpp"
#include "../../fs/fsa/fs_idirectory.hpp"
#include "../../fs/fsa/fs_ifilesystem.hpp"
#include <stratosphere/fs/fs_common.hpp>
#include <stratosphere/fs/fsa/fs_ifile.hpp>
#include <stratosphere/fs/fsa/fs_idirectory.hpp>
#include <stratosphere/fs/fsa/fs_ifilesystem.hpp>
#include <stratosphere/fs/impl/fs_newable.hpp>
namespace ams::fssystem::impl {
template<typename Impl>
class IPathResolutionFileSystem : public fs::fsa::IFileSystem {
class IPathResolutionFileSystem : public fs::fsa::IFileSystem, public fs::impl::Newable {
NON_COPYABLE(IPathResolutionFileSystem);
private:
std::shared_ptr<fs::fsa::IFileSystem> shared_fs;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
* Copyright (c) 2019-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,

View file

@ -0,0 +1,22 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/psc/psc_types.hpp>
#include <stratosphere/psc/psc_pm_module_id.hpp>
#include <stratosphere/psc/sf/psc_sf_i_pm_module.hpp>
#include <stratosphere/psc/psc_pm_module.hpp>

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#if defined(ATMOSPHERE_OS_HORIZON)
#include <stratosphere/psc/psc_pm_module.os.horizon.hpp>
#else
#error "Unknown OS for psc::PmModule"
#endif

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/psc/psc_types.hpp>
#include <stratosphere/psc/psc_pm_module_id.hpp>
#include <stratosphere/psc/sf/psc_sf_i_pm_module.hpp>
namespace ams::psc {
class PmModule {
NON_COPYABLE(PmModule);
NON_MOVEABLE(PmModule);
private:
std::shared_ptr<psc::sf::IPmModule> intf;
os::SystemEvent system_event;
bool initialized;
PmModuleId module_id;
uintptr_t reserved;
public:
PmModule();
~PmModule();
Result Initialize(const PmModuleId mid, const PmModuleId *dependencies, u32 dependency_count, os::EventClearMode clear_mode);
Result Finalize();
constexpr PmModuleId GetId() const { return this->module_id; }
Result GetRequest(PmState *out_state, PmFlagSet *out_flags);
Result Acknowledge(PmState state, Result res);
os::SystemEvent *GetEventPointer();
};
}

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::psc {
enum PmModuleId : u16 {
PmModuleId_Usb = 4,
PmModuleId_Ethernet = 5,
PmModuleId_Fgm = 6,
PmModuleId_PcvClock = 7,
PmModuleId_PcvVoltage = 8,
PmModuleId_Gpio = 9,
PmModuleId_Pinmux = 10,
PmModuleId_Uart = 11,
PmModuleId_I2c = 12,
PmModuleId_I2cPcv = 13,
PmModuleId_Spi = 14,
PmModuleId_Pwm = 15,
PmModuleId_Psm = 16,
PmModuleId_Tc = 17,
PmModuleId_Omm = 18,
PmModuleId_Pcie = 19,
PmModuleId_Lbl = 20,
PmModuleId_Display = 21,
PmModuleId_Hid = 24,
PmModuleId_WlanSockets = 25,
PmModuleId_Fs = 27,
PmModuleId_Audio = 28,
PmModuleId_TmaHostIo = 30,
PmModuleId_Bluetooth = 31,
PmModuleId_Bpc = 32,
PmModuleId_Fan = 33,
PmModuleId_Pcm = 34,
PmModuleId_Nfc = 35,
PmModuleId_Apm = 36,
PmModuleId_Btm = 37,
PmModuleId_Nifm = 38,
PmModuleId_GpioLow = 39,
PmModuleId_Npns = 40,
PmModuleId_Lm = 41,
PmModuleId_Bcat = 42,
PmModuleId_Time = 43,
PmModuleId_Pctl = 44,
PmModuleId_Erpt = 45,
PmModuleId_Eupld = 46,
PmModuleId_Friends = 47,
PmModuleId_Bgtc = 48,
PmModuleId_Account = 49,
PmModuleId_Sasbus = 50,
PmModuleId_Ntc = 51,
PmModuleId_Idle = 52,
PmModuleId_Tcap = 53,
PmModuleId_PsmLow = 54,
PmModuleId_Ndd = 55,
PmModuleId_Olsc = 56,
PmModuleId_Ns = 61,
PmModuleId_Nvservices = 101,
PmModuleId_Spsm = 127,
};
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::psc {
enum PmState {
PmState_Awake = 0,
PmState_ReadyAwaken = 1,
PmState_ReadySleep = 2,
PmState_ReadySleepCritical = 3,
PmState_ReadyAwakenCritical = 4,
PmState_ReadyShutdown = 5,
};
constexpr inline u32 MaximumDependencyLevels = 20;
struct PmFlag {
};
using PmFlagSet = util::BitFlagSet<BITSIZEOF(u32), PmFlag>;
}

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/psc/psc_types.hpp>
#include <stratosphere/psc/psc_pm_module_id.hpp>
namespace ams::psc::sf {
class IPmModule : public ams::sf::IServiceObject {
protected:
enum class CommandId {
Initialize = 0,
GetRequest = 1,
Acknowledge = 2,
Finalize = 3,
AcknowledgeEx = 4,
};
public:
/* Actual commands. */
virtual Result Initialize(ams::sf::OutCopyHandle out, psc::PmModuleId module_id, const ams::sf::InBuffer &child_list) = 0;
virtual Result GetRequest(ams::sf::Out<PmState> out_state, ams::sf::Out<PmFlagSet> out_flags) = 0;
virtual Result Acknowledge() = 0;
virtual Result Finalize() = 0;
virtual Result AcknowledgeEx(PmState state) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(Initialize),
MAKE_SERVICE_COMMAND_META(GetRequest),
MAKE_SERVICE_COMMAND_META(Acknowledge),
MAKE_SERVICE_COMMAND_META(Finalize),
MAKE_SERVICE_COMMAND_META(AcknowledgeEx, hos::Version_600), /* TODO: This is really 5.1.0... */
};
};
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/psc/sf/psc_sf_i_pm_module.hpp>
namespace ams::psc::sf {
class IPmService : public ams::sf::IServiceObject {
protected:
enum class CommandId {
Initialize = 0,
};
public:
/* Actual commands. */
virtual Result Initialize(ams::sf::Out<std::shared_ptr<psc::sf::IPmModule>> out) = 0;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(Initialize),
};
};
}

View file

@ -19,3 +19,7 @@
#include "settings/settings_types.hpp"
#include "settings/settings_fwdbg_types.hpp"
#include "settings/settings_fwdbg_api.hpp"
#include "settings/system/settings_firmware_version.hpp"
#include "settings/system/settings_product_model.hpp"
#include "settings/system/settings_region.hpp"
#include "settings/system/settings_serial_number.hpp"

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/settings/settings_types.hpp>
namespace ams::settings::system {
struct alignas(4) FirmwareVersion {
u8 major;
u8 minor;
u8 micro;
u8 padding1;
u8 revision_major;
u8 revision_minor;
u8 padding2;
u8 padding3;
char platform[0x20];
char revision[0x40];
char display_version[0x18];
char display_name[0x80];
constexpr int GetComparableVersion() const {
return (static_cast<int>(major) << 16) | (static_cast<int>(minor) << 8) | (static_cast<int>(micro) << 0);
}
constexpr friend bool operator==(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
return lhs.GetComparableVersion() == rhs.GetComparableVersion();
}
constexpr friend bool operator!=(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
return lhs.GetComparableVersion() != rhs.GetComparableVersion();
}
constexpr friend bool operator<=(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
return lhs.GetComparableVersion() <= rhs.GetComparableVersion();
}
constexpr friend bool operator>=(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
return lhs.GetComparableVersion() >= rhs.GetComparableVersion();
}
constexpr friend bool operator<(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
return lhs.GetComparableVersion() < rhs.GetComparableVersion();
}
constexpr friend bool operator>(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
return lhs.GetComparableVersion() > rhs.GetComparableVersion();
}
};
void GetFirmwareVersion(FirmwareVersion *out);
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/settings/settings_types.hpp>
namespace ams::settings::system {
enum ProductModel {
ProductModel_Invalid = 0,
ProductModel_Nx = 1,
};
ProductModel GetProductModel();
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/settings/settings_types.hpp>
namespace ams::settings::system {
enum RegionCode {
RegionCode_Japan = 0,
RegionCode_Usa = 1,
RegionCode_Europe = 2,
RegionCode_Australia = 3,
RegionCode_HongKongTaiwanKorea = 4,
RegionCode_China = 5,
};
void GetRegionCode(RegionCode *out);
}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/settings/settings_types.hpp>
namespace ams::settings::system {
struct SerialNumber {
char str[0x18];
};
void GetSerialNumber(SerialNumber *out);
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/time/time_common.hpp>
#include <stratosphere/time/time_posix_time.hpp>
#include <stratosphere/time/time_steady_clock_time_point.hpp>
#include <stratosphere/time/time_api.hpp>
#include <stratosphere/time/time_standard_steady_clock.hpp>
#include <stratosphere/time/time_standard_user_system_clock.hpp>
#include <stratosphere/time/time_standard_network_system_clock.hpp>
#include <stratosphere/time/impl/util/time_impl_util_api.hpp>

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
#include <stratosphere/time/time_posix_time.hpp>
#include <stratosphere/time/time_steady_clock_time_point.hpp>
namespace ams::time::impl::util {
Result GetSpanBetween(s64 *out, const SteadyClockTimePoint &from, const SteadyClockTimePoint &to);
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
#include <stratosphere/time/time_posix_time.hpp>
#include <stratosphere/time/time_steady_clock_time_point.hpp>
namespace ams::time {
Result Initialize();
Result InitializeForSystem();
Result InitializeForSystemUser();
Result Finalize();
bool IsInitialized();
Result GetElapsedSecondsBetween(s64 *out, const SteadyClockTimePoint &from, const SteadyClockTimePoint &to);
}

View file

@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::time {
using SourceId = util::Uuid;
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
namespace ams::time {
struct PosixTime {
s64 value;
constexpr PosixTime &operator+=(const TimeSpan &ts) { this->value += ts.GetSeconds(); return *this; }
constexpr PosixTime &operator-=(const TimeSpan &ts) { this->value -= ts.GetSeconds(); return *this; }
constexpr friend PosixTime operator+(const PosixTime &lhs, const TimeSpan &rhs) { return { .value = lhs.value + rhs.GetSeconds() }; }
constexpr friend PosixTime operator-(const PosixTime &lhs, const TimeSpan &rhs) { return { .value = lhs.value - rhs.GetSeconds() }; }
constexpr friend TimeSpan operator-(const PosixTime &lhs, const PosixTime &rhs) { return TimeSpan::FromSeconds(lhs.value - rhs.value); }
constexpr friend bool operator==(const PosixTime &lhs, const PosixTime &rhs) { return lhs.value == rhs.value; }
constexpr friend bool operator!=(const PosixTime &lhs, const PosixTime &rhs) { return lhs.value != rhs.value; }
constexpr friend bool operator<=(const PosixTime &lhs, const PosixTime &rhs) { return lhs.value <= rhs.value; }
constexpr friend bool operator>=(const PosixTime &lhs, const PosixTime &rhs) { return lhs.value >= rhs.value; }
constexpr friend bool operator< (const PosixTime &lhs, const PosixTime &rhs) { return lhs.value < rhs.value; }
constexpr friend bool operator> (const PosixTime &lhs, const PosixTime &rhs) { return lhs.value > rhs.value; }
};
static_assert(sizeof(PosixTime) == sizeof(s64));
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
#include <stratosphere/time/time_system_clock_common.hpp>
#include <stratosphere/time/time_posix_time.hpp>
namespace ams::time {
class StandardNetworkSystemClock {
public:
using rep = SystemClockTraits::rep;
using period = SystemClockTraits::period;
using duration = SystemClockTraits::duration;
using time_point = SystemClockTraits::time_point;
static constexpr bool is_steady = false;
public:
static time_point now();
static std::time_t to_time_t(const StandardUserSystemClock::time_point &t);
static time_point from_time_t(std::time_t t);
public:
static Result GetCurrentTime(PosixTime *out);
/* TODO: static Result GetSystemClockContext(SystemClockContext *out); */
};
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
#include <stratosphere/time/time_steady_clock_time_point.hpp>
namespace ams::time {
class StandardSteadyClock {
public:
using rep = s64;
using period = std::ratio<1>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<StandardSteadyClock>;
static constexpr bool is_steady = true;
public:
static time_point now();
public:
static Result GetCurrentTimePoint(SteadyClockTimePoint *out);
};
Result GetStandardSteadyClockCurrentTimePoint(SteadyClockTimePoint *out);
TimeSpan GetStandardSteadyClockInternalOffset();
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
#include <stratosphere/time/time_system_clock_common.hpp>
#include <stratosphere/time/time_posix_time.hpp>
namespace ams::time {
class StandardUserSystemClock {
public:
using rep = SystemClockTraits::rep;
using period = SystemClockTraits::period;
using duration = SystemClockTraits::duration;
using time_point = SystemClockTraits::time_point;
static constexpr bool is_steady = false;
public:
static time_point now();
static std::time_t to_time_t(const StandardUserSystemClock::time_point &t);
static time_point from_time_t(std::time_t t);
public:
static Result GetCurrentTime(PosixTime *out);
/* TODO: static Result GetSystemClockContext(SystemClockContext *out); */
};
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
namespace ams::time {
struct SteadyClockTimePoint {
s64 value;
SourceId source_id;
constexpr SteadyClockTimePoint &operator+=(const TimeSpan &ts) { this->value += ts.GetSeconds(); return *this; }
constexpr SteadyClockTimePoint &operator-=(const TimeSpan &ts) { this->value -= ts.GetSeconds(); return *this; }
constexpr friend SteadyClockTimePoint operator+(const SteadyClockTimePoint &lhs, const TimeSpan &rhs) { return { .value = lhs.value + rhs.GetSeconds(), .source_id = lhs.source_id }; }
constexpr friend SteadyClockTimePoint operator-(const SteadyClockTimePoint &lhs, const TimeSpan &rhs) { return { .value = lhs.value - rhs.GetSeconds(), .source_id = lhs.source_id }; }
constexpr friend bool operator==(const SteadyClockTimePoint &lhs, const SteadyClockTimePoint &rhs) { return lhs.value == rhs.value && lhs.source_id == rhs.source_id; }
constexpr friend bool operator!=(const SteadyClockTimePoint &lhs, const SteadyClockTimePoint &rhs) { return !(lhs == rhs); }
};
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/time/time_common.hpp>
namespace ams::time {
class SystemClockTraits {
public:
using rep = s64;
using period = std::ratio<1>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<SystemClockTraits>;
};
}