summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/ReadLoggingStream.cpp28
-rw-r--r--lib/common/ReadLoggingStream.h19
2 files changed, 29 insertions, 18 deletions
diff --git a/lib/common/ReadLoggingStream.cpp b/lib/common/ReadLoggingStream.cpp
index 9023f827..54c99c95 100644
--- a/lib/common/ReadLoggingStream.cpp
+++ b/lib/common/ReadLoggingStream.cpp
@@ -25,12 +25,13 @@
// Created: 2007/01/16
//
// --------------------------------------------------------------------------
-ReadLoggingStream::ReadLoggingStream(IOStream& rSource)
+ReadLoggingStream::ReadLoggingStream(IOStream& rSource, Logger& rLogger)
: mrSource(rSource),
mOffset(0),
mLength(mrSource.BytesLeftToRead()),
mTotalRead(0),
- mStartTime(GetCurrentBoxTime())
+ mStartTime(GetCurrentBoxTime()),
+ mrLogger(rLogger)
{ }
@@ -52,26 +53,21 @@ int ReadLoggingStream::Read(void *pBuffer, int NBytes, int Timeout)
mOffset += numBytesRead;
}
- if (mLength >= 0 && mTotalRead > 0)
+ if (mLength == 0)
{
- box_time_t timeNow = GetCurrentBoxTime();
- box_time_t elapsed = timeNow - mStartTime;
- box_time_t finish = (elapsed * mLength) / mTotalRead;
- box_time_t remain = finish - elapsed;
-
- BOX_TRACE("Read " << numBytesRead << " bytes at " << mOffset <<
- ", " << (mLength - mOffset) << " remain, eta " <<
- BoxTimeToSeconds(remain) << "s");
+ mrLogger.Log(numBytesRead, mOffset);
}
- else if (mLength >= 0 && mTotalRead == 0)
+ else if (mTotalRead == 0)
{
- BOX_TRACE("Read " << numBytesRead << " bytes at " << mOffset <<
- ", " << (mLength - mOffset) << " remain");
+ mrLogger.Log(numBytesRead, mOffset, mLength);
}
else
{
- BOX_TRACE("Read " << numBytesRead << " bytes at " << mOffset <<
- ", unknown bytes remaining");
+ box_time_t timeNow = GetCurrentBoxTime();
+ box_time_t elapsed = timeNow - mStartTime;
+ box_time_t finish = (elapsed * mLength) / mTotalRead;
+ // box_time_t remain = finish - elapsed;
+ mrLogger.Log(numBytesRead, mOffset, mLength, elapsed, finish);
}
return numBytesRead;
diff --git a/lib/common/ReadLoggingStream.h b/lib/common/ReadLoggingStream.h
index 15c3ef48..b23b542c 100644
--- a/lib/common/ReadLoggingStream.h
+++ b/lib/common/ReadLoggingStream.h
@@ -15,13 +15,27 @@
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);
+ ReadLoggingStream(IOStream& rSource, Logger& rLogger);
virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
virtual pos_type BytesLeftToRead();
@@ -35,7 +49,8 @@ public:
private:
ReadLoggingStream(const ReadLoggingStream &rToCopy)
- : mrSource(rToCopy.mrSource) { /* do not call */ }
+ : mrSource(rToCopy.mrSource), mrLogger(rToCopy.mrLogger)
+ { /* do not call */ }
};
#endif // READLOGGINGSTREAM__H