1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 18:26:39 +00:00

TitleMetadataTask: use a struct instead of a vector

The struct has been typedef'd as TitleApplicationMetadataInfo. It holds the pointer to the array returned by titleGetApplicationMetadataEntries(), as well as the number of elements available in the array.

There's no point in populating a vector when we already have an array we can work with.
This commit is contained in:
Pablo Curiel 2024-05-06 00:41:41 +02:00
parent 5cc387c9b6
commit d9c8d93180
5 changed files with 38 additions and 45 deletions

View file

@ -31,23 +31,26 @@
namespace nxdt::tasks namespace nxdt::tasks
{ {
/* Used to hold pointers to application metadata entries. */ /* Used to hold an application metadata array + its number of elements. */
typedef std::vector<TitleApplicationMetadata*> TitleApplicationMetadataVector; typedef struct {
TitleApplicationMetadata **app_metadata;
u32 app_metadata_count;
} TitleApplicationMetadataInfo;
/* Custom event type. */ /* Custom event type. */
typedef brls::Event<const TitleApplicationMetadataVector&> UserTitleEvent; typedef brls::Event<const TitleApplicationMetadataInfo&> UserTitleEvent;
/* Title metadata task. */ /* Title metadata task. */
/* Its event provides a const reference to a TitleApplicationMetadataVector with metadata for user titles (system titles don't change at runtime). */ /* Its event provides a const reference to a TitleApplicationMetadataInfo with metadata for user titles (system titles don't change at runtime). */
class TitleMetadataTask: public brls::RepeatingTask class TitleMetadataTask: public brls::RepeatingTask
{ {
private: private:
UserTitleEvent user_title_event; UserTitleEvent user_title_event;
TitleApplicationMetadataVector system_metadata{}; TitleApplicationMetadataInfo system_metadata_info{};
TitleApplicationMetadataVector user_metadata{}; TitleApplicationMetadataInfo user_metadata_info{};
void PopulateApplicationMetadataVector(bool is_system); void PopulateApplicationMetadataInfo(bool is_system);
protected: protected:
void run(retro_time_t current_time) override; void run(retro_time_t current_time) override;
@ -57,9 +60,9 @@ namespace nxdt::tasks
~TitleMetadataTask(); ~TitleMetadataTask();
/* Intentionally left here to let views retrieve title metadata on-demand. */ /* Intentionally left here to let views retrieve title metadata on-demand. */
ALWAYS_INLINE const TitleApplicationMetadataVector& GetApplicationMetadata(bool is_system) ALWAYS_INLINE const TitleApplicationMetadataInfo& GetApplicationMetadataInfo(bool is_system)
{ {
return (is_system ? this->system_metadata : this->user_metadata); return (is_system ? this->system_metadata_info : this->user_metadata_info);
} }
ALWAYS_INLINE UserTitleEvent::Subscription RegisterListener(UserTitleEvent::Callback cb) ALWAYS_INLINE UserTitleEvent::Subscription RegisterListener(UserTitleEvent::Callback cb)

View file

@ -95,9 +95,9 @@ namespace nxdt::views
return this->gc_status_task->GetGameCardStatus(); return this->gc_status_task->GetGameCardStatus();
} }
ALWAYS_INLINE const nxdt::tasks::TitleApplicationMetadataVector& GetApplicationMetadata(bool is_system) ALWAYS_INLINE const nxdt::tasks::TitleApplicationMetadataInfo& GetApplicationMetadataInfo(bool is_system)
{ {
return this->title_metadata_task->GetApplicationMetadata(is_system); return this->title_metadata_task->GetApplicationMetadataInfo(is_system);
} }
ALWAYS_INLINE const nxdt::tasks::UmsDeviceVector& GetUmsDevices(void) ALWAYS_INLINE const nxdt::tasks::UmsDeviceVector& GetUmsDevices(void)

View file

@ -76,7 +76,7 @@ namespace nxdt::views
nxdt::tasks::UserTitleEvent::Subscription title_task_sub; nxdt::tasks::UserTitleEvent::Subscription title_task_sub;
bool is_system = false; bool is_system = false;
void PopulateList(const nxdt::tasks::TitleApplicationMetadataVector& app_metadata); void PopulateList(const nxdt::tasks::TitleApplicationMetadataInfo& app_metadata_info);
public: public:
TitlesTab(RootView *root_view, bool is_system); TitlesTab(RootView *root_view, bool is_system);

View file

@ -30,10 +30,10 @@ namespace nxdt::tasks
LOG_MSG_DEBUG("Title metadata task started."); LOG_MSG_DEBUG("Title metadata task started.");
/* Get system metadata entries. */ /* Get system metadata entries. */
this->PopulateApplicationMetadataVector(true); this->PopulateApplicationMetadataInfo(true);
/* Get user metadata entries. */ /* Get user metadata entries. */
this->PopulateApplicationMetadataVector(false); this->PopulateApplicationMetadataInfo(false);
/* Start task. */ /* Start task. */
brls::RepeatingTask::start(); brls::RepeatingTask::start();
@ -41,9 +41,9 @@ namespace nxdt::tasks
TitleMetadataTask::~TitleMetadataTask() TitleMetadataTask::~TitleMetadataTask()
{ {
/* Clear application metadata vectors. */ /* Free application metadata arrays. */
this->system_metadata.clear(); if (this->system_metadata_info.app_metadata) free(this->system_metadata_info.app_metadata);
this->user_metadata.clear(); if (this->user_metadata_info.app_metadata) free(this->user_metadata_info.app_metadata);
LOG_MSG_DEBUG("Title metadata task stopped."); LOG_MSG_DEBUG("Title metadata task stopped.");
} }
@ -54,37 +54,27 @@ namespace nxdt::tasks
if (titleIsGameCardInfoUpdated()) if (titleIsGameCardInfoUpdated())
{ {
/* Update user metadata vector. */ /* Update user metadata array. */
this->PopulateApplicationMetadataVector(false); this->PopulateApplicationMetadataInfo(false);
/* Fire task event. */ /* Fire task event. */
this->user_title_event.fire(this->user_metadata); this->user_title_event.fire(this->user_metadata_info);
//brls::Application::notify("tasks/notifications/user_titles"_i18n); //brls::Application::notify("tasks/notifications/user_titles"_i18n);
LOG_MSG_DEBUG("Title info updated."); LOG_MSG_DEBUG("Title info updated.");
} }
} }
void TitleMetadataTask::PopulateApplicationMetadataVector(bool is_system) void TitleMetadataTask::PopulateApplicationMetadataInfo(bool is_system)
{ {
TitleApplicationMetadata **app_metadata = nullptr; /* Get reference to output struct. */
u32 app_metadata_count = 0; TitleApplicationMetadataInfo& info = (is_system ? this->system_metadata_info : this->user_metadata_info);
if (info.app_metadata) free(info.app_metadata);
/* Get pointer to output vector. */ info.app_metadata_count = 0;
TitleApplicationMetadataVector& vector = (is_system ? this->system_metadata : this->user_metadata);
vector.clear();
/* Get application metadata entries. */ /* Get application metadata entries. */
app_metadata = titleGetApplicationMetadataEntries(is_system, &app_metadata_count); info.app_metadata = titleGetApplicationMetadataEntries(is_system, &(info.app_metadata_count));
if (app_metadata)
{
/* Fill output vector. */
for(u32 i = 0; i < app_metadata_count; i++) vector.push_back(app_metadata[i]);
/* Free application metadata array. */ LOG_MSG_DEBUG("Retrieved %u %s metadata %s.", info.app_metadata_count, is_system ? "system" : "user", info.app_metadata_count == 1 ? "entry" : "entries");
free(app_metadata);
}
LOG_MSG_DEBUG("Retrieved %u %s metadata %s.", app_metadata_count, is_system ? "system" : "user", app_metadata_count == 1 ? "entry" : "entries");
} }
} }

