frontend/applets: misc fixes

* Renamed applet to applets

* Added log classes Applet and Applet.SWKBD

* Fixes to get it compile
This commit is contained in:
zhupengfei 2018-06-20 12:01:54 +08:00
parent caacefcc2e
commit 18664c719e
No known key found for this signature in database
GPG key ID: 85B82A3E62174206
9 changed files with 147 additions and 50 deletions

View file

@ -158,6 +158,8 @@ void FileBackend::Write(const Entry& entry) {
SUB(Debug, GDBStub) \ SUB(Debug, GDBStub) \
CLS(Kernel) \ CLS(Kernel) \
SUB(Kernel, SVC) \ SUB(Kernel, SVC) \
CLS(Applet) \
SUB(Applet, SWKBD) \
CLS(Service) \ CLS(Service) \
SUB(Service, SRV) \ SUB(Service, SRV) \
SUB(Service, FRD) \ SUB(Service, FRD) \

View file

@ -48,6 +48,9 @@ enum class Class : ClassType {
Debug_GDBStub, ///< GDB Stub Debug_GDBStub, ///< GDB Stub
Kernel, ///< The HLE implementation of the CTR kernel Kernel, ///< The HLE implementation of the CTR kernel
Kernel_SVC, ///< Kernel system calls Kernel_SVC, ///< Kernel system calls
Applet, ///< HLE implementation of system applets. Each applet
/// should have its own subclass.
Applet_SWKBD, ///< The Software Keyboard applet
Service, ///< HLE implementation of system services. Each major service Service, ///< HLE implementation of system services. Each major service
/// should have its own subclass. /// should have its own subclass.
Service_SRV, ///< The SRV (Service Directory) implementation Service_SRV, ///< The SRV (Service Directory) implementation

View file

@ -68,10 +68,10 @@ add_library(core STATIC
file_sys/savedata_archive.h file_sys/savedata_archive.h
file_sys/title_metadata.cpp file_sys/title_metadata.cpp
file_sys/title_metadata.h file_sys/title_metadata.h
frontend/applet/interface.cpp frontend/applets/interface.cpp
frontend/applet/interface.h frontend/applets/interface.h
frontend/applet/swkbd.cpp frontend/applets/swkbd.cpp
frontend/applet/swkbd.h frontend/applets/swkbd.h
frontend/camera/blank_camera.cpp frontend/camera/blank_camera.cpp
frontend/camera/blank_camera.h frontend/camera/blank_camera.h
frontend/camera/factory.cpp frontend/camera/factory.cpp

View file

@ -3,7 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <unordered_map> #include <unordered_map>
#include "core/frontend/interface.h" #include "core/frontend/applets/interface.h"
namespace Frontend { namespace Frontend {
@ -17,4 +17,8 @@ void UnregisterFrontendApplet(AppletType type) {
registered_applets.erase(type); registered_applets.erase(type);
} }
std::shared_ptr<AppletInterface> GetRegisteredApplet(AppletType type) {
return registered_applets.at(type);
}
} // namespace Frontend } // namespace Frontend

View file

@ -16,6 +16,7 @@ enum class AppletType {
class AppletConfig {}; class AppletConfig {};
class AppletData {}; class AppletData {};
// TODO(jroweboy) add ability to draw to framebuffer
class AppletInterface { class AppletInterface {
public: public:
virtual ~AppletInterface() = default; virtual ~AppletInterface() = default;
@ -24,12 +25,7 @@ public:
* On applet start, the applet specific configuration will be passed in along with the * On applet start, the applet specific configuration will be passed in along with the
* framebuffer. * framebuffer.
*/ */
// virtual void Setup(const Config* /*, framebuffer */) = 0; virtual void Setup(const AppletConfig*) = 0;
/**
* Called on a fixed schedule to have the applet update any state such as the framebuffer.
*/
virtual void Update() = 0;
/** /**
* Checked every update to see if the applet is still running. When the applet is done, the core * Checked every update to see if the applet is still running. When the applet is done, the core
@ -39,9 +35,14 @@ public:
return running; return running;
} }
private: /**
// framebuffer; * Called by the core to receive the result data of this applet.
std::atomic_bool running = false; * Frontend implementation **should** block until the data is ready.
*/
virtual const AppletData* ReceiveData() = 0;
protected:
std::atomic<bool> running = false;
}; };
/** /**

View file

@ -2,13 +2,16 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "core/frontend/applet/swkbd.h" #include "common/assert.h"
#include "common/logging/log.h"
#include "core/frontend/applets/swkbd.h"
namespace Frontend { namespace Frontend {
ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) { ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
if (config.filters.prevent_digit) { if (config.filters.prevent_digit) {
if (std::any_of(input.begin(), input.end(), std::isdigit)) { if (std::any_of(input.begin(), input.end(),
[](unsigned char c) { return std::isdigit(c); })) {
return ValidationError::DigitNotAllowed; return ValidationError::DigitNotAllowed;
} }
} }
@ -22,7 +25,7 @@ ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
return ValidationError::PercentNotAllowed; return ValidationError::PercentNotAllowed;
} }
} }
if (config.filter.prevent_backslash) { if (config.filters.prevent_backslash) {
if (input.find('\\') != std::string::npos) { if (input.find('\\') != std::string::npos) {
return ValidationError::BackslashNotAllowed; return ValidationError::BackslashNotAllowed;
} }
@ -35,7 +38,7 @@ ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
// TODO: check the callback // TODO: check the callback
LOG_INFO(Frontend, "App requested a swkbd callback, but its not implemented."); LOG_INFO(Frontend, "App requested a swkbd callback, but its not implemented.");
} }
return valid; return ValidationError::None;
} }
ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) { ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
@ -49,9 +52,12 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
return ValidationError::MaxLengthExceeded; return ValidationError::MaxLengthExceeded;
} }
auto is_blank = [&] { return std::all_of(input.begin(), input.end(), std::isspace); }; auto is_blank = [&] {
return std::all_of(input.begin(), input.end(),
[](unsigned char c) { return std::isspace(c); });
};
auto is_empty = [&] { return input.empty(); }; auto is_empty = [&] { return input.empty(); };
switch (config.valid_input) { switch (config.accept_mode) {
case AcceptedInput::FixedLength: case AcceptedInput::FixedLength:
if (input.size() != config.max_text_length) { if (input.size() != config.max_text_length) {
return ValidationError::FixedLengthRequired; return ValidationError::FixedLengthRequired;
@ -80,12 +86,12 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
default: default:
// TODO(jroweboy): What does hardware do in this case? // TODO(jroweboy): What does hardware do in this case?
NGLOG_CRITICAL(Frontend, "Application requested unknown validation method. Method: {}", NGLOG_CRITICAL(Frontend, "Application requested unknown validation method. Method: {}",
static_cast<u32>(config.valid_input)); static_cast<u32>(config.accept_mode));
UNREACHABLE(); UNREACHABLE();
} }
return ValidationError::None; return ValidationError::None;
} // namespace Frontend }
ValidationError SoftwareKeyboard::ValidateButton(u8 button) { ValidationError SoftwareKeyboard::ValidateButton(u8 button) {
switch (config.button_config) { switch (config.button_config) {
@ -112,12 +118,12 @@ ValidationError SoftwareKeyboard::ValidateButton(u8 button) {
return ValidationError::None; return ValidationError::None;
} }
ValidationError Finalize(cosnt std::string& text, u8 button) { ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) {
ValidationError error; ValidationError error;
if ((error = ValidateInput(text)) != ValidationError::NONE) { if ((error = ValidateInput(text)) != ValidationError::None) {
return error; return error;
} }
if ((error = ValidateButton(button)) != ValidationError::NONE) { if ((error = ValidateButton(button)) != ValidationError::None) {
return error; return error;
} }
data = {text, button}; data = {text, button};

View file

@ -4,8 +4,12 @@
#pragma once #pragma once
#include <codecvt>
#include <locale>
#include <unordered_map> #include <unordered_map>
#include "core/frontend/applet/interface.h" #include <utility>
#include <vector>
#include "core/frontend/applets/interface.h"
namespace Frontend { namespace Frontend {
@ -38,8 +42,8 @@ static const std::unordered_map<ButtonConfig, std::vector<std::string>> DEFAULT_
}; };
/// Configuration thats relevent to frontend implementation of applets. Anything missing that we /// 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 backed HLE applet /// later learn is needed can be added here and filled in by the backend HLE applet
struct KeyboardConfig { struct KeyboardConfig : public AppletConfig {
ButtonConfig button_config; ButtonConfig button_config;
AcceptedInput accept_mode; /// What kinds of input are accepted (blank/empty/fixed width) AcceptedInput accept_mode; /// What kinds of input are accepted (blank/empty/fixed width)
bool multiline_mode; /// True if the keyboard accepts multiple lines of input bool multiline_mode; /// True if the keyboard accepts multiple lines of input
@ -49,8 +53,8 @@ struct KeyboardConfig {
bool has_custom_button_text; /// If true, use the button_text instead bool has_custom_button_text; /// If true, use the button_text instead
std::vector<std::string> button_text; /// Contains the button text that the caller provides std::vector<std::string> button_text; /// Contains the button text that the caller provides
struct Filters { struct Filters {
bool prevent_digit; /// Disallow the use of more than a certain number of digits (TODO how bool prevent_digit; /// Disallow the use of more than a certain number of digits
/// many is a certain number) /// TODO: how many is a certain number
bool prevent_at; /// Disallow the use of the @ sign. bool prevent_at; /// Disallow the use of the @ sign.
bool prevent_percent; /// Disallow the use of the % sign. bool prevent_percent; /// Disallow the use of the % sign.
bool prevent_backslash; /// Disallow the use of the \ sign. bool prevent_backslash; /// Disallow the use of the \ sign.
@ -59,9 +63,13 @@ struct KeyboardConfig {
} filters; } filters;
}; };
struct KeyboardData { class KeyboardData : public AppletData {
public:
std::string text; std::string text;
u8 button; u8 button{};
KeyboardData(std::string text, u8 button) : text(std::move(text)), button(button) {}
KeyboardData() = default;
}; };
enum class ValidationError { enum class ValidationError {
@ -77,13 +85,20 @@ enum class ValidationError {
CallbackFailed, CallbackFailed,
// Allowed Input Type // Allowed Input Type
FixedLengthRequired, FixedLengthRequired,
MaxLengthExceeded,
BlankInputNotAllowed, BlankInputNotAllowed,
EmptyInputNotAllowed, EmptyInputNotAllowed,
}; };
class SoftwareKeyboard : public AppletInterface { class SoftwareKeyboard : public AppletInterface {
public: public:
explict SoftwareKeyboard(KeyboardConfig config) : AppletInterface(), config(config) {} explicit SoftwareKeyboard() : AppletInterface() {}
const AppletData* ReceiveData() override {
return &data;
}
void Setup(const AppletConfig* config) override {
this->config = KeyboardConfig(*static_cast<const KeyboardConfig*>(config));
}
protected: protected:
/** /**
@ -109,13 +124,9 @@ protected:
* Runs all validation phases. If successful, stores the data so that the HLE applet in core can * Runs all validation phases. If successful, stores the data so that the HLE applet in core can
* send this to the calling application * send this to the calling application
*/ */
ValidationError Finialize(const std::string&, u8 button); ValidationError Finalize(const std::string& text, u8 button);
private: private:
KeyboardData ReceiveData() override {
return data;
}
KeyboardConfig config; KeyboardConfig config;
KeyboardData data; KeyboardData data;
}; };

View file

@ -69,22 +69,51 @@ ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter cons
DrawScreenKeyboard(); DrawScreenKeyboard();
using namespace Frontend;
frontend_applet = GetRegisteredApplet(AppletType::SoftwareKeyboard);
if (frontend_applet) {
KeyboardConfig frontend_config = ToFrontendConfig(config);
frontend_applet->Setup(&frontend_config);
}
is_running = true; is_running = true;
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
void SoftwareKeyboard::Update() { void SoftwareKeyboard::Update() {
// TODO(Subv): Handle input using the touch events from the HID module using namespace Frontend;
KeyboardData data(*static_cast<const KeyboardData*>(frontend_applet->ReceiveData()));
// TODO(Subv): Remove this hardcoded text std::u16string text = Common::UTF8ToUTF16(data.text);
std::u16string text = Common::UTF8ToUTF16("Citra");
memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t)); memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t));
switch (config.num_buttons_m1) {
case SoftwareKeyboardButtonConfig::SINGLE_BUTTON:
config.return_code = SoftwareKeyboardResult::D0_CLICK;
break;
case SoftwareKeyboardButtonConfig::DUAL_BUTTON:
if (data.button == 0)
config.return_code = SoftwareKeyboardResult::D1_CLICK0;
else
config.return_code = SoftwareKeyboardResult::D1_CLICK1;
break;
case SoftwareKeyboardButtonConfig::TRIPLE_BUTTON:
if (data.button == 0)
config.return_code = SoftwareKeyboardResult::D2_CLICK0;
else if (data.button == 1)
config.return_code = SoftwareKeyboardResult::D2_CLICK1;
else
config.return_code = SoftwareKeyboardResult::D2_CLICK2;
break;
case SoftwareKeyboardButtonConfig::NO_BUTTON:
// TODO: find out what is actually returned
config.return_code = SoftwareKeyboardResult::NONE;
break;
default:
NGLOG_CRITICAL(Applet_SWKBD, "Unknown button config {}",
static_cast<int>(config.num_buttons_m1));
UNREACHABLE();
}
// TODO(Subv): Ask for input and write it to the shared memory config.text_length = static_cast<u16>(text.size() + 1);
// TODO(Subv): Find out what are the possible values for the return code,
// some games seem to check for a hardcoded 2
config.return_code = 2;
config.text_length = 6;
config.text_offset = 0; config.text_offset = 0;
// TODO(Subv): We're finalizing the applet immediately after it's started, // TODO(Subv): We're finalizing the applet immediately after it's started,
@ -114,5 +143,42 @@ void SoftwareKeyboard::Finalize() {
is_running = false; is_running = false;
} }
Frontend::KeyboardConfig SoftwareKeyboard::ToFrontendConfig(SoftwareKeyboardConfig config) {
using namespace Frontend;
KeyboardConfig frontend_config;
frontend_config.button_config = static_cast<ButtonConfig>(config.num_buttons_m1);
frontend_config.accept_mode = static_cast<AcceptedInput>(config.valid_input);
frontend_config.multiline_mode = config.multiline;
frontend_config.max_text_length = config.max_text_length;
frontend_config.max_digits = config.max_digits;
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
frontend_config.hint_text =
convert.to_bytes(reinterpret_cast<const char16_t*>(config.hint_text.data()));
frontend_config.has_custom_button_text =
std::all_of(config.button_text.begin(), config.button_text.end(),
[](std::array<u16, HLE::Applets::MAX_BUTTON_TEXT_LEN + 1> x) {
return std::all_of(x.begin(), x.end(), [](u16 x) { return x == 0; });
});
if (frontend_config.has_custom_button_text) {
for (const auto& text : config.button_text) {
frontend_config.button_text.push_back(
convert.to_bytes(reinterpret_cast<const char16_t*>(text.data())));
}
}
frontend_config.filters.prevent_digit =
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::DIGITS);
frontend_config.filters.prevent_at =
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::AT);
frontend_config.filters.prevent_percent =
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::PERCENT);
frontend_config.filters.prevent_backslash =
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::BACKSLASH);
frontend_config.filters.prevent_profanity =
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::PROFANITY);
frontend_config.filters.enable_callback =
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::CALLBACK);
return frontend_config;
}
} // namespace Applets } // namespace Applets
} // namespace HLE } // namespace HLE

View file

@ -6,7 +6,7 @@
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/frontend/applet/swkbd.h" #include "core/frontend/applets/swkbd.h"
#include "core/hle/applets/applet.h" #include "core/hle/applets/applet.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/shared_memory.h"
@ -197,6 +197,8 @@ public:
void Finalize(); void Finalize();
private: private:
Frontend::KeyboardConfig ToFrontendConfig(SoftwareKeyboardConfig config);
/// This SharedMemory will be created when we receive the LibAppJustStarted message. /// This SharedMemory will be created when we receive the LibAppJustStarted message.
/// It holds the framebuffer info retrieved by the application with /// It holds the framebuffer info retrieved by the application with
/// GSPGPU::ImportDisplayCaptureInfo /// GSPGPU::ImportDisplayCaptureInfo
@ -207,6 +209,8 @@ private:
/// Configuration of this instance of the SoftwareKeyboard, as received from the application /// Configuration of this instance of the SoftwareKeyboard, as received from the application
SoftwareKeyboardConfig config; SoftwareKeyboardConfig config;
std::shared_ptr<Frontend::AppletInterface> frontend_applet;
}; };
} // namespace Applets } // namespace Applets
} // namespace HLE } // namespace HLE