* 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
This commit is contained in:
Michael Lotz
2009-02-12 23:05:57 +00:00
parent f7de06baf3
commit 576cd2495d
+44 -56
View File
@@ -95,67 +95,56 @@ DumpConfiguration(const BUSBConfiguration *configuration)
static void static void
DumpInfo(BUSBDevice &device, bool verbose) DumpInfo(BUSBDevice &device, bool verbose)
{ {
if (verbose) { if (!verbose) {
printf("[Device %s]\n", device.Location()); printf("%04x:%04x /dev/bus/usb%s \"%s\" \"%s\" ver. %04x\n",
printf(" Class .................. 0x%02x\n", device.Class()); device.VendorID(), device.ProductID(), device.Location(),
printf(" Subclass ............... 0x%02x\n", device.Subclass()); device.ManufacturerString(), device.ProductString(),
printf(" Protocol ............... 0x%02x\n", device.Protocol()); device.Version());
printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); return;
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("[Device /dev/bus/usb%s]\n", device.Location());
printf(" [Configuration %lu]\n", i); printf(" Class .................. 0x%02x\n", device.Class());
DumpConfiguration(device.ConfigurationAt(i)); printf(" Subclass ............... 0x%02x\n", device.Subclass());
} printf(" Protocol ............... 0x%02x\n", device.Protocol());
} else { printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize());
printf("%04x:%04x %s %s (version %04x)\n", device.VendorID(), device.ProductID(), device.ManufacturerString(), device.ProductString(), device.Version()); 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); class DumpRoster : public BUSBRoster {
virtual void DeviceRemoved(BUSBDevice *device); public:
DumpRoster(bool verbose)
: fVerbose(verbose)
{
}
private: virtual status_t DeviceAdded(BUSBDevice *device)
bool fVerbose; {
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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@@ -186,10 +175,9 @@ main(int argc, char *argv[])
return 0; return 0;
} }
} else { } else {
DumpRoster *roster = new DumpRoster(verbose); DumpRoster roster(verbose);
roster->Start(); roster.Start();
roster->Stop(); roster.Stop();
delete roster;
} }
return 0; return 0;