summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp8
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.h1
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Device.h1
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp13
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ExpressionParser.h2
5 files changed, 20 insertions, 5 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
index cc80b7b234..cf726698f1 100644
--- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
@@ -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
//
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
index 24f92fd3c1..198a2c180b 100644
--- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
+++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
@@ -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;
diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h
index e3fe4c11cd..657ece5016 100644
--- a/Source/Core/InputCommon/ControllerInterface/Device.h
+++ b/Source/Core/InputCommon/ControllerInterface/Device.h
@@ -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;
diff --git a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp
index 6e9b8b77ab..2960888148 100644
--- a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp
@@ -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;
}
diff --git a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.h b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.h
index 992ca65f03..2c8f5a793f 100644
--- a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.h
+++ b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.h
@@ -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;