Proper applet manager class

This commit is contained in:
wheremyfoodat 2023-08-23 18:07:24 +03:00
parent f099cc12fa
commit 74f7aeedbb
5 changed files with 45 additions and 26 deletions

View file

@ -150,7 +150,7 @@ set(FS_SOURCE_FILES src/core/fs/archive_self_ncch.cpp src/core/fs/archive_save_d
src/core/fs/ivfc.cpp
)
set(APPLET_SOURCE_FILES src/core/applets/applet.cpp src/core/applets/mii_selector.cpp src/core/applets/software_keyboard.cpp)
set(APPLET_SOURCE_FILES src/core/applets/applet.cpp src/core/applets/mii_selector.cpp src/core/applets/software_keyboard.cpp src/core/applets/applet_manager.cpp)
set(RENDERER_SW_SOURCE_FILES src/core/renderer_sw/renderer_sw.cpp)
set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/termcolor.hpp
@ -180,7 +180,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/termcolor.hpp
include/action_replay.hpp include/renderer_sw/renderer_sw.hpp include/compiler_builtins.hpp
include/fs/romfs.hpp include/fs/ivfc.hpp include/discord_rpc.hpp include/services/http.hpp include/result/result_cfg.hpp
include/applets/applet.hpp include/applets/mii_selector.hpp include/math_util.hpp include/services/soc.hpp
include/services/news_u.hpp include/applets/software_keyboard.hpp
include/services/news_u.hpp include/applets/software_keyboard.hpp include/applets/applet_manager.hpp
)
cmrc_add_resource_library(

View file

@ -0,0 +1,17 @@
#include "applets/mii_selector.hpp"
#include "applets/software_keyboard.hpp"
#include "helpers.hpp"
#include "memory.hpp"
#include "result/result.hpp"
namespace Applets {
class AppletManager {
MiiSelectorApplet miiSelector;
SoftwareKeyboardApplet swkbd;
public:
AppletManager(Memory& mem);
void reset();
AppletBase* getApplet(u32 id);
};
} // namespace Applets

View file

@ -6,8 +6,7 @@
#include "memory.hpp"
#include "result/result.hpp"
#include "applets/mii_selector.hpp"
#include "applets/software_keyboard.hpp"
#include "applets/applet_manager.hpp"
// Yay, more circular dependencies
class Kernel;
@ -26,11 +25,7 @@ class APTService {
std::optional<Handle> resumeEvent = std::nullopt;
ConsoleModel model = ConsoleModel::Old3DS;
// Applets here
Applets::MiiSelectorApplet miiSelector;
Applets::SoftwareKeyboardApplet swkbd;
Applets::AppletBase* getApplet(u32 id);
Applets::AppletManager appletManager;
MAKE_LOG_FUNCTION(log, aptLogger)
@ -80,7 +75,7 @@ class APTService {
u32 screencapPostPermission;
public:
APTService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel), miiSelector(mem), swkbd(mem) {}
APTService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel), appletManager(mem) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -0,0 +1,21 @@
#include "applets/applet_manager.hpp"
using namespace Applets;
AppletManager::AppletManager(Memory& mem) : miiSelector(mem), swkbd(mem) {}
void AppletManager::reset() {
miiSelector.reset();
swkbd.reset();
}
AppletBase* AppletManager::getApplet(u32 id) {
switch (id) {
case AppletIDs::MiiSelector:
case AppletIDs::MiiSelector2: return &miiSelector;
case AppletIDs::SoftwareKeyboard:
case AppletIDs::SoftwareKeyboard2: return &swkbd;
default: return nullptr;
}
}

View file

@ -66,21 +66,7 @@ void APTService::reset() {
notificationEvent = std::nullopt;
resumeEvent = std::nullopt;
miiSelector.reset();
}
Applets::AppletBase* APTService::getApplet(u32 id) {
using namespace Applets;
switch (id) {
case AppletIDs::MiiSelector:
case AppletIDs::MiiSelector2: return &miiSelector;
case AppletIDs::SoftwareKeyboard:
case AppletIDs::SoftwareKeyboard2: return &swkbd;
default: return nullptr;
}
appletManager.reset();
}
void APTService::handleSyncRequest(u32 messagePointer) {
@ -264,7 +250,7 @@ void APTService::sendParameter(u32 messagePointer) {
Helpers::warn("APT::SendParameter: Unimplemented source applet ID");
}
Applets::AppletBase* destApplet = getApplet(destAppID);
Applets::AppletBase* destApplet = appletManager.getApplet(destAppID);
if (destApplet == nullptr) {
Helpers::warn("APT::SendParameter: Unimplemented dest applet ID");
} else {