00001 /* 00002 * This file is part of the "Archon" framework. 00003 * (http://files3d.sourceforge.net) 00004 * 00005 * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen. 00006 * 00007 * Permission to use, copy, modify, and distribute this software and 00008 * its documentation under the terms of the GNU General Public License is 00009 * hereby granted. No representations are made about the suitability of 00010 * this software for any purpose. It is provided "as is" without express 00011 * or implied warranty. See the GNU General Public License 00012 * (http://www.gnu.org/copyleft/gpl.html) for more details. 00013 * 00014 * The characters in this file are ISO8859-1 encoded. 00015 * 00016 * The documentation in this file is in "Doxygen" style 00017 * (http://www.doxygen.org). 00018 */ 00019 00020 #ifndef ARCHON_X3D_CONTEXT_H 00021 #define ARCHON_X3D_CONTEXT_H 00022 00029 #include <vector> 00030 #include <string> 00031 00032 #include <archon/util/ref.H> 00033 #include <archon/util/stream.H> 00034 #include <archon/util/uri.H> 00035 00036 #include <archon/x3d/server/exception.H> 00037 #include <archon/x3d/server/node.H> 00038 00039 namespace Archon 00040 { 00041 namespace X3D 00042 { 00043 using namespace std; 00044 using namespace Utilities; 00045 00046 struct Server; // "server.H" 00047 00048 struct FrameDrivenNode: virtual NodeBase 00049 { 00055 virtual void tick() = 0; 00056 00057 ~FrameDrivenNode(); 00058 00059 void onRealized(); 00060 }; 00061 00062 struct AbstractFileServer: virtual BackRefObjectBase 00063 { 00064 struct RequestException: Exception 00065 { 00066 RequestException(string l, string m): Exception(l, m) {} 00067 }; 00068 00072 virtual Ref<Stream::Reader> request(string path) 00073 throw(RequestException) = 0; 00074 00075 string getFileServerId() 00076 { 00077 return id; 00078 } 00079 00080 AbstractFileServer(): id(getNextId()) {} 00081 00082 private: 00083 string id; 00084 00085 static string getNextId(); 00086 }; 00087 00088 struct ExecutionContext: virtual BackRefObjectBase 00089 { 00090 virtual ~ExecutionContext(); 00091 00098 struct RealizedException: Exception 00099 { 00100 RealizedException(string l): Exception(l) {} 00101 }; 00102 00109 void realize(); 00110 00111 bool isRealized() const; 00112 00113 Uri getBaseUri() const; 00114 00115 Ref<NodeBase> lookupNode(string name) const; 00116 00121 void tick(); 00122 00123 const BackRef<Server> server; 00124 00129 const BackRef<AbstractFileServer> fileServer; 00130 00131 protected: 00136 ExecutionContext(Ref<Server>, Uri baseUri, 00137 Ref<AbstractFileServer> fileServer=0); 00138 00142 const Mutex contextMutex; 00143 00144 bool isRealizedNoLock() const { return realized; } 00145 00146 private: 00147 Uri baseUri; 00148 bool realized; 00149 00150 friend struct Route; 00158 Mutex routesMutex; 00159 list<Route *> routes; 00160 void add(Route *); 00161 void remove(Route *); 00162 00163 friend struct NodeBase; 00171 Mutex namedNodesMutex; 00172 map<string, NodeBase *> namedNodes; 00173 void changeNodeName(NodeBase *, string oldName, string newName) 00174 throw(NodeNameInUseException); 00175 00176 friend struct FrameDrivenNode; 00184 Mutex frameDrivenNodesMutex; 00185 list<FrameDrivenNode *> frameDrivenNodes; 00186 void addFrameDrivenNode(FrameDrivenNode *); 00187 void removeFrameDrivenNode(FrameDrivenNode *); 00188 }; 00189 } 00190 } 00191 00192 #endif // ARCHON_X3D_CONTEXT_H