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_manager_impl.hpp"
|
|
|
|
#include "erpt_srv_journal.hpp"
|
|
|
|
|
|
|
|
namespace ams::erpt::srv {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ManagerList = util::IntrusiveListBaseTraits<ManagerImpl>::ListType;
|
|
|
|
|
2021-10-10 07:14:06 +00:00
|
|
|
constinit ManagerList g_manager_list;
|
2020-04-14 00:07:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-10 07:14:06 +00:00
|
|
|
ManagerImpl::ManagerImpl() : m_system_event(os::EventClearMode_AutoClear, true) {
|
2020-04-14 00:07:37 +00:00
|
|
|
g_manager_list.push_front(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ManagerImpl::~ManagerImpl() {
|
|
|
|
g_manager_list.erase(g_manager_list.iterator_to(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ManagerImpl::NotifyOne() {
|
2021-10-10 07:14:06 +00:00
|
|
|
m_system_event.Signal();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::NotifyAll() {
|
|
|
|
for (auto &manager : g_manager_list) {
|
|
|
|
manager.NotifyOne();
|
|
|
|
}
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter) {
|
|
|
|
R_UNLESS(out_list.GetSize() == sizeof(ReportList), erpt::ResultInvalidArgument());
|
|
|
|
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(Journal::GetReportList(reinterpret_cast<ReportList *>(out_list.GetPointer()), type_filter));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::GetEvent(ams::sf::OutCopyHandle out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
out.SetValue(m_system_event.GetReadableHandle(), false);
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::CleanupReports() {
|
|
|
|
Journal::CleanupReports();
|
|
|
|
Journal::CleanupAttachments();
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(Journal::Commit());
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::DeleteReport(const ReportId &report_id) {
|
|
|
|
R_TRY(Journal::Delete(report_id));
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(Journal::Commit());
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::GetStorageUsageStatistics(ams::sf::Out<StorageUsageStatistics> out) {
|
|
|
|
StorageUsageStatistics stats = {};
|
|
|
|
|
|
|
|
stats.journal_uuid = Journal::GetJournalId();
|
|
|
|
stats.used_storage_size = Journal::GetUsedStorage();
|
|
|
|
stats.max_report_size = Journal::GetMaxReportSize();
|
|
|
|
|
|
|
|
for (int i = ReportType_Start; i < ReportType_End; i++) {
|
|
|
|
const auto type = static_cast<ReportType>(i);
|
|
|
|
stats.report_count[i] = Journal::GetStoredReportCount(type);
|
|
|
|
stats.transmitted_count[i] = Journal::GetTransmittedCount(type);
|
|
|
|
stats.untransmitted_count[i] = Journal::GetUntransmittedCount(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
out.SetValue(stats);
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerImpl::GetAttachmentList(const ams::sf::OutBuffer &out_list, const ReportId &report_id) {
|
|
|
|
R_UNLESS(out_list.GetSize() == sizeof(AttachmentList), erpt::ResultInvalidArgument());
|
|
|
|
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(Journal::GetAttachmentList(reinterpret_cast<AttachmentList *>(out_list.GetPointer()), report_id));
|
2020-04-14 00:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|