1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
// idk in case I wanted to change it to double or something, idk what's best
typedef double ControlState;
namespace ciface
{
namespace Core
{
//
// Device
//
// A device class
//
class Device
{
public:
class Input;
class Output;
//
// Control
//
// Control includes inputs and outputs
//
class Control // input or output
{
public:
virtual std::string GetName() const = 0;
virtual ~Control() {}
virtual Input* ToInput() { return nullptr; }
virtual Output* ToOutput() { return nullptr; }
};
//
// Input
//
// An input on a device
//
class Input : public Control
{
public:
// things like absolute axes/ absolute mouse position will override this
virtual bool IsDetectable() { return true; }
virtual ControlState GetState() const = 0;
Input* ToInput() override { return this; }
};
//
// Output
//
// An output on a device
//
class Output : public Control
{
public:
virtual ~Output() {}
virtual void SetState(ControlState state) = 0;
Output* ToOutput() override { return this; }
};
virtual ~Device();
int GetId() const { return m_id; }
void SetId(int id) { m_id = id; }
virtual std::string GetName() const = 0;
virtual std::string GetSource() const = 0;
std::string GetQualifiedName() const;
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;
Output* FindOutput(const std::string& name) const;
protected:
void AddInput(Input* const i);
void AddOutput(Output* const o);
class FullAnalogSurface : public Input
{
public:
FullAnalogSurface(Input* low, Input* high) : m_low(*low), m_high(*high) {}
ControlState GetState() const override
{
return (1 + m_high.GetState() - m_low.GetState()) / 2;
}
std::string GetName() const override { return m_low.GetName() + *m_high.GetName().rbegin(); }
private:
Input& m_low;
Input& m_high;
};
void AddAnalogInputs(Input* low, Input* high)
{
AddInput(low);
AddInput(high);
AddInput(new FullAnalogSurface(low, high));
AddInput(new FullAnalogSurface(high, low));
}
private:
int m_id;
std::vector<Input*> m_inputs;
std::vector<Output*> m_outputs;
};
//
// DeviceQualifier
//
// Device qualifier used to match devices.
// Currently has ( source, id, name ) properties which match a device
//
class DeviceQualifier
{
public:
DeviceQualifier() : cid(-1) {}
DeviceQualifier(const std::string& _source, const int _id, const std::string& _name)
: source(_source), cid(_id), name(_name)
{
}
void FromDevice(const Device* const dev);
void FromString(const std::string& str);
std::string ToString() const;
bool operator==(const DeviceQualifier& devq) const;
bool operator!=(const DeviceQualifier& devq) const;
bool operator==(const Device* dev) const;
bool operator!=(const Device* dev) const;
std::string source;
int cid;
std::string name;
};
class DeviceContainer
{
public:
Device::Input* FindInput(const std::string& name, const Device* def_dev) const;
Device::Output* FindOutput(const std::string& name, const Device* def_dev) const;
std::vector<std::string> GetAllDeviceStrings() const;
std::string GetDefaultDeviceString() const;
std::shared_ptr<Device> FindDevice(const DeviceQualifier& devq) const;
bool HasConnectedDevice(const DeviceQualifier& qualifier) const;
protected:
mutable std::mutex m_devices_mutex;
std::vector<std::shared_ptr<Device>> m_devices;
};
}
}
|