1218a8c03SAugustin Cavalier /* 2218a8c03SAugustin Cavalier * Copyright 2016 Haiku, Inc. All rights reserved. 3218a8c03SAugustin Cavalier * Distributed under the terms of the MIT License. 4218a8c03SAugustin Cavalier */ 5218a8c03SAugustin Cavalier #ifndef _ADAPTER_IO_H 6218a8c03SAugustin Cavalier #define _ADAPTER_IO_H 7218a8c03SAugustin Cavalier 8218a8c03SAugustin Cavalier 9218a8c03SAugustin Cavalier #include <MediaIO.h> 10218a8c03SAugustin Cavalier #include <OS.h> 11218a8c03SAugustin Cavalier #include <RWLocker.h> 12218a8c03SAugustin Cavalier #include <SupportDefs.h> 13218a8c03SAugustin Cavalier 14218a8c03SAugustin Cavalier 15218a8c03SAugustin Cavalier class BAdapterIO; 16218a8c03SAugustin Cavalier class RelativePositionIO; 17218a8c03SAugustin Cavalier 18218a8c03SAugustin Cavalier 19218a8c03SAugustin Cavalier class BInputAdapter { 20218a8c03SAugustin Cavalier public: 21218a8c03SAugustin Cavalier virtual ssize_t Write(const void* buffer, size_t size); 22218a8c03SAugustin Cavalier 23218a8c03SAugustin Cavalier private: 24218a8c03SAugustin Cavalier friend class BAdapterIO; 25218a8c03SAugustin Cavalier 26218a8c03SAugustin Cavalier BInputAdapter(BAdapterIO* io); 27218a8c03SAugustin Cavalier virtual ~BInputAdapter(); 28218a8c03SAugustin Cavalier 29218a8c03SAugustin Cavalier BAdapterIO* fIO; 30218a8c03SAugustin Cavalier 31218a8c03SAugustin Cavalier virtual void _ReservedInputAdapter1(); 32218a8c03SAugustin Cavalier virtual void _ReservedInputAdapter2(); 33218a8c03SAugustin Cavalier 34218a8c03SAugustin Cavalier uint32 _reserved[2]; 35218a8c03SAugustin Cavalier }; 36218a8c03SAugustin Cavalier 37218a8c03SAugustin Cavalier 38218a8c03SAugustin Cavalier class BAdapterIO : public BMediaIO { 39218a8c03SAugustin Cavalier public: 40218a8c03SAugustin Cavalier BAdapterIO( 41218a8c03SAugustin Cavalier int32 flags, 42218a8c03SAugustin Cavalier bigtime_t timeout); 43218a8c03SAugustin Cavalier virtual ~BAdapterIO(); 44218a8c03SAugustin Cavalier 45218a8c03SAugustin Cavalier virtual void GetFlags(int32* flags) const; 46218a8c03SAugustin Cavalier 47218a8c03SAugustin Cavalier virtual ssize_t ReadAt(off_t position, void* buffer, 48218a8c03SAugustin Cavalier size_t size); 49218a8c03SAugustin Cavalier virtual ssize_t WriteAt(off_t position, 50218a8c03SAugustin Cavalier const void* buffer, size_t size); 51218a8c03SAugustin Cavalier 52218a8c03SAugustin Cavalier virtual off_t Seek(off_t position, uint32 seekMode); 53218a8c03SAugustin Cavalier virtual off_t Position() const; 54218a8c03SAugustin Cavalier 55218a8c03SAugustin Cavalier virtual status_t SetSize(off_t size); 56218a8c03SAugustin Cavalier virtual status_t GetSize(off_t* size) const; 57218a8c03SAugustin Cavalier 58218a8c03SAugustin Cavalier virtual status_t Open(); 59218a8c03SAugustin Cavalier 60218a8c03SAugustin Cavalier virtual bool IsRunning() const; 61218a8c03SAugustin Cavalier 62218a8c03SAugustin Cavalier void SeekCompleted(); 63218a8c03SAugustin Cavalier status_t SetBuffer(BPositionIO* buffer); 64218a8c03SAugustin Cavalier 65*591a1d17SJérôme Duval status_t FlushBefore(off_t position); 66*591a1d17SJérôme Duval 67218a8c03SAugustin Cavalier BInputAdapter* BuildInputAdapter(); 68218a8c03SAugustin Cavalier 69218a8c03SAugustin Cavalier protected: 70218a8c03SAugustin Cavalier friend class BInputAdapter; 71218a8c03SAugustin Cavalier 72218a8c03SAugustin Cavalier virtual status_t SeekRequested(off_t position); 73218a8c03SAugustin Cavalier 74218a8c03SAugustin Cavalier ssize_t BackWrite(const void* buffer, size_t size); 75218a8c03SAugustin Cavalier 76218a8c03SAugustin Cavalier private: 77218a8c03SAugustin Cavalier status_t _EvaluateWait(off_t pos, off_t size); 78218a8c03SAugustin Cavalier 79218a8c03SAugustin Cavalier int32 fFlags; 80218a8c03SAugustin Cavalier 81218a8c03SAugustin Cavalier RelativePositionIO* fBuffer; 82218a8c03SAugustin Cavalier off_t fTotalSize; 83218a8c03SAugustin Cavalier bool fOpened; 84218a8c03SAugustin Cavalier sem_id fSeekSem; 85218a8c03SAugustin Cavalier 86218a8c03SAugustin Cavalier BInputAdapter* fInputAdapter; 87218a8c03SAugustin Cavalier 88218a8c03SAugustin Cavalier BAdapterIO(const BAdapterIO&); 89218a8c03SAugustin Cavalier BAdapterIO& operator=(const BAdapterIO&); 90218a8c03SAugustin Cavalier 91218a8c03SAugustin Cavalier virtual void _ReservedAdapterIO1(); 92218a8c03SAugustin Cavalier virtual void _ReservedAdapterIO2(); 93218a8c03SAugustin Cavalier virtual void _ReservedAdapterIO3(); 94218a8c03SAugustin Cavalier virtual void _ReservedAdapterIO4(); 95218a8c03SAugustin Cavalier virtual void _ReservedAdapterIO5(); 96218a8c03SAugustin Cavalier 97218a8c03SAugustin Cavalier uint32 _reserved[5]; 98218a8c03SAugustin Cavalier }; 99218a8c03SAugustin Cavalier 100218a8c03SAugustin Cavalier #endif // _ADAPTER_IO_H 101