vfs: check userland buffers before reading them.
[haiku.git] / src / apps / devices / DeviceACPI.cpp
blob291d341877612bb26d637d25a92baa6d66abb4bb
1 /*
2 * Copyright 2008-2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Alexander von Gluck (kallisti5)
7 */
10 #include "DeviceACPI.h"
12 #include <sstream>
13 #include <stdlib.h>
15 #include <Catalog.h>
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "DeviceACPI"
21 DeviceACPI::DeviceACPI(Device* parent)
23 Device(parent)
28 DeviceACPI::~DeviceACPI()
33 void
34 DeviceACPI::InitFromAttributes()
36 BString outlineName;
37 BString nodeACPIPath;
38 BString rootACPIPath;
40 rootACPIPath = nodeACPIPath = GetAttribute("acpi/path").fValue;
42 // Grab just the root node info
43 // We grab 6 characters to not identify sub nodes of root node
44 rootACPIPath.Truncate(6);
45 // Grab node leaf name
46 nodeACPIPath.Remove(0, nodeACPIPath.FindLast(".") + 1);
48 fCategory = (Category)CAT_ACPI;
50 // Identify Predefined root namespaces (ACPI Spec 4.0a, p162)
51 if (rootACPIPath == "\\_SB_") {
52 outlineName = B_TRANSLATE("ACPI System Bus");
53 } else if (rootACPIPath == "\\_TZ_") {
54 outlineName = B_TRANSLATE("ACPI Thermal Zone");
55 } else if (rootACPIPath == "\\_PR_.") {
56 // This allows to localize apostrophes, too
57 BString string(B_TRANSLATE("ACPI Processor Namespace '%2'"));
58 string.ReplaceFirst("%2", nodeACPIPath);
59 // each CPU node is considered a root node
60 outlineName << string.String();
61 } else if (rootACPIPath == "\\_SI_") {
62 outlineName = B_TRANSLATE("ACPI System Indicator");
63 } else {
64 // This allows to localize apostrophes, too
65 BString string(B_TRANSLATE("ACPI node '%1'"));
66 string.ReplaceFirst("%1", nodeACPIPath);
67 outlineName << string.String();
70 SetAttribute(B_TRANSLATE("Device name"), outlineName.String());
71 SetAttribute(B_TRANSLATE("Manufacturer"), B_TRANSLATE("Not implemented"));
73 SetText(outlineName.String());
77 Attributes
78 DeviceACPI::GetBusAttributes()
80 // Push back things that matter for ACPI
81 Attributes attributes;
82 attributes.push_back(GetAttribute("device/bus"));
83 attributes.push_back(GetAttribute("acpi/path"));
84 attributes.push_back(GetAttribute("acpi/type"));
85 return attributes;
89 BString
90 DeviceACPI::GetBusStrings()
92 BString str(B_TRANSLATE("Class Info:\t\t\t\t: %classInfo%"));
93 str.ReplaceFirst("%classInfo%", fAttributeMap["Class Info"]);
95 return str;
99 BString
100 DeviceACPI::GetBusTabName()
102 return B_TRANSLATE("ACPI Information");