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