FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
BrowserStream.h
1 /**********************************************************\
2 Original Author: Matthias (nitrogenycs)
3 
4 Created: Feb 28, 2010
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2010 PacketPass, Inc and the Firebreath development team
13 \**********************************************************/
14 
15 #pragma once
16 #ifndef H_FB_BROWSERSTREAM
17 #define H_FB_BROWSERSTREAM
18 
19 #include <string>
20 #include "APITypes.h"
21 #include "PluginEventSource.h"
22 #include "PluginEventSink.h"
23 #include "PluginEvents/StreamEvents.h"
24 
25 namespace FB {
26  FB_FORWARD_PTR(BrowserStream);
27 
42  {
43  public:
51  struct Range
52  {
53  Range( size_t start, size_t end );
54 
55  size_t start, end;
56  };
57 
58  public:
66  BrowserStream( const std::string& url, bool cache, bool requestSeekable, size_t internalBufferSize);
67 
75  virtual ~BrowserStream();
76 
77  virtual BrowserStreamPtr shared_from_this() { return FB::ptr_cast<BrowserStream>(PluginEventSource::shared_from_this()); }
78 
91  virtual bool readRange( size_t start, size_t end );
92 
103  virtual bool readRanges( const std::vector<Range>& ranges ) = 0;
104 
118  virtual bool write(const char* data, size_t dataLength, size_t& written) = 0;
119 
129  virtual bool close() = 0;
130 
131 
132  public:
133  // property getters
134 
139  // BrowserHost::createStream.
143  virtual std::string getUrl() const;
144 
152  virtual bool isSeekableByServer() const;
153 
161  virtual bool isSeekableRequested() const;
162 
170  virtual bool isSeekable() const;
171 
180  virtual bool isCached() const;
181 
189  virtual bool isCompleted() const;
190 
198  virtual bool isOpen() const;
199 
207  virtual std::string getMimeType() const;
208 
217  virtual std::wstring getCacheFilename() const;
218 
226  virtual std::string getHeaders() const;
227 
235  virtual size_t getInternalBufferSize() const;
236 
244  virtual size_t getLength() const;
245 
246  protected:
247  // property setters
248  virtual void setUrl(const std::string& url);
249  virtual void setSeekableByServer(bool seekable);
250  virtual void setCached(bool cached);
251  virtual void setCompleted(bool completed);
252  virtual void setOpen(bool open);
253  virtual void setMimeType(const std::string& mimeType);
254  virtual void setCacheFilename(const std::wstring& cacheFilename);
255  virtual void setHeaders(const std::string& headers);
256  virtual void setInternalBufferSize(size_t internalBufferSize);
257  virtual void setLength(size_t length);
258 
259  private:
260  // properties
261  std::string url;
262  bool seekableRequested;
263  bool seekableByServer;
264  bool cached;
265  size_t internalBufferSize;
266  std::wstring cacheFilename;
267  size_t length;
268  std::string mimeType;
269  bool completed;
270  bool opened;
271  std::string headers;
272  };
273 };
274 
275 #endif
276 
virtual bool isSeekableRequested() const
Returns true if a stream was requested to be seekable. Not all servers support this.
virtual std::string getMimeType() const
Returns the mime type of this stream, e.g. "text/plain".
Specifies the range for a read range request (start to end) in bytes.
Definition: BrowserStream.h:51
virtual bool isCached() const
Returns true if the content of this stream should be cached (i.e. a physical file must be created)...
virtual bool isOpen() const
Returns true if the stream is open.
virtual bool write(const char *data, size_t dataLength, size_t &written)=0
Writes data to the stream.
This is the abstract base class (interface class) for a browser stream.
Definition: BrowserStream.h:41
boost::shared_ptr< T > ptr_cast(boost::shared_ptr< U > const &r)
Convenience function for doing a dynamic cast of one boost::shared_ptr to another.
Definition: APITypes.h:339
virtual bool readRanges(const std::vector< Range > &ranges)=0
Same functionality as BrowserStream::readRange( size_t start, size_t end ), except multiple ranges ca...
BrowserStream(const std::string &url, bool cache, bool requestSeekable, size_t internalBufferSize)
Default constructor. Dont't use directly, use BrowserHost::createStream instead.
virtual ~BrowserStream()
Destructor.
virtual size_t getLength() const
Returns the length of the stream in bytes (if server gives info like content-length).
virtual std::wstring getCacheFilename() const
If this is a cached stream, returns the physical filename of the file in the browser's cache...
virtual std::string getHeaders() const
Returns the http headers.
virtual bool isSeekable() const
Returns true if a stream was requested to be seekable and the server supports it. ...
virtual size_t getInternalBufferSize() const
Returns the size of the internal buffer used by this stream.
virtual bool isCompleted() const
Returns true if download of this stream is completed (e.g. due to error or download finished)...
virtual std::string getUrl() const
Returns the url associated with this stream. This is the url supplied to.
Base class for any object, such as BrowserStream or PluginWindow, that needs to fire events to a Plug...
virtual bool close()=0
Closes and destroys the stream.
virtual bool readRange(size_t start, size_t end)
Performs a read range request, returns the bytes in the range [start, end).
virtual bool isSeekableByServer() const
Returns true if the stream is actually seekable (server says so).