1/*
2 * Copyright 2008-2011, Michael Lotz <mmlr@mlotz.ch>
3 * Distributed under the terms of the MIT license.
4 */
5#ifndef USB_HID_DEVICE_H
6#define USB_HID_DEVICE_H
7
8
9#include "HIDParser.h"
10
11#include <USB3.h>
12
13
14class ProtocolHandler;
15
16
17class HIDDevice {
18public:
19								HIDDevice(usb_device device,
20									const usb_configuration_info *config,
21									size_t interfaceIndex, int32 quirkyIndex);
22								~HIDDevice();
23
24			void				SetParentCookie(int32 cookie);
25			int32				ParentCookie() const { return fParentCookie; }
26
27			status_t			InitCheck() const { return fStatus; }
28
29			bool				IsOpen() const { return fOpenCount > 0; }
30			status_t			Open(ProtocolHandler *handler, uint32 flags);
31			status_t			Close(ProtocolHandler *handler);
32			int32				OpenCount() const { return fOpenCount; }
33
34			void				Removed();
35			bool				IsRemoved() const { return fRemoved; }
36
37			status_t			MaybeScheduleTransfer();
38
39			status_t			SendReport(HIDReport *report);
40
41			HIDParser &			Parser() { return fParser; }
42			ProtocolHandler *	ProtocolHandlerAt(uint32 index) const;
43
44			// only to be used for the kernel debugger information
45			usb_pipe			InterruptPipe() const { return fInterruptPipe; }
46
47private:
48	static	void				_TransferCallback(void *cookie,
49									status_t status, void *data,
50									size_t actualLength);
51
52private:
53			status_t			fStatus;
54			usb_device			fDevice;
55			usb_pipe			fInterruptPipe;
56			size_t				fInterfaceIndex;
57
58			int32				fTransferScheduled;
59			size_t				fTransferBufferSize;
60			uint8 *				fTransferBuffer;
61
62			int32				fParentCookie;
63			int32				fOpenCount;
64			bool				fRemoved;
65
66			HIDParser			fParser;
67
68			uint32				fProtocolHandlerCount;
69			ProtocolHandler *	fProtocolHandlerList;
70};
71
72
73#endif // USB_HID_DEVICE_H
74