From 576cd2495d7f29bc8a56d70915d3ebcd52290a13 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Thu, 12 Feb 2009 23:05:57 +0000 Subject: [PATCH] * Compacted some of the code and inlined the DumpRoster implementation into the class as it's so little code. * No need to allocate the roster on the heap. * Add /dev/bus/usb to the device location to make it more clear. * Add the device location to the non-verbose output as well. * Put the manufacturer and product strings into quotes to make it clearer that those are just strings. Avoids just blank output when a device doesn't provide those strings. * Remove trailing whitespace. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29187 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/listusb.cpp | 110 ++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 61 deletions(-) diff --git a/src/bin/listusb.cpp b/src/bin/listusb.cpp index 4d34b6187b..7e875c2c80 100644 --- a/src/bin/listusb.cpp +++ b/src/bin/listusb.cpp @@ -95,67 +95,56 @@ DumpConfiguration(const BUSBConfiguration *configuration) static void DumpInfo(BUSBDevice &device, bool verbose) { - if (verbose) { - printf("[Device %s]\n", device.Location()); - printf(" Class .................. 0x%02x\n", device.Class()); - printf(" Subclass ............... 0x%02x\n", device.Subclass()); - printf(" Protocol ............... 0x%02x\n", device.Protocol()); - printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); - printf(" USB Version ............ 0x%04x\n", device.USBVersion()); - printf(" Vendor ID .............. 0x%04x\n", device.VendorID()); - printf(" Product ID ............. 0x%04x\n", device.ProductID()); - printf(" Product Version ........ 0x%04x\n", device.Version()); - printf(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); - printf(" Product String ......... \"%s\"\n", device.ProductString()); - printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString()); - - for (uint32 i = 0; i < device.CountConfigurations(); i++) { - printf(" [Configuration %lu]\n", i); - DumpConfiguration(device.ConfigurationAt(i)); - } - } else { - printf("%04x:%04x %s %s (version %04x)\n", device.VendorID(), device.ProductID(), device.ManufacturerString(), device.ProductString(), device.Version()); + if (!verbose) { + printf("%04x:%04x /dev/bus/usb%s \"%s\" \"%s\" ver. %04x\n", + device.VendorID(), device.ProductID(), device.Location(), + device.ManufacturerString(), device.ProductString(), + device.Version()); + return; + } + + printf("[Device /dev/bus/usb%s]\n", device.Location()); + printf(" Class .................. 0x%02x\n", device.Class()); + printf(" Subclass ............... 0x%02x\n", device.Subclass()); + printf(" Protocol ............... 0x%02x\n", device.Protocol()); + printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); + printf(" USB Version ............ 0x%04x\n", device.USBVersion()); + printf(" Vendor ID .............. 0x%04x\n", device.VendorID()); + printf(" Product ID ............. 0x%04x\n", device.ProductID()); + printf(" Product Version ........ 0x%04x\n", device.Version()); + printf(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); + printf(" Product String ......... \"%s\"\n", device.ProductString()); + printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString()); + + for (uint32 i = 0; i < device.CountConfigurations(); i++) { + printf(" [Configuration %lu]\n", i); + DumpConfiguration(device.ConfigurationAt(i)); } } -class DumpRoster : public BUSBRoster -{ - public: - DumpRoster(bool verbose); - ~DumpRoster(); - - virtual status_t DeviceAdded(BUSBDevice *device); - virtual void DeviceRemoved(BUSBDevice *device); - - private: - bool fVerbose; + +class DumpRoster : public BUSBRoster { +public: + DumpRoster(bool verbose) + : fVerbose(verbose) + { + } + +virtual status_t DeviceAdded(BUSBDevice *device) + { + DumpInfo(*device, fVerbose); + return B_OK; + } + +virtual void DeviceRemoved(BUSBDevice *device) + { + } + +private: + bool fVerbose; }; -DumpRoster::DumpRoster(bool verbose) - : BUSBRoster(), - fVerbose(verbose) -{ -} - - -DumpRoster::~DumpRoster() -{ -} - -status_t -DumpRoster::DeviceAdded(BUSBDevice *device) -{ - DumpInfo(*device, fVerbose); - return B_OK; -} - -void -DumpRoster::DeviceRemoved(BUSBDevice *) -{ -} - - int main(int argc, char *argv[]) { @@ -175,7 +164,7 @@ main(int argc, char *argv[]) devname = argv[i]; } } - + if (devname.Length() > 0) { BUSBDevice device(devname.String()); if (device.InitCheck() < B_OK) { @@ -186,11 +175,10 @@ main(int argc, char *argv[]) return 0; } } else { - DumpRoster *roster = new DumpRoster(verbose); - roster->Start(); - roster->Stop(); - delete roster; + DumpRoster roster(verbose); + roster.Start(); + roster.Stop(); } - + return 0; }