BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / devices / DevicePCI.cpp
blob0913373dcbd7f84173bc187f29d21387ad51b092
1 /*
2 * Copyright 2008-2009 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Pieter Panman
7 */
10 #include "DevicePCI.h"
12 #include <sstream>
13 #include <stdlib.h>
15 #include <Catalog.h>
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "DevicePCI"
20 extern "C" {
21 #include "dm_wrapper.h"
22 #include "pcihdr.h"
23 #include "pci-utils.h"
27 DevicePCI::DevicePCI(Device* parent)
29 Device(parent),
30 fClassBaseId(0),
31 fClassSubId(0),
32 fClassApiId(0),
33 fVendorId(0),
34 fDeviceId(0),
35 fSubsystemVendorId(0),
36 fSubSystemId(0)
41 DevicePCI::~DevicePCI()
46 BString ToHex(uint16 num)
48 std::stringstream ss;
49 ss.flags(std::ios::hex | std::ios::showbase);
50 ss << num;
51 return BString(ss.str().c_str());
55 void
56 DevicePCI::InitFromAttributes()
58 // Process the attributes
59 fClassBaseId = atoi(fAttributeMap[B_DEVICE_TYPE].String());
60 fClassSubId = atoi(fAttributeMap[B_DEVICE_SUB_TYPE].String());
61 fClassApiId = atoi(fAttributeMap[B_DEVICE_INTERFACE].String());
62 fVendorId = atoi(fAttributeMap[B_DEVICE_VENDOR_ID].String());
63 fDeviceId = atoi(fAttributeMap[B_DEVICE_ID].String());
65 // Looks better in Hex, so rewrite
66 fAttributeMap[B_DEVICE_TYPE] = ToHex(fClassBaseId);
67 fAttributeMap[B_DEVICE_SUB_TYPE] = ToHex(fClassSubId);
68 fAttributeMap[B_DEVICE_INTERFACE] = ToHex(fClassApiId);
69 fAttributeMap[B_DEVICE_VENDOR_ID] = ToHex(fVendorId);
70 fAttributeMap[B_DEVICE_ID] = ToHex(fDeviceId);
72 // Fetch ClassInfo
73 char classInfo[64];
74 get_class_info(fClassBaseId, fClassSubId, fClassApiId, classInfo,
75 sizeof(classInfo));
77 // Fetch ManufacturerName
78 BString ManufacturerName;
79 const char *venShort;
80 const char *venFull;
81 get_vendor_info(fVendorId, &venShort, &venFull);
82 if (!venShort && !venFull) {
83 ManufacturerName << B_TRANSLATE("Unknown");
84 } else if (venShort && venFull) {
85 ManufacturerName << venFull << "(" << venShort << ")";
86 } else {
87 ManufacturerName << (venShort ? venShort : venFull);
90 // Fetch DeviceName
91 BString DeviceName;
92 const char *devShort;
93 const char *devFull;
94 get_device_info(fVendorId, fDeviceId, fSubsystemVendorId, fSubSystemId,
95 &devShort, &devFull);
96 if (!devShort && !devFull) {
97 DeviceName << B_TRANSLATE("Unknown");
98 } else if (devShort && devFull) {
99 DeviceName << devFull << "(" << devShort << ")";
100 } else {
101 DeviceName << (devShort ? devShort : devFull);
104 SetAttribute(B_TRANSLATE("Device name"), DeviceName);
105 SetAttribute(B_TRANSLATE("Manufacturer"), ManufacturerName);
106 SetAttribute(B_TRANSLATE("Driver used"), B_TRANSLATE("Not implemented"));
107 SetAttribute(B_TRANSLATE("Device paths"), B_TRANSLATE("Not implemented"));
108 SetAttribute(B_TRANSLATE("Class info"), classInfo);
109 fCategory = (Category)fClassBaseId;
110 BString outlineName;
111 outlineName << ManufacturerName << " " << DeviceName;
112 SetText(outlineName.String());
116 Attributes
117 DevicePCI::GetBusAttributes()
119 Attributes attributes;
120 attributes.push_back(GetAttribute(B_DEVICE_TYPE));
121 attributes.push_back(GetAttribute(B_DEVICE_SUB_TYPE));
122 attributes.push_back(GetAttribute(B_DEVICE_INTERFACE));
123 attributes.push_back(GetAttribute(B_DEVICE_VENDOR_ID));
124 attributes.push_back(GetAttribute(B_DEVICE_ID));
125 return attributes;
129 BString
130 DevicePCI::GetBusStrings()
132 BString str("Class Info:\t\t\t\t: %classInfo%");
133 str.ReplaceFirst("%classInfo%", fAttributeMap["Class Info"]);
134 return str;
138 BString
139 DevicePCI::GetBusTabName()
141 return B_TRANSLATE("PCI Information");