// ======================================================================== // // I/O Interface // // Abstract base class for a generic byte-oriented I/O interface as // expected by the rest of the code. This naive interface ignores errors // for now; we can always extend it later if/when it becomes necessary. // // The 'send' method must ensure that the data gets sent; it need not wait // for the data to send as long as it's queued. // // The 'recv' method will return as much data as is currently available, // but should not block. // // The 'pump' method should send any data that's queued to send, and // drain any incoming data to a private queue for a future call to 'recv'. // The pump method should not block, however. It should just do a best // effort "send what I can send; receive what I can receive" without // blocking. // // The 'flush' method is like 'pump', except it blocks on send. It will // try to send data until all queued data goes, or until it fails to // advance for "a time." (Undefined; recommend timing out at a couple // seconds without advancing.) // // ======================================================================== // #ifndef IO_IF_HPP_ #define IO_IF_HPP_ #include #include class io_if { public: typedef enum { FLUSH_FAILED, FLUSH_OK } flush_status; virtual ~io_if() { }; virtual void send( uint8_t b ) = 0; virtual void send( std::vector< uint8_t >& ) = 0; virtual int recv( uint8_t &b ) = 0; virtual int recv( std::vector< uint8_t >& ) = 0; virtual void pump( void ) = 0; virtual flush_status flush( void ) = 0; virtual int remaining_to_send() = 0; }; #endif