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("USB bus"); 52 B_TRANSLATE_MARK_VOID("Unknown device"); 53 54 55 Device::Device(Device* physicalParent, BusType busType, Category category, 56 const BString& name, const BString& manufacturer, 57 const BString& driverUsed, const BString& devPathsPublished) 58 : 59 BStringItem(name.String()), 60 fBusType(busType), 61 fCategory(category), 62 fPhysicalParent(physicalParent) 63 { 64 SetAttribute(B_TRANSLATE("Device name"), B_TRANSLATE(name)); 65 SetAttribute(B_TRANSLATE("Manufacturer"), B_TRANSLATE(manufacturer)); 66 SetAttribute(B_TRANSLATE("Driver used"), B_TRANSLATE(driverUsed)); 67 SetAttribute(B_TRANSLATE("Device paths"), B_TRANSLATE(devPathsPublished)); 68 } 69 70 71 Device::~Device() 72 { 73 } 74 75 76 BString 77 Device::GetName() 78 { 79 return fAttributeMap[B_TRANSLATE("Device name")]; 80 } 81 82 83 BString 84 Device::GetManufacturer() 85 { 86 return fAttributeMap[B_TRANSLATE("Manufacturer")]; 87 } 88 89 90 BString 91 Device::GetDriverUsed() 92 { 93 return fAttributeMap[B_TRANSLATE("Driver used")]; 94 } 95 96 97 BString 98 Device::GetDevPathsPublished() 99 { 100 return fAttributeMap[B_TRANSLATE("Device paths")]; 101 } 102 103 104 void 105 Device::SetAttribute(const BString& name, const BString& value) 106 { 107 if (name == B_TRANSLATE("Device name")) { 108 SetText(value.String()); 109 } 110 fAttributeMap[name] = value; 111 } 112 113 114 Attributes 115 Device::GetBasicAttributes() 116 { 117 Attributes attributes; 118 attributes.push_back(Attribute(B_TRANSLATE("Device name:"), GetName())); 119 attributes.push_back(Attribute(B_TRANSLATE("Manufacturer:"), 120 GetManufacturer())); 121 return attributes; 122 } 123 124 125 Attributes 126 Device::GetBusAttributes() 127 { 128 Attributes attributes; 129 attributes.push_back(Attribute("None", "")); 130 return attributes; 131 } 132 133 134 Attributes 135 Device::GetAllAttributes() 136 { 137 Attributes attributes; 138 AttributeMapIterator iter; 139 for (iter = fAttributeMap.begin(); iter != fAttributeMap.end(); iter++) { 140 attributes.push_back(Attribute(iter->first, iter->second)); 141 } 142 return attributes; 143 } 144 145 146 BString 147 Device::GetBasicStrings() 148 { 149 BString str(B_TRANSLATE("Device Name\t\t\t\t: %Name%\n" 150 "Manufacturer\t\t\t: %Manufacturer%\n" 151 "Driver used\t\t\t\t: %DriverUsed%\n" 152 "Device paths\t: %DevicePaths%")); 153 154 str.ReplaceFirst("%Name%", GetName()); 155 str.ReplaceFirst("%Manufacturer%", GetManufacturer()); 156 str.ReplaceFirst("%DriverUsed%", GetDriverUsed()); 157 str.ReplaceFirst("%DevicePaths%", GetDevPathsPublished()); 158 159 return str; 160 } 161 162 BString 163 Device::GetBusStrings() 164 { 165 return B_TRANSLATE("None"); 166 } 167 168 169 BString 170 Device::GetBusTabName() 171 { 172 return B_TRANSLATE("Bus Information"); 173 } 174 175 176 BString 177 Device::GetAllStrings() 178 { 179 BString str; 180 AttributeMapIterator iter; 181 for (iter = fAttributeMap.begin(); iter != fAttributeMap.end(); iter++) { 182 str << iter->first << " : " << iter->second << "\n"; 183 } 184 return str; 185 } 186