xref: /haiku/headers/os/support/BufferedDataIO.h (revision 29e8fa5922c9f9a5eb09a2fcc92e7fb321d4cc59)
129e07dd0SAxel Dörfler /*
2*29e8fa59SJohn Scipione  * Copyright 2011 Haiku, Inc. All rights reserved.
329e07dd0SAxel Dörfler  * Distributed under the terms of the MIT License.
429e07dd0SAxel Dörfler  */
529e07dd0SAxel Dörfler #ifndef _BUFFERED_DATA_IO_H
629e07dd0SAxel Dörfler #define _BUFFERED_DATA_IO_H
729e07dd0SAxel Dörfler 
829e07dd0SAxel Dörfler 
929e07dd0SAxel Dörfler #include <DataIO.h>
1029e07dd0SAxel Dörfler 
1129e07dd0SAxel Dörfler 
1229e07dd0SAxel Dörfler class BBufferedDataIO : public BDataIO {
1329e07dd0SAxel Dörfler public:
1429e07dd0SAxel Dörfler 								BBufferedDataIO(BDataIO& stream,
1529e07dd0SAxel Dörfler 									size_t bufferSize = 65536L,
1629e07dd0SAxel Dörfler 									bool ownsStream = true,
1729e07dd0SAxel Dörfler 									bool partialReads = false);
1829e07dd0SAxel Dörfler 	virtual						~BBufferedDataIO();
1929e07dd0SAxel Dörfler 
2029e07dd0SAxel Dörfler 			status_t			InitCheck() const;
2129e07dd0SAxel Dörfler 
2229e07dd0SAxel Dörfler 			BDataIO*			Stream() const;
2329e07dd0SAxel Dörfler 			size_t				BufferSize() const;
2429e07dd0SAxel Dörfler 			bool				OwnsStream() const;
2529e07dd0SAxel Dörfler 			void				SetOwnsStream(bool ownsStream);
2629e07dd0SAxel Dörfler 			status_t			Flush();
2729e07dd0SAxel Dörfler 
2829e07dd0SAxel Dörfler 	// BDataIO interface
2929e07dd0SAxel Dörfler 	virtual	ssize_t				Read(void* buffer, size_t size);
3029e07dd0SAxel Dörfler 	virtual	ssize_t				Write(const void* buffer, size_t size);
3129e07dd0SAxel Dörfler 
3229e07dd0SAxel Dörfler private:
33362ae0a2SAxel Dörfler 								BBufferedDataIO(const BBufferedDataIO& other);
34362ae0a2SAxel Dörfler 									// not implemented
35362ae0a2SAxel Dörfler 
3629e07dd0SAxel Dörfler 	virtual	status_t			_Reserved0(void*);
3729e07dd0SAxel Dörfler 	virtual	status_t			_Reserved1(void*);
3829e07dd0SAxel Dörfler 	virtual	status_t			_Reserved2(void*);
3929e07dd0SAxel Dörfler 	virtual	status_t			_Reserved3(void*);
4029e07dd0SAxel Dörfler 	virtual	status_t			_Reserved4(void*);
4129e07dd0SAxel Dörfler 
4229e07dd0SAxel Dörfler private:
4329e07dd0SAxel Dörfler 			BDataIO&			fStream;
4429e07dd0SAxel Dörfler 			uint8*				fBuffer;
4529e07dd0SAxel Dörfler 			size_t				fBufferSize;
4629e07dd0SAxel Dörfler 			size_t				fPosition;
4729e07dd0SAxel Dörfler 			size_t				fSize;
4829e07dd0SAxel Dörfler 
4929e07dd0SAxel Dörfler 			uint32				_reserved_ints[4];
5029e07dd0SAxel Dörfler 
5129e07dd0SAxel Dörfler 			bool				fDirty;
5229e07dd0SAxel Dörfler 			bool				fOwnsStream;
5329e07dd0SAxel Dörfler 			bool				fPartialReads;
5429e07dd0SAxel Dörfler 
5529e07dd0SAxel Dörfler 			bool				_reserved_bools[5];
5629e07dd0SAxel Dörfler };
5729e07dd0SAxel Dörfler 
5829e07dd0SAxel Dörfler 
5929e07dd0SAxel Dörfler #endif	// _BUFFERED_DATA_IO_H
60