context.H

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_PROXY_CONTEXT_H
00021 #define ARCHON_X3D_PROXY_CONTEXT_H
00022 
00023 #include <archon/util/uri.H>
00024 
00025 #include <archon/x3d/proxy/session.H>
00026 
00027 namespace Archon
00028 {
00029   namespace X3D
00030   {
00031     namespace Proxy
00032     {
00033       struct Session;
00034       struct NodeBase;
00035       struct Node;
00036       struct Group;
00037       struct Field;
00038 
00039       template<typename F> struct EventSource;
00040       template<typename F> struct EventTarget;
00041 
00042       struct ExecutionContext: virtual RefObjectBase
00043       {
00044         Ref<Session> getSession() const { return session; }
00045 
00046         Uri getBaseUri() const;
00047         Ref<Group> getRootGroup() const;
00048         void setRootGroup(Ref<Group>);
00049         Ref<Node> getNamedNode(string name) const;
00050         //Ref<GroupingNode> createGroupFromStream(Ref<Stream::Reader> r);
00051 
00052         ~ExecutionContext() { session->destroyContext(this); }
00053 
00054         template<typename F, typename G>
00055         void createRoute(EventSource<F> &s, EventTarget<G> &t)
00056         {
00057           route(s, t, false);
00058         }
00059 
00060         template<typename F, typename G>
00061         void removeRoute(EventSource<F> &s, EventTarget<G> &t)
00062         {
00063           route(s, t, true);
00064         }
00065 
00066       protected:
00067         friend struct NodeBase;
00068         friend struct Session;
00069 
00070         ExecutionContext(Session *s, unsigned long id):
00071           session(s), id(id), transCount(0) {}
00072 
00073         Ref<Session> session;
00074 
00075         unsigned long id;
00076         unsigned long transCount;
00077 
00078       private:
00079         template<typename T> static void checkDerivation(T *) {}
00080 
00081         template<typename F, typename G>
00082         void route(EventSource<F> &s, EventTarget<G> &t, bool destroy)
00083         {
00084           if(false) { F *p; checkDerivation<G>(p); }
00085           route(&s, &t, destroy);
00086         }
00087 
00088         template<typename C, typename D>
00089         void route(EventSource<SFNode<C> > &s, EventTarget<SFNode<D> > &t, bool destroy)
00090         {
00091           if(false) { C *p; checkDerivation<D>(p); }
00092           route(&s, &t, destroy);
00093         }
00094 
00095         template<typename C, typename D>
00096         void route(EventSource<MFNode<C> > &s, EventTarget<MFNode<D> > &t, bool destroy)
00097         {
00098           if(false) { C *p; checkDerivation<D>(p); }
00099           route(&s, &t, destroy);
00100         }
00101 
00102         void route(Field *s, Field *t, bool destroy);
00103       };
00104     }
00105   }
00106 }
00107 
00108 #endif // ARCHON_X3D_PROXY_CONTEXT_H

Generated on Sun Jul 30 22:55:42 2006 for Archon by  doxygen 1.4.4