route.C

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 #include <archon/x3d/server/scene.H>
00021 
00022 #include <archon/x3d/sai/route.H>
00023 
00024 namespace Archon
00025 {
00026   namespace X3D
00027   {
00028     namespace SAI
00029     {
00030       using namespace Utilities;
00031   
00032       void ExternalRoute::cascadeEvent(const Event *e) const
00033       {
00034         try { session->handleExternalEvent(e->value.get(), cookie); }
00035         catch(ForwardDestroyedException &) {}
00036       }
00037 
00038       void ExternalRoute::add(Ref<NodeBase> sourceNode, const FieldBase *sourceField,
00039                               Ref<Session> session, unsigned long cookie)
00040         throw(AccessException)
00041       {
00042         // Field input/output capabilities
00043         if(!sourceField->getIsEventSource()) ARCHON_THROW(AccessException);
00044 
00045         ExternalRoute *r =
00046           new ExternalRoute(sourceNode, sourceField, session, cookie);
00047         Ref<RouteTail> t(dynamic_cast<RouteTail *>(r));
00048         Ref<ExternalRouteHead> h(dynamic_cast<ExternalRouteHead *>(r));
00049         if(sourceField->addRoute(sourceNode.get(), t.get()))
00050           session->addRouteHead(h);
00051       }
00052 
00053       bool ExternalRoute::del(Ref<NodeBase> sourceNode, const FieldBase *sourceField,
00054                               Ref<Session> session, unsigned long cookie)
00055       {
00056         ExternalRoute r(sourceNode, sourceField, session, cookie);
00057         return sourceField->delRouteMatch(sourceNode.get(), &r);
00058       }
00059 
00060       void ExternalRoute::refDispose(Mutex::Lock &l)
00061       {
00062         if(getTailCountNoLock() == 0)
00063         {
00064           if(getHeadCountNoLock() == 0)
00065           {
00066             l.release();
00067             delete this;
00068             return;
00069           }
00070           Ref<ExternalRouteHead> h(this, RefNoLockTag());
00071           l.release();
00072           try
00073           {
00074             session->removeRouteHead(h);
00075           }
00076           catch(ForwardDestroyedException &) {}
00077           return;
00078         }
00079         Ref<RouteTail> t(this, RefNoLockTag());
00080         l.release();
00081         try
00082         {
00083           Ref<NodeBase> n = sourceNode.getRef();
00084           sourceField->delRoute(n.get(), t.get());
00085         }
00086         catch(ForwardDestroyedException &) {}
00087       }
00088 
00089       ExternalRoute::~ExternalRoute()
00090       {
00091       }
00092 
00093       ExternalRoute::ExternalRoute(Ref<NodeBase> sourceNode, const FieldBase *sourceField,
00094                                    Ref<Session> session, unsigned long cookie):
00095         RouteTail(sourceNode, sourceField),
00096         ExternalRouteHead(session, cookie)
00097       {
00098       }
00099 
00100       bool ExternalRoute::match(const RouteTail *r) const
00101       {
00102         const ExternalRoute *s = dynamic_cast<const ExternalRoute *>(r);
00103         return s && s->session == session &&
00104           s->cookie == cookie;
00105       }
00106     }
00107   }
00108 }

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