diff --git a/src/inputdrv/abs_to_btn.cpp b/src/inputdrv/abs_to_btn.cpp index e777ba0..cb8e1d2 100644 --- a/src/inputdrv/abs_to_btn.cpp +++ b/src/inputdrv/abs_to_btn.cpp @@ -16,9 +16,15 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <boost/bind.hpp> #include "abs_to_btn.hpp" - + +#include <boost/bind.hpp> + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" + AbsToBtn::AbsToBtn(int threshold) : threshold(threshold) { @@ -56,5 +62,5 @@ void AbsToBtn::update(float delta) { } - + /* EOF */ diff --git a/src/inputdrv/abs_to_rel.cpp b/src/inputdrv/abs_to_rel.cpp index 04ebe1c..661d822 100644 --- a/src/inputdrv/abs_to_rel.cpp +++ b/src/inputdrv/abs_to_rel.cpp @@ -16,9 +16,15 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <boost/bind.hpp> #include "abs_to_rel.hpp" +#include <boost/bind.hpp> + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + AbsToRel::AbsToRel() { abs_port_in.push_back(new AbsPortIn("AbsToRel-In", 0, 0, diff --git a/src/inputdrv/autofire_button.cpp b/src/inputdrv/autofire_button.cpp index 2971e97..baaccea 100644 --- a/src/inputdrv/autofire_button.cpp +++ b/src/inputdrv/autofire_button.cpp @@ -16,8 +16,12 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <boost/bind.hpp> #include "autofire_button.hpp" + +#include <boost/bind.hpp> + +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" AutofireButton::AutofireButton(int rate) : rate(rate), diff --git a/src/inputdrv/btn_to_abs.cpp b/src/inputdrv/btn_to_abs.cpp index 17d6eb6..0215682 100644 --- a/src/inputdrv/btn_to_abs.cpp +++ b/src/inputdrv/btn_to_abs.cpp @@ -16,9 +16,15 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <boost/bind.hpp> #include "btn_to_abs.hpp" +#include <boost/bind.hpp> + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" + BtnToAbs::BtnToAbs() : target_value(0) { diff --git a/src/inputdrv/control.cpp b/src/inputdrv/control.cpp index 53380dd..bda6de1 100644 --- a/src/inputdrv/control.cpp +++ b/src/inputdrv/control.cpp @@ -17,21 +17,34 @@ */ #include "control.hpp" - -void -BtnPortOut::connect(BtnPortIn* in) + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + +Control::Control() { - if (in) - { - in->out_port = this; - sig_change.connect(in->on_change); - } } -void -BtnPortOut::connect(boost::function<void(BtnPortOut*)> func) +Control::~Control() { - sig_change.connect(func); + for(std::vector<BtnPortIn*>::iterator i = btn_port_in.begin(); i != btn_port_in.end(); ++i) + delete *i; + for(std::vector<BtnPortOut*>::iterator i = btn_port_out.begin(); i != btn_port_out.end(); ++i) + delete *i; + + for(std::vector<AbsPortIn*>::iterator i = abs_port_in.begin(); i != abs_port_in.end(); ++i) + delete *i; + for(std::vector<AbsPortOut*>::iterator i = abs_port_out.begin(); i != abs_port_out.end(); ++i) + delete *i; + + for(std::vector<RelPortIn*>::iterator i = rel_port_in.begin(); i != rel_port_in.end(); ++i) + delete *i; + for(std::vector<RelPortOut*>::iterator i = rel_port_out.begin(); i != rel_port_out.end(); ++i) + delete *i; } BtnPortIn* @@ -51,22 +64,6 @@ Control::get_btn_port_out(int idx) else return 0; } - -void -AbsPortOut::connect(AbsPortIn* in) -{ - if (in) - { - in->out_port = this; - sig_change.connect(in->on_change); - } -} - -void -AbsPortOut::connect(boost::function<void(AbsPortOut*)> func) -{ - sig_change.connect(func); -} AbsPortIn* Control::get_abs_port_in(int idx) @@ -91,22 +88,6 @@ Control::get_abs_port_out(int idx) return 0; } } - -void -RelPortOut::connect(RelPortIn* in) -{ - if (in) - { - in->out_port = this; - sig_change.connect(in->on_change); - } -} - -void -RelPortOut::connect(boost::function<void(RelPortOut*)> func) -{ - sig_change.connect(func); -} RelPortIn* Control::get_rel_port_in(int idx) @@ -142,7 +123,7 @@ void connect_btn(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i) else LOG("Couldn't establish connection between " << lhs_ctrl << " and " << rhs_ctrl); } - + void connect_abs(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i) { AbsPortOut* out = lhs_ctrl->get_abs_port_out(lhs_i); @@ -153,7 +134,7 @@ void connect_abs(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i) else LOG("Couldn't establish connection between " << lhs_ctrl << " and " << rhs_ctrl); } - + void connect_rel(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i) { RelPortOut* out = lhs_ctrl->get_rel_port_out(lhs_i); diff --git a/src/inputdrv/control.hpp b/src/inputdrv/control.hpp index 03a4571..c685978 100644 --- a/src/inputdrv/control.hpp +++ b/src/inputdrv/control.hpp @@ -23,125 +23,13 @@ #include "log.hpp" class BtnPortIn; +class BtnPortOut; -class BtnPortOut -{ -public: - std::string label; - - // true if pressed, false otherwise - bool state; - - boost::signal<void(BtnPortOut*)> sig_change; - - BtnPortOut(const std::string& label) - : label(label), - state(false) - {} - - std::string get_label() { return label; } - bool get_state() { return state; } - void set_state(bool s) { if (state != s) { state = s; sig_change(this); } } - - void connect(BtnPortIn* in); - void connect(boost::function<void(BtnPortOut*)> func); -}; - -struct BtnPortIn -{ - std::string label; - boost::function<void(BtnPortOut*)> on_change; - BtnPortOut* out_port; - - BtnPortIn(const std::string& label, const boost::function<void(BtnPortOut*)>& on_change) - : label(label), on_change(on_change), out_port(0) {} -}; - class AbsPortIn; +class AbsPortOut; -class AbsPortOut -{ -public: - std::string label; - - boost::signal<void(AbsPortOut*)> sig_change; - - // true if pressed, false otherwise - int state; - int min_value; - int max_value; - - AbsPortOut(const std::string& label, int min_value, int max_value) - : label(label), - state(0), - min_value(min_value), - max_value(max_value) - {} - - - std::string get_label() { return label; } - int get_state() { return state; } - void set_state(int s) { if (state != s) { state = s; sig_change(this); } } - - void connect(AbsPortIn* in); - void connect(boost::function<void(AbsPortOut*)> func); -}; - -class AbsPortIn -{ -public: - std::string label; - int min_value; - int max_value; - - boost::function<void(AbsPortOut*)> on_change; - AbsPortOut* out_port; - - AbsPortIn(const std::string& label, int min_value, int max_value, - const boost::function<void(AbsPortOut*)>& on_change) - : label(label), - min_value(min_value), - max_value(max_value), - on_change(on_change), out_port(0) {} -}; - class RelPortIn; - -class RelPortOut -{ -public: - std::string label; - - boost::signal<void(RelPortOut*)> sig_change; - - // true if pressed, false otherwise - int state; - - RelPortOut(const std::string& label) - : label(label) - {} - - - std::string get_label() { return label; } - int get_state() { return state; } - void set_state(int s) { state = s; sig_change(this); } - - void connect(RelPortIn* in); - void connect(boost::function<void(RelPortOut*)> func); -}; - -class RelPortIn -{ -public: - std::string label; - - boost::function<void(RelPortOut*)> on_change; - RelPortOut* out_port; - - RelPortIn(const std::string& label, const boost::function<void(RelPortOut*)>& on_change) - : label(label), - on_change(on_change), out_port(0) {} -}; +class RelPortOut; class Control { @@ -156,26 +44,8 @@ protected: std::vector<RelPortOut*> rel_port_out; public: - Control() { - } - - virtual ~Control() - { - for(std::vector<BtnPortIn*>::iterator i = btn_port_in.begin(); i != btn_port_in.end(); ++i) - delete *i; - for(std::vector<BtnPortOut*>::iterator i = btn_port_out.begin(); i != btn_port_out.end(); ++i) - delete *i; - - for(std::vector<AbsPortIn*>::iterator i = abs_port_in.begin(); i != abs_port_in.end(); ++i) - delete *i; - for(std::vector<AbsPortOut*>::iterator i = abs_port_out.begin(); i != abs_port_out.end(); ++i) - delete *i; - - for(std::vector<RelPortIn*>::iterator i = rel_port_in.begin(); i != rel_port_in.end(); ++i) - delete *i; - for(std::vector<RelPortOut*>::iterator i = rel_port_out.begin(); i != rel_port_out.end(); ++i) - delete *i; - } + Control(); + virtual ~Control(); virtual std::string get_name() const =0; diff --git a/src/inputdrv/evdev_driver.cpp b/src/inputdrv/evdev_driver.cpp index 4af0e84..ef2c50d 100644 --- a/src/inputdrv/evdev_driver.cpp +++ b/src/inputdrv/evdev_driver.cpp @@ -28,6 +28,13 @@ #include "evdev_driver.hpp" +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + #define BITS_PER_LONG (sizeof(long) * 8) #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) #define OFF(x) ((x)%BITS_PER_LONG) diff --git a/src/inputdrv/inputdrv.cpp b/src/inputdrv/inputdrv.cpp index 593fa8e..792277d 100644 --- a/src/inputdrv/inputdrv.cpp +++ b/src/inputdrv/inputdrv.cpp @@ -22,17 +22,25 @@ #include <sstream> #include <boost/bind.hpp> #include <boost/format.hpp> -#include "xbox360_driver.hpp" -#include "uinput_driver.hpp" + #include "abs_to_rel.hpp" -#include "toggle_button.hpp" #include "autofire_button.hpp" -#include "join_axis.hpp" #include "btn_to_abs.hpp" -#include "throttle.hpp" -#include "evdev_driver.hpp" #include "control.hpp" +#include "evdev_driver.hpp" #include "inputdrv.hpp" +#include "join_axis.hpp" +#include "throttle.hpp" +#include "toggle_button.hpp" +#include "uinput_driver.hpp" +#include "xbox360_driver.hpp" + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" void btn_change(BtnPortOut* port) { diff --git a/src/inputdrv/join_axis.cpp b/src/inputdrv/join_axis.cpp index 7acf093..e970976 100644 --- a/src/inputdrv/join_axis.cpp +++ b/src/inputdrv/join_axis.cpp @@ -16,9 +16,17 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <boost/bind.hpp> #include "join_axis.hpp" +#include <boost/bind.hpp> + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + JoinAxis::JoinAxis() { abs_port_in.push_back(new AbsPortIn("JoinAxis-1", 0, 0, diff --git a/src/inputdrv/throttle.cpp b/src/inputdrv/throttle.cpp index af3314d..c4cae2e 100644 --- a/src/inputdrv/throttle.cpp +++ b/src/inputdrv/throttle.cpp @@ -16,9 +16,17 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <boost/bind.hpp> #include "throttle.hpp" +#include <boost/bind.hpp> + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + Throttle::Throttle() : value(0) { diff --git a/src/inputdrv/toggle_button.cpp b/src/inputdrv/toggle_button.cpp index 79f5870..1fd4250 100644 --- a/src/inputdrv/toggle_button.cpp +++ b/src/inputdrv/toggle_button.cpp @@ -16,9 +16,17 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <boost/bind.hpp> #include "toggle_button.hpp" +#include <boost/bind.hpp> + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + ToggleButton::ToggleButton() : state(false) { diff --git a/src/inputdrv/uinput_driver.cpp b/src/inputdrv/uinput_driver.cpp index 8d28738..629ff3a 100644 --- a/src/inputdrv/uinput_driver.cpp +++ b/src/inputdrv/uinput_driver.cpp @@ -16,13 +16,22 @@ ** along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "uinput_driver.hpp" + #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <linux/uinput.h> #include <boost/bind.hpp> -#include "uinput_driver.hpp" + +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + UInputDriver::UInputDriver(const std::string& name) : abs_bit(false), diff --git a/src/inputdrv/xbox360_driver.cpp b/src/inputdrv/xbox360_driver.cpp index a79da5e..fe9b394 100644 --- a/src/inputdrv/xbox360_driver.cpp +++ b/src/inputdrv/xbox360_driver.cpp @@ -29,6 +29,13 @@ #include "xbox360_usb_thread.hpp" #include "xbox360_driver.hpp" +#include "abs_port_in.hpp" +#include "abs_port_out.hpp" +#include "btn_port_in.hpp" +#include "btn_port_out.hpp" +#include "rel_port_in.hpp" +#include "rel_port_out.hpp" + struct usb_device* find_usb_device_by_path(const std::string& busid, const std::string& devid) { struct usb_bus* busses = usb_get_busses();