Panda3D
virtualFileMountHTTP.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 virtualFileMountHTTP.h
10  * @author drose
11  * @date 2008-10-30
12  */
13 
14 #ifndef VIRTUALFILEMOUNTHTTP_H
15 #define VIRTUALFILEMOUNTHTTP_H
16 
17 #include "pandabase.h"
18 
19 #ifdef HAVE_OPENSSL
20 
21 #include "virtualFileMount.h"
22 #include "httpClient.h"
23 #include "httpChannel.h"
24 #include "urlSpec.h"
25 #include "pointerTo.h"
26 #include "mutexImpl.h"
27 
28 /**
29  * Maps a web page (URL root) into the VirtualFileSystem.
30  */
31 class EXPCL_PANDA_DOWNLOADER VirtualFileMountHTTP : public VirtualFileMount {
32 PUBLISHED:
33  explicit VirtualFileMountHTTP(const URLSpec &root, HTTPClient *http = HTTPClient::get_global_ptr());
34  virtual ~VirtualFileMountHTTP();
35 
36  INLINE HTTPClient *get_http_client() const;
37  INLINE const URLSpec &get_root() const;
38 
39  static void reload_vfs_mount_url();
40 
41 public:
42  virtual PT(VirtualFile) make_virtual_file(const Filename &local_filename,
43  const Filename &original_filename,
44  bool implicit_pz_file,
45  int open_flags);
46 
47  virtual bool has_file(const Filename &file) const;
48  virtual bool is_directory(const Filename &file) const;
49  virtual bool is_regular_file(const Filename &file) const;
50 
51  virtual std::istream *open_read_file(const Filename &file) const;
52  virtual std::streamsize get_file_size(const Filename &file, std::istream *stream) const;
53  virtual std::streamsize get_file_size(const Filename &file) const;
54  virtual time_t get_timestamp(const Filename &file) const;
55 
56  virtual bool scan_directory(vector_string &contents,
57  const Filename &dir) const;
58 
59  virtual void output(std::ostream &out) const;
60 
61  PT(HTTPChannel) get_channel();
62  void recycle_channel(HTTPChannel *channel);
63 
64 private:
65  PT(HTTPClient) _http;
66  URLSpec _root;
67 
68  MutexImpl _channels_lock;
69  typedef pvector< PT(HTTPChannel) > Channels;
70  Channels _channels;
71 
72 public:
73  virtual TypeHandle get_type() const {
74  return get_class_type();
75  }
76  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
77  static TypeHandle get_class_type() {
78  return _type_handle;
79  }
80  static void init_type() {
81  VirtualFileMount::init_type();
82  register_type(_type_handle, "VirtualFileMountHTTP",
83  VirtualFileMount::get_class_type());
84  }
85 
86 private:
87  static TypeHandle _type_handle;
88 };
89 
90 #include "virtualFileMountHTTP.I"
91 
92 #endif // HAVE_OPENSSL
93 
94 #endif
A container for a URL, e.g.
Definition: urlSpec.h:28
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(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The abstract base class for a mount definition used within a VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A fake mutex implementation for single-threaded applications that don't need any synchronization cont...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
virtual PointerTo< VirtualFile > make_virtual_file(const Filename &local_filename, const Filename &original_filename, bool implicit_pz_file, int open_flags)
Constructs and returns a new VirtualFile instance that corresponds to the indicated filename within t...