1 /* 2 * Copyright 2009-2011, Michael Lotz, mmlr@mlotz.ch. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef PROTOCOL_HANDLER_H 6 #define PROTOCOL_HANDLER_H 7 8 9 #include <SupportDefs.h> 10 11 12 #define PROTOCOL_HANDLER_COOKIE_FLAG_CLOSED 0x80000000 13 14 15 class HIDDevice; 16 class HIDReport; 17 18 19 class ProtocolHandler { 20 public: 21 ProtocolHandler(HIDDevice *device, 22 const char *basePath, 23 size_t ringBufferSize); 24 virtual ~ProtocolHandler(); 25 26 status_t InitCheck() { return fStatus; } 27 28 HIDDevice * Device() { return fDevice; } 29 30 const char * BasePath() { return fBasePath; } 31 void SetPublishPath(char *publishPath); 32 const char * PublishPath() { return fPublishPath; } 33 34 static void AddHandlers(HIDDevice &device, 35 ProtocolHandler *&handlerList, 36 uint32 &handlerCount); 37 38 virtual status_t Open(uint32 flags, uint32 *cookie); 39 virtual status_t Close(uint32 *cookie); 40 41 virtual status_t Read(uint32 *cookie, off_t position, 42 void *buffer, size_t *numBytes); 43 virtual status_t Write(uint32 *cookie, off_t position, 44 const void *buffer, size_t *numBytes); 45 46 virtual status_t Control(uint32 *cookie, uint32 op, void *buffer, 47 size_t length); 48 49 int32 RingBufferReadable(); 50 status_t RingBufferRead(void *buffer, size_t length); 51 status_t RingBufferWrite(const void *buffer, 52 size_t length); 53 54 void SetNextHandler(ProtocolHandler *next); 55 ProtocolHandler * NextHandler() { return fNextHandler; }; 56 57 status_t IOGetDeviceName(const char *name, void *buffer, 58 size_t length); 59 60 protected: 61 status_t fStatus; 62 63 private: 64 HIDDevice * fDevice; 65 const char * fBasePath; 66 char * fPublishPath; 67 struct ring_buffer *fRingBuffer; 68 69 ProtocolHandler * fNextHandler; 70 }; 71 72 73 #endif // PROTOCOL_HANDLER_H 74