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 #ifndef DEVICE_H 9 #define DEVICE_H 10 11 12 #include <map> 13 #include <vector> 14 15 #include <String.h> 16 #include <StringItem.h> 17 18 extern "C" { 19 #include "dm_wrapper.h" 20 } 21 22 23 typedef enum { 24 BUS_ISA = 1, 25 BUS_PCI, 26 BUS_SCSI, 27 BUS_ACPI, 28 BUS_NONE 29 } BusType; 30 31 32 struct Attribute { 33 Attribute(BString name, BString value) 34 { fName = name; fValue = value; } 35 BString fName; 36 BString fValue; 37 }; 38 39 40 typedef std::map<BString, BString>::const_iterator AttributeMapIterator; 41 typedef std::map<BString, BString> AttributeMap; 42 typedef std::pair<BString, BString> AttributePair; 43 typedef std::vector<Attribute> Attributes; 44 45 46 typedef enum { 47 CAT_NONE = 0, 48 CAT_BUS = 6, 49 CAT_COMPUTER = 0x12, 50 CAT_ACPI = 0x13 51 } Category; 52 53 54 extern const char* kCategoryString[]; 55 56 57 class Device : public BStringItem { 58 public: 59 Device(Device* physicalParent, 60 BusType busType=BUS_NONE, 61 Category category=CAT_NONE, 62 const BString& name = "unknown", 63 const BString& manufacturer = "unknown", 64 const BString& driverUsed = "unknown", 65 const BString& devPathsPublished = "unknown"); 66 virtual ~Device(); 67 68 virtual BString GetName() 69 { return fAttributeMap["Device name"]; } 70 virtual BString GetManufacturer() 71 { return fAttributeMap["Manufacturer"]; } 72 virtual BString GetDriverUsed() 73 { return fAttributeMap["Driver used"]; } 74 virtual BString GetDevPathsPublished() 75 { return fAttributeMap["Device paths"]; } 76 virtual Category GetCategory() const 77 { return fCategory; } 78 virtual Device* GetPhysicalParent() const 79 { return fPhysicalParent; } 80 virtual BusType GetBusType() const 81 { return fBusType; } 82 83 virtual Attributes GetBasicAttributes(); 84 virtual Attributes GetBusAttributes(); 85 virtual Attributes GetAllAttributes(); 86 87 virtual BString GetBasicStrings(); 88 virtual BString GetBusStrings(); 89 virtual BString GetAllStrings(); 90 91 virtual BString GetBusTabName() 92 { return "Bus Information"; } 93 94 virtual Attribute GetAttribute(const BString& name) 95 { return Attribute(name.String(), 96 fAttributeMap[name]); } 97 98 virtual void SetAttribute(const BString& name, 99 const BString& value); 100 101 virtual void InitFromAttributes() { return; } 102 103 protected: 104 AttributeMap fAttributeMap; 105 BusType fBusType; 106 Category fCategory; 107 Device* fPhysicalParent; 108 }; 109 110 #endif /* DEVICE_H */ 111 112