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:
parent
caacefcc2e
commit
18664c719e
9 changed files with 147 additions and 50 deletions
|
@ -3,7 +3,7 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include <unordered_map>
|
||||
#include "core/frontend/interface.h"
|
||||
#include "core/frontend/applets/interface.h"
|
||||
|
||||
namespace Frontend {
|
||||
|
||||
|
@ -17,4 +17,8 @@ void UnregisterFrontendApplet(AppletType type) {
|
|||
registered_applets.erase(type);
|
||||
}
|
||||
|
||||
std::shared_ptr<AppletInterface> GetRegisteredApplet(AppletType type) {
|
||||
return registered_applets.at(type);
|
||||
}
|
||||
|
||||
} // namespace Frontend
|
|
@ -16,6 +16,7 @@ enum class AppletType {
|
|||
class AppletConfig {};
|
||||
class AppletData {};
|
||||
|
||||
// TODO(jroweboy) add ability to draw to framebuffer
|
||||
class AppletInterface {
|
||||
public:
|
||||
virtual ~AppletInterface() = default;
|
||||
|
@ -24,12 +25,7 @@ public:
|
|||
* On applet start, the applet specific configuration will be passed in along with the
|
||||
* framebuffer.
|
||||
*/
|
||||
// virtual void Setup(const Config* /*, framebuffer */) = 0;
|
||||
|
||||
/**
|
||||
* Called on a fixed schedule to have the applet update any state such as the framebuffer.
|
||||
*/
|
||||
virtual void Update() = 0;
|
||||
virtual void Setup(const AppletConfig*) = 0;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
private:
|
||||
// framebuffer;
|
||||
std::atomic_bool running = false;
|
||||
/**
|
||||
* Called by the core to receive the result data of this applet.
|
||||
* Frontend implementation **should** block until the data is ready.
|
||||
*/
|
||||
virtual const AppletData* ReceiveData() = 0;
|
||||
|
||||
protected:
|
||||
std::atomic<bool> running = false;
|
||||
};
|
||||
|
||||
/**
|
|
@ -2,13 +2,16 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// 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 {
|
||||
|
||||
ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +25,7 @@ ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
|
|||
return ValidationError::PercentNotAllowed;
|
||||
}
|
||||
}
|
||||
if (config.filter.prevent_backslash) {
|
||||
if (config.filters.prevent_backslash) {
|
||||
if (input.find('\\') != std::string::npos) {
|
||||
return ValidationError::BackslashNotAllowed;
|
||||
}
|
||||
|
@ -35,7 +38,7 @@ ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
|
|||
// TODO: check the callback
|
||||
LOG_INFO(Frontend, "App requested a swkbd callback, but its not implemented.");
|
||||
}
|
||||
return valid;
|
||||
return ValidationError::None;
|
||||
}
|
||||
|
||||
ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
|
||||
|
@ -49,9 +52,12 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
|
|||
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(); };
|
||||
switch (config.valid_input) {
|
||||
switch (config.accept_mode) {
|
||||
case AcceptedInput::FixedLength:
|
||||
if (input.size() != config.max_text_length) {
|
||||
return ValidationError::FixedLengthRequired;
|
||||
|
@ -80,12 +86,12 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
|
|||
default:
|
||||
// TODO(jroweboy): What does hardware do in this case?
|
||||
NGLOG_CRITICAL(Frontend, "Application requested unknown validation method. Method: {}",
|
||||
static_cast<u32>(config.valid_input));
|
||||
static_cast<u32>(config.accept_mode));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
return ValidationError::None;
|
||||
} // namespace Frontend
|
||||
}
|
||||
|
||||
ValidationError SoftwareKeyboard::ValidateButton(u8 button) {
|
||||
switch (config.button_config) {
|
||||
|
@ -112,12 +118,12 @@ ValidationError SoftwareKeyboard::ValidateButton(u8 button) {
|
|||
return ValidationError::None;
|
||||
}
|
||||
|
||||
ValidationError Finalize(cosnt std::string& text, u8 button) {
|
||||
ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) {
|
||||
ValidationError error;
|
||||
if ((error = ValidateInput(text)) != ValidationError::NONE) {
|
||||
if ((error = ValidateInput(text)) != ValidationError::None) {
|
||||
return error;
|
||||
}
|
||||
if ((error = ValidateButton(button)) != ValidationError::NONE) {
|
||||
if ((error = ValidateButton(button)) != ValidationError::None) {
|
||||
return error;
|
||||
}
|
||||
data = {text, button};
|
|
@ -4,8 +4,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <unordered_map>
|
||||
#include "core/frontend/applet/interface.h"
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "core/frontend/applets/interface.h"
|
||||
|
||||
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
|
||||
/// later learn is needed can be added here and filled in by the backed HLE applet
|
||||
struct KeyboardConfig {
|
||||
/// later learn is needed can be added here and filled in by the backend HLE applet
|
||||
struct KeyboardConfig : public AppletConfig {
|
||||
ButtonConfig button_config;
|
||||
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
|
||||
|
@ -49,19 +53,23 @@ struct KeyboardConfig {
|
|||
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
|
||||
struct Filters {
|
||||
bool prevent_digit; /// Disallow the use of more than a certain number of digits (TODO how
|
||||
/// many is a certain number)
|
||||
bool prevent_at; /// Disallow the use of the @ sign.
|
||||
bool prevent_percent; /// Disallow the use of the % sign.
|
||||
bool prevent_digit; /// Disallow the use of more than a certain number of digits
|
||||
/// TODO: how many is a certain number
|
||||
bool prevent_at; /// 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_profanity; /// Disallow profanity using Nintendo's profanity filter.
|
||||
bool enable_callback; /// Use a callback in order to check the input.
|
||||
} filters;
|
||||
};
|
||||
|
||||
struct KeyboardData {
|
||||
class KeyboardData : public AppletData {
|
||||
public:
|
||||
std::string text;
|
||||
u8 button;
|
||||
u8 button{};
|
||||
|
||||
KeyboardData(std::string text, u8 button) : text(std::move(text)), button(button) {}
|
||||
KeyboardData() = default;
|
||||
};
|
||||
|
||||
enum class ValidationError {
|
||||
|
@ -77,13 +85,20 @@ enum class ValidationError {
|
|||
CallbackFailed,
|
||||
// Allowed Input Type
|
||||
FixedLengthRequired,
|
||||
MaxLengthExceeded,
|
||||
BlankInputNotAllowed,
|
||||
EmptyInputNotAllowed,
|
||||
};
|
||||
|
||||
class SoftwareKeyboard : public AppletInterface {
|
||||
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:
|
||||
/**
|
||||
|
@ -109,13 +124,9 @@ protected:
|
|||
* Runs all validation phases. If successful, stores the data so that the HLE applet in core can
|
||||
* send this to the calling application
|
||||
*/
|
||||
ValidationError Finialize(const std::string&, u8 button);
|
||||
ValidationError Finalize(const std::string& text, u8 button);
|
||||
|
||||
private:
|
||||
KeyboardData ReceiveData() override {
|
||||
return data;
|
||||
}
|
||||
|
||||
KeyboardConfig config;
|
||||
KeyboardData data;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue