From 283cbf48f3ae9c5f220f783a748b91d13fc2bfe7 Mon Sep 17 00:00:00 2001
From: Ingo Ruhnke <grumbel@gmx.de>
Date: Thu, 27 Jan 2011 01:10:51 +0100
Subject: [PATCH] Some code cleanup

---
 TODO                   | 67 +++++++++++++++++++++---------------------
 src/axis_event.cpp     |  7 +----
 src/linux_uinput.cpp   |  2 +-
 src/uinput_config.cpp  |  6 ++--
 src/xboxdrv.cpp        | 16 +++++++---
 src/xboxdrv_daemon.cpp |  4 +--
 src/xboxmsg.cpp        |  2 --
 7 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/TODO b/TODO
index 9285ebf..793cfbb 100644
--- a/TODO
+++ b/TODO
@@ -42,38 +42,11 @@ $ dput my-ppa ../xboxdrv_0.7.0-1~lucid1_source.changes
 Stuff to do before 0.7.0 release:
 =================================
 
-* get rid of all std::cout stuff when using detached daemon, redirect
-  log output to a file somewhere else: 
-
-  --silent:  stops event output
-  --quiet:   stops all stdout output (automatically used when --detach is given)
-  --verbose: print info level log output
-  --debug:   print debug level log output
-  --log-level: only log stuff at LEVEL or below
-
-* figure out a good place to set the LEDs off when Xboxdrv is quit,
-  just doing it in the destructor causes trouble, as the usbdev might
-  be no longer usable (when controller got unplugged)
-
 * AxisSensitivity filter has overflow issue 
 
-* fix the FIXME's
-
-* need to hide/disable the toggle button from the UIButtonmap
-  - maybe implement some full post-parsing option verification to
-    check for conflicts and necessary modifications?
-  - Options::finish() to do final things?
-
-* move XBOX_BTN_UNKNOWN behind XBOX_BTN_MAX, so iteration can start
-  from 0 instead of 1, also fix incorrect iterations all over the
-  place -> doesn't work as some code uses XBOX_BTN_UNKNOWN as 'no
-  button is pressed'
-
 Daemon Related Stuff
 ====================
 
-* improve output on which uinput devices are created
-
 * cleanup device_id, don't manually do (slot<<16) | devid
 
 * might need magic to give device-ids in a slot fashion: 
@@ -95,13 +68,34 @@ List Output
 
 * rename --list-key to --help-key?
 
-* do modifier/filter dump when --verbose is given, make verbose
-  overall more useful
-
 * turn EnumBox into singleton
 
 * Keysym2Keycode is currently always constructed at startup, even when
-  not used, construct it on demand
+  not used, construct it on demand to avoid X11 server connection
+
+Stuff to do before 0.7.1 release:
+=================================
+
+* figure out a good place to set the LEDs off when Xboxdrv is quit,
+  just doing it in the destructor causes trouble, as the usbdev might
+  be no longer usable (when controller got unplugged)
+
+* get rid of all std::cout stuff when using detached daemon, redirect
+  log output to a file somewhere else: 
+
+  --silent:  stops event output
+  --quiet:   stops all stdout output (automatically used when --detach is given)
+  --verbose: print info level log output
+  --debug:   print debug level log output
+
+* move XBOX_BTN_UNKNOWN behind XBOX_BTN_MAX, so iteration can start
+  from 0 instead of 1, also fix incorrect iterations all over the
+  place -> doesn't work as some code uses XBOX_BTN_UNKNOWN as 'no
+  button is pressed'
+
+* improve output on which uinput devices are created (even with udev
+  there doesn't seem to be a bullet proof way to detect what gets
+  created)
 
 * document significant patches in AUTHORS
 
@@ -112,9 +106,14 @@ List Output
       1 Author: Aaron Denney <wnoise@ofb.net>
       1     hal daemon from Thomas Debouverie <debouverie_thomas@yahoo.fr>
       1     Implemented --ui-buttonmap A=BTN_A@{device_id} ??!?!?
-
-Stuff to do before 0.7.1 release:
-=================================
+
+* do modifier/filter dump when --verbose is given, make verbose
+  overall more useful
+
+* need to hide/disable the toggle button from the UIButtonmap
+  - maybe implement some full post-parsing option verification to
+    check for conflicts and necessary modifications?
+  - Options::finish() to do final things?
 
 * print controller type/name in daemon (little tricky as that is only
   known after opening the USB connection)
diff --git a/src/axis_event.cpp b/src/axis_event.cpp
index e81320f..413c0bd 100644
--- a/src/axis_event.cpp
+++ b/src/axis_event.cpp
@@ -317,13 +317,8 @@ AbsAxisEventHandler::init(UInput& uinput, int slot, bool extra_devices)
 }
 
 void
-AbsAxisEventHandler:: send(UInput& uinput, int value)
+AbsAxisEventHandler::send(UInput& uinput, int value)
 {
-  /*FIXME for(std::vector<AxisFilterPtr>::const_iterator i = m_filters.begin(); i != m_filters.end(); ++i)
-  {
-    value = (*i)->filter(old_value, value);
-    }*/
-
   uinput.send_abs(m_code.get_device_id(), m_code.code, value);
 }
  
