Panda3D
 All Classes Functions Variables Enumerations
virtualFileHTTP.h
1 // Filename: virtualFileHTTP.h
2 // Created by: drose (31Oct08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef VIRTUALFILEHTTP_H
16 #define VIRTUALFILEHTTP_H
17 
18 #include "pandabase.h"
19 
20 #include "virtualFile.h"
21 #include "httpChannel.h"
22 #include "urlSpec.h"
23 
24 #ifdef HAVE_OPENSSL
25 
26 class VirtualFileMountHTTP;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : VirtualFileHTTP
30 // Description : This maps a document retrieved from an HTTPClient
31 // into the VirtualFileSystem, allowing models etc. to
32 // be loaded directly from a web page.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDAEXPRESS VirtualFileHTTP : public VirtualFile {
35 public:
36  VirtualFileHTTP(VirtualFileMountHTTP *mount,
37  const Filename &local_filename,
38  bool implicit_pz_file,
39  int open_flags);
40  virtual ~VirtualFileHTTP();
41 
42  virtual VirtualFileSystem *get_file_system() const;
43  virtual Filename get_filename() const;
44 
45  virtual bool has_file() const;
46  virtual bool is_directory() const;
47  virtual bool is_regular_file() const;
48  INLINE bool is_implicit_pz_file() const;
49 
50  virtual istream *open_read_file(bool auto_unwrap) const;
51  virtual bool was_read_successful() const;
52  virtual streamsize get_file_size(istream *stream) const;
53  virtual streamsize get_file_size() const;
54  virtual time_t get_timestamp() const;
55 
56 private:
57  bool fetch_file(ostream *buffer_stream) const;
58  istream *return_file(istream *buffer_stream, bool auto_unwrap) const;
59 
60  VirtualFileMountHTTP *_mount;
61  Filename _local_filename;
62  bool _implicit_pz_file;
63  bool _status_only;
64  URLSpec _url;
65  PT(HTTPChannel) _channel;
66 
67 public:
68  virtual TypeHandle get_type() const {
69  return get_class_type();
70  }
71  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
72 
73 PUBLISHED:
74  static TypeHandle get_class_type() {
75  return _type_handle;
76  }
77 
78 public:
79  static void init_type() {
80  VirtualFile::init_type();
81  register_type(_type_handle, "VirtualFileHTTP",
82  VirtualFile::get_class_type());
83  }
84 
85 private:
86  static TypeHandle _type_handle;
87 };
88 
89 #include "virtualFileHTTP.I"
90 
91 #endif // HAVE_OPENSSL
92 
93 #endif
94 
virtual istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
A container for a URL, e.g.
Definition: urlSpec.h:29
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
The abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:37
virtual bool is_regular_file() const
Returns true if this file represents a regular file (and read_file() may be called), false otherwise.
Definition: virtualFile.cxx:52
virtual bool has_file() const
Returns true if this file exists, false otherwise.
Definition: virtualFile.cxx:30
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
virtual bool was_read_successful() const
Call this method after a reading the istream returned by open_read_file() to completion.
virtual streamsize get_file_size() const
Returns the current size on disk (or wherever it is) of the file before it has been opened...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.
Definition: virtualFile.cxx:41