IByteStream.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 _SUPPORT_BYTESTREAM_INTERFACE_H
00014 #define _SUPPORT_BYTESTREAM_INTERFACE_H
00015 
00021 #include <support/IInterface.h>
00022 #include <sys/uio.h>
00023 
00024 #if _SUPPORTS_NAMESPACE
00025 namespace palmos {
00026 namespace support {
00027 #endif
00028 
00033 
00034 enum {
00035     B_WRITE_TRANSACTION         = 'WRTE',
00036     B_WRITE_FLAGS_TRANSACTION   = 'WRFL',
00037     B_READ_TRANSACTION          = 'READ'
00038 };
00039 
00040 
00042 enum {
00044 
00049     B_DO_NOT_BLOCK              = 0x00000001
00050 };
00051 
00053 enum {
00055 
00061     B_WRITE_END                 = 0x00010000
00062 };
00063 
00064 /*-------------------------------------------------------------*/
00065 /*------- IByteInput Interface --------------------------------*/
00066 
00068 class IByteInput : public IInterface
00069 {
00070     public:
00071 
00072         B_DECLARE_META_INTERFACE(ByteInput)
00073 
00074                 
00075 
00079         virtual ssize_t     ReadV(const iovec *vector, ssize_t count, uint32_t flags = 0) = 0;
00080         
00082                 ssize_t     Read(void *buffer, size_t size, uint32_t flags = 0);
00083 };
00084 
00085 /*-------------------------------------------------------------*/
00086 /*------- IByteOutput Interface -------------------------------*/
00087 
00089 class IByteOutput : public IInterface
00090 {
00091     public:
00092 
00093         B_DECLARE_META_INTERFACE(ByteOutput)
00094 
00095                 
00096 
00104         virtual ssize_t     WriteV(const iovec *vector, ssize_t count, uint32_t flags = 0) = 0;
00105         
00107                 ssize_t     Write(const void *buffer, size_t size, uint32_t flags = 0);
00108                 
00110 
00112         virtual status_t    Sync() = 0;
00113 };
00114 
00115 /*-------------------------------------------------------------*/
00116 /*------- IByteSeekable Interface -----------------------------*/
00117 
00119 class IByteSeekable : public IInterface
00120 {
00121     public:
00122 
00123         B_DECLARE_META_INTERFACE(ByteSeekable)
00124 
00125                 
00126         virtual off_t       Position() const = 0;
00127         
00129 
00132         virtual off_t       Seek(off_t position, uint32_t seek_mode) = 0;
00133 };
00134 
00137 /*-------------------------------------------------------------*/
00138 /*---- No user serviceable parts after this -------------------*/
00139 
00140 inline ssize_t IByteInput::Read(void *buffer, size_t size, uint32_t flags)
00141 {
00142     iovec v;
00143     v.iov_base = buffer;
00144     v.iov_len = size;
00145     return ReadV(&v,1,flags);
00146 }
00147 
00148 inline ssize_t IByteOutput::Write(const void *buffer, size_t size, uint32_t flags)
00149 {
00150     iovec v;
00151     v.iov_base = const_cast<void*>(buffer);
00152     v.iov_len = size;
00153     return WriteV(&v,1,flags);
00154 }
00155 
00156 /*-------------------------------------------------------------*/
00157 
00158 #if _SUPPORTS_NAMESPACE
00159 } } // namespace palmos::support
00160 #endif
00161 
00162 #endif /* _SUPPORT_BYTESTREAM_INTERFACE_H */