Panda3D
Loading...
Searching...
No Matches
downloadDb.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 downloadDb.h
10 * @author shochet
11 * @date 2000-09-06
12 */
13
14#ifndef DOWNLOADDB_H
15#define DOWNLOADDB_H
16
17#include "pandabase.h"
18#include "pnotify.h"
19#include "filename.h"
20#include "multifile.h"
21#include "datagram.h"
22#include "datagramIterator.h"
23
24#include "pvector.h"
25#include "pointerTo.h"
26#include "pmap.h"
27
28#include "hashVal.h"
29
30class StreamReader;
31class StreamWriter;
32typedef PN_stdfloat Phase;
33class Ramfile;
34
35/*
36// Database Format
37magic_number
38number_of_multifiles
39header_length multifile_name phase version size status num_files
40 header_length file_name version hash
41 header_length file_name version hash
42header_length multifile_name phase version size status num_files
43 header_length file_name version hash
44 header_length file_name version hash
45 ...
46...
47
48
49A Db is a Vector<MultifileRecord>
50MultifileRecord is a Vector<FileRecord>
51*/
52
53
54/**
55 * A listing of files within multifiles for management of client-side
56 * synchronization with a server-provided set of files.
57 *
58 * This class manages one copy of the database for the client, representing
59 * the files on the client system, and another copy for the server,
60 * representing the files the server has available.
61 */
62class EXPCL_PANDA_DOWNLOADER DownloadDb {
63PUBLISHED:
64 // Status of a multifile is stored in this enum Note these values are in
65 // increasing order of "doneness" So if you are decompressed, you are
66 // complete If you are extracted, you are decompressed and complete
67 enum Status {
68 Status_incomplete = 0,
69 Status_complete = 1,
70 Status_decompressed = 2,
71 Status_extracted = 3
72 };
73
74 DownloadDb();
75 explicit DownloadDb(Ramfile &server_file, Filename &client_file);
76 explicit DownloadDb(Filename &server_file, Filename &client_file);
78
79 void output(std::ostream &out) const;
80 void write(std::ostream &out) const;
81 void write_version_map(std::ostream &out) const;
82
83 // Write a database file
84 bool write_client_db(Filename &file);
85 bool write_server_db(Filename &file);
86
87 INLINE int get_client_num_multifiles() const;
88 INLINE int get_server_num_multifiles() const;
89
90 INLINE std::string get_client_multifile_name(int index) const;
91 INLINE std::string get_server_multifile_name(int index) const;
92
93 INLINE int get_client_multifile_size(std::string mfname) const;
94 INLINE void set_client_multifile_size(std::string mfname, int size);
95 INLINE int set_client_multifile_delta_size(std::string mfname, int size);
96 INLINE int get_server_multifile_size(std::string mfname) const;
97 INLINE void set_server_multifile_size(std::string mfname, int size);
98
99 INLINE Phase get_client_multifile_phase(std::string mfname) const;
100 INLINE Phase get_server_multifile_phase(std::string mfname) const;
101
102 INLINE void set_client_multifile_incomplete(std::string mfname);
103 INLINE void set_client_multifile_complete(std::string mfname);
104 INLINE void set_client_multifile_decompressed(std::string mfname);
105 INLINE void set_client_multifile_extracted(std::string mfname);
106
107 INLINE int get_server_num_files(std::string mfname) const;
108 INLINE std::string get_server_file_name(std::string mfname, int index) const;
109
110 // Queries from the Launcher
111 bool client_multifile_exists(std::string mfname) const;
112 bool client_multifile_complete(std::string mfname) const;
113 bool client_multifile_decompressed(std::string mfname) const;
114 bool client_multifile_extracted(std::string mfname) const;
115
116 // Ask what version (told with the hash) this multifile is
117 HashVal get_client_multifile_hash(std::string mfname) const;
118 void set_client_multifile_hash(std::string mfname, HashVal val);
119 HashVal get_server_multifile_hash(std::string mfname) const;
120 void set_server_multifile_hash(std::string mfname, HashVal val);
121
122 // Operations on multifiles
123 void delete_client_multifile(std::string mfname);
124 void add_client_multifile(std::string server_mfname);
125 void expand_client_multifile(std::string mfname);
126
127 // Server side operations to create multifile records
128 void create_new_server_db();
129 void server_add_multifile(std::string mfname, Phase phase, int size, int status);
130 void server_add_file(std::string mfname, std::string fname);
131
132public:
133
134 class EXPCL_PANDA_DOWNLOADER FileRecord : public ReferenceCount {
135 public:
136 FileRecord();
137 FileRecord(std::string name);
138 void write(std::ostream &out) const;
139 std::string _name;
140 };
141
142 typedef pvector< PT(FileRecord) > FileRecords;
143
144 class EXPCL_PANDA_DOWNLOADER MultifileRecord : public ReferenceCount {
145 public:
147 MultifileRecord(std::string name, Phase phase, int size, int status);
148 void write(std::ostream &out) const;
149 int get_num_files() const;
150 std::string get_file_name(int index) const;
151 bool file_exists(std::string fname) const;
152 PT(FileRecord) get_file_record_named(std::string fname) const;
153 void add_file_record(PT(FileRecord) fr);
154 std::string _name;
155 Phase _phase;
156 int _size;
157 int _status;
158 HashVal _hash;
159 int32_t _num_files;
160 FileRecords _file_records;
161 };
162
164
165 class EXPCL_PANDA_DOWNLOADER Db {
166 public:
167 Db();
168 void write(std::ostream &out) const;
169 int get_num_multifiles() const;
170 std::string get_multifile_name(int index) const;
171 bool multifile_exists(std::string mfname) const;
172 PT(MultifileRecord) get_multifile_record_named(std::string mfname) const;
173 void add_multifile_record(PT(MultifileRecord) mfr);
174 int parse_header(Datagram dg);
175 int parse_record_header(Datagram dg);
176 PT(MultifileRecord) parse_mfr(Datagram dg);
177 PT(FileRecord) parse_fr(Datagram dg);
178 bool read(StreamReader &sr, bool want_server_info);
179 bool write(StreamWriter &sw, bool want_server_info);
180 Filename _filename;
181 MultifileRecords _mfile_records;
182 bool write_header(std::ostream &write_stream);
183 bool write_bogus_header(StreamWriter &sw);
184 private:
185 int32_t _header_length;
186 };
187
188PUBLISHED:
189 Db read_db(Filename &file, bool want_server_info);
190 Db read_db(Ramfile &file, bool want_server_info);
191 bool write_db(Filename &file, Db db, bool want_server_info);
192
193public:
194 // The download db stores two databases, one that represents the client's
195 // state and one that represents the server state.
196 Db _client_db;
197 Db _server_db;
198
199 // Magic number for knowing this is a download Db
200 static uint32_t _magic_number;
201 static uint32_t _bogus_magic_number;
204
205PUBLISHED:
206 void add_version(const Filename &name, const HashVal &hash, int version);
207 void insert_new_version(const Filename &name, const HashVal &hash);
208 bool has_version(const Filename &name) const;
209 int get_num_versions(const Filename &name) const;
210 void set_num_versions(const Filename &name, int num_versions);
211
212 int get_version(const Filename &name, const HashVal &hash) const;
213 const HashVal &get_hash(const Filename &name, int version) const;
214
215protected:
216 void write_version_map(StreamWriter &sw);
217 bool read_version_map(StreamReader &sr);
218 VersionMap _versions;
219};
220
221INLINE std::ostream &operator << (std::ostream &out, const DownloadDb &dldb) {
222 dldb.output(out);
223 return out;
224}
225
226
227#include "downloadDb.I"
228
229#endif
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
A listing of files within multifiles for management of client-side synchronization with a server-prov...
Definition downloadDb.h:62
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
Stores a 128-bit value that represents the hashed contents (typically MD5) of a file or buffer.
Definition hashVal.h:31
An in-memory buffer specifically designed for downloading files to memory.
Definition ramfile.h:25
A base class for all things that want to be reference-counted.
A class to read sequential binary data directly from an istream.
A StreamWriter object is used to write sequential binary data directly to an ostream.
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.