event_source.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/event.H>
00021 #include <archon/x3d/server/event_source.H>
00022 
00023 namespace Archon
00024 {
00025   using namespace Utilities;
00026 
00027   namespace X3D
00028   {
00029     bool EventSource::addRoute(const RouteTail *r)
00030     {
00031       Mutex::Lock l(mutex);
00032       list<Ref<const RouteTail> >::iterator i = routes.begin();
00033       while(i != routes.end())
00034       {
00035         if((*i)->match(r)) return false;
00036         ++i;
00037       }
00038       routes.push_back(r);
00039       return true;
00040     }
00041       
00042     void EventSource::delRoute(const RouteTail *r)
00043     {
00044       Mutex::Lock l(mutex);
00045       routes.remove(Ref<const RouteTail>(r));
00046     }
00047       
00048     bool EventSource::delRouteMatch(const RouteTail *r)
00049     {
00050       Mutex::Lock l(mutex);
00051       list<Ref<const RouteTail> >::iterator i = routes.begin();
00052       while(i != routes.end())
00053       {
00054         if((*i)->match(r))
00055         {
00056           routes.erase(i);
00057           return true;
00058         }
00059         ++i;
00060       }
00061       return false;
00062     }
00063 
00064     void EventSource::cascadeEvent(const Event *e) const
00065     {
00066       vector<Ref<const RouteTail> > r(routes.size());
00067       vector<Ref<const RouteTail> >::iterator i=r.begin();
00068       {
00069         Mutex::Lock l(mutex);
00070         list<Ref<const RouteTail> >::const_iterator j=routes.begin();
00071         while(j!=routes.end()) *i++ = *j++;
00072       }
00073       i=r.begin();
00074       while(i!=r.end()) (*i++)->cascadeEvent(e);
00075     }
00076 
00077     void EventSource::clear()
00078     {
00079       list<Ref<const RouteTail> > r;
00080       Mutex::Lock l(mutex);
00081       swap(routes, r);
00082     }
00083   }
00084 }

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