mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-12-26 22:10:07 +00:00
am: add application creator and accessor methods
This commit is contained in:
parent
a6a9c19984
commit
400c0c5e8c
@ -9,12 +9,15 @@
|
||||
#include "core/hle/service/am/service/application_accessor.h"
|
||||
#include "core/hle/service/am/service/library_applet_accessor.h"
|
||||
#include "core/hle/service/am/service/storage.h"
|
||||
#include "core/hle/service/am/window_system.h"
|
||||
#include "core/hle/service/cmif_serialization.h"
|
||||
|
||||
namespace Service::AM {
|
||||
|
||||
IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet)
|
||||
: ServiceFramework{system_, "IApplicationAccessor"}, m_applet(std::move(applet)) {
|
||||
IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet,
|
||||
WindowSystem& window_system)
|
||||
: ServiceFramework{system_, "IApplicationAccessor"}, m_window_system(window_system),
|
||||
m_applet(std::move(applet)) {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, D<&IApplicationAccessor::GetAppletStateChangedEvent>, "GetAppletStateChangedEvent"},
|
||||
@ -59,7 +62,15 @@ Result IApplicationAccessor::Start() {
|
||||
|
||||
Result IApplicationAccessor::RequestExit() {
|
||||
LOG_INFO(Service_AM, "called");
|
||||
m_applet->lifecycle_manager.RequestExit();
|
||||
|
||||
std::scoped_lock lk{m_applet->lock};
|
||||
if (m_applet->exit_locked) {
|
||||
m_applet->lifecycle_manager.RequestExit();
|
||||
m_applet->UpdateSuspensionStateLocked(true);
|
||||
} else {
|
||||
m_applet->process->Terminate();
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
@ -114,8 +125,9 @@ Result IApplicationAccessor::GetCurrentLibraryApplet(
|
||||
}
|
||||
|
||||
Result IApplicationAccessor::RequestForApplicationToGetForeground() {
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
R_THROW(ResultUnknown);
|
||||
LOG_INFO(Service_AM, "called");
|
||||
m_window_system.RequestApplicationToGetForeground();
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result IApplicationAccessor::CheckRightsEnvironmentAvailable(Out<bool> out_is_available) {
|
||||
|
@ -13,10 +13,12 @@ namespace Service::AM {
|
||||
struct Applet;
|
||||
class ILibraryAppletAccessor;
|
||||
class IStorage;
|
||||
class WindowSystem;
|
||||
|
||||
class IApplicationAccessor final : public ServiceFramework<IApplicationAccessor> {
|
||||
public:
|
||||
explicit IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet);
|
||||
explicit IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet,
|
||||
WindowSystem& window_system);
|
||||
~IApplicationAccessor() override;
|
||||
|
||||
private:
|
||||
@ -34,6 +36,7 @@ private:
|
||||
Result GetNsRightsEnvironmentHandle(Out<u64> out_handle);
|
||||
Result ReportApplicationExitTimeout();
|
||||
|
||||
WindowSystem& m_window_system;
|
||||
const std::shared_ptr<Applet> m_applet;
|
||||
};
|
||||
|
||||
|
@ -1,17 +1,57 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/file_sys/nca_metadata.h"
|
||||
#include "core/file_sys/registered_cache.h"
|
||||
#include "core/hle/service/am/am_types.h"
|
||||
#include "core/hle/service/am/applet.h"
|
||||
#include "core/hle/service/am/applet_manager.h"
|
||||
#include "core/hle/service/am/process_creation.h"
|
||||
#include "core/hle/service/am/service/application_accessor.h"
|
||||
#include "core/hle/service/am/service/application_creator.h"
|
||||
#include "core/hle/service/am/window_system.h"
|
||||
#include "core/hle/service/cmif_serialization.h"
|
||||
#include "core/loader/loader.h"
|
||||
|
||||
namespace Service::AM {
|
||||
|
||||
IApplicationCreator::IApplicationCreator(Core::System& system_)
|
||||
: ServiceFramework{system_, "IApplicationCreator"} {
|
||||
namespace {
|
||||
|
||||
Result CreateGuestApplication(SharedPointer<IApplicationAccessor>* out_application_accessor,
|
||||
Core::System& system, WindowSystem& window_system, u64 program_id) {
|
||||
FileSys::VirtualFile nca_raw{};
|
||||
|
||||
// Get the program NCA from storage.
|
||||
auto& storage = system.GetContentProviderUnion();
|
||||
nca_raw = storage.GetEntryRaw(program_id, FileSys::ContentRecordType::Program);
|
||||
|
||||
// Ensure we retrieved a program NCA.
|
||||
R_UNLESS(nca_raw != nullptr, ResultUnknown);
|
||||
|
||||
std::vector<u8> control;
|
||||
std::unique_ptr<Loader::AppLoader> loader;
|
||||
Loader::ResultStatus result;
|
||||
auto process =
|
||||
CreateApplicationProcess(control, loader, result, system, nca_raw, program_id, 0);
|
||||
R_UNLESS(process != nullptr, ResultUnknown);
|
||||
|
||||
const auto applet = std::make_shared<Applet>(system, std::move(process), true);
|
||||
applet->program_id = program_id;
|
||||
applet->applet_id = AppletId::Application;
|
||||
applet->type = AppletType::Application;
|
||||
applet->library_applet_mode = LibraryAppletMode::AllForeground;
|
||||
|
||||
window_system.TrackApplet(applet, true);
|
||||
|
||||
*out_application_accessor =
|
||||
std::make_shared<IApplicationAccessor>(system, applet, window_system);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
IApplicationCreator::IApplicationCreator(Core::System& system_, WindowSystem& window_system)
|
||||
: ServiceFramework{system_, "IApplicationCreator"}, m_window_system{window_system} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, D<&IApplicationCreator::CreateApplication>, "CreateApplication"},
|
||||
@ -28,8 +68,9 @@ IApplicationCreator::~IApplicationCreator() = default;
|
||||
|
||||
Result IApplicationCreator::CreateApplication(
|
||||
Out<SharedPointer<IApplicationAccessor>> out_application_accessor, u64 application_id) {
|
||||
LOG_ERROR(Service_NS, "called, application_id={:x}", application_id);
|
||||
R_THROW(ResultUnknown);
|
||||
LOG_INFO(Service_NS, "called, application_id={:016X}", application_id);
|
||||
R_RETURN(
|
||||
CreateGuestApplication(out_application_accessor, system, m_window_system, application_id));
|
||||
}
|
||||
|
||||
} // namespace Service::AM
|
||||
|
@ -10,14 +10,17 @@ namespace Service::AM {
|
||||
|
||||
class IApplicationAccessor;
|
||||
struct Applet;
|
||||
class WindowSystem;
|
||||
|
||||
class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
|
||||
public:
|
||||
explicit IApplicationCreator(Core::System& system_);
|
||||
explicit IApplicationCreator(Core::System& system_, WindowSystem& window_system);
|
||||
~IApplicationCreator() override;
|
||||
|
||||
private:
|
||||
Result CreateApplication(Out<SharedPointer<IApplicationAccessor>>, u64 application_id);
|
||||
|
||||
WindowSystem& m_window_system;
|
||||
};
|
||||
|
||||
} // namespace Service::AM
|
||||
|
@ -104,7 +104,7 @@ Result ISystemAppletProxy::GetLibraryAppletCreator(
|
||||
Result ISystemAppletProxy::GetApplicationCreator(
|
||||
Out<SharedPointer<IApplicationCreator>> out_application_creator) {
|
||||
LOG_DEBUG(Service_AM, "called");
|
||||
*out_application_creator = std::make_shared<IApplicationCreator>(system);
|
||||
*out_application_creator = std::make_shared<IApplicationCreator>(system, m_window_system);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user