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
21class HIDCollection;
22class HIDReportItem;
23
24class HIDReport {
25public:
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		uint32 *				Usages();
55		uint32					CountUsages() { return fUsages.Count(); };
56
57#ifndef USERLAND_HID
58		status_t				WaitForReport(bigtime_t timeout);
59		void					DoneProcessing();
60#endif
61
62		void					PrintToStream();
63
64private:
65		void					_SignExtend(uint32 &minimum, uint32 &maximum);
66
67		HIDParser *				fParser;
68
69		uint8					fType;
70		uint8					fReportID;
71		uint32					fReportSize;
72
73		Vector<HIDReportItem *>	fItems;
74
75		status_t				fReportStatus;
76		uint8 *					fCurrentReport;
77		int32					fBusyCount;
78
79		Vector<uint32>			fUsages;
80
81#ifndef USERLAND_HID
82		ConditionVariable		fConditionVariable;
83#endif
84};
85
86#endif // HID_REPORT_H
87