BufferIO.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
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 /*  @addtogroup CoreSupportDataModel
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                 // XXX remove in favor of Sync()??
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;         // _reserved_ints[0-1]
00077                 off_t           m_len;              // _reserved_ints[2-3]
00078                 bool            m_buffer_dirty : 1;
00079                 bool            m_owns_stream : 1;
00080 };
00081 
00084 #if _SUPPORTS_NAMESPACE
00085 } } // namespace palmos::support
00086 #endif
00087 
00088 #endif /* _SUPPORT2_BUFFERIO_H */