00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 }