1 /* 2 * Copyright 2008-2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Pieter Panman 7 */ 8 9 10 #include "Device.h" 11 12 #include <iostream> 13 14 #include <Catalog.h> 15 16 #undef B_TRANSLATION_CONTEXT 17 #define B_TRANSLATION_CONTEXT "Device" 18 19 // This list comes from the pciid list, except for the last ones 20 const char* kCategoryString[] = { 21 B_TRANSLATE("Unclassified device"), // 0x00 22 B_TRANSLATE("Mass storage controller"), // 0x01 23 B_TRANSLATE("Network controller"), // 0x02 24 B_TRANSLATE("Display controller"), // 0x03 25 B_TRANSLATE("Multimedia controller"), // 0x04 26 B_TRANSLATE("Memory controller"), // 0x05 27 B_TRANSLATE("Bridge"), // 0x06 28 B_TRANSLATE("Communication controller"), // 0x07 29 B_TRANSLATE("Generic system peripheral"), // 0x08 30 B_TRANSLATE("Input device controller"), // 0x09 31 B_TRANSLATE("Docking station"), // 0x0a 32 B_TRANSLATE("Processor"), // 0x0b 33 B_TRANSLATE("Serial bus controller"), // 0x0c 34 B_TRANSLATE("Wireless controller"), // 0x0d 35 B_TRANSLATE("Intelligent controller"), // 0x0e 36 B_TRANSLATE("Satellite communications controller"), // 0x0f 37 B_TRANSLATE("Encryption controller"), // 0x10 38 B_TRANSLATE("Signal processing controller"), // 0x11 39 B_TRANSLATE("Computer"), // 0x12 (added later) 40 B_TRANSLATE("ACPI controller") // 0x13 (added later) 41 }; 42 const int kCategoryStringLength = sizeof(kCategoryString)/sizeof(char *); 43 44 // This list is only used to translate Device properties 45 B_TRANSLATE_MARK_VOID("unknown"); 46 B_TRANSLATE_MARK_VOID("Device"); 47 B_TRANSLATE_MARK_VOID("Computer"); 48 B_TRANSLATE_MARK_VOID("ACPI bus"); 49 B_TRANSLATE_MARK_VOID("PCI bus"); 50 B_TRANSLATE_MARK_VOID("ISA bus"); 51 B_TRANSLATE_MARK_VOID("Unknown device"); 52 53 54 Device::Device(Device* physicalParent, BusType busType, Category category, 55 const BString& name, const BString& manufacturer, 56 const BString& driverUsed, const BString& devPathsPublished) 57 : 58 BStringItem(name.String()), 59 fBusType(busType), 60 fCategory(category), 61 fPhysicalParent(physicalParent) 62 { 63 SetAttribute(B_TRANSLATE("Device name"), B_TRANSLATE(name)); 64 SetAttribute(B_TRANSLATE("Manufacturer"), B_TRANSLATE(manufacturer)); 65 SetAttribute(B_TRANSLATE("Driver used"), B_TRANSLATE(driverUsed)); 66 SetAttribute(B_TRANSLATE("Device paths"), B_TRANSLATE(devPathsPublished)); 67 } 68 69 70 Device::~Device() 71 { 72 } 73 74 75 BString 76 Device::GetName() 77 { 78 return fAttributeMap[B_TRANSLATE("Device name")]; 79 } 80 81 82 BString 83 Device::GetManufacturer() 84 { 85 return fAttributeMap[B_TRANSLATE("Manufacturer")]; 86 } 87 88 89 BString 90 Device::GetDriverUsed() 91 { 92 return fAttributeMap[B_TRANSLATE("Driver used")]; 93 } 94 95 96 BString 97 Device::GetDevPathsPublished() 98 { 99 return fAttributeMap[B_TRANSLATE("Device paths")]; 100 } 101 102 103 void 104 Device::SetAttribute(const BString& name, const BString& value) 105 { 106 if (name == B_TRANSLATE("Device name")) { 107 SetText(value.String()); 108 } 109 fAttributeMap[name] = value; 110 } 111 112 113 Attributes 114 Device::GetBasicAttributes() 115 { 116 Attributes attributes; 117 attributes.push_back(Attribute(B_TRANSLATE("Device name:"), GetName())); 118 attributes.push_back(Attribute(B_TRANSLATE("Manufacturer:"), 119 GetManufacturer())); 120 return attributes; 121 } 122 123 124 Attributes 125 Device::GetBusAttributes() 126 { 127 Attributes attributes; 128 attributes.push_back(Attribute("None", "")); 129 return attributes; 130 } 131 132 133 Attributes 134 Device::GetAllAttributes() 135 { 136 Attributes attributes; 137 AttributeMapIterator iter; 138 for (iter = fAttributeMap.begin(); iter != fAttributeMap.end(); iter++) { 139 attributes.push_back(Attribute(iter->first, iter->second)); 140 } 141 return attributes; 142 } 143 144 145 BString 146 Device::GetBasicStrings() 147 { 148 BString str(B_TRANSLATE("Device Name\t\t\t\t: %Name%\n" 149 "Manufacturer\t\t\t: %Manufacturer%\n" 150 "Driver used\t\t\t\t: %DriverUsed%\n" 151 "Device paths\t: %DevicePaths%")); 152 153 str.ReplaceFirst("%Name%", GetName()); 154 str.ReplaceFirst("%Manufacturer%", GetManufacturer()); 155 str.ReplaceFirst("%DriverUsed%", GetDriverUsed()); 156 str.ReplaceFirst("%DevicePaths%", GetDevPathsPublished()); 157 158 return str; 159 } 160 161 BString 162 Device::GetBusStrings() 163 { 164 return B_TRANSLATE("None"); 165 } 166 167 168 BString 169 Device::GetBusTabName() 170 { 171 return B_TRANSLATE("Bus Information"); 172 } 173 174 175 BString 176 Device::GetAllStrings() 177 { 178 BString str; 179 AttributeMapIterator iter; 180 for (iter = fAttributeMap.begin(); iter != fAttributeMap.end(); iter++) { 181 str << iter->first << " : " << iter->second << "\n"; 182 } 183 return str; 184 } 185