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