erpt: update server code for 16.0.0 logic changes

This commit is contained in:
Michael Scire 2023-02-23 21:51:51 -07:00
parent 46094cfb3e
commit 33d42f4831
4 changed files with 15 additions and 44 deletions

View file

@ -29,7 +29,7 @@ namespace ams::erpt::srv {
} }
Context::Context(CategoryId cat, u32 max_records) : m_category(cat), m_max_record_count(max_records), m_record_count(0) { Context::Context(CategoryId cat) : m_category(cat) {
g_category_list.push_front(*this); g_category_list.push_front(*this);
} }
@ -38,12 +38,11 @@ namespace ams::erpt::srv {
} }
Result Context::AddCategoryToReport(Report *report) { Result Context::AddCategoryToReport(Report *report) {
R_SUCCEED_IF(m_record_list.empty()); if (m_record != nullptr) {
const auto *entry = m_record->GetContextEntryPtr();
for (auto it = m_record_list.begin(); it != m_record_list.end(); it++) { for (u32 i = 0; i < entry->field_count; i++) {
for (u32 i = 0; i < it->m_ctx.field_count; i++) { auto *field = std::addressof(entry->fields[i]);
auto *field = std::addressof(it->m_ctx.fields[i]); u8 *arr_buf = entry->array_buffer;
u8 *arr_buf = it->m_ctx.array_buffer;
switch (field->type) { switch (field->type) {
case FieldType_Bool: R_TRY(Cipher::AddField(report, field->id, field->value_bool)); break; case FieldType_Bool: R_TRY(Cipher::AddField(report, field->id, field->value_bool)); break;
@ -70,46 +69,23 @@ namespace ams::erpt::srv {
R_SUCCEED(); R_SUCCEED();
} }
Result Context::AddContextToCategory(const ContextEntry *entry, const u8 *data, u32 data_size) { Result Context::SubmitContext(const ContextEntry *entry, const u8 *data, u32 data_size) {
auto record = std::make_unique<ContextRecord>(); auto record = std::make_unique<ContextRecord>();
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory()); R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
R_TRY(record->Initialize(entry, data, data_size)); R_TRY(record->Initialize(entry, data, data_size));
this->AddContextRecordToCategory(std::move(record)); R_RETURN(SubmitContextRecord(std::move(record)));
R_SUCCEED();
}
Result Context::AddContextRecordToCategory(std::unique_ptr<ContextRecord> record) {
if (m_record_count < m_max_record_count) {
m_record_list.push_front(*record.release());
m_record_count++;
} else {
ContextRecord *back = std::addressof(m_record_list.back());
m_record_list.pop_back();
m_record_list.push_front(*record.release());
delete back;
}
R_SUCCEED();
}
Result Context::SubmitContext(const ContextEntry *entry, const u8 *data, u32 data_size) {
auto it = util::range::find_if(g_category_list, [&](const Context &cur) {
return cur.m_category == entry->category;
});
R_UNLESS(it != g_category_list.end(), erpt::ResultCategoryNotFound());
R_RETURN(it->AddContextToCategory(entry, data, data_size));
} }
Result Context::SubmitContextRecord(std::unique_ptr<ContextRecord> record) { Result Context::SubmitContextRecord(std::unique_ptr<ContextRecord> record) {
auto it = util::range::find_if(g_category_list, [&](const Context &cur) { auto it = util::range::find_if(g_category_list, [&](const Context &cur) {
return cur.m_category == record->m_ctx.category; return cur.m_category == record->GetContextEntryPtr()->category;
}); });
R_UNLESS(it != g_category_list.end(), erpt::ResultCategoryNotFound()); R_UNLESS(it != g_category_list.end(), erpt::ResultCategoryNotFound());
R_RETURN(it->AddContextRecordToCategory(std::move(record))); it->m_record = std::move(record);
R_SUCCEED();
} }
Result Context::WriteContextsToReport(Report *report) { Result Context::WriteContextsToReport(Report *report) {

View file

@ -26,16 +26,12 @@ namespace ams::erpt::srv {
class Context : public Allocator, public util::IntrusiveListBaseNode<Context> { class Context : public Allocator, public util::IntrusiveListBaseNode<Context> {
private: private:
const CategoryId m_category; const CategoryId m_category;
const u32 m_max_record_count; std::unique_ptr<ContextRecord> m_record;
u32 m_record_count;
util::IntrusiveListBaseTraits<ContextRecord>::ListType m_record_list;
public: public:
Context(CategoryId cat, u32 max_records); Context(CategoryId cat);
~Context(); ~Context();
Result AddCategoryToReport(Report *report); Result AddCategoryToReport(Report *report);
Result AddContextToCategory(const ContextEntry *entry, const u8 *data, u32 data_size);
Result AddContextRecordToCategory(std::unique_ptr<ContextRecord> record);
public: public:
static Result SubmitContext(const ContextEntry *entry, const u8 *data, u32 data_size); static Result SubmitContext(const ContextEntry *entry, const u8 *data, u32 data_size);
static Result SubmitContextRecord(std::unique_ptr<ContextRecord> record); static Result SubmitContextRecord(std::unique_ptr<ContextRecord> record);

View file

@ -21,8 +21,7 @@ namespace ams::erpt::srv {
class Context; class Context;
class ContextRecord : public Allocator, public util::IntrusiveListBaseNode<ContextRecord> { class ContextRecord : public Allocator {
friend class Context;
private: private:
static u32 s_record_count; static u32 s_record_count;
public: public:

View file

@ -106,7 +106,7 @@ namespace ams::erpt::srv {
g_sf_allocator.Attach(g_heap_handle); g_sf_allocator.Attach(g_heap_handle);
for (auto i = 0; i < CategoryId_Count; i++) { for (auto i = 0; i < CategoryId_Count; i++) {
Context *ctx = new Context(static_cast<CategoryId>(i), 1); Context *ctx = new Context(static_cast<CategoryId>(i));
AMS_ABORT_UNLESS(ctx != nullptr); AMS_ABORT_UNLESS(ctx != nullptr);
} }