mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-23 04:35:40 +01: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/application_accessor.h"
|
||||||
#include "core/hle/service/am/service/library_applet_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/service/storage.h"
|
||||||
|
#include "core/hle/service/am/window_system.h"
|
||||||
#include "core/hle/service/cmif_serialization.h"
|
#include "core/hle/service/cmif_serialization.h"
|
||||||
|
|
||||||
namespace Service::AM {
|
namespace Service::AM {
|
||||||
|
|
||||||
IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet)
|
IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet,
|
||||||
: ServiceFramework{system_, "IApplicationAccessor"}, m_applet(std::move(applet)) {
|
WindowSystem& window_system)
|
||||||
|
: ServiceFramework{system_, "IApplicationAccessor"}, m_window_system(window_system),
|
||||||
|
m_applet(std::move(applet)) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, D<&IApplicationAccessor::GetAppletStateChangedEvent>, "GetAppletStateChangedEvent"},
|
{0, D<&IApplicationAccessor::GetAppletStateChangedEvent>, "GetAppletStateChangedEvent"},
|
||||||
@ -59,7 +62,15 @@ Result IApplicationAccessor::Start() {
|
|||||||
|
|
||||||
Result IApplicationAccessor::RequestExit() {
|
Result IApplicationAccessor::RequestExit() {
|
||||||
LOG_INFO(Service_AM, "called");
|
LOG_INFO(Service_AM, "called");
|
||||||
|
|
||||||
|
std::scoped_lock lk{m_applet->lock};
|
||||||
|
if (m_applet->exit_locked) {
|
||||||
m_applet->lifecycle_manager.RequestExit();
|
m_applet->lifecycle_manager.RequestExit();
|
||||||
|
m_applet->UpdateSuspensionStateLocked(true);
|
||||||
|
} else {
|
||||||
|
m_applet->process->Terminate();
|
||||||
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +125,9 @@ Result IApplicationAccessor::GetCurrentLibraryApplet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result IApplicationAccessor::RequestForApplicationToGetForeground() {
|
Result IApplicationAccessor::RequestForApplicationToGetForeground() {
|
||||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
LOG_INFO(Service_AM, "called");
|
||||||
R_THROW(ResultUnknown);
|
m_window_system.RequestApplicationToGetForeground();
|
||||||
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result IApplicationAccessor::CheckRightsEnvironmentAvailable(Out<bool> out_is_available) {
|
Result IApplicationAccessor::CheckRightsEnvironmentAvailable(Out<bool> out_is_available) {
|
||||||
|
@ -13,10 +13,12 @@ namespace Service::AM {
|
|||||||
struct Applet;
|
struct Applet;
|
||||||
class ILibraryAppletAccessor;
|
class ILibraryAppletAccessor;
|
||||||
class IStorage;
|
class IStorage;
|
||||||
|
class WindowSystem;
|
||||||
|
|
||||||
class IApplicationAccessor final : public ServiceFramework<IApplicationAccessor> {
|
class IApplicationAccessor final : public ServiceFramework<IApplicationAccessor> {
|
||||||
public:
|
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;
|
~IApplicationAccessor() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -34,6 +36,7 @@ private:
|
|||||||
Result GetNsRightsEnvironmentHandle(Out<u64> out_handle);
|
Result GetNsRightsEnvironmentHandle(Out<u64> out_handle);
|
||||||
Result ReportApplicationExitTimeout();
|
Result ReportApplicationExitTimeout();
|
||||||
|
|
||||||
|
WindowSystem& m_window_system;
|
||||||
const std::shared_ptr<Applet> m_applet;
|
const std::shared_ptr<Applet> m_applet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,17 +1,57 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// 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/am_types.h"
|
||||||
#include "core/hle/service/am/applet.h"
|
#include "core/hle/service/am/applet.h"
|
||||||
#include "core/hle/service/am/applet_manager.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_accessor.h"
|
||||||
#include "core/hle/service/am/service/application_creator.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/hle/service/cmif_serialization.h"
|
||||||
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
namespace Service::AM {
|
namespace Service::AM {
|
||||||
|
|
||||||
IApplicationCreator::IApplicationCreator(Core::System& system_)
|
namespace {
|
||||||
: ServiceFramework{system_, "IApplicationCreator"} {
|
|
||||||
|
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
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, D<&IApplicationCreator::CreateApplication>, "CreateApplication"},
|
{0, D<&IApplicationCreator::CreateApplication>, "CreateApplication"},
|
||||||
@ -28,8 +68,9 @@ IApplicationCreator::~IApplicationCreator() = default;
|
|||||||
|
|
||||||
Result IApplicationCreator::CreateApplication(
|
Result IApplicationCreator::CreateApplication(
|
||||||
Out<SharedPointer<IApplicationAccessor>> out_application_accessor, u64 application_id) {
|
Out<SharedPointer<IApplicationAccessor>> out_application_accessor, u64 application_id) {
|
||||||
LOG_ERROR(Service_NS, "called, application_id={:x}", application_id);
|
LOG_INFO(Service_NS, "called, application_id={:016X}", application_id);
|
||||||
R_THROW(ResultUnknown);
|
R_RETURN(
|
||||||
|
CreateGuestApplication(out_application_accessor, system, m_window_system, application_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Service::AM
|
} // namespace Service::AM
|
||||||
|
@ -10,14 +10,17 @@ namespace Service::AM {
|
|||||||
|
|
||||||
class IApplicationAccessor;
|
class IApplicationAccessor;
|
||||||
struct Applet;
|
struct Applet;
|
||||||
|
class WindowSystem;
|
||||||
|
|
||||||
class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
|
class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
|
||||||
public:
|
public:
|
||||||
explicit IApplicationCreator(Core::System& system_);
|
explicit IApplicationCreator(Core::System& system_, WindowSystem& window_system);
|
||||||
~IApplicationCreator() override;
|
~IApplicationCreator() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Result CreateApplication(Out<SharedPointer<IApplicationAccessor>>, u64 application_id);
|
Result CreateApplication(Out<SharedPointer<IApplicationAccessor>>, u64 application_id);
|
||||||
|
|
||||||
|
WindowSystem& m_window_system;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::AM
|
} // namespace Service::AM
|
||||||
|
@ -104,7 +104,7 @@ Result ISystemAppletProxy::GetLibraryAppletCreator(
|
|||||||
Result ISystemAppletProxy::GetApplicationCreator(
|
Result ISystemAppletProxy::GetApplicationCreator(
|
||||||
Out<SharedPointer<IApplicationCreator>> out_application_creator) {
|
Out<SharedPointer<IApplicationCreator>> out_application_creator) {
|
||||||
LOG_DEBUG(Service_AM, "called");
|
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();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user