Moved length() and seek() methods to the Stream class so seekable streams can be implemented.

git-svn-id: http://yate.null.ro/svn/yate/trunk@2513 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2009-03-05 13:10:31 +00:00
parent c80ee5b9ad
commit d46d577cbd
3 changed files with 43 additions and 19 deletions

View File

@ -373,6 +373,16 @@ bool Stream::setBlocking(bool block)
return false;
}
int64_t Stream::length()
{
return 0;
}
int64_t Stream::seek(SeekPos pos, int64_t offset)
{
return -1;
}
int Stream::writeData(const char* str)
{
if (null(str))
@ -751,7 +761,7 @@ bool File::getFileTime(unsigned int& secEpoch)
// Build the MD5 hex digest of an opened file.
bool File::md5(String& buffer)
{
if (-1 == seek())
if (-1 == Stream::seek(0))
return false;
MD5 md5;
unsigned char buf[65536];

View File

@ -416,7 +416,7 @@ void FileSource::run()
unsigned long tStamp = 0;
start = Time::msecNow();
// Set file pos at start
if (-1 == m_file.seek()) {
if (-1 == m_file.Stream::seek(0)) {
Thread::errorString(error,m_file.error());
break;
}

View File

@ -4226,6 +4226,15 @@ private:
class YATE_API Stream
{
public:
/**
* Enumerate seek start position
*/
enum SeekPos {
SeekBegin, // Seek from start of stream
SeekEnd, // Seek from stream end
SeekCurrent // Seek from current position
};
/**
* Destructor, terminates the stream
*/
@ -4302,6 +4311,28 @@ public:
*/
virtual int readData(void* buffer, int length) = 0;
/**
* Find the length of the stream if it has one
* @return Length of the stream or zero if length is not defined
*/
virtual int64_t length();
/**
* Set the stream read/write pointer
* @param pos The seek start as enumeration
* @param offset The number of bytes to move the pointer from starting position
* @return The new position of the stream read/write pointer. Negative on failure
*/
virtual int64_t seek(SeekPos pos, int64_t offset = 0);
/**
* Set the read/write pointer from begin of stream
* @param offset The position in stream to move the pointer
* @return The new position of the stream read/write pointer. Negative on failure
*/
inline int64_t seek(int64_t offset)
{ return seek(SeekBegin,offset); }
/**
* Allocate a new pair of unidirectionally pipe connected streams
* @param reader Reference of a pointer receiving the newly allocated reading side of the pipe
@ -4354,15 +4385,6 @@ protected:
class YATE_API File : public Stream
{
public:
/**
* Enumerate seek start position
*/
enum SeekPos {
SeekBegin, // Seek from file begine
SeekEnd, // Seek from file end
SeekCurrent // Seek from current position
};
/**
* Default constructor, creates a closed file
*/
@ -4456,14 +4478,6 @@ public:
*/
virtual int64_t seek(SeekPos pos, int64_t offset = 0);
/**
* Set the file read/write pointer from begin of file
* @param offset The position in file to move the pointer
* @return The new position of the file read/write pointer. Negative on failure
*/
inline int64_t seek(int64_t offset = 0)
{ return seek(SeekBegin,offset); }
/**
* Write data to an open file
* @param buffer Buffer for data transfer