2 #include <sigc++/bind.h>
15 unsigned Hub::attach(Device &dev)
17 unsigned index = devices.size();
18 devices.push_back(&dev);
19 dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index));
20 dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index));
21 dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index));
25 std::string Hub::get_button_name(unsigned btn) const
27 unsigned dev_index = btn>>12;
28 if(dev_index>=devices.size())
29 throw invalid_argument("Hub::get_button_name");
31 const Device &dev = *devices[dev_index];
32 return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
35 std::string Hub::get_axis_name(unsigned axis) const
37 unsigned dev_index = axis>>12;
38 if(dev_index>=devices.size())
39 throw invalid_argument("Hub::get_axis_name");
41 const Device &dev = *devices[dev_index];
42 return dev.get_name()+": "+dev.get_axis_name(axis&0xFFF);
45 void Hub::button_press(unsigned btn, unsigned index)
47 set_button_state((index<<12) | (btn&0xFFF), true, true);
50 void Hub::button_release(unsigned btn, unsigned index)
52 set_button_state((index<<12) | (btn&0xFFF), false, true);
55 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
57 set_axis_value((index<<12) | (axis&0xFFF), value, true);