View file

@ -82,14 +82,14 @@ namespace nxdt::views
TitlesTab::TitlesTab(RootView *root_view, bool is_system) : LayeredErrorFrame("titles_tab/no_titles_available"_i18n), root_view(root_view), is_system(is_system) TitlesTab::TitlesTab(RootView *root_view, bool is_system) : LayeredErrorFrame("titles_tab/no_titles_available"_i18n), root_view(root_view), is_system(is_system)
{ {
/* Populate list. */ /* Populate list. */
this->PopulateList(this->root_view->GetApplicationMetadata(this->is_system)); this->PopulateList(this->root_view->GetApplicationMetadataInfo(this->is_system));
/* Subscribe to the title event if this is the user titles tab. */ /* Subscribe to the title event if this is the user titles tab. */
if (!this->is_system) if (!this->is_system)
{ {
this->title_task_sub = this->root_view->RegisterTitleMetadataTaskListener([this](const nxdt::tasks::TitleApplicationMetadataVector& app_metadata) { this->title_task_sub = this->root_view->RegisterTitleMetadataTaskListener([this](const nxdt::tasks::TitleApplicationMetadataInfo& app_metadata_info) {
/* Update list. */ /* Update list. */
this->PopulateList(app_metadata); this->PopulateList(app_metadata_info);
}); });
} }
} }
@ -100,34 +100,34 @@ namespace nxdt::views
if (!this->is_system) this->root_view->UnregisterTitleMetadataTaskListener(this->title_task_sub); if (!this->is_system) this->root_view->UnregisterTitleMetadataTaskListener(this->title_task_sub);
} }
void TitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataVector& app_metadata) void TitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataInfo& app_metadata_info)
{ {
/* Block user inputs. */ /* Block user inputs. */
brls::Application::blockInputs(); brls::Application::blockInputs();
/* Populate variables. */ /* Populate variables. */
size_t app_metadata_count = app_metadata.size();
bool update_focused_view = this->IsListItemFocused(); bool update_focused_view = this->IsListItemFocused();
int focus_stack_index = this->GetFocusStackViewIndex(); int focus_stack_index = this->GetFocusStackViewIndex();
/* If needed, switch to the error frame *before* cleaning up our list. */ /* If needed, switch to the error frame *before* cleaning up our list. */
if (!app_metadata_count) this->SwitchLayerView(true); if (!app_metadata_info.app_metadata_count) this->SwitchLayerView(true);
/* Clear list. */ /* Clear list. */
this->list->clear(); this->list->clear();
this->list->invalidate(true); this->list->invalidate(true);
/* Return immediately if we have no application metadata. */ /* Return immediately if we have no application metadata. */
if (!app_metadata_count) if (!app_metadata_info.app_metadata_count)
{ {
brls::Application::unblockInputs(); brls::Application::unblockInputs();
return; return;
} }
/* Populate list. */ /* Populate list. */
for(const TitleApplicationMetadata *cur_app_metadata : app_metadata) for(u32 i = 0; i < app_metadata_info.app_metadata_count; i++)
{ {
/* Create list item. */ /* Create list item. */
const TitleApplicationMetadata *cur_app_metadata = app_metadata_info.app_metadata[i];
TitlesTabItem *item = new TitlesTabItem(cur_app_metadata, this->is_system); TitlesTabItem *item = new TitlesTabItem(cur_app_metadata, this->is_system);
/* Register click event. */ /* Register click event. */