Panda3D
Loading...
Searching...
No Matches
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
25class 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 */
32class EXPCL_PANDA_DOWNLOADER VirtualFileHTTP : public VirtualFile {
33public:
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
56private:
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
67public:
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
73PUBLISHED:
74 static TypeHandle get_class_type() {
75 return _type_handle;
76 }
77
78public:
79 static void init_type() {
80 VirtualFile::init_type();
81 register_type(_type_handle, "VirtualFileHTTP",
82 VirtualFile::get_class_type());
83 }
84
85private:
86 static TypeHandle _type_handle;
87};
88
89#include "virtualFileHTTP.I"
90
91#endif // HAVE_OPENSSL
92
93#endif
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
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,...
The abstract base class for a file or directory within the VirtualFileSystem.
Definition virtualFile.h:35
virtual std::istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
virtual bool is_regular_file() const
Returns true if this file represents a regular file (and read_file() may be called),...
virtual bool has_file() const
Returns true if this file exists, false otherwise.
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called),...
virtual bool was_read_successful() const
Call this method after a reading the istream returned by open_read_file() to completion.
std::string read_file(bool auto_unwrap) const
Returns the entire contents of the file as a string.
Definition virtualFile.I:35
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.