mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
ControllerInterface: Add RemoveDevice()
This adds RemoveDevice() to ControllerInterface, fixes ExpressionParser and some other code to support device removals without crashing, and adds an IsValid() method to Device, to prepare for hotplugging.
This commit is contained in:
@ -160,6 +160,14 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
|
||||
m_devices.emplace_back(std::move(device));
|
||||
}
|
||||
|
||||
void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m_devices_mutex);
|
||||
m_devices.erase(std::remove_if(m_devices.begin(), m_devices.end(),
|
||||
[&callback](const auto& dev) { return callback(dev.get()); }),
|
||||
m_devices.end());
|
||||
}
|
||||
|
||||
//
|
||||
// UpdateInput
|
||||
//
|
||||
|
@ -122,6 +122,7 @@ public:
|
||||
void Reinitialize();
|
||||
void Shutdown();
|
||||
void AddDevice(std::shared_ptr<ciface::Core::Device> device);
|
||||
void RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback);
|
||||
bool IsInit() const { return m_is_init; }
|
||||
void UpdateReference(ControlReference* control,
|
||||
const ciface::Core::DeviceQualifier& default_device) const;
|
||||
|
@ -98,6 +98,7 @@ public:
|
||||
virtual std::string GetName() const = 0;
|
||||
virtual std::string GetSource() const = 0;
|
||||
virtual void UpdateInput() {}
|
||||
virtual bool IsValid() const { return true; }
|
||||
const std::vector<Input*>& Inputs() const { return m_inputs; }
|
||||
const std::vector<Output*>& Outputs() const { return m_outputs; }
|
||||
Input* FindInput(const std::string& name) const;
|
||||
|
@ -235,8 +235,9 @@ public:
|
||||
ControlQualifier qualifier;
|
||||
Device::Control* control;
|
||||
|
||||
ControlExpression(ControlQualifier qualifier_, Device::Control* control_)
|
||||
: qualifier(qualifier_), control(control_)
|
||||
ControlExpression(ControlQualifier qualifier_, std::shared_ptr<Device> device,
|
||||
Device::Control* control_)
|
||||
: qualifier(qualifier_), control(control_), m_device(device)
|
||||
{
|
||||
}
|
||||
|
||||
@ -244,6 +245,8 @@ public:
|
||||
void SetValue(ControlState value) override { control->ToOutput()->SetGatedState(value); }
|
||||
int CountNumControls() override { return 1; }
|
||||
operator std::string() override { return "`" + (std::string)qualifier + "`"; }
|
||||
private:
|
||||
std::shared_ptr<Device> m_device;
|
||||
};
|
||||
|
||||
class BinaryExpression : public ExpressionNode
|
||||
@ -393,6 +396,7 @@ private:
|
||||
{
|
||||
case TOK_CONTROL:
|
||||
{
|
||||
std::shared_ptr<Device> device = finder.FindDevice(tok.qualifier);
|
||||
Device::Control* control = finder.FindControl(tok.qualifier);
|
||||
if (control == nullptr)
|
||||
{
|
||||
@ -400,7 +404,7 @@ private:
|
||||
return EXPRESSION_PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
*expr_out = new ControlExpression(tok.qualifier, control);
|
||||
*expr_out = new ControlExpression(tok.qualifier, device, control);
|
||||
return EXPRESSION_PARSE_SUCCESS;
|
||||
}
|
||||
case TOK_LPAREN:
|
||||
@ -550,10 +554,11 @@ ExpressionParseStatus ParseExpression(const std::string& str, ControlFinder& fin
|
||||
qualifier.control_name = str;
|
||||
qualifier.has_device = false;
|
||||
|
||||
std::shared_ptr<Device> device = finder.FindDevice(qualifier);
|
||||
Device::Control* control = finder.FindControl(qualifier);
|
||||
if (control)
|
||||
{
|
||||
*expr_out = new Expression(new ControlExpression(qualifier, control));
|
||||
*expr_out = new Expression(new ControlExpression(qualifier, device, control));
|
||||
return EXPRESSION_PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,10 @@ public:
|
||||
: container(container_), default_device(default_), is_input(is_input_)
|
||||
{
|
||||
}
|
||||
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier);
|
||||
Core::Device::Control* FindControl(ControlQualifier qualifier);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier);
|
||||
const Core::DeviceContainer& container;
|
||||
const Core::DeviceQualifier& default_device;
|
||||
bool is_input;
|
||||
|
Reference in New Issue
Block a user