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