2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CBUFFEREDINPUTSTREAM_H
|
|
|
|
#define CBUFFEREDINPUTSTREAM_H
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "IInputStream.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
#include "CStreamBuffer.h"
|
|
|
|
#include "CCondVar.h"
|
|
|
|
|
|
|
|
class CMutex;
|
|
|
|
class IJob;
|
|
|
|
|
|
|
|
class CBufferedInputStream : public IInputStream {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2001-10-06 14:13:28 +00:00
|
|
|
CBufferedInputStream(CMutex*, IJob* adoptedCloseCB);
|
|
|
|
~CBufferedInputStream();
|
|
|
|
|
|
|
|
// the caller is expected to lock the mutex before calling
|
|
|
|
// methods unless otherwise noted.
|
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
|
|
|
// write() appends n bytes to the buffer
|
2001-10-14 16:58:01 +00:00
|
|
|
void write(const void*, UInt32 n);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// causes read() to always return immediately. if there is no
|
|
|
|
// more data then it returns 0. further writes are discarded.
|
2001-10-14 16:58:01 +00:00
|
|
|
void hangup();
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// same as read() but caller must lock the mutex
|
2002-06-26 16:31:48 +00:00
|
|
|
UInt32 readNoLock(void*, UInt32 count, double timeout);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
|
|
|
// same as getSize() but caller must lock the mutex
|
2001-10-14 16:58:01 +00:00
|
|
|
UInt32 getSizeNoLock() const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// IInputStream overrides
|
|
|
|
// these all lock the mutex for their duration
|
2001-10-14 16:58:01 +00:00
|
|
|
virtual void close();
|
2002-06-26 16:31:48 +00:00
|
|
|
virtual UInt32 read(void*, UInt32 count, double timeout);
|
2001-10-14 16:58:01 +00:00
|
|
|
virtual UInt32 getSize() const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2001-10-06 14:13:28 +00:00
|
|
|
CMutex* m_mutex;
|
|
|
|
CCondVar<bool> m_empty;
|
|
|
|
IJob* m_closeCB;
|
|
|
|
CStreamBuffer m_buffer;
|
|
|
|
bool m_closed;
|
|
|
|
bool m_hungup;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|