00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_X3D_LOAD_H
00021 #define ARCHON_X3D_LOAD_H
00022
00023 #include <string>
00024
00025 #include <archon/util/logger.H>
00026 #include <archon/util/web_client.H>
00027 #include <archon/util/job.H>
00028 #include <archon/util/image.H>
00029
00030 #include <archon/x3d/server/core.H>
00031 #include <archon/x3d/server/group.H>
00032
00033 namespace Archon
00034 {
00035 namespace X3D
00036 {
00037 using namespace std;
00038 using namespace Utilities;
00039
00040 struct Server;
00041 struct Scene;
00042
00071 struct Loader: virtual RefObjectBase
00072 {
00078 enum UriType
00079 {
00080 uriType_X3D,
00081 uriType_Image,
00082 uriType_Movie,
00083 uriType_Script
00084 };
00085
00090 struct Contents: virtual RefObjectBase
00091 {
00122 struct Id
00123 {
00124 Id(): id(0) {}
00125
00126 static Id next()
00127 {
00128 static unsigned long counter = 0;
00129 return Id(++counter);
00130 }
00131
00132 operator bool() { return id; }
00133 bool operator<(const Id &i) const { return id<i.id; }
00134
00135 private:
00136 Id(unsigned long id): id(id) {}
00137 unsigned long id;
00138 };
00139
00140 Contents(): id(Id::next()) {}
00141
00142 Id getId() const { return id; }
00143
00144 private:
00145 Id id;
00146 };
00147
00148 struct X3DContents: Contents
00149 {
00150 Ref<Scene> rootScene;
00151 X3DContents(Ref<Scene> rootScene): rootScene(rootScene) {}
00152 };
00153
00154 struct ImageContents: Contents
00155 {
00156 Image image;
00157 };
00158
00162 struct MovieContents: Contents
00163 {
00164 };
00165
00166 struct ScriptContents: Contents
00167 {
00168 string language;
00169 string sourceCode;
00170 string sourceName;
00171 int sourceLine;
00172 ScriptContents(string language, string sourceCode,
00173 string sourceName, int sourceLine):
00174 language(language), sourceCode(sourceCode),
00175 sourceName(sourceName), sourceLine(sourceLine) {}
00176 };
00177
00193 struct Job: Utilities::Job
00194 {
00199 Job(Ref<Loader>, Uri baseUri,
00200 const vector<string> &uriList, UriType uriType,
00201 Ref<AbstractFileServer> fileServer=0);
00202
00203 virtual ~Job();
00204
00209 bool isCompleted() { return completed; }
00210
00215 void wait();
00216
00221 void kill();
00222
00229 Ref<const Contents> getContents();
00230
00231 protected:
00236 virtual void onCompletion() {}
00237
00238 private:
00239 friend struct Loader;
00240
00241 Ref<const Contents> loadX3D(Ref<Stream::Reader>, string contentType,
00242 Uri sourceUri, int sourceLine, Logger *);
00243 Ref<const Contents> loadImage(Ref<Stream::Reader>, string contentType,
00244 Uri sourceUri, Logger *);
00245 Ref<const Contents> loadMovie(Ref<Stream::Reader>, string contentType,
00246 Uri sourceUri, Logger *);
00247 Ref<const Contents> loadScript(Ref<Stream::Reader>, string contentType,
00248 Uri sourceUri, int sourceLine, Logger *);
00249 Ref<const Contents> load(Ref<Stream::Reader>, string contentType,
00250 Uri sourceUri, int sourceLine, Logger *);
00251 void main();
00252
00253 Ref<Loader> loader;
00254 Ref<Web::Client> webClient;
00255 Uri baseUri;
00256 vector<string> uriList;
00257 UriType uriType;
00258 Ref<const Contents> contents;
00259 bool completed;
00260 Ref<AbstractFileServer> fileServer;
00261 };
00262
00263 ~Loader();
00264
00265 Loader(Ref<Server>, Ref<Web::Client>);
00266
00275 void submitJob(Ref<Job>);
00276
00277 const BackRef<Server> server;
00278
00279 Ref<Web::Client> getWebClient() const { return webClient; }
00280
00281 private:
00282 Logger *logger;
00283 Ref<Web::Client> webClient;
00284 Utilities::Job::Queue jobQueue;
00285
00290 map<string, Ref<const Contents> > cache;
00291
00292 Mutex mutex;
00293 Condition cacheChange;
00294 Condition jobCompletion;
00295 };
00296 }
00297 }
00298
00299 #endif // ARCHON_X3D_LOAD_H