summaryrefslogtreecommitdiff
path: root/lib/common/ReadLoggingStream.h
blob: bee7e1d622bb0f0158e146d94f910612aae6d97e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// --------------------------------------------------------------------------
//
// File
//		Name:    ReadLoggingStream.h
//		Purpose: Wrapper around IOStreams that logs read progress
//		Created: 2007/01/16
//
// --------------------------------------------------------------------------

#ifndef READLOGGINGSTREAM__H
#define READLOGGINGSTREAM__H

#include "IOStream.h"
#include "BoxTime.h"

class ReadLoggingStream : public IOStream
{
public:
	class Logger
	{
	public:
		virtual ~Logger() { }
		virtual void Log(int64_t readSize, int64_t offset,
			int64_t length, box_time_t elapsed,
			box_time_t finish) = 0;
		virtual void Log(int64_t readSize, int64_t offset,
			int64_t length) = 0;
		virtual void Log(int64_t readSize, int64_t offset) = 0;
	};

private:
	IOStream& mrSource;
	IOStream::pos_type mOffset, mLength, mTotalRead;
	box_time_t mStartTime;
	Logger& mrLogger;

public:
	ReadLoggingStream(IOStream& rSource, Logger& rLogger);
	
	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
	virtual pos_type BytesLeftToRead();
	virtual void Write(const void *pBuffer, int NBytes,
		int Timeout = IOStream::TimeOutInfinite);
	virtual pos_type GetPosition() const;
	virtual void Seek(IOStream::pos_type Offset, int SeekType);
	virtual void Close();
	
	virtual bool StreamDataLeft();
	virtual bool StreamClosed();

private:
	ReadLoggingStream(const ReadLoggingStream &rToCopy)
	: mrSource(rToCopy.mrSource), mrLogger(rToCopy.mrLogger)
	{ /* do not call */ }
};

#endif // READLOGGINGSTREAM__H