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