chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-14 20:06:02 -04:00
|
|
|
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-09-20 15:56:55 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
2022-11-21 11:31:18 -05:00
|
|
|
#include <vector>
|
2021-09-20 15:56:55 -04:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "common/param_package.h"
|
2021-11-03 00:50:30 -04:00
|
|
|
#include "common/uuid.h"
|
2021-09-20 15:56:55 -04:00
|
|
|
|
2021-10-30 23:23:10 -04:00
|
|
|
namespace Common::Input {
|
2021-09-20 15:56:55 -04:00
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Type of data that is expected to recieve or send
|
2021-09-20 15:56:55 -04:00
|
|
|
enum class InputType {
|
|
|
|
None,
|
|
|
|
Battery,
|
|
|
|
Button,
|
|
|
|
Stick,
|
|
|
|
Analog,
|
|
|
|
Trigger,
|
|
|
|
Motion,
|
|
|
|
Touch,
|
|
|
|
Color,
|
|
|
|
Vibration,
|
|
|
|
Nfc,
|
2022-06-19 00:32:07 -04:00
|
|
|
IrSensor,
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Internal battery charge level
|
2021-11-01 16:17:53 -04:00
|
|
|
enum class BatteryLevel : u32 {
|
2021-10-19 01:12:24 -04:00
|
|
|
None,
|
2021-09-20 15:56:55 -04:00
|
|
|
Empty,
|
|
|
|
Critical,
|
|
|
|
Low,
|
|
|
|
Medium,
|
|
|
|
Full,
|
|
|
|
Charging,
|
|
|
|
};
|
|
|
|
|
2021-10-11 01:43:11 -04:00
|
|
|
enum class PollingMode {
|
2021-11-04 00:35:45 -04:00
|
|
|
// Constant polling of buttons, analogs and motion data
|
2021-10-11 01:43:11 -04:00
|
|
|
Active,
|
2021-11-04 00:35:45 -04:00
|
|
|
// Only update on button change, digital analogs
|
2023-03-07 21:15:46 -05:00
|
|
|
Passive,
|
2021-11-04 00:35:45 -04:00
|
|
|
// Enable near field communication polling
|
|
|
|
NFC,
|
|
|
|
// Enable infrared camera polling
|
2021-10-11 01:43:11 -04:00
|
|
|
IR,
|
2022-12-20 12:34:33 -05:00
|
|
|
// Enable ring controller polling
|
|
|
|
Ring,
|
2021-10-11 01:43:11 -04:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:32:07 -04:00
|
|
|
enum class CameraFormat {
|
|
|
|
Size320x240,
|
|
|
|
Size160x120,
|
|
|
|
Size80x60,
|
|
|
|
Size40x30,
|
|
|
|
Size20x15,
|
|
|
|
None,
|
|
|
|
};
|
|
|
|
|
2022-12-26 12:11:01 -05:00
|
|
|
// Different results that can happen from a device request
|
|
|
|
enum class DriverResult {
|
|
|
|
Success,
|
|
|
|
WrongReply,
|
|
|
|
Timeout,
|
|
|
|
UnsupportedControllerType,
|
|
|
|
HandleInUse,
|
|
|
|
ErrorReadingData,
|
|
|
|
ErrorWritingData,
|
|
|
|
NoDeviceDetected,
|
2022-12-20 12:34:33 -05:00
|
|
|
InvalidHandle,
|
2021-10-11 01:43:11 -04:00
|
|
|
NotSupported,
|
2022-12-26 12:11:01 -05:00
|
|
|
Disabled,
|
2021-10-11 01:43:11 -04:00
|
|
|
Unknown,
|
|
|
|
};
|
|
|
|
|
2022-09-24 20:46:49 -04:00
|
|
|
// Nfc reply from the controller
|
|
|
|
enum class NfcState {
|
|
|
|
Success,
|
|
|
|
NewAmiibo,
|
|
|
|
WaitingForAmiibo,
|
|
|
|
AmiiboRemoved,
|
|
|
|
NotAnAmiibo,
|
|
|
|
NotSupported,
|
|
|
|
WrongDeviceState,
|
|
|
|
WriteFailed,
|
|
|
|
Unknown,
|
|
|
|
};
|
|
|
|
|
2021-10-20 15:41:56 -04:00
|
|
|
// Hint for amplification curve to be used
|
|
|
|
enum class VibrationAmplificationType {
|
|
|
|
Linear,
|
|
|
|
Exponential,
|
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Analog properties for calibration
|
2021-09-20 15:56:55 -04:00
|
|
|
struct AnalogProperties {
|
2021-11-04 00:35:45 -04:00
|
|
|
// Anything below this value will be detected as zero
|
2021-09-20 15:56:55 -04:00
|
|
|
float deadzone{};
|
2021-11-04 00:35:45 -04:00
|
|
|
// Anyting above this values will be detected as one
|
2021-09-20 15:56:55 -04:00
|
|
|
float range{1.0f};
|
2021-11-04 00:35:45 -04:00
|
|
|
// Minimum value to be detected as active
|
2021-09-20 15:56:55 -04:00
|
|
|
float threshold{0.5f};
|
2021-11-04 00:35:45 -04:00
|
|
|
// Drift correction applied to the raw data
|
2021-09-20 15:56:55 -04:00
|
|
|
float offset{};
|
2021-11-04 00:35:45 -04:00
|
|
|
// Invert direction of the sensor data
|
2021-09-20 15:56:55 -04:00
|
|
|
bool inverted{};
|
2022-09-06 12:20:53 -04:00
|
|
|
// Press once to activate, press again to release
|
|
|
|
bool toggle{};
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Single analog sensor data
|
2021-09-20 15:56:55 -04:00
|
|
|
struct AnalogStatus {
|
|
|
|
float value{};
|
|
|
|
float raw_value{};
|
|
|
|
AnalogProperties properties{};
|
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Button data
|
2021-09-20 15:56:55 -04:00
|
|
|
struct ButtonStatus {
|
2021-11-03 00:50:30 -04:00
|
|
|
Common::UUID uuid{};
|
2021-09-20 15:56:55 -04:00
|
|
|
bool value{};
|
2022-09-06 12:20:53 -04:00
|
|
|
// Invert value of the button
|
2021-09-20 15:56:55 -04:00
|
|
|
bool inverted{};
|
2022-09-06 12:20:53 -04:00
|
|
|
// Press once to activate, press again to release
|
2021-09-20 15:56:55 -04:00
|
|
|
bool toggle{};
|
2023-01-28 19:19:15 -05:00
|
|
|
// Spams the button when active
|
|
|
|
bool turbo{};
|
2022-09-06 12:20:53 -04:00
|
|
|
// Internal lock for the toggle status
|
2021-09-20 15:56:55 -04:00
|
|
|
bool locked{};
|
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Internal battery data
|
2021-09-20 15:56:55 -04:00
|
|
|
using BatteryStatus = BatteryLevel;
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Analog and digital joystick data
|
2021-09-20 15:56:55 -04:00
|
|
|
struct StickStatus {
|
2021-11-03 00:50:30 -04:00
|
|
|
Common::UUID uuid{};
|
2021-09-20 15:56:55 -04:00
|
|
|
AnalogStatus x{};
|
|
|
|
AnalogStatus y{};
|
|
|
|
bool left{};
|
|
|
|
bool right{};
|
|
|
|
bool up{};
|
|
|
|
bool down{};
|
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Analog and digital trigger data
|
2021-09-20 15:56:55 -04:00
|
|
|
struct TriggerStatus {
|
2021-11-03 00:50:30 -04:00
|
|
|
Common::UUID uuid{};
|
2021-09-20 15:56:55 -04:00
|
|
|
AnalogStatus analog{};
|
2021-10-31 11:41:44 -04:00
|
|
|
ButtonStatus pressed{};
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// 3D vector representing motion input
|
2021-09-20 15:56:55 -04:00
|
|
|
struct MotionSensor {
|
|
|
|
AnalogStatus x{};
|
|
|
|
AnalogStatus y{};
|
|
|
|
AnalogStatus z{};
|
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Motion data used to calculate controller orientation
|
2021-09-20 15:56:55 -04:00
|
|
|
struct MotionStatus {
|
2021-11-01 21:49:14 -04:00
|
|
|
// Gyroscope vector measurement in radians/s.
|
2021-09-20 15:56:55 -04:00
|
|
|
MotionSensor gyro{};
|
2021-11-01 21:49:14 -04:00
|
|
|
// Acceleration vector measurement in G force
|
2021-09-20 15:56:55 -04:00
|
|
|
MotionSensor accel{};
|
2021-11-01 21:49:14 -04:00
|
|
|
// Time since last measurement in microseconds
|
2021-09-20 15:56:55 -04:00
|
|
|
u64 delta_timestamp{};
|
2021-11-01 21:49:14 -04:00
|
|
|
// Request to update after reading the value
|
|
|
|
bool force_update{};
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Data of a single point on a touch screen
|
2021-09-20 15:56:55 -04:00
|
|
|
struct TouchStatus {
|
|
|
|
ButtonStatus pressed{};
|
|
|
|
AnalogStatus x{};
|
|
|
|
AnalogStatus y{};
|
2021-10-31 11:41:44 -04:00
|
|
|
int id{};
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Physical controller color in RGB format
|
2021-09-20 15:56:55 -04:00
|
|
|
struct BodyColorStatus {
|
|
|
|
u32 body{};
|
|
|
|
u32 buttons{};
|
2022-12-20 12:34:33 -05:00
|
|
|
u32 left_grip{};
|
|
|
|
u32 right_grip{};
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// HD rumble data
|
2021-09-20 15:56:55 -04:00
|
|
|
struct VibrationStatus {
|
|
|
|
f32 low_amplitude{};
|
|
|
|
f32 low_frequency{};
|
|
|
|
f32 high_amplitude{};
|
|
|
|
f32 high_frequency{};
|
2021-10-20 15:41:56 -04:00
|
|
|
VibrationAmplificationType type;
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Physical controller LED pattern
|
2021-09-20 15:56:55 -04:00
|
|
|
struct LedStatus {
|
|
|
|
bool led_1{};
|
|
|
|
bool led_2{};
|
|
|
|
bool led_3{};
|
|
|
|
bool led_4{};
|
|
|
|
};
|
|
|
|
|
2022-06-19 00:32:07 -04:00
|
|
|
// Raw data fom camera
|
|
|
|
struct CameraStatus {
|
|
|
|
CameraFormat format{CameraFormat::None};
|
|
|
|
std::vector<u8> data{};
|
|
|
|
};
|
|
|
|
|
2022-09-24 20:46:49 -04:00
|
|
|
struct NfcStatus {
|
|
|
|
NfcState state{};
|
|
|
|
std::vector<u8> data{};
|
|
|
|
};
|
|
|
|
|
2021-11-21 15:12:01 -05:00
|
|
|
// List of buttons to be passed to Qt that can be translated
|
|
|
|
enum class ButtonNames {
|
|
|
|
Undefined,
|
|
|
|
Invalid,
|
|
|
|
// This will display the engine name instead of the button name
|
|
|
|
Engine,
|
|
|
|
// This will display the button by value instead of the button name
|
|
|
|
Value,
|
2022-12-20 12:34:33 -05:00
|
|
|
|
|
|
|
// Joycon button names
|
2021-11-21 15:12:01 -05:00
|
|
|
ButtonLeft,
|
|
|
|
ButtonRight,
|
|
|
|
ButtonDown,
|
|
|
|
ButtonUp,
|
|
|
|
ButtonA,
|
|
|
|
ButtonB,
|
|
|
|
ButtonX,
|
|
|
|
ButtonY,
|
2022-12-20 12:34:33 -05:00
|
|
|
ButtonPlus,
|
|
|
|
ButtonMinus,
|
|
|
|
ButtonHome,
|
|
|
|
ButtonCapture,
|
|
|
|
ButtonStickL,
|
|
|
|
ButtonStickR,
|
|
|
|
TriggerL,
|
|
|
|
TriggerZL,
|
|
|
|
TriggerSL,
|
|
|
|
TriggerR,
|
|
|
|
TriggerZR,
|
|
|
|
TriggerSR,
|
|
|
|
|
|
|
|
// GC button names
|
|
|
|
TriggerZ,
|
2021-11-21 15:12:01 -05:00
|
|
|
ButtonStart,
|
2021-11-26 16:45:37 -05:00
|
|
|
|
|
|
|
// DS4 button names
|
|
|
|
L1,
|
|
|
|
L2,
|
|
|
|
L3,
|
|
|
|
R1,
|
|
|
|
R2,
|
|
|
|
R3,
|
|
|
|
Circle,
|
|
|
|
Cross,
|
|
|
|
Square,
|
|
|
|
Triangle,
|
|
|
|
Share,
|
|
|
|
Options,
|
2022-01-30 10:15:29 -05:00
|
|
|
Home,
|
|
|
|
Touch,
|
2022-01-16 19:03:11 -05:00
|
|
|
|
|
|
|
// Mouse buttons
|
|
|
|
ButtonMouseWheel,
|
|
|
|
ButtonBackward,
|
|
|
|
ButtonForward,
|
|
|
|
ButtonTask,
|
|
|
|
ButtonExtra,
|
2021-11-21 15:12:01 -05:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Callback data consisting of an input type and the equivalent data status
|
2021-09-20 15:56:55 -04:00
|
|
|
struct CallbackStatus {
|
|
|
|
InputType type{InputType::None};
|
|
|
|
ButtonStatus button_status{};
|
|
|
|
StickStatus stick_status{};
|
|
|
|
AnalogStatus analog_status{};
|
|
|
|
TriggerStatus trigger_status{};
|
|
|
|
MotionStatus motion_status{};
|
|
|
|
TouchStatus touch_status{};
|
|
|
|
BodyColorStatus color_status{};
|
|
|
|
BatteryStatus battery_status{};
|
|
|
|
VibrationStatus vibration_status{};
|
2022-10-09 13:49:07 -04:00
|
|
|
CameraFormat camera_status{CameraFormat::None};
|
|
|
|
NfcState nfc_status{NfcState::Unknown};
|
|
|
|
std::vector<u8> raw_data{};
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Triggered once every input change
|
2021-09-20 15:56:55 -04:00
|
|
|
struct InputCallback {
|
2021-12-13 21:09:28 -05:00
|
|
|
std::function<void(const CallbackStatus&)> on_change;
|
2021-09-20 15:56:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/// An abstract class template for an input device (a button, an analog input, etc.).
|
|
|
|
class InputDevice {
|
|
|
|
public:
|
|
|
|
virtual ~InputDevice() = default;
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Force input device to update data regardless of the current state
|
2021-12-13 20:43:09 -05:00
|
|
|
virtual void ForceUpdate() {}
|
2021-10-24 21:28:54 -04:00
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Sets the function to be triggered when input changes
|
2021-09-20 15:56:55 -04:00
|
|
|
void SetCallback(InputCallback callback_) {
|
|
|
|
callback = std::move(callback_);
|
|
|
|
}
|
|
|
|
|
2021-11-04 00:35:45 -04:00
|
|
|
// Triggers the function set in the callback
|
2021-12-13 21:09:28 -05:00
|
|
|
void TriggerOnChange(const CallbackStatus& status) {
|
2021-09-20 15:56:55 -04:00
|
|
|
if (callback.on_change) {
|
|
|
|
callback.on_change(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
InputCallback callback;
|
|
|
|
};
|
|
|
|
|
2021-10-11 01:43:11 -04:00
|
|
|
/// An abstract class template for an output device (rumble, LED pattern, polling mode).
|
|
|
|
class OutputDevice {
|
|
|
|
public:
|
|
|
|
virtual ~OutputDevice() = default;
|
|
|
|
|
2022-12-26 12:11:01 -05:00
|
|
|
virtual DriverResult SetLED([[maybe_unused]] const LedStatus& led_status) {
|
|
|
|
return DriverResult::NotSupported;
|
|
|
|
}
|
2021-10-11 01:43:11 -04:00
|
|
|
|
2022-12-26 12:11:01 -05:00
|
|
|
virtual DriverResult SetVibration([[maybe_unused]] const VibrationStatus& vibration_status) {
|
|
|
|
return DriverResult::NotSupported;
|
2021-10-11 01:43:11 -04:00
|
|
|
}
|
|
|
|
|
2022-10-21 01:23:12 -04:00
|
|
|
virtual bool IsVibrationEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-26 12:11:01 -05:00
|
|
|
virtual DriverResult SetPollingMode([[maybe_unused]] PollingMode polling_mode) {
|
|
|
|
return DriverResult::NotSupported;
|
2021-10-11 01:43:11 -04:00
|
|
|
}
|
2022-06-19 00:32:07 -04:00
|
|
|
|
2022-12-26 12:11:01 -05:00
|
|
|
virtual DriverResult SetCameraFormat([[maybe_unused]] CameraFormat camera_format) {
|
|
|
|
return DriverResult::NotSupported;
|
2022-06-19 00:32:07 -04:00
|
|
|
}
|
2022-09-24 20:46:49 -04:00
|
|
|
|
2022-09-24 23:52:33 -04:00
|
|
|
virtual NfcState SupportsNfc() const {
|
2022-09-24 20:46:49 -04:00
|
|
|
return NfcState::NotSupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual NfcState WriteNfcData([[maybe_unused]] const std::vector<u8>& data) {
|
|
|
|
return NfcState::NotSupported;
|
|
|
|
}
|
2021-10-11 01:43:11 -04:00
|
|
|
};
|
|
|
|
|
2021-09-20 15:56:55 -04:00
|
|
|
/// An abstract class template for a factory that can create input devices.
|
|
|
|
template <typename InputDeviceType>
|
|
|
|
class Factory {
|
|
|
|
public:
|
|
|
|
virtual ~Factory() = default;
|
|
|
|
virtual std::unique_ptr<InputDeviceType> Create(const Common::ParamPackage&) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace Impl {
|
|
|
|
|
|
|
|
template <typename InputDeviceType>
|
|
|
|
using FactoryListType = std::unordered_map<std::string, std::shared_ptr<Factory<InputDeviceType>>>;
|
|
|
|
|
|
|
|
template <typename InputDeviceType>
|
|
|
|
struct FactoryList {
|
|
|
|
static FactoryListType<InputDeviceType> list;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename InputDeviceType>
|
|
|
|
FactoryListType<InputDeviceType> FactoryList<InputDeviceType>::list;
|
|
|
|
|
|
|
|
} // namespace Impl
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers an input device factory.
|
|
|
|
* @tparam InputDeviceType the type of input devices the factory can create
|
|
|
|
* @param name the name of the factory. Will be used to match the "engine" parameter when creating
|
|
|
|
* a device
|
|
|
|
* @param factory the factory object to register
|
|
|
|
*/
|
|
|
|
template <typename InputDeviceType>
|
|
|
|
void RegisterFactory(const std::string& name, std::shared_ptr<Factory<InputDeviceType>> factory) {
|
|
|
|
auto pair = std::make_pair(name, std::move(factory));
|
|
|
|
if (!Impl::FactoryList<InputDeviceType>::list.insert(std::move(pair)).second) {
|
|
|
|
LOG_ERROR(Input, "Factory '{}' already registered", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 09:19:01 -05:00
|
|
|
inline void RegisterInputFactory(const std::string& name,
|
|
|
|
std::shared_ptr<Factory<InputDevice>> factory) {
|
|
|
|
RegisterFactory<InputDevice>(name, std::move(factory));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RegisterOutputFactory(const std::string& name,
|
|
|
|
std::shared_ptr<Factory<OutputDevice>> factory) {
|
|
|
|
RegisterFactory<OutputDevice>(name, std::move(factory));
|
|
|
|
}
|
|
|
|
|
2021-09-20 15:56:55 -04:00
|
|
|
/**
|
|
|
|
* Unregisters an input device factory.
|
|
|
|
* @tparam InputDeviceType the type of input devices the factory can create
|
|
|
|
* @param name the name of the factory to unregister
|
|
|
|
*/
|
|
|
|
template <typename InputDeviceType>
|
|
|
|
void UnregisterFactory(const std::string& name) {
|
|
|
|
if (Impl::FactoryList<InputDeviceType>::list.erase(name) == 0) {
|
|
|
|
LOG_ERROR(Input, "Factory '{}' not registered", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 09:19:01 -05:00
|
|
|
inline void UnregisterInputFactory(const std::string& name) {
|
|
|
|
UnregisterFactory<InputDevice>(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void UnregisterOutputFactory(const std::string& name) {
|
|
|
|
UnregisterFactory<OutputDevice>(name);
|
|
|
|
}
|
|
|
|
|
2021-09-20 15:56:55 -04:00
|
|
|
/**
|
|
|
|
* Create an input device from given paramters.
|
|
|
|
* @tparam InputDeviceType the type of input devices to create
|
|
|
|
* @param params a serialized ParamPackage string that contains all parameters for creating the
|
|
|
|
* device
|
|
|
|
*/
|
|
|
|
template <typename InputDeviceType>
|
|
|
|
std::unique_ptr<InputDeviceType> CreateDeviceFromString(const std::string& params) {
|
|
|
|
const Common::ParamPackage package(params);
|
|
|
|
const std::string engine = package.Get("engine", "null");
|
|
|
|
const auto& factory_list = Impl::FactoryList<InputDeviceType>::list;
|
|
|
|
const auto pair = factory_list.find(engine);
|
|
|
|
if (pair == factory_list.end()) {
|
|
|
|
if (engine != "null") {
|
|
|
|
LOG_ERROR(Input, "Unknown engine name: {}", engine);
|
|
|
|
}
|
|
|
|
return std::make_unique<InputDeviceType>();
|
|
|
|
}
|
|
|
|
return pair->second->Create(package);
|
|
|
|
}
|
|
|
|
|
2022-11-28 09:19:01 -05:00
|
|
|
inline std::unique_ptr<InputDevice> CreateInputDeviceFromString(const std::string& params) {
|
|
|
|
return CreateDeviceFromString<InputDevice>(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::unique_ptr<OutputDevice> CreateOutputDeviceFromString(const std::string& params) {
|
|
|
|
return CreateDeviceFromString<OutputDevice>(params);
|
|
|
|
}
|
|
|
|
|
2021-09-20 15:56:55 -04:00
|
|
|
/**
|
2022-11-28 09:11:56 -05:00
|
|
|
* Create an input device from given parameters.
|
2021-09-20 15:56:55 -04:00
|
|
|
* @tparam InputDeviceType the type of input devices to create
|
2022-11-28 09:11:56 -05:00
|
|
|
* @param package A ParamPackage that contains all parameters for creating the device
|
2021-09-20 15:56:55 -04:00
|
|
|
*/
|
|
|
|
template <typename InputDeviceType>
|
2022-11-28 09:11:56 -05:00
|
|
|
std::unique_ptr<InputDeviceType> CreateDevice(const ParamPackage& package) {
|
2021-09-20 15:56:55 -04:00
|
|
|
const std::string engine = package.Get("engine", "null");
|
|
|
|
const auto& factory_list = Impl::FactoryList<InputDeviceType>::list;
|
|
|
|
const auto pair = factory_list.find(engine);
|
|
|
|
if (pair == factory_list.end()) {
|
|
|
|
if (engine != "null") {
|
|
|
|
LOG_ERROR(Input, "Unknown engine name: {}", engine);
|
|
|
|
}
|
|
|
|
return std::make_unique<InputDeviceType>();
|
|
|
|
}
|
|
|
|
return pair->second->Create(package);
|
|
|
|
}
|
|
|
|
|
2022-11-28 09:19:01 -05:00
|
|
|
inline std::unique_ptr<InputDevice> CreateInputDevice(const ParamPackage& package) {
|
|
|
|
return CreateDevice<InputDevice>(package);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::unique_ptr<OutputDevice> CreateOutputDevice(const ParamPackage& package) {
|
|
|
|
return CreateDevice<OutputDevice>(package);
|
|
|
|
}
|
|
|
|
|
2021-10-30 23:23:10 -04:00
|
|
|
} // namespace Common::Input
|