2009-07-24 21:11:01 +02:00
|
|
|
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
#ifndef _STREAM_IMPL_H
|
|
|
|
#define _STREAM_IMPL_H
|
|
|
|
|
|
|
|
#include "../include/cef.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
// Implementation of CefStreamReader for files.
|
|
|
|
class CefFileReader : public CefThreadSafeBase<CefStreamReader>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefFileReader(FILE* file, bool close);
|
2009-08-21 19:41:09 +02:00
|
|
|
virtual ~CefFileReader();
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
virtual size_t Read(void* ptr, size_t size, size_t n);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual int Seek(long offset, int whence);
|
|
|
|
virtual long Tell();
|
|
|
|
virtual int Eof();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool close_;
|
|
|
|
FILE *file_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamWriter for files.
|
|
|
|
class CefFileWriter : public CefThreadSafeBase<CefStreamWriter>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefFileWriter(FILE* file, bool close);
|
2009-08-21 19:41:09 +02:00
|
|
|
virtual ~CefFileWriter();
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
virtual size_t Write(const void* ptr, size_t size, size_t n);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual int Seek(long offset, int whence);
|
|
|
|
virtual long Tell();
|
|
|
|
virtual int Flush();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
FILE *file_;
|
|
|
|
bool close_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamReader for byte buffers.
|
|
|
|
class CefBytesReader : public CefThreadSafeBase<CefStreamReader>
|
|
|
|
{
|
|
|
|
public:
|
2009-06-25 17:59:48 +02:00
|
|
|
CefBytesReader(void* data, long datasize, bool copy);
|
2009-08-21 19:41:09 +02:00
|
|
|
virtual ~CefBytesReader();
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
virtual size_t Read(void* ptr, size_t size, size_t n);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual int Seek(long offset, int whence);
|
|
|
|
virtual long Tell();
|
|
|
|
virtual int Eof();
|
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
void SetData(void* data, long datasize, bool copy);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
void* GetData() { return data_; }
|
2008-12-02 16:48:14 +01:00
|
|
|
size_t GetDataSize() { return offset_; }
|
|
|
|
|
|
|
|
protected:
|
2009-06-25 17:59:48 +02:00
|
|
|
void* data_;
|
2008-12-02 16:48:14 +01:00
|
|
|
size_t datasize_;
|
|
|
|
bool copy_;
|
|
|
|
size_t offset_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamWriter for byte buffers.
|
|
|
|
class CefBytesWriter : public CefThreadSafeBase<CefStreamWriter>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefBytesWriter(size_t grow);
|
2009-08-21 19:41:09 +02:00
|
|
|
virtual ~CefBytesWriter();
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
virtual size_t Write(const void* ptr, size_t size, size_t n);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual int Seek(long offset, int whence);
|
|
|
|
virtual long Tell();
|
|
|
|
virtual int Flush();
|
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
void* GetData() { return data_; }
|
2008-12-02 16:48:14 +01:00
|
|
|
size_t GetDataSize() { return offset_; }
|
|
|
|
std::string GetDataString();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t Grow(size_t size);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t grow_;
|
2009-06-25 17:59:48 +02:00
|
|
|
void* data_;
|
2008-12-02 16:48:14 +01:00
|
|
|
size_t datasize_;
|
|
|
|
size_t offset_;
|
|
|
|
};
|
|
|
|
|
2009-08-21 19:41:09 +02:00
|
|
|
// Implementation of CefStreamReader for handlers.
|
|
|
|
class CefHandlerReader : public CefThreadSafeBase<CefStreamReader>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefHandlerReader(CefRefPtr<CefReadHandler> handler) : handler_(handler) {}
|
|
|
|
|
|
|
|
virtual size_t Read(void* ptr, size_t size, size_t n)
|
|
|
|
{
|
|
|
|
return handler_->Read(ptr, size, n);
|
|
|
|
}
|
|
|
|
virtual int Seek(long offset, int whence)
|
|
|
|
{
|
|
|
|
return handler_->Seek(offset, whence);
|
|
|
|
}
|
|
|
|
virtual long Tell()
|
|
|
|
{
|
|
|
|
return handler_->Tell();
|
|
|
|
}
|
|
|
|
virtual int Eof()
|
|
|
|
{
|
|
|
|
return handler_->Eof();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CefRefPtr<CefReadHandler> handler_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamWriter for handlers.
|
|
|
|
class CefHandlerWriter : public CefThreadSafeBase<CefStreamWriter>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefHandlerWriter(CefRefPtr<CefWriteHandler> handler) : handler_(handler) {}
|
|
|
|
|
|
|
|
virtual size_t Write(const void* ptr, size_t size, size_t n)
|
|
|
|
{
|
|
|
|
return handler_->Write(ptr, size, n);
|
|
|
|
}
|
|
|
|
virtual int Seek(long offset, int whence)
|
|
|
|
{
|
|
|
|
return handler_->Seek(offset, whence);
|
|
|
|
}
|
|
|
|
virtual long Tell()
|
|
|
|
{
|
|
|
|
return handler_->Tell();
|
|
|
|
}
|
|
|
|
virtual int Flush()
|
|
|
|
{
|
|
|
|
return handler_->Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CefRefPtr<CefWriteHandler> handler_;
|
|
|
|
};
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
#endif // _STREAM_IMPL_H
|