Got rid of USBController::start()/stop(), do work in Constructor instead
This commit is contained in:
parent
ba98b21678
commit
15ebae464b
16 changed files with 53 additions and 136 deletions
src
controller.hppevdev_controller.cppevdev_controller.hppfirestorm_dual_controller.cppplaystation3_usb_controller.cppsaitek_p2500_controller.cppsaitek_p2500_controller.hppxbox360_controller.cppxbox360_controller.hppxbox360_wireless_controller.cppxbox360_wireless_controller.hppxbox_controller.cppxbox_controller.hppxboxdrv_daemon.cppxboxdrv_main.cpp
test
|
@ -38,9 +38,6 @@ public:
|
|||
Controller();
|
||||
virtual ~Controller();
|
||||
|
||||
virtual void start() {}
|
||||
virtual void stop() {}
|
||||
|
||||
virtual void set_rumble(uint8_t left, uint8_t right) =0;
|
||||
virtual void set_led(uint8_t status) =0;
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ EvdevController::EvdevController(const std::string& filename,
|
|||
bool grab,
|
||||
bool debug) :
|
||||
m_fd(-1),
|
||||
m_io_channel(),
|
||||
m_name(),
|
||||
m_grab(grab),
|
||||
m_debug(debug),
|
||||
|
@ -102,8 +103,6 @@ EvdevController::EvdevController(const std::string& filename,
|
|||
|
||||
log_debug(boost::format("abs: %-20s min: %6d max: %6d") % abs2str(i) % absinfo.minimum % absinfo.maximum);
|
||||
m_absinfo[i] = absinfo;
|
||||
//abs2idx[i] = abs_port_out.size();
|
||||
//abs_port_out.push_back(new AbsPortOut("EvdevDriver:abs", absinfo.minimum, absinfo.maximum));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,8 +111,6 @@ EvdevController::EvdevController(const std::string& filename,
|
|||
if (test_bit(i, rel_bit))
|
||||
{
|
||||
log_debug("rel: " << rel2str(i));
|
||||
//rel2idx[i] = rel_port_out.size();
|
||||
//rel_port_out.push_back(new RelPortOut("EvdevDriver:rel"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,35 +119,30 @@ EvdevController::EvdevController(const std::string& filename,
|
|||
if (test_bit(i, key_bit))
|
||||
{
|
||||
log_debug("key: " << key2str(i));
|
||||
//key2idx[i] = btn_port_out.size();
|
||||
//btn_port_out.push_back(new BtnPortOut("EvdevDriver:btn"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EvdevController::start()
|
||||
{
|
||||
GIOChannel* channel = g_io_channel_unix_new(m_fd);
|
||||
{ // start g_io_channel
|
||||
m_io_channel = g_io_channel_unix_new(m_fd);
|
||||
|
||||
// set encoding to binary
|
||||
GError* error;
|
||||
if (g_io_channel_set_encoding(channel, NULL, &error) != G_IO_STATUS_NORMAL)
|
||||
{
|
||||
log_error(error->message);
|
||||
g_error_free(error);
|
||||
// set encoding to binary
|
||||
GError* error;
|
||||
if (g_io_channel_set_encoding(m_io_channel, NULL, &error) != G_IO_STATUS_NORMAL)
|
||||
{
|
||||
log_error(error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
guint source_id;
|
||||
source_id = g_io_add_watch(m_io_channel, static_cast<GIOCondition>(G_IO_IN | G_IO_ERR),
|
||||
&EvdevController::on_read_data_wrap, this);
|
||||
}
|
||||
|
||||
guint source_id;
|
||||
source_id = g_io_add_watch(channel, static_cast<GIOCondition>(G_IO_IN | G_IO_ERR),
|
||||
&EvdevController::on_read_data_wrap, this);
|
||||
}
|
||||
|
||||
void
|
||||
EvdevController::stop()
|
||||
EvdevController::~EvdevController()
|
||||
{
|
||||
|
||||
g_io_channel_close(m_io_channel);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -33,6 +33,8 @@ class EvdevController : public Controller
|
|||
{
|
||||
private:
|
||||
int m_fd;
|
||||
GIOChannel* m_io_channel;
|
||||
|
||||
std::string m_name;
|
||||
bool m_grab;
|
||||
bool m_debug;
|
||||
|
@ -54,9 +56,7 @@ public:
|
|||
const std::map<int, XboxButton>& keyMap,
|
||||
bool grab,
|
||||
bool debug);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
~EvdevController();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
|
|
|
@ -88,10 +88,13 @@ FirestormDualController::FirestormDualController(libusb_device* dev, bool is_vsb
|
|||
right_rumble(-1)
|
||||
{
|
||||
usb_claim_interface(0, try_detach);
|
||||
//usb_submit_read();
|
||||
assert(!"not implemented");
|
||||
}
|
||||
|
||||
FirestormDualController::~FirestormDualController()
|
||||
{
|
||||
usb_cancel_read();
|
||||
usb_release_interface(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ Playstation3USBController::Playstation3USBController(libusb_device* dev, bool tr
|
|||
endpoint_out(2)
|
||||
{
|
||||
usb_claim_interface(0, try_detach);
|
||||
assert(!"not implemented");
|
||||
}
|
||||
|
||||
Playstation3USBController::~Playstation3USBController()
|
||||
|
|
|
@ -61,10 +61,12 @@ SaitekP2500Controller::SaitekP2500Controller(libusb_device* dev, bool try_detach
|
|||
right_rumble(-1)
|
||||
{
|
||||
usb_claim_interface(0, try_detach);
|
||||
usb_submit_read(1, sizeof(SaitekP2500Msg));
|
||||
}
|
||||
|
||||
SaitekP2500Controller::~SaitekP2500Controller()
|
||||
{
|
||||
usb_cancel_read();
|
||||
usb_release_interface(0);
|
||||
}
|
||||
|
||||
|
@ -91,30 +93,6 @@ SaitekP2500Controller::set_led(uint8_t status)
|
|||
// not supported
|
||||
}
|
||||
|
||||
bool
|
||||
SaitekP2500Controller::read(XboxGenericMsg& msg, int timeout)
|
||||
{
|
||||
uint8_t data[sizeof(SaitekP2500Msg)];
|
||||
int len = 0;
|
||||
int ret = libusb_interrupt_transfer(m_handle, LIBUSB_ENDPOINT_IN | 1,
|
||||
reinterpret_cast<uint8_t*>(&data), sizeof(data),
|
||||
&len, timeout);
|
||||
if (ret == LIBUSB_ERROR_TIMEOUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (ret != LIBUSB_SUCCESS)
|
||||
{ // Error
|
||||
std::ostringstream str;
|
||||
str << "USBError: " << ret << "\n" << usb_strerror(ret);
|
||||
throw std::runtime_error(str.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
return parse(data, len, &msg);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
SaitekP2500Controller::parse(uint8_t* data, int len, XboxGenericMsg* msg_out)
|
||||
{
|
||||
|
|
|
@ -36,8 +36,6 @@ public:
|
|||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
|
||||
/** @param timeout timeout in msec, 0 means forever */
|
||||
bool read(XboxGenericMsg& msg, int timeout);
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
private:
|
||||
|
|
|
@ -46,8 +46,8 @@ Xbox360Controller::Xbox360Controller(libusb_device* dev,
|
|||
log_debug("EP(IN): " << endpoint_in);
|
||||
log_debug("EP(OUT): " << endpoint_out);
|
||||
|
||||
// claim interface
|
||||
usb_claim_interface(0, try_detach);
|
||||
usb_submit_read(endpoint_in, 32);
|
||||
|
||||
// create chatpad
|
||||
if (chatpad)
|
||||
|
@ -75,21 +75,8 @@ Xbox360Controller::Xbox360Controller(libusb_device* dev,
|
|||
|
||||
Xbox360Controller::~Xbox360Controller()
|
||||
{
|
||||
usb_release_interface(0);
|
||||
}
|
||||
|
||||
void
|
||||
Xbox360Controller::start()
|
||||
{
|
||||
log_trace();
|
||||
usb_submit_read(endpoint_in, 32);
|
||||
}
|
||||
|
||||
void
|
||||
Xbox360Controller::stop()
|
||||
{
|
||||
log_trace();
|
||||
usb_cancel_read();
|
||||
usb_release_interface(0);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -50,9 +50,6 @@ public:
|
|||
bool try_detach);
|
||||
~Xbox360Controller();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
|
|
@ -44,25 +44,13 @@ Xbox360WirelessController::Xbox360WirelessController(libusb_device* dev, int con
|
|||
m_interface = controller_id*2;
|
||||
|
||||
usb_claim_interface(m_interface, try_detach);
|
||||
usb_submit_read(m_endpoint, 32);
|
||||
}
|
||||
|
||||
Xbox360WirelessController::~Xbox360WirelessController()
|
||||
{
|
||||
usb_release_interface(m_interface);
|
||||
}
|
||||
|
||||
void
|
||||
Xbox360WirelessController::start()
|
||||
{
|
||||
log_trace();
|
||||
usb_submit_read(m_endpoint, 32);
|
||||
}
|
||||
|
||||
void
|
||||
Xbox360WirelessController::stop()
|
||||
{
|
||||
log_trace();
|
||||
usb_cancel_read();
|
||||
usb_release_interface(m_interface);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -43,9 +43,6 @@ public:
|
|||
Xbox360WirelessController(libusb_device* dev, int controller_id, bool try_detach);
|
||||
virtual ~Xbox360WirelessController();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
|
|
|
@ -36,25 +36,13 @@ XboxController::XboxController(libusb_device* dev, bool try_detach) :
|
|||
m_endpoint_out = usb_find_ep(LIBUSB_ENDPOINT_OUT, 88, 66, 0);
|
||||
|
||||
usb_claim_interface(0, try_detach);
|
||||
usb_submit_read(m_endpoint_in, 32);
|
||||
}
|
||||
|
||||
XboxController::~XboxController()
|
||||
{
|
||||
usb_release_interface(0);
|
||||
}
|
||||
|
||||
void
|
||||
XboxController::start()
|
||||
{
|
||||
log_trace();
|
||||
usb_submit_read(m_endpoint_in, 32);
|
||||
}
|
||||
|
||||
void
|
||||
XboxController::stop()
|
||||
{
|
||||
log_trace();
|
||||
usb_cancel_read();
|
||||
usb_release_interface(0);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -35,9 +35,6 @@ public:
|
|||
XboxController(libusb_device* dev, bool try_detach);
|
||||
virtual ~XboxController();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
|
|
@ -679,9 +679,6 @@ XboxdrvDaemon::launch_controller_thread(udev_device* udev_dev,
|
|||
// FIXME: Little dirty hack
|
||||
controller->set_udev_device(udev_dev);
|
||||
|
||||
// FIXME: where is the best place to start()?
|
||||
controller->start();
|
||||
|
||||
if (controller->is_active())
|
||||
{
|
||||
// controller is active, so launch a thread if we have a free slot
|
||||
|
|
|
@ -127,7 +127,6 @@ XboxdrvMain::run()
|
|||
{
|
||||
ControllerPtr controller = create_controller();
|
||||
init_controller(controller);
|
||||
controller->start();
|
||||
|
||||
if (!m_opts.quiet)
|
||||
std::cout << std::endl;
|
||||
|
@ -138,7 +137,12 @@ XboxdrvMain::run()
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!m_opts.no_uinput)
|
||||
if (m_opts.no_uinput)
|
||||
{
|
||||
if (!m_opts.quiet)
|
||||
std::cout << "Starting without uinput" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_opts.quiet)
|
||||
std::cout << "Starting with uinput" << std::endl;
|
||||
|
@ -147,11 +151,6 @@ XboxdrvMain::run()
|
|||
m_uinput->set_device_names(m_opts.uinput_device_names);
|
||||
m_uinput->set_device_usbids(m_opts.uinput_device_usbids);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_opts.quiet)
|
||||
std::cout << "Starting without uinput" << std::endl;
|
||||
}
|
||||
|
||||
if (!m_opts.quiet)
|
||||
{
|
||||
|
@ -207,25 +206,25 @@ XboxdrvMain::main_loop(const ControllerPtr& controller)
|
|||
{
|
||||
// start the main loop
|
||||
GMainLoop* m_gmain = g_main_loop_new(NULL, false);
|
||||
{
|
||||
boost::scoped_ptr<USBGSource> usb_gsource(new USBGSource);
|
||||
usb_gsource->attach(NULL);
|
||||
|
||||
boost::scoped_ptr<USBGSource> usb_gsource(new USBGSource);
|
||||
usb_gsource->attach(NULL);
|
||||
|
||||
ControllerThread thread(controller, m_opts);
|
||||
thread.set_message_proc(create_message_proc());
|
||||
log_debug("launching thread");
|
||||
thread.start();
|
||||
ControllerThread thread(controller, m_opts);
|
||||
thread.set_message_proc(create_message_proc());
|
||||
log_debug("launching thread");
|
||||
thread.start();
|
||||
|
||||
pid_t pid = 0;
|
||||
if (!m_opts.exec.empty())
|
||||
{
|
||||
pid = spawn_exe(m_opts.exec);
|
||||
}
|
||||
|
||||
log_debug("launching main loop");
|
||||
g_main_loop_run(m_gmain);
|
||||
thread.stop();
|
||||
pid_t pid = 0;
|
||||
if (!m_opts.exec.empty())
|
||||
{
|
||||
pid = spawn_exe(m_opts.exec);
|
||||
}
|
||||
|
||||
log_debug("launching main loop");
|
||||
g_main_loop_run(m_gmain);
|
||||
thread.stop();
|
||||
|
||||
g_main_loop_unref(m_gmain);
|
||||
|
||||
if (!m_opts.quiet)
|
||||
|
|
|
@ -90,8 +90,6 @@ int main()
|
|||
"",
|
||||
"",
|
||||
false);
|
||||
//controller->set_message_proc(std::auto_ptr<MessageProcessor>(new DummyMessageProcessor()));
|
||||
controller->start();
|
||||
controller->set_led(2);
|
||||
g_main_loop_run(m_gmain);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue