Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

SignalDispatcher.h

00001 #ifndef ERIS_SIGNAL_DISPATCH_H 00002 #define ERIS_SIGNAL_DISPATCH_H 00003 00004 #include <Eris/Dispatcher.h> 00005 00006 #include <Atlas/Message/Element.h> 00007 00008 #include <sigc++/object.h> 00009 #include <sigc++/signal.h> 00010 00011 namespace Eris { 00012 00013 template <class T> 00014 class SignalDispatcher : 00015 public LeafDispatcher, 00016 virtual public SigC::Object 00017 { 00018 public: 00019 SignalDispatcher(const std::string &nm, const SigC::Slot1<void, const T& > &slot) : 00020 LeafDispatcher(nm) 00021 { Signal.connect(slot); } 00022 00023 virtual ~SignalDispatcher() {;} 00024 00026 virtual bool dispatch(DispatchContextDeque &dq) 00027 { 00028 T object; 00029 Atlas::Message::Element::MapType::const_iterator I = dq.front().asMap().begin(); 00030 00031 for (; I != dq.front().asMap().end(); ++I) 00032 object.setAttr(I->first, I->second); 00033 Signal.emit(object); 00034 00035 return LeafDispatcher::dispatch(dq); 00036 } 00037 00039 SigC::Signal1<void, const T&> Signal; 00040 protected: 00041 00042 }; 00043 00044 class SignalDispatcher0 : 00045 public LeafDispatcher, 00046 virtual public SigC::Object 00047 { 00048 public: 00049 SignalDispatcher0(const std::string &nm, const SigC::Slot0<void> &slot) : 00050 LeafDispatcher(nm) 00051 { Signal.connect(slot); } 00052 00053 virtual ~SignalDispatcher0() {;} 00054 00056 virtual bool dispatch(DispatchContextDeque &dq) 00057 { 00058 Signal.emit(); 00059 return LeafDispatcher::dispatch(dq); 00060 } 00061 00063 SigC::Signal0<void> Signal; 00064 protected: 00065 00066 }; 00067 00068 template <class T, class S> 00069 class SignalDispatcher2 : 00070 public LeafDispatcher, 00071 virtual public SigC::Object 00072 { 00073 public: 00074 SignalDispatcher2(const std::string &nm, 00075 const SigC::Slot2<void, const T&, const S& > &slot) : 00076 LeafDispatcher(nm) 00077 { Signal.connect(slot); } 00078 00079 virtual ~SignalDispatcher2() {;} 00080 00082 virtual bool dispatch(DispatchContextDeque &dq) 00083 { 00084 DispatchContextDeque::iterator Q = dq.begin(); 00085 00086 S object; 00087 Atlas::Message::Element::MapType::const_iterator I = Q->asMap().begin(); 00088 00089 for (; I != Q->asMap().end(); ++I) 00090 object.setAttr(I->first, I->second); 00091 ++Q; 00092 T parent; 00093 I = Q->asMap().begin(); 00094 for (; I != Q->asMap().end(); ++I) 00095 parent.setAttr(I->first, I->second); 00096 00097 Signal.emit(parent, object); 00098 return LeafDispatcher::dispatch(dq); 00099 } 00100 00104 SigC::Signal2<void, const T&, const S&> Signal; 00105 protected: 00106 00107 }; 00108 00112 class MessageDispatcher : 00113 public Dispatcher, 00114 virtual public SigC::Object 00115 { 00116 public: 00120 MessageDispatcher(const std::string &nm, const SigC::Slot1<void, const Atlas::Message::Element&> &slot) : 00121 Dispatcher(nm) 00122 { Signal.connect(slot); } 00123 00124 virtual ~MessageDispatcher() {;} 00125 00126 virtual bool dispatch(DispatchContextDeque &dq) 00127 { 00128 Signal.emit(dq.front()); 00129 return false; 00130 } 00131 protected: 00132 SigC::Signal1<void, const Atlas::Message::Element&> Signal; 00133 }; 00134 00135 00136 } // of namespace 00137 00138 #endif

Generated on Thu Jul 29 08:12:34 2004 for Eris by doxygen 1.3.7