Panda3D
virtualFileHTTP.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file virtualFileHTTP.h
10  * @author drose
11  * @date 2008-10-31
12  */
13 
14 #ifndef VIRTUALFILEHTTP_H
15 #define VIRTUALFILEHTTP_H
16 
17 #include "pandabase.h"
18 
19 #include "virtualFile.h"
20 #include "httpChannel.h"
21 #include "urlSpec.h"
22 
23 #ifdef HAVE_OPENSSL
24 
25 class VirtualFileMountHTTP;
26 
27 /**
28  * This maps a document retrieved from an HTTPClient into the
29  * VirtualFileSystem, allowing models etc. to be loaded directly from a web
30  * page.
31  */
32 class EXPCL_PANDA_DOWNLOADER VirtualFileHTTP : public VirtualFile {
33 public:
34  VirtualFileHTTP(VirtualFileMountHTTP *mount,
35  const Filename &local_filename,
36  bool implicit_pz_file,
37  int open_flags);
38  virtual ~VirtualFileHTTP();
39 
40  virtual VirtualFileSystem *get_file_system() const;
41  virtual Filename get_filename() const;
42 
43  virtual bool has_file() const;
44  virtual bool is_directory() const;
45  virtual bool is_regular_file() const;
46  INLINE bool is_implicit_pz_file() const;
47 
48  virtual std::istream *open_read_file(bool auto_unwrap) const;
49  virtual bool was_read_successful() const;
50  virtual std::streamsize get_file_size(std::istream *stream) const;
51  virtual std::streamsize get_file_size() const;
52  virtual time_t get_timestamp() const;
53 
54 private:
55  bool fetch_file(std::ostream *buffer_stream) const;
56  std::istream *return_file(std::istream *buffer_stream, bool auto_unwrap) const;
57 
58  VirtualFileMountHTTP *_mount;
59  Filename _local_filename;
60  bool _implicit_pz_file;
61  bool _status_only;
62  URLSpec _url;
63  PT(HTTPChannel) _channel;
64 
65 public:
66  virtual TypeHandle get_type() const {
67  return get_class_type();
68  }
69  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
70 
71 PUBLISHED:
72  static TypeHandle get_class_type() {
73  return _type_handle;
74  }
75 
76 public:
77  static void init_type() {
78  VirtualFile::init_type();
79  register_type(_type_handle, "VirtualFileHTTP",
80  VirtualFile::get_class_type());
81  }
82 
83 private:
84  static TypeHandle _type_handle;
85 };
86 
87 #include "virtualFileHTTP.I"
88 
89 #endif // HAVE_OPENSSL
90 
91 #endif
A container for a URL, e.g.
Definition: urlSpec.h:28
A hierarchy of directories and files that appears to be one continuous file system,...
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called),...
Definition: virtualFile.cxx:41
virtual bool was_read_successful() const
Call this method after a reading the istream returned by open_read_file() to completion.
virtual bool has_file() const
Returns true if this file exists, false otherwise.
Definition: virtualFile.cxx:32
virtual std::istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::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:81
virtual bool is_regular_file() const
Returns true if this file represents a regular file (and read_file() may be called),...
Definition: virtualFile.cxx:50
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.