Address first batch of review comments

This commit is contained in:
fearlessTobi 2019-02-15 19:20:06 +01:00
parent 041638ea4d
commit 781d4b787a
14 changed files with 91 additions and 131 deletions

View file

@ -40,6 +40,9 @@ public:
Path() : type(LowPathType::Invalid) {}
Path(const char* path) : type(LowPathType::Char), string(path) {}
Path(std::vector<u8> binary_data) : type(LowPathType::Binary), binary(std::move(binary_data)) {}
template <std::size_t size>
Path(std::array<u8, size> binary_data)
: type(LowPathType::Binary), binary(binary_data.begin(), binary_data.end()) {}
Path(LowPathType type, const std::vector<u8>& data);
LowPathType GetType() const {

View file

@ -2,13 +2,14 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "core/core.h"
#include "core/frontend/applets/default_applets.h"
#include "core/frontend/applets/mii_selector.h"
#include "core/frontend/applets/swkbd.h"
namespace Frontend {
void RegisterDefaultApplets() {
RegisterSoftwareKeyboard(std::make_shared<DefaultKeyboard>());
RegisterMiiSelector(std::make_shared<DefaultMiiSelector>());
Core::System::GetInstance().RegisterSoftwareKeyboard(std::make_shared<DefaultKeyboard>());
Core::System::GetInstance().RegisterMiiSelector(std::make_shared<DefaultMiiSelector>());
}
} // namespace Frontend

View file

@ -2,7 +2,6 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "core/core.h"
#include "core/frontend/applets/mii_selector.h"
namespace Frontend {
@ -11,17 +10,9 @@ void MiiSelector::Finalize(u32 return_code, HLE::Applets::MiiData mii) {
data = {return_code, mii};
}
void DefaultMiiSelector::Setup(const Frontend::MiiSelectorConfig* config) {
void DefaultMiiSelector::Setup(const Frontend::MiiSelectorConfig& config) {
MiiSelector::Setup(config);
Finalize(0, HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data);
}
void RegisterMiiSelector(std::shared_ptr<MiiSelector> applet) {
Core::System::GetInstance().RegisterMiiSelector(applet);
}
std::shared_ptr<MiiSelector> GetRegisteredMiiSelector() {
return Core::System::GetInstance().GetMiiSelector();
}
} // namespace Frontend

View file

@ -4,13 +4,16 @@
#pragma once
#include <array>
#include <memory>
#include <string>
#include "core/hle/applets/mii_selector.h"
namespace Frontend {
/// Default English button text mappings. Frontends may need to copy this to internationalize it.
constexpr char MII_BUTTON_OKAY[] = "Ok";
constexpr char MII_BUTTON_CANCEL[] = "Cancel";
/// Configuration that's relevant to frontend implementation of applet. Anything missing that we
/// later learn is needed can be added here and filled in by the backend HLE applet
struct MiiSelectorConfig {
@ -26,11 +29,12 @@ struct MiiSelectorData {
class MiiSelector {
public:
virtual void Setup(const MiiSelectorConfig* config) {
this->config = MiiSelectorConfig(*config);
virtual void Setup(const MiiSelectorConfig& config) {
this->config = MiiSelectorConfig(config);
}
const MiiSelectorData* ReceiveData() {
return &data;
const MiiSelectorData& ReceiveData() const {
return data;
}
/**
@ -46,11 +50,7 @@ protected:
class DefaultMiiSelector final : public MiiSelector {
public:
void Setup(const MiiSelectorConfig* config) override;
void Setup(const MiiSelectorConfig& config) override;
};
void RegisterMiiSelector(std::shared_ptr<MiiSelector> applet);
std::shared_ptr<MiiSelector> GetRegisteredMiiSelector();
} // namespace Frontend

View file

@ -135,7 +135,7 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) {
return ValidationError::None;
}
void DefaultKeyboard::Setup(const Frontend::KeyboardConfig* config) {
void DefaultKeyboard::Setup(const Frontend::KeyboardConfig& config) {
SoftwareKeyboard::Setup(config);
auto cfg = Service::CFG::GetModule(Core::System::GetInstance());
@ -157,12 +157,4 @@ void DefaultKeyboard::Setup(const Frontend::KeyboardConfig* config) {
}
}
void RegisterSoftwareKeyboard(std::shared_ptr<SoftwareKeyboard> applet) {
Core::System::GetInstance().RegisterSoftwareKeyboard(applet);
}
std::shared_ptr<SoftwareKeyboard> GetRegisteredSoftwareKeyboard() {
return Core::System::GetInstance().GetSoftwareKeyboard();
}
} // namespace Frontend

View file

@ -30,9 +30,9 @@ enum class ButtonConfig {
};
/// Default English button text mappings. Frontends may need to copy this to internationalize it.
constexpr char BUTTON_OKAY[] = "Ok";
constexpr char BUTTON_CANCEL[] = "Cancel";
constexpr char BUTTON_FORGOT[] = "I Forgot";
constexpr char SWKBD_BUTTON_OKAY[] = "Ok";
constexpr char SWKBD_BUTTON_CANCEL[] = "Cancel";
constexpr char SWKBD_BUTTON_FORGOT[] = "I Forgot";
/// Configuration thats relevent to frontend implementation of applets. Anything missing that we
/// later learn is needed can be added here and filled in by the backend HLE applet
@ -82,11 +82,12 @@ enum class ValidationError {
class SoftwareKeyboard {
public:
virtual void Setup(const KeyboardConfig* config) {
this->config = KeyboardConfig(*config);
virtual void Setup(const KeyboardConfig& config) {
this->config = KeyboardConfig(config);
}
const KeyboardData* ReceiveData() {
return &data;
const KeyboardData& ReceiveData() const {
return data;
}
/**
@ -121,11 +122,7 @@ protected:
class DefaultKeyboard final : public SoftwareKeyboard {
public:
void Setup(const KeyboardConfig* config) override;
void Setup(const KeyboardConfig& config) override;
};
void RegisterSoftwareKeyboard(std::shared_ptr<SoftwareKeyboard> applet);
std::shared_ptr<SoftwareKeyboard> GetRegisteredSoftwareKeyboard();
} // namespace Frontend

View file

@ -60,11 +60,11 @@ ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& pa
memcpy(&config, parameter.buffer.data(), parameter.buffer.size());
using namespace Frontend;
frontend_applet = GetRegisteredMiiSelector();
if (frontend_applet) {
MiiSelectorConfig frontend_config = ToFrontendConfig(config);
frontend_applet->Setup(&frontend_config);
}
frontend_applet = Core::System::GetInstance().GetMiiSelector();
ASSERT(frontend_applet);
MiiSelectorConfig frontend_config = ToFrontendConfig(config);
frontend_applet->Setup(frontend_config);
is_running = true;
return RESULT_SUCCESS;
@ -72,9 +72,9 @@ ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& pa
void MiiSelector::Update() {
using namespace Frontend;
const MiiSelectorData* data = frontend_applet->ReceiveData();
result.return_code = data->return_code;
result.selected_mii_data = data->mii;
const MiiSelectorData& data = frontend_applet->ReceiveData();
result.return_code = data.return_code;
result.selected_mii_data = data.mii;
// Calculate the checksum of the selected Mii, see https://www.3dbrew.org/wiki/Mii#Checksum
result.mii_data_checksum = boost::crc<16, 0x1021, 0, 0, false, false>(
&result.selected_mii_data, sizeof(HLE::Applets::MiiData) + sizeof(result.unknown1));

View file

@ -68,11 +68,11 @@ ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter cons
DrawScreenKeyboard();
using namespace Frontend;
frontend_applet = GetRegisteredSoftwareKeyboard();
if (frontend_applet) {
KeyboardConfig frontend_config = ToFrontendConfig(config);
frontend_applet->Setup(&frontend_config);
}
frontend_applet = Core::System::GetInstance().GetSoftwareKeyboard();
ASSERT(frontend_applet);
KeyboardConfig frontend_config = ToFrontendConfig(config);
frontend_applet->Setup(frontend_config);
is_running = true;
return RESULT_SUCCESS;
@ -80,7 +80,7 @@ ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter cons
void SoftwareKeyboard::Update() {
using namespace Frontend;
KeyboardData data(*frontend_applet->ReceiveData());
KeyboardData data(frontend_applet->ReceiveData());
std::u16string text = Common::UTF8ToUTF16(data.text);
memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t));
switch (config.num_buttons_m1) {

View file

@ -16,7 +16,7 @@ class System;
namespace Service::PTM {
/// Id of the SharedExtData archive used by the PTM process
static const std::vector<u8> ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0};
constexpr std::array<u8, 12> ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0};
/// Charge levels used by PTM functions
enum class ChargeLevels : u32 {