From e51d33f0cee74f9fbd58439b411e6d3fef57576d Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 11 Mar 2019 19:32:59 -0400 Subject: applets: Add AppletManager class to control lifetime --- src/core/hle/service/am/applets/applets.cpp | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'src/core/hle/service/am/applets/applets.cpp') diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index a6064c63f..7f70b10df 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -5,11 +5,21 @@ #include #include "common/assert.h" #include "core/core.h" +#include "core/frontend/applets/error.h" +#include "core/frontend/applets/general_frontend.h" +#include "core/frontend/applets/profile_select.h" +#include "core/frontend/applets/software_keyboard.h" +#include "core/frontend/applets/web_browser.h" #include "core/hle/kernel/readable_event.h" #include "core/hle/kernel/server_session.h" #include "core/hle/kernel/writable_event.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applets.h" +#include "core/hle/service/am/applets/error.h" +#include "core/hle/service/am/applets/general_backend.h" +#include "core/hle/service/am/applets/profile_select.h" +#include "core/hle/service/am/applets/software_keyboard.h" +#include "core/hle/service/am/applets/web_browser.h" namespace Service::AM::Applets { @@ -111,4 +121,76 @@ void Applet::Initialize() { initialized = true; } +AppletManager::AppletManager() = default; + +AppletManager::~AppletManager() = default; + +void AppletManager::SetAppletFrontendSet(AppletFrontendSet set) { + if (set.error != nullptr) + frontend.error = std::move(set.error); + if (set.photo_viewer != nullptr) + frontend.photo_viewer = std::move(set.photo_viewer); + if (set.profile_select != nullptr) + frontend.profile_select = std::move(set.profile_select); + if (set.software_keyboard != nullptr) + frontend.software_keyboard = std::move(set.software_keyboard); + if (set.web_browser != nullptr) + frontend.web_browser = std::move(set.web_browser); +} + +void AppletManager::SetDefaultAppletFrontendSet() { + frontend.error = std::make_unique(); + frontend.photo_viewer = std::make_unique(); + frontend.profile_select = std::make_unique(); + frontend.software_keyboard = std::make_unique(); + frontend.web_browser = std::make_unique(); +} + +void AppletManager::SetDefaultAppletsIfMissing() { + if (frontend.error == nullptr) { + frontend.error = std::make_unique(); + } + + if (frontend.photo_viewer == nullptr) { + frontend.photo_viewer = std::make_unique(); + } + + if (frontend.profile_select == nullptr) { + frontend.profile_select = std::make_unique(); + } + + if (frontend.software_keyboard == nullptr) { + frontend.software_keyboard = + std::make_unique(); + } + + if (frontend.web_browser == nullptr) { + frontend.web_browser = std::make_unique(); + } +} + +void AppletManager::ClearAll() { + frontend = {}; +} + +std::shared_ptr AppletManager::GetApplet(AppletId id) const { + switch (id) { + case AppletId::Error: + return std::make_shared(*frontend.error); + case AppletId::ProfileSelect: + return std::make_shared(*frontend.profile_select); + case AppletId::SoftwareKeyboard: + return std::make_shared(*frontend.software_keyboard); + case AppletId::PhotoViewer: + return std::make_shared(*frontend.photo_viewer); + case AppletId::LibAppletOff: + return std::make_shared(*frontend.web_browser); + default: + UNIMPLEMENTED_MSG( + "No backend implementation exists for applet_id={:02X}! Falling back to stub applet.", + static_cast(id)); + return std::make_shared(); + } +} + } // namespace Service::AM::Applets -- cgit v1.2.3