xref: /haiku/headers/os/bluetooth/DeviceClass.h (revision 155fa31ec619414bb0e0fb1ffe9ad913e4ecd398)
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 0x00
14 
15 
16 class DeviceClass {
17 
18 public:
19 
20 	static const uint8 PixelsForIcon = 32;
21 	static const uint8 IconInsets = 5;
22 
23 	DeviceClass(uint8 record[3])
24 	{
25 		SetRecord(record);
26 	}
27 
28 
29 	DeviceClass(uint32 record)
30 	{
31 		SetRecord(record);
32 	}
33 
34 
35 	DeviceClass(void)
36 	{
37 		this->record = UNKNOWN_CLASS_OF_DEVICE;
38 	}
39 
40 	void SetRecord(uint8 record[3])
41 	{
42 		this->record = record[0]|record[1]<<8|record[2]<<16;
43 	}
44 
45 	void SetRecord(uint32 record)
46 	{
47 		this->record = record;
48 	}
49 
50 	uint GetServiceClass()
51 	{
52 		return (record & 0x00FFE000) >> 13;
53 	}
54 
55 	uint GetMajorDeviceClass()
56 	{
57 		return (record & 0x00001F00) >> 8;
58 	}
59 
60 	uint GetMinorDeviceClass()
61 	{
62 		return (record & 0x000000FF) >> 2;
63 	}
64 
65 	bool IsUnknownDeviceClass()
66 	{
67 		return (record == UNKNOWN_CLASS_OF_DEVICE);
68 	}
69 
70 	void GetServiceClass(BString&);
71 	void GetMajorDeviceClass(BString&);
72 	void GetMinorDeviceClass(BString&);
73 
74 	void DumpDeviceClass(BString&);
75 
76 	void Draw(BView* view, const BPoint& point);
77 
78 private:
79 	uint32 record;
80 
81 };
82 
83 }
84 
85 #ifndef _BT_USE_EXPLICIT_NAMESPACE
86 using Bluetooth::DeviceClass;
87 #endif
88 
89 #endif // _DEVICE_CLASS_H
90