xref: /haiku/headers/private/media/experimental/AdapterIO.h (revision c237c4ce593ee823d9867fd997e51e4c447f5623)
1 /*
2  * Copyright 2016 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _ADAPTER_IO_H
6 #define _ADAPTER_IO_H
7 
8 
9 #include <MediaIO.h>
10 #include <OS.h>
11 #include <RWLocker.h>
12 #include <SupportDefs.h>
13 
14 
15 class BAdapterIO;
16 class RelativePositionIO;
17 
18 
19 class BInputAdapter {
20 public:
21 	virtual	ssize_t					Write(const void* buffer, size_t size);
22 
23 private:
24 	friend class BAdapterIO;
25 
26 									BInputAdapter(BAdapterIO* io);
27 	virtual							~BInputAdapter();
28 
29 			BAdapterIO*				fIO;
30 
31 	virtual	void					_ReservedInputAdapter1();
32 	virtual void					_ReservedInputAdapter2();
33 
34 			uint32					_reserved[2];
35 };
36 
37 
38 class BAdapterIO : public BMediaIO {
39 public:
40 									BAdapterIO(
41 										int32 flags,
42 										bigtime_t timeout);
43 	virtual							~BAdapterIO();
44 
45 	virtual void					GetFlags(int32* flags) const;
46 
47 	virtual	ssize_t					ReadAt(off_t position, void* buffer,
48 										size_t size);
49 	virtual	ssize_t					WriteAt(off_t position,
50 										const void* buffer, size_t size);
51 
52 	virtual	off_t					Seek(off_t position, uint32 seekMode);
53 	virtual off_t					Position() const;
54 
55 	virtual	status_t				SetSize(off_t size);
56 	virtual	status_t				GetSize(off_t* size) const;
57 
58 	virtual status_t				Open();
59 
60 	virtual bool					IsRunning() const;
61 
62 			void					SeekCompleted();
63 			status_t				SetBuffer(BPositionIO* buffer);
64 
65 			status_t				FlushBefore(off_t position);
66 
67 			BInputAdapter*			BuildInputAdapter();
68 
69 protected:
70 	friend class BInputAdapter;
71 
72 	virtual	status_t				SeekRequested(off_t position);
73 
74 			ssize_t					BackWrite(const void* buffer, size_t size);
75 
76 private:
77 			status_t				_EvaluateWait(off_t pos, off_t size);
78 
79 			int32					fFlags;
80 
81 			RelativePositionIO*		fBuffer;
82 			off_t					fTotalSize;
83 			bool					fOpened;
84 			sem_id					fSeekSem;
85 
86 			BInputAdapter*			fInputAdapter;
87 
88 									BAdapterIO(const BAdapterIO&);
89 			BAdapterIO&				operator=(const BAdapterIO&);
90 
91 	virtual	void					_ReservedAdapterIO1();
92 	virtual void					_ReservedAdapterIO2();
93 	virtual void					_ReservedAdapterIO3();
94 	virtual void					_ReservedAdapterIO4();
95 	virtual void					_ReservedAdapterIO5();
96 
97 			uint32					_reserved[5];
98 };
99 
100 #endif	// _ADAPTER_IO_H
101