xref: /haiku/headers/os/bluetooth/DeviceClass.h (revision 981f1b1135291a4fca290fbdf69910dc2f24abdd)
1 /*
2  * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef _DEVICE_CLASS_H
6 #define _DEVICE_CLASS_H
7 
8 #include <String.h>
9 #include <View.h>
10 
11 namespace Bluetooth {
12 
13 #define UNKNOWN_CLASS_OF_DEVICE 0x000000
14 
15 class DeviceClass {
16 
17 public:
18 
19 	static const uint8 PixelsForIcon = 32;
20 	static const uint8 IconInsets = 5;
21 
DeviceClass(uint8 record[3])22 	DeviceClass(uint8 record[3])
23 	{
24 		SetRecord(record);
25 	}
26 
27 
DeviceClass(uint8 major,uint8 minor,uint16 service)28 	DeviceClass(uint8 major, uint8 minor, uint16 service)
29 	{
30 		SetRecord(major, minor, service);
31 	}
32 
33 
DeviceClass(void)34 	DeviceClass(void)
35 	{
36 		fRecord = UNKNOWN_CLASS_OF_DEVICE;
37 	}
38 
SetRecord(uint8 record[3])39 	void SetRecord(uint8 record[3])
40 	{
41 		fRecord = record[0]|record[1]<<8|record[2]<<16;
42 	}
43 
SetRecord(uint8 major,uint8 minor,uint16 service)44 	void SetRecord(uint8 major, uint8 minor, uint16 service)
45 	{
46 		fRecord = (minor & 0x3F) << 2;
47 		fRecord |= (major & 0x1F) << 8;
48 		fRecord |= (service & 0x7FF) << 13;
49 	}
50 
51 
ServiceClass()52 	uint16 ServiceClass()
53 	{
54 		return (fRecord & 0x00FFE000) >> 13;
55 	}
56 
MajorDeviceClass()57 	uint8 MajorDeviceClass()
58 	{
59 		return (fRecord & 0x00001F00) >> 8;
60 	}
61 
MinorDeviceClass()62 	uint8 MinorDeviceClass()
63 	{
64 		return (fRecord & 0x000000FF) >> 2;
65 	}
66 
Record()67 	uint32 Record()
68 	{
69 		return fRecord;
70 	}
71 
IsUnknownDeviceClass()72 	bool IsUnknownDeviceClass()
73 	{
74 		return (fRecord == UNKNOWN_CLASS_OF_DEVICE);
75 	}
76 
77 	void GetServiceClass(BString&);
78 	void GetMajorDeviceClass(BString&);
79 	void GetMinorDeviceClass(BString&);
80 
81 	void DumpDeviceClass(BString&);
82 
83 	void Draw(BView* view, const BPoint& point);
84 
85 private:
86 	uint32 fRecord;
87 
88 };
89 
90 }
91 
92 #ifndef _BT_USE_EXPLICIT_NAMESPACE
93 using Bluetooth::DeviceClass;
94 #endif
95 
96 #endif // _DEVICE_CLASS_H
97