1 /* 2 * Copyright 2008-2019 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Rob Gill <rrobgill@protonmail.com> 7 * Alexander von Gluck (kallisti5) 8 */ 9 10 11 #include "DeviceACPI.h" 12 13 #include <sstream> 14 #include <stdlib.h> 15 16 #include <Catalog.h> 17 18 #undef B_TRANSLATION_CONTEXT 19 #define B_TRANSLATION_CONTEXT "DeviceACPI" 20 21 22 DeviceACPI::DeviceACPI(Device* parent) 23 : 24 Device(parent) 25 { 26 } 27 28 29 DeviceACPI::~DeviceACPI() 30 { 31 } 32 33 34 void 35 DeviceACPI::InitFromAttributes() 36 { 37 BString outlineName; 38 BString nodeACPIPath; 39 BString rootACPIPath; 40 BString nodeACPIHid; 41 42 rootACPIPath = nodeACPIPath = GetAttribute("acpi/path").fValue; 43 nodeACPIHid = GetAttribute("acpi/hid").fValue; 44 45 // Grab just the root node info 46 // We grab 6 characters to not identify sub nodes of root node 47 rootACPIPath.Truncate(6); 48 // Grab node leaf name 49 nodeACPIPath.Remove(0, nodeACPIPath.FindLast(".") + 1); 50 51 fCategory = (Category)CAT_ACPI; 52 53 // Identify Predefined root namespaces (ACPI Spec 4.0a, p162) 54 if (rootACPIPath == "\\_SB_") { 55 outlineName = B_TRANSLATE("ACPI System Bus"); 56 } else if (rootACPIPath == "\\_TZ_") { 57 outlineName = B_TRANSLATE("ACPI Thermal Zone"); 58 } else if (rootACPIPath == "\\_PR_.") { 59 // This allows to localize apostrophes, too 60 BString string(B_TRANSLATE("ACPI Processor Namespace '%2'")); 61 string.ReplaceFirst("%2", nodeACPIPath); 62 // each CPU node is considered a root node 63 outlineName << string.String(); 64 } else if (rootACPIPath == "\\_SI_") { 65 outlineName = B_TRANSLATE("ACPI System Indicator"); 66 } else if (nodeACPIPath != "") { 67 // This allows to localize apostrophes, too 68 BString string(B_TRANSLATE("ACPI node '%1'")); 69 string.ReplaceFirst("%1", nodeACPIPath); 70 outlineName << string.String(); 71 } else if (nodeACPIPath == "" && nodeACPIHid != "") { 72 // Handle ACPI HID entries that do not return a path 73 nodeACPIHid.Remove(0, nodeACPIHid.FindLast("_") + 1); 74 BString string(B_TRANSLATE("ACPI Button '%1'")); 75 string.ReplaceFirst("%1", nodeACPIHid); 76 outlineName << string.String(); 77 } else { 78 BString string(B_TRANSLATE("ACPI <unknown>")); 79 outlineName << string.String(); 80 } 81 82 SetAttribute(B_TRANSLATE("Device name"), outlineName.String()); 83 #if 0 84 // These are a source of confusion for users. 85 // Until we can display something useful, let's not show the lines at all. 86 SetAttribute(B_TRANSLATE("Manufacturer"), B_TRANSLATE("Not implemented")); 87 #endif 88 SetText(outlineName.String()); 89 } 90 91 92 Attributes 93 DeviceACPI::GetBusAttributes() 94 { 95 // Push back things that matter for ACPI 96 Attributes attributes; 97 attributes.push_back(GetAttribute("device/bus")); 98 attributes.push_back(GetAttribute("acpi/path")); 99 attributes.push_back(GetAttribute("acpi/type")); 100 return attributes; 101 } 102 103 104 BString 105 DeviceACPI::GetBusStrings() 106 { 107 BString str(B_TRANSLATE("Class Info:\t\t\t\t: %classInfo%")); 108 str.ReplaceFirst("%classInfo%", fAttributeMap["Class Info"]); 109 110 return str; 111 } 112 113 114 BString 115 DeviceACPI::GetBusTabName() 116 { 117 return B_TRANSLATE("ACPI Information"); 118 } 119 120