#ifndef _USBTHREADS_H__ #define _USBTHREADS_H__ #include "util/process.h" #include "networkprotocols.h" struct usbcontext : context { typedef boost::shared_ptr ptr; usbcontext() { } static ptr make() { return ptr(new usbcontext()); } virtual std::string asstring() const { return "usb"; } }; class usbserialreader : public process { ByteVector _buf; usbdev& _dev; protocollayer::ptr _prot; public: usbserialreader(usbdev& dev, protocollayer::ptr prot) : _buf(65536), _dev(dev), _prot(prot) { start(); } virtual ~usbserialreader() { stop(); } virtual const char*name () { return "usbserialreader"; } virtual void service() { size_t n= _dev.bulkread(_buf.begin(), _buf.end()); if (n) { context::ptr ctx= usbcontext::make(); pktdata pkt(&_buf.front(), n); if (n==6 && memcmp(pkt.begin(), "CLIENT", 6)==0) { printf("client detected\n"); const uint8_t *cs= (const uint8_t *)"CLIENTSERVER"; _dev.bulkwrite(cs, cs+12); } _prot->recv(ctx, pkt); } } }; class rndisreader : public process { ByteVector _buf; usbdev& _dev; protocollayer::ptr _prot; public: rndisreader(usbdev& dev, protocollayer::ptr prot) : _buf(65536), _dev(dev), _prot(prot) { start(); } virtual ~rndisreader() { stop(); } virtual const char*name () { return "rndisreader"; } virtual void service() { size_t n= _dev.bulkread(_buf.begin(), _buf.end()); if (n) { context::ptr ctx= usbcontext::make(); pktdata pkt(&_buf.front(), n); _prot->recv(ctx, pkt); } } }; #endif