vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / input_server / devices / wacom / DeviceReader.h
blobf0b549e4f8df38b5df2611d1753ecfb455961bd2
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
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.
19 #include <SupportDefs.h>
21 class BFile;
22 class BString;
24 class DeviceReader {
25 public:
26 DeviceReader();
27 virtual ~DeviceReader();
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);
36 virtual status_t InitCheck() const;
38 const char* DevicePath() const;
39 BFile* DeviceFile() const;
41 // query the device for information
42 uint16 VendorID() const;
43 uint16 ProductID() const;
45 size_t MaxPacketSize() const;
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;
53 protected:
54 void _Unset();
56 char* fDevicePath;
57 BFile* fDeviceFile;
59 uint16 fVendorID;
60 uint16 fProductID;
61 size_t fMaxPackedSize;
63 #endif // USB_DEVICE_MONITOR_H