1/*
2 * Copyright 2005-2008 Stephan A��mus <superstippi@gmx.de>. All rights reserved.
3 * Distributed under the terms of the MIT license.
4 */
5#ifndef USB_DEVICE_MONITOR_H
6#define USB_DEVICE_MONITOR_H
7
8
9// This class is designed to work with the generic USB input device driver
10// the driver creates an entry in /dev/input/???
11// clients can open and read from the device file, the driver will than
12// block on waiting for an interrupt transfer (timeout is 500 ms) and write
13// the received data to the supplied buffer. In front of the buffer, it will
14// write vendorID, productID and maxPacketSize, so you can read from the file
15// with a buffer of just enough size to contain these fields, in this case, no
16// interrupt transfer will be triggered, and the client can then configure itself
17// with a more appropriate setup.
18
19#include <SupportDefs.h>
20
21class BFile;
22class BString;
23
24class DeviceReader {
25 public:
26								DeviceReader();
27	virtual						~DeviceReader();
28
29								// initializes the object
30								// by trying to read from the supplied device file
31								// on success (B_OK), all member variables will be set
32								// and the object is ready for operation
33								// on failure, a hopefully meaningful error is returned
34	virtual	status_t			SetTo(const char* path);
35
36	virtual	status_t			InitCheck() const;
37
38			const char*			DevicePath() const;
39			BFile*				DeviceFile() const;
40
41			// query the device for information
42			uint16				VendorID() const;
43			uint16				ProductID() const;
44
45			size_t				MaxPacketSize() const;
46
47			// trigger an interrupt transfer and write the data in the buffer
48			// it should be save to call this function with
49			// size != MaxPacketSize, remaining bytes will be zero'd out
50			ssize_t				ReadData(uint8* data,
51									const size_t size) const;
52
53 protected:
54			void				_Unset();
55
56			char*				fDevicePath;
57			BFile*				fDeviceFile;
58
59			uint16				fVendorID;
60			uint16				fProductID;
61			size_t				fMaxPacketSize;
62};
63#endif // USB_DEVICE_MONITOR_H
64