2020-04-14 00:07:37 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-04-14 00:07:37 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "erpt_srv_report_impl.hpp"
|
|
|
|
#include "erpt_srv_report.hpp"
|
|
|
|
|
|
|
|
namespace ams::erpt::srv {
|
|
|
|
|
|
|
|
ReportFileName Report::FileName(ReportId report_id, bool redirect_to_sd) {
|
|
|
|
ReportFileName report_name;
|
2021-01-12 10:59:41 +00:00
|
|
|
util::SNPrintf(report_name.name, sizeof(report_name.name),
|
2020-04-14 00:07:37 +00:00
|
|
|
"%s:/%08x-%04x-%04x-%02x%02x-%04x%08x",
|
|
|
|
(redirect_to_sd ? ReportOnSdStoragePath : ReportStoragePath),
|
|
|
|
report_id.uuid_data.time_low,
|
|
|
|
report_id.uuid_data.time_mid,
|
|
|
|
report_id.uuid_data.time_high_and_version,
|
|
|
|
report_id.uuid_data.clock_high,
|
|
|
|
report_id.uuid_data.clock_low,
|
|
|
|
static_cast<u32>((report_id.uuid_data.node >> BITSIZEOF(u32)) & 0x0000FFFF),
|
|
|
|
static_cast<u32>((report_id.uuid_data.node >> 0) & 0xFFFFFFFF));
|
|
|
|
return report_name;
|
|
|
|
}
|
|
|
|
|
2021-10-10 07:14:06 +00:00
|
|
|
Report::Report(JournalRecord<ReportInfo> *r, bool redirect_to_sd) : m_record(r), m_redirect_to_sd_card(redirect_to_sd) {
|
|
|
|
m_record->AddReference();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Report::~Report() {
|
|
|
|
this->CloseStream();
|
2021-10-10 07:14:06 +00:00
|
|
|
if (m_record->RemoveReference()) {
|
2020-04-14 00:07:37 +00:00
|
|
|
this->DeleteStream(this->FileName().name);
|
2021-10-10 07:14:06 +00:00
|
|
|
delete m_record;
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 19:13:35 +00:00
|
|
|
ReportFileName Report::FileName() const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return FileName(m_record->m_info.id, m_redirect_to_sd_card);
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Report::Open(ReportOpenType type) {
|
|
|
|
switch (type) {
|
2022-03-26 21:48:33 +00:00
|
|
|
case ReportOpenType_Create: R_RETURN(this->OpenStream(this->FileName().name, StreamMode_Write, ReportStreamBufferSize));
|
|
|
|
case ReportOpenType_Read: R_RETURN(this->OpenStream(this->FileName().name, StreamMode_Read, ReportStreamBufferSize));
|
2022-03-26 07:14:36 +00:00
|
|
|
default: R_THROW(erpt::ResultInvalidArgument());
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Result Report::Read(u32 *out_read_count, u8 *dst, u32 dst_size) {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(this->ReadStream(out_read_count, dst, dst_size));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Report::Delete() {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(this->DeleteStream(this->FileName().name));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Report::Close() {
|
|
|
|
return this->CloseStream();
|
|
|
|
}
|
|
|
|
|
2020-12-03 19:13:35 +00:00
|
|
|
Result Report::GetFlags(ReportFlagSet *out) const {
|
2021-10-10 07:14:06 +00:00
|
|
|
*out = m_record->m_info.flags;
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Report::SetFlags(ReportFlagSet flags) {
|
2021-10-10 07:14:06 +00:00
|
|
|
if (((~m_record->m_info.flags) & flags).IsAnySet()) {
|
|
|
|
m_record->m_info.flags |= flags;
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(Journal::Commit());
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 19:13:35 +00:00
|
|
|
Result Report::GetSize(s64 *out) const {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(this->GetStreamSize(out));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|