applet: Fix HLE applet pre-start lifecycle. (#6362)

This commit is contained in:
Steveice10 2023-03-25 14:36:14 -07:00 committed by GitHub
parent 44097c2a8d
commit d9d0fc63ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 11 deletions

View File

@ -80,6 +80,9 @@ ResultCode Applet::Create(Service::APT::AppletId id, Service::APT::AppletId pare
manager->FinishPreloadingLibraryApplet(id);
}
// Schedule the update event
Core::System::GetInstance().CoreTiming().ScheduleEvent(
usToCycles(applet_update_interval_us), applet_update_event, static_cast<u64>(id));
return RESULT_SUCCESS;
}
@ -96,7 +99,9 @@ static void AppletUpdateEvent(u64 applet_id, s64 cycles_late) {
const auto applet = Applet::Get(id);
ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id={:08X}", id);
if (applet->IsActive()) {
applet->Update();
}
// If the applet is still running after the last update, reschedule the event
if (applet->IsRunning()) {
@ -112,14 +117,16 @@ bool Applet::IsRunning() const {
return is_running;
}
bool Applet::IsActive() const {
return is_active;
}
ResultCode Applet::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
switch (parameter.signal) {
case Service::APT::SignalType::Wakeup: {
ResultCode result = Start(parameter);
if (!result.IsError()) {
// Schedule the update event
Core::System::GetInstance().CoreTiming().ScheduleEvent(
usToCycles(applet_update_interval_us), applet_update_event, static_cast<u64>(id));
is_active = true;
}
return result;
}
@ -146,6 +153,7 @@ void Applet::CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vect
LOG_ERROR(Service_APT, "called after destructing applet manager");
}
is_active = false;
is_running = false;
}

View File

@ -40,10 +40,15 @@ public:
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter);
/**
* Whether the applet is currently executing instead of the host application or not.
* Whether the applet is currently running.
*/
[[nodiscard]] bool IsRunning() const;
/**
* Whether the applet is currently active instead of the host application or not.
*/
[[nodiscard]] bool IsActive() const;
/**
* Handles an update tick for the Applet, lets it update the screen, send commands, etc.
*/
@ -79,8 +84,11 @@ protected:
bool preload; ///< Whether the Applet is being preloaded.
std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet
/// Whether this applet is currently running instead of the host application or not.
bool is_running = false;
/// Whether this applet is running.
bool is_running = true;
/// Whether this applet is currently active instead of the host application or not.
bool is_active = false;
void SendParameter(const Service::APT::MessageParameter& parameter);
void CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vector<u8>& buffer);

View File

@ -44,7 +44,6 @@ ResultCode ErrEula::ReceiveParameterImpl(const Service::APT::MessageParameter& p
}
ResultCode ErrEula::Start(const Service::APT::MessageParameter& parameter) {
is_running = true;
startup_param = parameter.buffer;
// TODO(Subv): Set the expected fields in the response buffer before resending it to the

View File

@ -65,7 +65,6 @@ ResultCode MiiSelector::Start(const Service::APT::MessageParameter& parameter) {
MiiSelectorConfig frontend_config = ToFrontendConfig(config);
frontend_applet->Setup(frontend_config);
is_running = true;
return RESULT_SUCCESS;
}

View File

@ -44,7 +44,6 @@ ResultCode Mint::ReceiveParameterImpl(const Service::APT::MessageParameter& para
}
ResultCode Mint::Start(const Service::APT::MessageParameter& parameter) {
is_running = true;
startup_param = parameter.buffer;
// TODO(Subv): Set the expected fields in the response buffer before resending it to the

View File

@ -106,7 +106,6 @@ ResultCode SoftwareKeyboard::Start(Service::APT::MessageParameter const& paramet
frontend_applet->Execute(ToFrontendConfig(config));
is_running = true;
return RESULT_SUCCESS;
}