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 virtual bool read_file(vector_uchar &result, bool auto_unwrap) const;
55
56 private:
57 bool fetch_file(std::ostream *buffer_stream) const;
58 std::istream *return_file(std::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
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
URLSpec
A container for a URL, e.g.
Definition: urlSpec.h:28
VirtualFileSystem
A hierarchy of directories and files that appears to be one continuous file system,...
Definition: virtualFileSystem.h:40
VirtualFile
The abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:35
VirtualFile::open_read_file
virtual std::istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
Definition: virtualFile.cxx:198
VirtualFile::is_regular_file
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
VirtualFile::has_file
virtual bool has_file() const
Returns true if this file exists, false otherwise.
Definition: virtualFile.cxx:32
VirtualFile::is_directory
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called),...
Definition: virtualFile.cxx:41
VirtualFile::was_read_successful
virtual bool was_read_successful() const
Call this method after a reading the istream returned by open_read_file() to completion.
Definition: virtualFile.cxx:221
VirtualFile::read_file
std::string read_file(bool auto_unwrap) const
Returns the entire contents of the file as a string.
Definition: virtualFile.I:35
VirtualFile::get_timestamp
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
Definition: virtualFile.cxx:317
VirtualFile::get_file_size
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.
Definition: virtualFile.cxx:302
httpChannel.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
urlSpec.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtualFileHTTP.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtualFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.