00001 #ifndef TRIGGER_H 00002 #define TRIGGER_H 00003 00029 #include <Logger.H> 00030 #include <Capability.H> 00031 #include <vector> 00032 #include <algorithm> 00033 00034 using namespace std; 00035 00036 namespace WURDE { 00037 00041 typedef enum { TRIGGER_TIMED, 00042 TRIGGER_DATA_AND, 00043 TRIGGER_DATA_OR 00044 } TriggerType; 00045 00051 class Trigger { 00052 public: 00053 Trigger(){}; 00054 Trigger(Capability *someObject){m_targets.push_back(someObject);} 00055 ~Trigger(){m_targets.clear();}; 00056 00057 bool add(Capability *someObject); 00058 bool activateObject(Capability *someObject); 00059 bool active(){return m_activated.size()==m_targets.size();}; 00060 void reset(){m_activated.clear(); m_lastActivation.now();}; 00061 void clear(){reset();m_targets.clear();}; 00062 00063 void setType(const TriggerType type){m_type=type;} 00064 const TriggerType getType(){return m_type;} 00065 00066 private: 00067 00068 TriggerType m_type; 00069 00070 Time m_length; 00071 Time m_lastActivation; 00072 00073 vector<Capability *> m_targets; 00074 vector<Capability *> m_activated; 00075 }; 00076 00077 00082 template < typename Type > 00083 class Callback : public Trigger { 00084 00085 public: 00086 void run(){Type();} 00087 00088 private: 00089 00090 }; 00091 00092 00093 } 00094 00095 #endif