xref: /haiku/src/add-ons/kernel/drivers/input/hid_shared/HIDReport.h (revision 3d4afef9cba2f328e238089d4609d00d4b1524f3)
1 /*
2  * Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef HID_REPORT_H
6 #define HID_REPORT_H
7 
8 #include "HIDParser.h"
9 #include "util/Vector.h"
10 
11 
12 #ifndef USERLAND_HID
13 #include <condition_variable.h>
14 #endif
15 
16 #define HID_REPORT_TYPE_INPUT		0x01
17 #define HID_REPORT_TYPE_OUTPUT		0x02
18 #define HID_REPORT_TYPE_FEATURE		0x04
19 #define HID_REPORT_TYPE_ANY			0x07
20 
21 class HIDCollection;
22 class HIDReportItem;
23 
24 class HIDReport {
25 public:
26 								HIDReport(HIDParser *parser, uint8 type,
27 									uint8 id);
28 								~HIDReport();
29 
30 		uint8					Type() { return fType; };
31 		uint8					ID() { return fReportID; };
32 		size_t					ReportSize() { return (fReportSize + 7) / 8; };
33 
34 		HIDParser *				Parser() { return fParser; };
35 		HIDDevice *				Device() { return fParser->Device(); };
36 
37 		void					AddMainItem(global_item_state &globalState,
38 									local_item_state &localState,
39 									main_item_data &mainData,
40 									HIDCollection *collection);
41 
42 		void					SetReport(status_t status, uint8 *report,
43 									size_t length);
44 		uint8 *					CurrentReport() { return fCurrentReport; };
45 
46 #ifndef USERLAND_HID
47 		status_t				SendReport();
48 #endif
49 
50 		uint32					CountItems() { return fItems.Count(); };
51 		HIDReportItem *			ItemAt(uint32 index);
52 		HIDReportItem *			FindItem(uint16 usagePage, uint16 usageID);
53 
54 #ifndef USERLAND_HID
55 		status_t				WaitForReport(bigtime_t timeout);
56 		void					DoneProcessing();
57 #endif
58 
59 		void					PrintToStream();
60 
61 private:
62 		void					_SignExtend(uint32 &minimum, uint32 &maximum);
63 
64 		HIDParser *				fParser;
65 
66 		uint8					fType;
67 		uint8					fReportID;
68 		uint32					fReportSize;
69 
70 		Vector<HIDReportItem *>	fItems;
71 
72 		status_t				fReportStatus;
73 		uint8 *					fCurrentReport;
74 		int32					fBusyCount;
75 
76 #ifndef USERLAND_HID
77 		ConditionVariable		fConditionVariable;
78 #endif
79 };
80 
81 #endif // HID_REPORT_H
82