diff --git a/src/linux_uinput.cpp b/src/linux_uinput.cpp
index 67ddd28..e8dc66e 100644
--- a/src/linux_uinput.cpp
+++ b/src/linux_uinput.cpp
@@ -201,7 +201,7 @@ LinuxUinput::finish()
       break;
 
     case kJoystickDevice:
-      // FIXME: the kernel and SDL have different rules for joystick
+      // the kernel and SDL have different rules for joystick
       // detection, so this is more a hack then a proper solution
       if (!key_lst[BTN_A])
       {
diff --git a/src/uinput_config.cpp b/src/uinput_config.cpp
index 505e0b7..1e6d71c 100644
--- a/src/uinput_config.cpp
+++ b/src/uinput_config.cpp
@@ -38,7 +38,7 @@ int16_t u8_to_s16(uint8_t value)
 
 UInputConfig::UInputConfig(UInput& uinput, int slot, bool extra_devices, const UInputOptions& opts) :
   m_uinput(uinput),
-  m_btn_map(opts.get_btn_map()), // FIXME: insert resolve magic right here
+  m_btn_map(opts.get_btn_map()), 
   m_axis_map(opts.get_axis_map())
 {
   std::fill_n(axis_state,   static_cast<int>(XBOX_AXIS_MAX), 0);
@@ -267,7 +267,7 @@ UInputConfig::send_button(XboxButton code, bool value)
 
     // in case a shift button was changed, we have to clear all
     // connected buttons
-    for(int i = 0; i < XBOX_BTN_MAX; ++i) // iterate over all buttons
+    for(int i = 1; i < XBOX_BTN_MAX; ++i) // iterate over all buttons
     {
       if (button_state[i])
       {
@@ -285,7 +285,7 @@ UInputConfig::send_button(XboxButton code, bool value)
     }
 
     // Shifted button events
-    for(int i = 0; i < XBOX_BTN_MAX; ++i)
+    for(int i = 1; i < XBOX_BTN_MAX; ++i)
     {
       if (button_state[i]) // shift button is pressed
       {
diff --git a/src/xboxdrv.cpp b/src/xboxdrv.cpp
index 14ca639..2fe85f5 100644
--- a/src/xboxdrv.cpp
+++ b/src/xboxdrv.cpp
@@ -205,8 +205,12 @@ Xboxdrv::find_controller_by_id(int id, int vendor_id, int product_id, libusb_dev
     libusb_device* dev = list[dev_it];
     libusb_device_descriptor desc;
 
-    // FIXME: we silently ignore failures
-    if (libusb_get_device_descriptor(dev, &desc) == LIBUSB_SUCCESS)
+    int ret = libusb_get_device_descriptor(dev, &desc);
+    if (ret != LIBUSB_SUCCESS)
+    {
+      log_warn("libusb_get_device_descriptor() failed: " << usb_strerror(ret));
+    }
+    else
     {
       if (desc.idVendor  == vendor_id &&
           desc.idProduct == product_id)
@@ -243,8 +247,12 @@ Xboxdrv::find_xbox360_controller(int id, libusb_device** xbox_device, XPadDevice
     libusb_device* dev = list[dev_it];
     libusb_device_descriptor desc;
 
-    // FIXME: we silently ignore failures
-    if (libusb_get_device_descriptor(dev, &desc) == LIBUSB_SUCCESS)
+    int ret = libusb_get_device_descriptor(dev, &desc);
+    if (ret != LIBUSB_SUCCESS)
+    {
+      log_warn("libusb_get_device_descriptor() failed: " << usb_strerror(ret));
+    }
+    else
     {
       for(int i = 0; i < xpad_devices_count; ++i)
       {
diff --git a/src/xboxdrv_daemon.cpp b/src/xboxdrv_daemon.cpp
index daac59d..28cf682 100644
--- a/src/xboxdrv_daemon.cpp
+++ b/src/xboxdrv_daemon.cpp
@@ -328,7 +328,6 @@ XboxdrvDaemon::run_loop(const Options& opts)
   while(!global_exit_xboxdrv)
   {
     // FIXME: udev_monitor_receive_device() will block, must break out of it somehow
-    // FIXME: we bust udev_unref_monitor() this
     struct udev_device* device = udev_monitor_receive_device(m_monitor);
 
     cleanup_threads();
@@ -346,8 +345,9 @@ XboxdrvDaemon::run_loop(const Options& opts)
       {
         process_match(opts, device);
       }
+
+      udev_device_unref(device);
     }
-    udev_device_unref(device);
   }
 }
 
diff --git a/src/xboxmsg.cpp b/src/xboxmsg.cpp
index cb2fd78..b2f666b 100644
--- a/src/xboxmsg.cpp
+++ b/src/xboxmsg.cpp
@@ -180,8 +180,6 @@ std::ostream& operator<<(std::ostream& out, const Playstation3USBMsg& msg)
     % static_cast<int>(msg.a_l1)
     % static_cast<int>(msg.a_r1);
 
-  // FIXME: include analog buttons to
-
   out << boost::format("  L2:%3d R2:%3d")
     % int(msg.a_l2) % int(msg.a_r2);