00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SUPPORT2_BUFFERIO_H
00014 #define _SUPPORT2_BUFFERIO_H
00015
00021 #include <support/ByteStream.h>
00022
00023 #if _SUPPORTS_NAMESPACE
00024 namespace palmos {
00025 namespace support {
00026 #endif
00027
00028
00029
00030
00031
00033
00038 class BBufferIO : public BnByteInput, public BnByteOutput, public BnByteSeekable
00039 {
00040 enum {
00041 DEFAULT_BUF_SIZE = 65536L
00042 };
00043
00044 public:
00045 BBufferIO(
00046 const sptr<IByteInput>& inStream,
00047 const sptr<IByteOutput>& outStream,
00048 const sptr<IByteSeekable>& seeker,
00049 size_t buf_size = DEFAULT_BUF_SIZE
00050 );
00051 virtual ~BBufferIO();
00052
00053 virtual ssize_t ReadV(const struct iovec *vector, ssize_t count, uint32_t flags = 0);
00054 virtual ssize_t WriteV(const struct iovec *vector, ssize_t count, uint32_t flags = 0);
00055 virtual status_t Sync();
00056
00057 virtual off_t Seek(off_t position, uint32_t seek_mode);
00058 virtual off_t Position() const;
00059
00060
00061 status_t Flush();
00062
00063 protected:
00064
00065 BBufferIO(size_t buf_size = DEFAULT_BUF_SIZE);
00066
00067 private:
00068
00069 IByteInput * m_in;
00070 IByteOutput * m_out;
00071 IByteSeekable * m_seeker;
00072 off_t m_buffer_start;
00073 char * m_buffer;
00074 size_t m_buffer_phys;
00075 size_t m_buffer_used;
00076 off_t m_seek_pos;
00077 off_t m_len;
00078 bool m_buffer_dirty : 1;
00079 bool m_owns_stream : 1;
00080 };
00081
00084 #if _SUPPORTS_NAMESPACE
00085 } }
00086 #endif
00087
00088 #endif