APT/Applet: move applet managing into its own class
This commit is contained in:
parent
44d07574b1
commit
92f0064b47
17 changed files with 773 additions and 623 deletions
|
@ -15,7 +15,6 @@
|
|||
#include "core/hle/applets/mint.h"
|
||||
#include "core/hle/applets/swkbd.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/apt/apt.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -43,23 +42,24 @@ static CoreTiming::EventType* applet_update_event = nullptr;
|
|||
/// The interval at which the Applet update callback will be called, 16.6ms
|
||||
static const u64 applet_update_interval_us = 16666;
|
||||
|
||||
ResultCode Applet::Create(Service::APT::AppletId id) {
|
||||
ResultCode Applet::Create(Service::APT::AppletId id,
|
||||
std::weak_ptr<Service::APT::AppletManager> manager) {
|
||||
switch (id) {
|
||||
case Service::APT::AppletId::SoftwareKeyboard1:
|
||||
case Service::APT::AppletId::SoftwareKeyboard2:
|
||||
applets[id] = std::make_shared<SoftwareKeyboard>(id);
|
||||
applets[id] = std::make_shared<SoftwareKeyboard>(id, std::move(manager));
|
||||
break;
|
||||
case Service::APT::AppletId::Ed1:
|
||||
case Service::APT::AppletId::Ed2:
|
||||
applets[id] = std::make_shared<MiiSelector>(id);
|
||||
applets[id] = std::make_shared<MiiSelector>(id, std::move(manager));
|
||||
break;
|
||||
case Service::APT::AppletId::Error:
|
||||
case Service::APT::AppletId::Error2:
|
||||
applets[id] = std::make_shared<ErrEula>(id);
|
||||
applets[id] = std::make_shared<ErrEula>(id, std::move(manager));
|
||||
break;
|
||||
case Service::APT::AppletId::Mint:
|
||||
case Service::APT::AppletId::Mint2:
|
||||
applets[id] = std::make_shared<Mint>(id);
|
||||
applets[id] = std::make_shared<Mint>(id, std::move(manager));
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR(Service_APT, "Could not create applet %u", static_cast<u32>(id));
|
||||
|
@ -110,6 +110,14 @@ bool Applet::IsRunning() const {
|
|||
return is_running;
|
||||
}
|
||||
|
||||
void Applet::SendParameter(const Service::APT::MessageParameter& parameter) {
|
||||
if (auto locked = manager.lock()) {
|
||||
locked->CancelAndSendParameter(parameter);
|
||||
} else {
|
||||
LOG_ERROR(Service_APT, "called after destructing applet manager");
|
||||
}
|
||||
}
|
||||
|
||||
bool IsLibraryAppletRunning() {
|
||||
// Check the applets map for instances of any applet
|
||||
for (auto itr = applets.begin(); itr != applets.end(); ++itr)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/apt/apt.h"
|
||||
#include "core/hle/service/apt/applet_manager.h"
|
||||
|
||||
namespace HLE {
|
||||
namespace Applets {
|
||||
|
@ -21,7 +21,8 @@ public:
|
|||
* @param id Id of the applet to create.
|
||||
* @returns ResultCode Whether the operation was successful or not.
|
||||
*/
|
||||
static ResultCode Create(Service::APT::AppletId id);
|
||||
static ResultCode Create(Service::APT::AppletId id,
|
||||
std::weak_ptr<Service::APT::AppletManager> manager);
|
||||
|
||||
/**
|
||||
* Retrieves the Applet instance identified by the specified id.
|
||||
|
@ -55,7 +56,8 @@ public:
|
|||
virtual void Update() = 0;
|
||||
|
||||
protected:
|
||||
explicit Applet(Service::APT::AppletId id) : id(id) {}
|
||||
Applet(Service::APT::AppletId id, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||
: id(id), manager(std::move(manager)) {}
|
||||
|
||||
/**
|
||||
* Handles the Applet start event, triggered from the application.
|
||||
|
@ -69,6 +71,11 @@ protected:
|
|||
|
||||
/// Whether this applet is currently running instead of the host application or not.
|
||||
bool is_running = false;
|
||||
|
||||
void SendParameter(const Service::APT::MessageParameter& parameter);
|
||||
|
||||
private:
|
||||
std::weak_ptr<Service::APT::AppletManager> manager;
|
||||
};
|
||||
|
||||
/// Returns whether a library applet is currently running
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace HLE {
|
|||
namespace Applets {
|
||||
|
||||
ResultCode ErrEula::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
|
||||
if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);
|
||||
if (parameter.signal != Service::APT::SignalType::Request) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", static_cast<u32>(parameter.signal));
|
||||
UNIMPLEMENTED();
|
||||
// TODO(Subv): Find the right error code
|
||||
return ResultCode(-1);
|
||||
|
@ -36,13 +36,13 @@ ResultCode ErrEula::ReceiveParameter(const Service::APT::MessageParameter& param
|
|||
|
||||
// Send the response message with the newly created SharedMemory
|
||||
Service::APT::MessageParameter result;
|
||||
result.signal = static_cast<u32>(Service::APT::SignalType::Response);
|
||||
result.signal = Service::APT::SignalType::Response;
|
||||
result.buffer.clear();
|
||||
result.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
result.sender_id = static_cast<u32>(id);
|
||||
result.destination_id = Service::APT::AppletId::Application;
|
||||
result.sender_id = id;
|
||||
result.object = framebuffer_memory;
|
||||
|
||||
Service::APT::SendParameter(result);
|
||||
SendParameter(result);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -57,10 +57,10 @@ ResultCode ErrEula::StartImpl(const Service::APT::AppletStartupParameter& parame
|
|||
Service::APT::MessageParameter message;
|
||||
message.buffer.resize(parameter.buffer.size());
|
||||
std::fill(message.buffer.begin(), message.buffer.end(), 0);
|
||||
message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit);
|
||||
message.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
message.sender_id = static_cast<u32>(id);
|
||||
Service::APT::SendParameter(message);
|
||||
message.signal = Service::APT::SignalType::WakeupByExit;
|
||||
message.destination_id = Service::APT::AppletId::Application;
|
||||
message.sender_id = id;
|
||||
SendParameter(message);
|
||||
|
||||
is_running = false;
|
||||
return RESULT_SUCCESS;
|
||||
|
|
|
@ -12,7 +12,8 @@ namespace Applets {
|
|||
|
||||
class ErrEula final : public Applet {
|
||||
public:
|
||||
explicit ErrEula(Service::APT::AppletId id) : Applet(id) {}
|
||||
explicit ErrEula(Service::APT::AppletId id, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||
: Applet(id, std::move(manager)) {}
|
||||
|
||||
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override;
|
||||
ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override;
|
||||
|
|
|
@ -18,8 +18,8 @@ namespace HLE {
|
|||
namespace Applets {
|
||||
|
||||
ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
|
||||
if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);
|
||||
if (parameter.signal != Service::APT::SignalType::Request) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", static_cast<u32>(parameter.signal));
|
||||
UNIMPLEMENTED();
|
||||
// TODO(Subv): Find the right error code
|
||||
return ResultCode(-1);
|
||||
|
@ -43,13 +43,13 @@ ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& p
|
|||
|
||||
// Send the response message with the newly created SharedMemory
|
||||
Service::APT::MessageParameter result;
|
||||
result.signal = static_cast<u32>(Service::APT::SignalType::Response);
|
||||
result.signal = Service::APT::SignalType::Response;
|
||||
result.buffer.clear();
|
||||
result.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
result.sender_id = static_cast<u32>(id);
|
||||
result.destination_id = Service::APT::AppletId::Application;
|
||||
result.sender_id = id;
|
||||
result.object = framebuffer_memory;
|
||||
|
||||
Service::APT::SendParameter(result);
|
||||
SendParameter(result);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -72,10 +72,10 @@ ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& pa
|
|||
Service::APT::MessageParameter message;
|
||||
message.buffer.resize(sizeof(MiiResult));
|
||||
std::memcpy(message.buffer.data(), &result, message.buffer.size());
|
||||
message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit);
|
||||
message.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
message.sender_id = static_cast<u32>(id);
|
||||
Service::APT::SendParameter(message);
|
||||
message.signal = Service::APT::SignalType::WakeupByExit;
|
||||
message.destination_id = Service::APT::AppletId::Application;
|
||||
message.sender_id = id;
|
||||
SendParameter(message);
|
||||
|
||||
is_running = false;
|
||||
return RESULT_SUCCESS;
|
||||
|
|
|
@ -60,7 +60,8 @@ ASSERT_REG_POSITION(guest_mii_name, 0x6C);
|
|||
|
||||
class MiiSelector final : public Applet {
|
||||
public:
|
||||
MiiSelector(Service::APT::AppletId id) : Applet(id) {}
|
||||
MiiSelector(Service::APT::AppletId id, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||
: Applet(id, std::move(manager)) {}
|
||||
|
||||
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override;
|
||||
ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override;
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace HLE {
|
|||
namespace Applets {
|
||||
|
||||
ResultCode Mint::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
|
||||
if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);
|
||||
if (parameter.signal != Service::APT::SignalType::Request) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", static_cast<u32>(parameter.signal));
|
||||
UNIMPLEMENTED();
|
||||
// TODO(Subv): Find the right error code
|
||||
return ResultCode(-1);
|
||||
|
@ -36,13 +36,13 @@ ResultCode Mint::ReceiveParameter(const Service::APT::MessageParameter& paramete
|
|||
|
||||
// Send the response message with the newly created SharedMemory
|
||||
Service::APT::MessageParameter result;
|
||||
result.signal = static_cast<u32>(Service::APT::SignalType::Response);
|
||||
result.signal = Service::APT::SignalType::Response;
|
||||
result.buffer.clear();
|
||||
result.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
result.sender_id = static_cast<u32>(id);
|
||||
result.destination_id = Service::APT::AppletId::Application;
|
||||
result.sender_id = id;
|
||||
result.object = framebuffer_memory;
|
||||
|
||||
Service::APT::SendParameter(result);
|
||||
SendParameter(result);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -57,10 +57,10 @@ ResultCode Mint::StartImpl(const Service::APT::AppletStartupParameter& parameter
|
|||
Service::APT::MessageParameter message;
|
||||
message.buffer.resize(parameter.buffer.size());
|
||||
std::fill(message.buffer.begin(), message.buffer.end(), 0);
|
||||
message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit);
|
||||
message.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
message.sender_id = static_cast<u32>(id);
|
||||
Service::APT::SendParameter(message);
|
||||
message.signal = Service::APT::SignalType::WakeupByExit;
|
||||
message.destination_id = Service::APT::AppletId::Application;
|
||||
message.sender_id = id;
|
||||
SendParameter(message);
|
||||
|
||||
is_running = false;
|
||||
return RESULT_SUCCESS;
|
||||
|
|
|
@ -12,7 +12,8 @@ namespace Applets {
|
|||
|
||||
class Mint final : public Applet {
|
||||
public:
|
||||
explicit Mint(Service::APT::AppletId id) : Applet(id) {}
|
||||
explicit Mint(Service::APT::AppletId id, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||
: Applet(id, std::move(manager)) {}
|
||||
|
||||
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override;
|
||||
ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override;
|
||||
|
|
|
@ -21,8 +21,8 @@ namespace HLE {
|
|||
namespace Applets {
|
||||
|
||||
ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter const& parameter) {
|
||||
if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);
|
||||
if (parameter.signal != Service::APT::SignalType::Request) {
|
||||
LOG_ERROR(Service_APT, "unsupported signal %u", static_cast<u32>(parameter.signal));
|
||||
UNIMPLEMENTED();
|
||||
// TODO(Subv): Find the right error code
|
||||
return ResultCode(-1);
|
||||
|
@ -46,13 +46,13 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con
|
|||
|
||||
// Send the response message with the newly created SharedMemory
|
||||
Service::APT::MessageParameter result;
|
||||
result.signal = static_cast<u32>(Service::APT::SignalType::Response);
|
||||
result.signal = Service::APT::SignalType::Response;
|
||||
result.buffer.clear();
|
||||
result.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
result.sender_id = static_cast<u32>(id);
|
||||
result.destination_id = Service::APT::AppletId::Application;
|
||||
result.sender_id = id;
|
||||
result.object = framebuffer_memory;
|
||||
|
||||
Service::APT::SendParameter(result);
|
||||
SendParameter(result);
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -107,10 +107,10 @@ void SoftwareKeyboard::Finalize() {
|
|||
Service::APT::MessageParameter message;
|
||||
message.buffer.resize(sizeof(SoftwareKeyboardConfig));
|
||||
std::memcpy(message.buffer.data(), &config, message.buffer.size());
|
||||
message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit);
|
||||
message.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
|
||||
message.sender_id = static_cast<u32>(id);
|
||||
Service::APT::SendParameter(message);
|
||||
message.signal = Service::APT::SignalType::WakeupByExit;
|
||||
message.destination_id = Service::APT::AppletId::Application;
|
||||
message.sender_id = id;
|
||||
SendParameter(message);
|
||||
|
||||
is_running = false;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,8 @@ static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config
|
|||
|
||||
class SoftwareKeyboard final : public Applet {
|
||||
public:
|
||||
SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) {}
|
||||
SoftwareKeyboard(Service::APT::AppletId id, std::weak_ptr<Service::APT::AppletManager> manager)
|
||||
: Applet(id, std::move(manager)) {}
|
||||
|
||||
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override;
|
||||
ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue