Panda3D
 All Classes Functions Variables Enumerations
virtualFileMountAndroidAsset.h
1 // Filename: virtualFileMountAndroidAsset.h
2 // Created by: rdb (21Jan13)
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 VIRTUALFILEMOUNTANDROIDASSET_H
16 #define VIRTUALFILEMOUNTANDROIDASSET_H
17 
18 #ifdef ANDROID
19 
20 #include "pandabase.h"
21 
22 #include "virtualFileMount.h"
23 #include "multifile.h"
24 #include "pointerTo.h"
25 
26 #include <android/asset_manager.h>
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : VirtualFileMountAndroidAsset
30 // Description : Maps a Multifile's contents into the
31 // VirtualFileSystem.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDAEXPRESS VirtualFileMountAndroidAsset : public VirtualFileMount {
34 PUBLISHED:
35  INLINE VirtualFileMountAndroidAsset(AAssetManager *mgr, const string &apk_path);
36  virtual ~VirtualFileMountAndroidAsset();
37 
38 public:
39  int get_fd(const Filename &file, off_t *start, off_t *end) const;
40 
41  virtual bool has_file(const Filename &file) const;
42  virtual bool is_directory(const Filename &file) const;
43  virtual bool is_regular_file(const Filename &file) const;
44 
45  virtual bool read_file(const Filename &file, bool do_uncompress,
46  pvector<unsigned char> &result) const;
47 
48  virtual istream *open_read_file(const Filename &file) const;
49  virtual streamsize get_file_size(const Filename &file, istream *stream) const;
50  virtual streamsize get_file_size(const Filename &file) const;
51  virtual time_t get_timestamp(const Filename &file) const;
52  virtual bool get_system_info(const Filename &file, SubfileInfo &info);
53 
54  virtual bool scan_directory(vector_string &contents,
55  const Filename &dir) const;
56 
57 private:
58  AAssetManager *_asset_mgr;
59  string _apk_path;
60 
61  class AssetStream : public istream {
62  public:
63  INLINE AssetStream(AAsset *asset);
64  virtual ~AssetStream();
65  };
66 
67  class AssetStreamBuf : public streambuf {
68  public:
69  AssetStreamBuf(AAsset *asset);
70  virtual ~AssetStreamBuf();
71 
72  virtual streampos seekoff(streamoff off, ios_seekdir dir, ios_openmode which);
73  virtual streampos seekpos(streampos pos, ios_openmode which);
74 
75  protected:
76  virtual int underflow();
77 
78  private:
79  AAsset *_asset;
80  off_t _offset;
81 
82  friend class VirtualFileMountAndroidAsset;
83  };
84 
85 public:
86  virtual TypeHandle get_type() const {
87  return get_class_type();
88  }
89  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
90  static TypeHandle get_class_type() {
91  return _type_handle;
92  }
93  static void init_type() {
94  VirtualFileMount::init_type();
95  register_type(_type_handle, "VirtualFileMountAndroidAsset",
96  VirtualFileMount::get_class_type());
97  }
98 
99 private:
100  static TypeHandle _type_handle;
101 };
102 
103 #include "virtualFileMountAndroidAsset.I"
104 
105 #endif // ANDROID
106 
107 #endif
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
virtual bool read_file(const Filename &file, bool do_uncompress, pvector< unsigned char > &result) const
Fills up the indicated pvector with the contents of the file, if it is a regular file.
virtual bool get_system_info(const Filename &file, SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
The abstract base class for a mount definition used within a VirtualFileSystem.
This class records a particular byte sub-range within an existing file on disk.
Definition: subfileInfo.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85