xref: /haiku/headers/os/support/DataIO.h (revision b773d89eba723039d3d293df77e106c128efa878)
1 /*
2  * Copyright 2005-2014 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _DATA_IO_H
6 #define _DATA_IO_H
7 
8 
9 #include <SupportDefs.h>
10 
11 
12 class BDataIO {
13 public:
14 								BDataIO();
15 	virtual						~BDataIO();
16 
17 	virtual	ssize_t				Read(void* buffer, size_t size);
18 	virtual	ssize_t				Write(const void* buffer, size_t size);
19 
20 	virtual	status_t			Flush();
21 
22 			status_t			ReadExactly(void* buffer, size_t size,
23 									size_t* _bytesRead = NULL);
24 			status_t			WriteExactly(const void* buffer, size_t size,
25 									size_t* _bytesWritten = NULL);
26 
27 private:
28 								BDataIO(const BDataIO&);
29 			BDataIO&			operator=(const BDataIO&);
30 
31 	virtual	void				_ReservedDataIO2();
32 	virtual	void				_ReservedDataIO3();
33 	virtual	void				_ReservedDataIO4();
34 	virtual	void				_ReservedDataIO5();
35 	virtual	void				_ReservedDataIO6();
36 	virtual	void				_ReservedDataIO7();
37 	virtual	void				_ReservedDataIO8();
38 	virtual	void				_ReservedDataIO9();
39 	virtual	void				_ReservedDataIO10();
40 	virtual	void				_ReservedDataIO11();
41 	virtual	void				_ReservedDataIO12();
42 
43 private:
44 			uint32				_reserved[2];
45 };
46 
47 
48 class BPositionIO : public BDataIO {
49 public:
50 								BPositionIO();
51 	virtual						~BPositionIO();
52 
53 	// BDataIO interface (implemented via ReadAt/WriteAt)
54 	virtual	ssize_t				Read(void* buffer, size_t size);
55 	virtual	ssize_t				Write(const void* buffer, size_t size);
56 
57 	// BPositionIO interface
58 	virtual	ssize_t				ReadAt(off_t position, void* buffer,
59 									size_t size) = 0;
60 	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
61 									size_t size) = 0;
62 
63 	virtual	off_t				Seek(off_t position, uint32 seekMode) = 0;
64 	virtual	off_t				Position() const = 0;
65 
66 	virtual	status_t			SetSize(off_t size);
67 	virtual	status_t			GetSize(off_t* size) const;
68 
69 private:
70 	virtual	void				_ReservedPositionIO2();
71 	virtual	void				_ReservedPositionIO3();
72 	virtual	void				_ReservedPositionIO4();
73 	virtual	void				_ReservedPositionIO5();
74 	virtual	void				_ReservedPositionIO6();
75 	virtual	void				_ReservedPositionIO7();
76 	virtual	void				_ReservedPositionIO8();
77 	virtual	void				_ReservedPositionIO9();
78 	virtual	void				_ReservedPositionIO10();
79 	virtual	void				_ReservedPositionIO11();
80 	virtual	void				_ReservedPositionIO12();
81 
82 private:
83 			uint32				_reserved[2];
84 };
85 
86 
87 class BMemoryIO : public BPositionIO {
88 public:
89 								BMemoryIO(void* data, size_t length);
90 								BMemoryIO(const void* data, size_t length);
91 	virtual						~BMemoryIO();
92 
93 	virtual	ssize_t				ReadAt(off_t position, void* buffer,
94 									size_t size);
95 	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
96 									size_t size);
97 
98 	virtual	off_t				Seek(off_t position, uint32 seekMode);
99 	virtual off_t				Position() const;
100 
101 	virtual	status_t			SetSize(off_t size);
102 
103 private:
104 								BMemoryIO(const BMemoryIO&);
105 			BMemoryIO&			operator=(const BMemoryIO&);
106 
107 	virtual	void				_ReservedMemoryIO1();
108 	virtual	void				_ReservedMemoryIO2();
109 
110 private:
111 			bool				fReadOnly;
112 			char*				fBuffer;
113 			size_t				fLength;
114 			size_t				fBufferSize;
115 			size_t				fPosition;
116 
117 			uint32				_reserved[1];
118 };
119 
120 
121 class BMallocIO : public BPositionIO {
122 public:
123 								BMallocIO();
124 	virtual						~BMallocIO();
125 
126 	virtual	ssize_t				ReadAt(off_t position, void* buffer,
127 									size_t size);
128 	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
129 									size_t size);
130 
131 	virtual	off_t				Seek(off_t position, uint32 seekMode);
132 	virtual	off_t				Position() const;
133 
134 	virtual	status_t			SetSize(off_t size);
135 
136 	// BMallocIO interface
137 			void				SetBlockSize(size_t blockSize);
138 
139 			const void*			Buffer() const;
140 			size_t				BufferLength() const;
141 
142 private:
143 								BMallocIO(const BMallocIO&);
144 			BMallocIO&			operator=(const BMallocIO&);
145 
146 	virtual	void				_ReservedMallocIO1();
147 	virtual void				_ReservedMallocIO2();
148 
149 private:
150 			size_t				fBlockSize;
151 			size_t				fMallocSize;
152 			size_t				fLength;
153 			char*				fData;
154 			off_t				fPosition;
155 
156 			uint32				_reserved[1];
157 };
158 
159 
160 #endif	// _DATA_IO_H
161