Panda3DS/src/core/applets/applet_manager.cpp
2024-01-25 17:31:17 +02:00

61 lines
No EOL
1.6 KiB
C++

#include "applets/applet_manager.hpp"
#include "services/apt.hpp"
using namespace Applets;
AppletManager::AppletManager(Memory& mem) : miiSelector(mem, nextParameter), swkbd(mem, nextParameter), error(mem, nextParameter) {}
void AppletManager::reset() {
nextParameter = std::nullopt;
miiSelector.reset();
swkbd.reset();
error.reset();
}
AppletBase* AppletManager::getApplet(u32 id) {
switch (id) {
case AppletIDs::MiiSelector:
case AppletIDs::MiiSelector2: return &miiSelector;
case AppletIDs::SoftwareKeyboard:
case AppletIDs::SoftwareKeyboard2: return &swkbd;
case AppletIDs::ErrDisp:
case AppletIDs::ErrDisp2: return &error;
default: return nullptr;
}
}
Applets::Parameter AppletManager::glanceParameter() {
if (nextParameter) {
// Copy parameter
Applets::Parameter param = nextParameter.value();
// APT module clears next parameter even for GlanceParameter for these 2 signals
if (param.signal == static_cast<u32>(APTSignal::DspWakeup) || param.signal == static_cast<u32>(APTSignal::DspSleep)) {
nextParameter = std::nullopt;
}
return param;
}
// Default return value. This is legacy code from before applets were implemented. TODO: Update it
else {
return Applets::Parameter{
.senderID = 0,
.destID = Applets::AppletIDs::Application,
.signal = static_cast<u32>(APTSignal::Wakeup),
.data = {},
};
}
}
Applets::Parameter AppletManager::receiveParameter() {
Applets::Parameter param = glanceParameter();
// ReceiveParameter always clears nextParameter whereas glanceParameter does not
nextParameter = std::nullopt;
return param;
}