From eaa31a573d4e8f6cb5e7a9ac65dc06207f411002 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Wed, 7 Sep 2011 22:39:08 +0000 Subject: [PATCH] * add DeviceSCSI for handling scsi / disk devices identified by scsi bus * complete static category defines * a few style fixes * ata / scsi trees are still ugly but make a little more sense now * search for a pretty name as a last resort before going 'Unknown device' * closes #6503 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42721 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/devices/Device.h | 28 ++++++-- src/apps/devices/DeviceSCSI.cpp | 109 +++++++++++++++++++++++++++++++ src/apps/devices/DeviceSCSI.h | 25 +++++++ src/apps/devices/DevicesView.cpp | 37 +++++++---- src/apps/devices/DevicesView.h | 1 + src/apps/devices/Jamfile | 2 + 6 files changed, 185 insertions(+), 17 deletions(-) create mode 100644 src/apps/devices/DeviceSCSI.cpp create mode 100644 src/apps/devices/DeviceSCSI.h diff --git a/src/apps/devices/Device.h b/src/apps/devices/Device.h index 126950a04e..5b1dc0ef68 100644 --- a/src/apps/devices/Device.h +++ b/src/apps/devices/Device.h @@ -44,10 +44,26 @@ typedef std::vector Attributes; typedef enum { - CAT_NONE = 0, - CAT_BUS = 6, - CAT_COMPUTER = 0x12, - CAT_ACPI = 0x13 + CAT_NONE, // 0x00 + CAT_MASS, // 0x01 + CAT_NETWORK, // 0x02 + CAT_DISPLAY, // 0x03 + CAT_MULTIMEDIA, // 0x04 + CAT_MEMORY, // 0x05 + CAT_BUS, // 0x06 + CAT_COMM, // 0x07 + CAT_GENERIC, // 0x08 + CAT_INPUT, // 0x09 + CAT_DOCK, // 0x0A + CAT_CPU, // 0x0B + CAT_SERIAL, // 0x0C + CAT_WIRELESS, // 0x0D + CAT_INTEL, // 0x0E + CAT_SATELLITE, // 0x0F + CAT_CRYPTO, // 0x10 + CAT_SIGNAL, // 0x11 + CAT_COMPUTER, // 0x12 + CAT_ACPI // 0x13 } Category; @@ -57,8 +73,8 @@ extern const char* kCategoryString[]; class Device : public BStringItem { public: Device(Device* physicalParent, - BusType busType=BUS_NONE, - Category category=CAT_NONE, + BusType busType = BUS_NONE, + Category category = CAT_NONE, const BString& name = "unknown", const BString& manufacturer = "unknown", const BString& driverUsed = "unknown", diff --git a/src/apps/devices/DeviceSCSI.cpp b/src/apps/devices/DeviceSCSI.cpp new file mode 100644 index 0000000000..fd38d97ad8 --- /dev/null +++ b/src/apps/devices/DeviceSCSI.cpp @@ -0,0 +1,109 @@ +/* + * Copyright 2008-2011, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck, kallisti5@unixzen.com + */ + + +#include "DeviceSCSI.h" + +#include +#include +#include + +#include + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "DeviceSCSI" + + +// standard SCSI device types +const char* SCSITypeMap[] = { + B_TRANSLATE("Disk Drive"), // 0x00 + B_TRANSLATE("Tape Drive"), // 0x01 + B_TRANSLATE("Printer"), // 0x02 + B_TRANSLATE("Processor"), // 0x03 + B_TRANSLATE("Worm"), // 0x04 + B_TRANSLATE("CD-ROM"), // 0x05 + B_TRANSLATE("Scanner"), // 0x06 + B_TRANSLATE("Optical Drive"), // 0x07 + B_TRANSLATE("Changer"), // 0x08 + B_TRANSLATE("Communications"), // 0x09 + B_TRANSLATE("Graphics Peripheral"), // 0x0A + B_TRANSLATE("Graphics Peripheral"), // 0x0B + B_TRANSLATE("Array"), // 0x0C + B_TRANSLATE("Enclosure"), // 0x0D + B_TRANSLATE("RBC"), // 0x0E + B_TRANSLATE("Card Reader"), // 0x0F + B_TRANSLATE("Bridge"), // 0x10 + B_TRANSLATE("Other") // 0x11 +}; + + +DeviceSCSI::DeviceSCSI(Device* parent) + : + Device(parent) +{ +} + + +DeviceSCSI::~DeviceSCSI() +{ +} + + +void +DeviceSCSI::InitFromAttributes() +{ + BString nodeVendor(GetAttribute("scsi/vendor").fValue); + BString nodeProduct(GetAttribute("scsi/product").fValue); + + fCategory = (Category)CAT_MASS; + + uint32 nodeTypeID = atoi(GetAttribute("scsi/type").fValue); + + SetAttribute(B_TRANSLATE("Device name"), nodeProduct.String()); + SetAttribute(B_TRANSLATE("Manufacturer"), nodeVendor.String()); + SetAttribute(B_TRANSLATE("Device class"), SCSITypeMap[nodeTypeID]); + + BString listName; + listName + << "SCSI " << SCSITypeMap[nodeTypeID] << " (" << nodeProduct << ")"; + + SetText(listName.String()); +} + + +Attributes +DeviceSCSI::GetBusAttributes() +{ + // Push back things that matter for SCSI devices + Attributes attributes; + attributes.push_back(GetAttribute(B_TRANSLATE("Device class"))); + attributes.push_back(GetAttribute(B_TRANSLATE("Device name"))); + attributes.push_back(GetAttribute(B_TRANSLATE("Manufacturer"))); + attributes.push_back(GetAttribute("scsi/revision")); + attributes.push_back(GetAttribute("scsi/target_id")); + attributes.push_back(GetAttribute("scsi/target_lun")); + return attributes; +} + + +BString +DeviceSCSI::GetBusStrings() +{ + BString str(B_TRANSLATE("Class Info:\t\t\t\t: %classInfo%")); + str.ReplaceFirst("%classInfo%", fAttributeMap["Class Info"]); + + return str; +} + + +BString +DeviceSCSI::GetBusTabName() +{ + return B_TRANSLATE("SCSI Information"); +} + diff --git a/src/apps/devices/DeviceSCSI.h b/src/apps/devices/DeviceSCSI.h new file mode 100644 index 0000000000..d97083905b --- /dev/null +++ b/src/apps/devices/DeviceSCSI.h @@ -0,0 +1,25 @@ +/* + * Copyright 2008-2011, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck, kallisti5@unixzen.com + */ +#ifndef DEVICESCSI_H +#define DEVICESCSI_H + + +#include "Device.h" + + +class DeviceSCSI : public Device { +public: + DeviceSCSI(Device* parent); + virtual ~DeviceSCSI(); + virtual Attributes GetBusAttributes(); + virtual BString GetBusStrings(); + virtual void InitFromAttributes(); + virtual BString GetBusTabName(); +}; + +#endif /* DEVICESCSI_H */ diff --git a/src/apps/devices/DevicesView.cpp b/src/apps/devices/DevicesView.cpp index bd3582d1b9..040ea43388 100644 --- a/src/apps/devices/DevicesView.cpp +++ b/src/apps/devices/DevicesView.cpp @@ -280,54 +280,69 @@ DevicesView::AddDeviceAndChildren(device_node_cookie *node, Device* parent) for (unsigned int i = 0; i < attributes.size(); i++) { // Devices Root if (attributes[i].fName == B_DEVICE_PRETTY_NAME - && attributes[i].fValue == "Devices Root") { + && attributes[i].fValue == "Devices Root") { newDevice = new Device(parent, BUS_NONE, - CAT_COMPUTER, B_TRANSLATE("Computer")); + CAT_COMPUTER, B_TRANSLATE("Computer")); break; } // ACPI Controller if (attributes[i].fName == B_DEVICE_PRETTY_NAME - && attributes[i].fValue == "ACPI") { + && attributes[i].fValue == "ACPI") { newDevice = new Device(parent, BUS_ACPI, - CAT_BUS, B_TRANSLATE("ACPI bus")); + CAT_BUS, B_TRANSLATE("ACPI bus")); break; } // PCI bus if (attributes[i].fName == B_DEVICE_PRETTY_NAME - && attributes[i].fValue == "PCI") { + && attributes[i].fValue == "PCI") { newDevice = new Device(parent, BUS_PCI, - CAT_BUS, B_TRANSLATE("PCI bus")); + CAT_BUS, B_TRANSLATE("PCI bus")); break; } // ISA bus if (attributes[i].fName == B_DEVICE_BUS - && attributes[i].fValue == "isa") { + && attributes[i].fValue == "isa") { newDevice = new Device(parent, BUS_ISA, - CAT_BUS, B_TRANSLATE("ISA bus")); + CAT_BUS, B_TRANSLATE("ISA bus")); break; } // PCI device if (attributes[i].fName == B_DEVICE_BUS - && attributes[i].fValue == "pci") { + && attributes[i].fValue == "pci") { newDevice = new DevicePCI(parent); break; } // ACPI device if (attributes[i].fName == B_DEVICE_BUS - && attributes[i].fValue == "acpi") { + && attributes[i].fValue == "acpi") { newDevice = new DeviceACPI(parent); break; } + + // SCSI device + if (attributes[i].fName == B_DEVICE_BUS + && attributes[i].fValue == "scsi") { + newDevice = new DeviceSCSI(parent); + break; + } + + // Last resort, lets look for a pretty name + if (attributes[i].fName == B_DEVICE_PRETTY_NAME) { + newDevice = new Device(parent, BUS_NONE, + CAT_NONE, attributes[i].fValue); + break; + } } + // A completely unknown device if (newDevice == NULL) { newDevice = new Device(parent, BUS_NONE, - CAT_NONE, B_TRANSLATE("Unknown device")); + CAT_NONE, B_TRANSLATE("Unknown device")); } // Add its attributes to the device, initialize it and add to the list. diff --git a/src/apps/devices/DevicesView.h b/src/apps/devices/DevicesView.h index c71d5e05bc..167c763708 100644 --- a/src/apps/devices/DevicesView.h +++ b/src/apps/devices/DevicesView.h @@ -21,6 +21,7 @@ #include "Device.h" #include "DevicePCI.h" #include "DeviceACPI.h" +#include "DeviceSCSI.h" #include "PropertyList.h" #include "PropertyListPlain.h" diff --git a/src/apps/devices/Jamfile b/src/apps/devices/Jamfile index fe7b609b71..e69b600b1e 100644 --- a/src/apps/devices/Jamfile +++ b/src/apps/devices/Jamfile @@ -69,6 +69,7 @@ Application Devices : dm_wrapper.c DevicePCI.cpp DeviceACPI.cpp + DeviceSCSI.cpp Device.cpp PropertyList.cpp PropertyListPlain.cpp @@ -86,6 +87,7 @@ DoCatalogs Devices : PropertyList.cpp PropertyListPlain.cpp DeviceACPI.cpp + DeviceSCSI.cpp Device.cpp ;