1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: DataIO.cpp 23 // Author(s): Ingo Weinhold (bonefish@users.sf.net) 24 // Stefano Ceccherini (burton666@libero.it) 25 // The Storage Team 26 // Description: Pure virtual BDataIO and BPositionIO classes provide 27 // the protocol for Read()/Write()/Seek(). 28 // 29 // BMallocIO and BMemoryIO classes implement the protocol, 30 // as does BFile in the Storage Kit. 31 //------------------------------------------------------------------------------ 32 #ifndef _DATA_IO_H 33 #define _DATA_IO_H 34 35 #include <SupportDefs.h> 36 37 // DataIO 38 class BDataIO { 39 public: 40 BDataIO(); 41 virtual ~BDataIO(); 42 43 virtual ssize_t Read(void *buffer, size_t size) = 0; 44 virtual ssize_t Write(const void *buffer, size_t size) = 0; 45 46 private: 47 BDataIO(const BDataIO &); 48 BDataIO &operator=(const BDataIO &); 49 50 virtual void _ReservedDataIO1(); 51 virtual void _ReservedDataIO2(); 52 virtual void _ReservedDataIO3(); 53 virtual void _ReservedDataIO4(); 54 virtual void _ReservedDataIO5(); 55 virtual void _ReservedDataIO6(); 56 virtual void _ReservedDataIO7(); 57 virtual void _ReservedDataIO8(); 58 virtual void _ReservedDataIO9(); 59 virtual void _ReservedDataIO10(); 60 virtual void _ReservedDataIO11(); 61 virtual void _ReservedDataIO12(); 62 63 uint32 _reserved[2]; 64 }; 65 66 // BPositionIO 67 class BPositionIO : public BDataIO { 68 public: 69 BPositionIO(); 70 virtual ~BPositionIO(); 71 72 virtual ssize_t Read(void *buffer, size_t size); 73 virtual ssize_t Write(const void *buffer, size_t size); 74 75 virtual ssize_t ReadAt(off_t position, void *buffer, size_t size) = 0; 76 virtual ssize_t WriteAt(off_t position, const void *buffer, 77 size_t size) = 0; 78 79 virtual off_t Seek(off_t position, uint32 seekMode) = 0; 80 virtual off_t Position() const = 0; 81 82 virtual status_t SetSize(off_t size); 83 84 private: 85 virtual void _ReservedPositionIO1(); 86 virtual void _ReservedPositionIO2(); 87 virtual void _ReservedPositionIO3(); 88 virtual void _ReservedPositionIO4(); 89 virtual void _ReservedPositionIO5(); 90 virtual void _ReservedPositionIO6(); 91 virtual void _ReservedPositionIO7(); 92 virtual void _ReservedPositionIO8(); 93 virtual void _ReservedPositionIO9(); 94 virtual void _ReservedPositionIO10(); 95 virtual void _ReservedPositionIO11(); 96 virtual void _ReservedPositionIO12(); 97 98 uint32 _reserved[2]; 99 }; 100 101 // BMemoryIO 102 class BMemoryIO : public BPositionIO { 103 public: 104 BMemoryIO(void *data, size_t len); 105 BMemoryIO(const void *data, size_t len); 106 virtual ~BMemoryIO(); 107 108 virtual ssize_t ReadAt(off_t position, void *buffer, size_t size); 109 virtual ssize_t WriteAt(off_t position, const void *buffer, size_t size); 110 111 virtual off_t Seek(off_t position, uint32 seekMode); 112 virtual off_t Position() const; 113 114 virtual status_t SetSize(off_t size); 115 116 private: 117 BMemoryIO(const BMemoryIO &); 118 BMemoryIO &operator=(const BMemoryIO &); 119 120 virtual void _ReservedMemoryIO1(); 121 virtual void _ReservedMemoryIO2(); 122 123 bool fReadOnly; 124 char *fBuf; 125 size_t fLen; 126 size_t fPhys; 127 size_t fPos; 128 uint32 _reserved[1]; 129 }; 130 131 // BMallocIO 132 class BMallocIO : public BPositionIO { 133 public: 134 BMallocIO(); 135 virtual ~BMallocIO(); 136 137 virtual ssize_t ReadAt(off_t position, void *buffer, size_t size); 138 virtual ssize_t WriteAt(off_t position, const void *buffer, size_t size); 139 140 virtual off_t Seek(off_t position, uint32 seekMode); 141 virtual off_t Position() const; 142 143 virtual status_t SetSize(off_t size); 144 145 void SetBlockSize(size_t blockSize); 146 147 const void *Buffer() const; 148 size_t BufferLength() const; 149 150 private: 151 BMallocIO(const BMallocIO &); 152 BMallocIO &operator=(const BMallocIO &); 153 154 virtual void _ReservedMallocIO1(); 155 virtual void _ReservedMallocIO2(); 156 157 size_t fBlockSize; 158 size_t fMallocSize; 159 size_t fLength; 160 char *fData; 161 off_t fPosition; 162 uint32 _reserved[1]; 163 }; 164 165 #endif 166