DataIO.h revision 7b79e069
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
12class BDataIO {
13public:
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
27private:
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
43private:
44			uint32				_reserved[2];
45};
46
47
48class BPositionIO : public BDataIO {
49public:
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			status_t			ReadAtExactly(off_t position, void* buffer,
64									size_t size, size_t* _bytesRead = NULL);
65			status_t			WriteAtExactly(off_t position,
66									const void* buffer, size_t size,
67									size_t* _bytesWritten = NULL);
68
69	virtual	off_t				Seek(off_t position, uint32 seekMode) = 0;
70	virtual	off_t				Position() const = 0;
71
72	virtual	status_t			SetSize(off_t size);
73	virtual	status_t			GetSize(off_t* size) const;
74
75private:
76	virtual	void				_ReservedPositionIO2();
77	virtual	void				_ReservedPositionIO3();
78	virtual	void				_ReservedPositionIO4();
79	virtual	void				_ReservedPositionIO5();
80	virtual	void				_ReservedPositionIO6();
81	virtual	void				_ReservedPositionIO7();
82	virtual	void				_ReservedPositionIO8();
83	virtual	void				_ReservedPositionIO9();
84	virtual	void				_ReservedPositionIO10();
85	virtual	void				_ReservedPositionIO11();
86	virtual	void				_ReservedPositionIO12();
87
88private:
89			uint32				_reserved[2];
90};
91
92
93class BMemoryIO : public BPositionIO {
94public:
95								BMemoryIO(void* data, size_t length);
96								BMemoryIO(const void* data, size_t length);
97	virtual						~BMemoryIO();
98
99	virtual	ssize_t				ReadAt(off_t position, void* buffer,
100									size_t size);
101	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
102									size_t size);
103
104	virtual	off_t				Seek(off_t position, uint32 seekMode);
105	virtual off_t				Position() const;
106
107	virtual	status_t			SetSize(off_t size);
108
109private:
110								BMemoryIO(const BMemoryIO&);
111			BMemoryIO&			operator=(const BMemoryIO&);
112
113	virtual	void				_ReservedMemoryIO1();
114	virtual	void				_ReservedMemoryIO2();
115
116private:
117			bool				fReadOnly;
118			char*				fBuffer;
119			size_t				fLength;
120			size_t				fBufferSize;
121			size_t				fPosition;
122
123			uint32				_reserved[1];
124};
125
126
127class BMallocIO : public BPositionIO {
128public:
129								BMallocIO();
130	virtual						~BMallocIO();
131
132	virtual	ssize_t				ReadAt(off_t position, void* buffer,
133									size_t size);
134	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
135									size_t size);
136
137	virtual	off_t				Seek(off_t position, uint32 seekMode);
138	virtual	off_t				Position() const;
139
140	virtual	status_t			SetSize(off_t size);
141
142	// BMallocIO interface
143			void				SetBlockSize(size_t blockSize);
144
145			const void*			Buffer() const;
146			size_t				BufferLength() const;
147
148private:
149								BMallocIO(const BMallocIO&);
150			BMallocIO&			operator=(const BMallocIO&);
151
152	virtual	void				_ReservedMallocIO1();
153	virtual void				_ReservedMallocIO2();
154
155private:
156			size_t				fBlockSize;
157			size_t				fMallocSize;
158			size_t				fLength;
159			char*				fData;
160			off_t				fPosition;
161
162			uint32				_reserved[1];
163};
164
165
166class BMediaIO : public BPositionIO {
167public:
168								BMediaIO();
169	virtual						~BMediaIO();
170
171	virtual bool				IsSeekable() const = 0;
172	virtual bool				IsFile() const = 0;
173
174	virtual	bool				IsEndless() const = 0;
175	virtual bool				IsCached() const = 0;
176	virtual size_t				CacheSize() const = 0;
177
178private:
179								BMediaIO(const BMediaIO&);
180			BMallocIO&			operator=(const BMediaIO&);
181
182	virtual	void				_ReservedMediaIO1();
183	virtual void				_ReservedMediaIO2();
184	virtual void				_ReservedMediaIO3();
185	virtual void				_ReservedMediaIO4();
186	virtual void				_ReservedMediaIO5();
187
188			uint32				_reserved[1];
189};
190
191#endif	// _DATA_IO_H
192