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(HIDReport*);
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	static	void				_UnstallCallback(void *cookie,
52									status_t status, void *data,
53									size_t actualLength);
54
55private:
56			status_t			fStatus;
57			usb_device			fDevice;
58			usb_pipe			fInterruptPipe;
59			size_t				fInterfaceIndex;
60			uint8				fEndpointAddress;
61
62			int32				fTransferScheduled;
63			size_t				fTransferBufferSize;
64			uint8 *				fTransferBuffer;
65
66			int32				fParentCookie;
67			int32				fOpenCount;
68			bool				fRemoved;
69
70			HIDParser			fParser;
71
72			uint32				fProtocolHandlerCount;
73			ProtocolHandler *	fProtocolHandlerList;
74};
75
76
77#endif // USB_HID_DEVICE_H
78