[haiku-commits] r42721 - haiku/trunk/src/apps/devices

  • From: kallisti5@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 8 Sep 2011 00:39:08 +0200 (CEST)

Author: kallisti5
Date: 2011-09-08 00:39:08 +0200 (Thu, 08 Sep 2011)
New Revision: 42721
Changeset: https://dev.haiku-os.org/changeset/42721
Ticket: https://dev.haiku-os.org/ticket/6503

Added:
   haiku/trunk/src/apps/devices/DeviceSCSI.cpp
   haiku/trunk/src/apps/devices/DeviceSCSI.h
Modified:
   haiku/trunk/src/apps/devices/Device.h
   haiku/trunk/src/apps/devices/DevicesView.cpp
   haiku/trunk/src/apps/devices/DevicesView.h
   haiku/trunk/src/apps/devices/Jamfile
Log:
* 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


Modified: haiku/trunk/src/apps/devices/Device.h
===================================================================
--- haiku/trunk/src/apps/devices/Device.h       2011-09-07 21:41:57 UTC (rev 
42720)
+++ haiku/trunk/src/apps/devices/Device.h       2011-09-07 22:39:08 UTC (rev 
42721)
@@ -44,10 +44,26 @@
 
 
 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 @@
 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",

Added: haiku/trunk/src/apps/devices/DeviceSCSI.cpp
===================================================================
--- haiku/trunk/src/apps/devices/DeviceSCSI.cpp                         (rev 0)
+++ haiku/trunk/src/apps/devices/DeviceSCSI.cpp 2011-09-07 22:39:08 UTC (rev 
42721)
@@ -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@xxxxxxxxxxx
+ */
+
+
+#include "DeviceSCSI.h"
+
+#include <scsi.h>
+#include <sstream>
+#include <stdlib.h>
+
+#include <Catalog.h>
+
+#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");
+}
+

Added: haiku/trunk/src/apps/devices/DeviceSCSI.h
===================================================================
--- haiku/trunk/src/apps/devices/DeviceSCSI.h                           (rev 0)
+++ haiku/trunk/src/apps/devices/DeviceSCSI.h   2011-09-07 22:39:08 UTC (rev 
42721)
@@ -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@xxxxxxxxxxx
+ */
+#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 */

Modified: haiku/trunk/src/apps/devices/DevicesView.cpp
===================================================================
--- haiku/trunk/src/apps/devices/DevicesView.cpp        2011-09-07 21:41:57 UTC 
(rev 42720)
+++ haiku/trunk/src/apps/devices/DevicesView.cpp        2011-09-07 22:39:08 UTC 
(rev 42721)
@@ -280,54 +280,69 @@
        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.

Modified: haiku/trunk/src/apps/devices/DevicesView.h
===================================================================
--- haiku/trunk/src/apps/devices/DevicesView.h  2011-09-07 21:41:57 UTC (rev 
42720)
+++ haiku/trunk/src/apps/devices/DevicesView.h  2011-09-07 22:39:08 UTC (rev 
42721)
@@ -21,6 +21,7 @@
 #include "Device.h"
 #include "DevicePCI.h"
 #include "DeviceACPI.h"
+#include "DeviceSCSI.h"
 #include "PropertyList.h"
 #include "PropertyListPlain.h"
 

Modified: haiku/trunk/src/apps/devices/Jamfile
===================================================================
--- haiku/trunk/src/apps/devices/Jamfile        2011-09-07 21:41:57 UTC (rev 
42720)
+++ haiku/trunk/src/apps/devices/Jamfile        2011-09-07 22:39:08 UTC (rev 
42721)
@@ -69,6 +69,7 @@
        dm_wrapper.c
        DevicePCI.cpp
        DeviceACPI.cpp
+       DeviceSCSI.cpp
        Device.cpp
        PropertyList.cpp
        PropertyListPlain.cpp
@@ -86,6 +87,7 @@
        PropertyList.cpp
        PropertyListPlain.cpp
        DeviceACPI.cpp
+       DeviceSCSI.cpp
        Device.cpp
 ;
 


Other related posts:

  • » [haiku-commits] r42721 - haiku/trunk/src/apps/devices - kallisti5