1/*
2 * Copyright 2008-2011 Michael Lotz <mmlr@mlotz.ch>
3 * Distributed under the terms of the MIT license.
4 */
5#ifndef USB_JOYSTICK_PROTOCOL_HANDLER_H
6#define USB_JOYSTICK_PROTOCOL_HANDLER_H
7
8
9#include <InterfaceDefs.h>
10
11#include "ProtocolHandler.h"
12
13#include <joystick_driver.h>
14#include <lock.h>
15
16
17class HIDCollection;
18class HIDReportItem;
19
20
21class JoystickProtocolHandler : public ProtocolHandler {
22public:
23									JoystickProtocolHandler(HIDReport &report);
24	virtual							~JoystickProtocolHandler();
25
26	static	void					AddHandlers(HIDDevice &device,
27										HIDCollection &collection,
28										ProtocolHandler *&handlerList);
29
30	virtual	status_t				Open(uint32 flags, uint32 *cookie);
31	virtual	status_t				Close(uint32 *cookie);
32
33	virtual	status_t				Read(uint32 *cookie, off_t position,
34										void *buffer, size_t *numBytes);
35	virtual	status_t				Write(uint32 *cookie, off_t position,
36										const void *buffer, size_t *numBytes);
37
38	virtual	status_t				Control(uint32 *cookie, uint32 op,
39										void *buffer, size_t length);
40
41private:
42	static	int32					_UpdateThread(void *data);
43			status_t				_Update();
44
45			HIDReport &				fReport;
46
47			uint32					fAxisCount;
48			HIDReportItem **		fAxis;
49			uint32					fHatCount;
50			HIDReportItem **		fHats;
51			uint32					fButtonCount;
52			uint32					fMaxButton;
53			HIDReportItem **		fButtons;
54
55			joystick_module_info 	fJoystickModuleInfo;
56			variable_joystick		fCurrentValues;
57
58			uint32					fOpenCount;
59			mutex					fUpdateLock;
60			thread_id				fUpdateThread;
61};
62
63#endif // USB_JOYSTICK_PROTOCOL_HANDLER_H
64