00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef SST_CORE_CORE_EVENT_H
00013 #define SST_CORE_CORE_EVENT_H
00014
00015 #include <sst/core/sst_types.h>
00016 #include <sst/core/serialization.h>
00017
00018 #include <string>
00019
00020 #include <sst/core/activity.h>
00021
00022 namespace SST {
00023
00024 class Link;
00025
00026
00027
00028
00029
00030 class Event : public Activity {
00031 public:
00032
00033
00034 typedef std::pair<uint64_t, int> id_type;
00035
00036 static const id_type NO_ID;
00037
00038
00039 Event() : Activity() {
00040 setPriority(EVENTPRIORITY);
00041 #if __SST_DEBUG_EVENT_TRACKING__
00042 first_comp = "";
00043 last_comp = "";
00044 #endif
00045 }
00046 virtual ~Event() = 0;
00047
00048
00049 void execute(void);
00050
00051
00052 virtual Event* clone();
00053
00054
00055 inline void setDeliveryLink(LinkId_t id, Link *link) {
00056 link_id = id;
00057 delivery_link = link;
00058 }
00059
00060
00061 inline Link* getDeliveryLink() {
00062 return delivery_link;
00063 }
00064
00065
00066 inline void setRemoteEvent() {
00067 delivery_link = NULL;
00068 }
00069
00070
00071 inline LinkId_t getLinkId(void) const { return link_id; }
00072
00073
00074
00075 class HandlerBase {
00076 public:
00077
00078 virtual void operator()(Event*) = 0;
00079 virtual ~HandlerBase() {}
00080 };
00081
00082
00083
00084
00085
00086 template <typename classT, typename argT = void>
00087 class Handler : public HandlerBase {
00088 private:
00089 typedef void (classT::*PtrMember)(Event*, argT);
00090 classT* object;
00091 const PtrMember member;
00092 argT data;
00093
00094 public:
00095
00096
00097
00098
00099
00100 Handler( classT* const object, PtrMember member, argT data ) :
00101 object(object),
00102 member(member),
00103 data(data)
00104 {}
00105
00106 void operator()(Event* event) {
00107 (object->*member)(event,data);
00108 }
00109 };
00110
00111
00112
00113
00114
00115 template <typename classT>
00116 class Handler<classT, void> : public HandlerBase {
00117 private:
00118 typedef void (classT::*PtrMember)(Event*);
00119 const PtrMember member;
00120 classT* object;
00121
00122 public:
00123
00124
00125
00126
00127 Handler( classT* const object, PtrMember member ) :
00128 member(member),
00129 object(object)
00130 {}
00131
00132 void operator()(Event* event) {
00133 (object->*member)(event);
00134 }
00135 };
00136
00137
00138 virtual void print(const std::string& header, Output &out) const {
00139 out.output("%s Generic Event to be delivered at %" PRIu64 " with priority %d\n",
00140 header.c_str(), getDeliveryTime(), getPriority());
00141 }
00142
00143 #ifdef __SST_DEBUG_EVENT_TRACKING__
00144
00145 virtual void printTrackingInfo(const std::string& header, Output &out) const {
00146 out.output("%s Event first sent from: %s:%s (type: %s) and last received by %s:%s (type: %s)\n", header.c_str(),
00147 first_comp.c_str(),first_port.c_str(),first_type.c_str(),
00148 last_comp.c_str(),last_port.c_str(),last_type.c_str());
00149 }
00150
00151 const std::string& getFirstComponentName() { return first_comp; }
00152 const std::string& getFirstComponentType() { return first_type; }
00153 const std::string& getFirstPort() { return first_port; }
00154 const std::string& getLastComponentName() { return last_comp; }
00155 const std::string& getLastComponentType() { return last_type; }
00156 const std::string& getLastPort() { return last_port; }
00157
00158 void addSendComponent(const std::string& comp, const std::string& type, const std::string& port) {
00159 if ( first_comp == "" ) {
00160 first_comp = comp;
00161 first_type = type;
00162 first_port = port;
00163 }
00164 }
00165 void addRecvComponent(const std::string& comp, const std::string& type, const std::string& port) {
00166 last_comp = comp;
00167 last_type = type;
00168 last_port = port;
00169 }
00170
00171 #endif
00172
00173 protected:
00174
00175 Link* delivery_link;
00176
00177
00178
00179
00180 id_type generateUniqueId();
00181
00182 private:
00183 static uint64_t id_counter;
00184 LinkId_t link_id;
00185
00186 #ifdef __SST_DEBUG_EVENT_TRACKING__
00187 std::string first_comp;
00188 std::string first_type;
00189 std::string first_port;
00190 std::string last_comp;
00191 std::string last_type;
00192 std::string last_port;
00193 #endif
00194
00195 friend class boost::serialization::access;
00196 template<class Archive>
00197 void
00198 serialize(Archive & ar, const unsigned int version );
00199 };
00200
00201
00202
00203
00204
00205 class NullEvent : public Event {
00206 public:
00207 NullEvent() : Event() {}
00208 ~NullEvent() {}
00209
00210 void execute(void);
00211
00212 virtual void print(const std::string& header, Output &out) const {
00213 out.output("%s NullEvent to be delivered at %" PRIu64 " with priority %d\n",
00214 header.c_str(), getDeliveryTime(), getPriority());
00215 }
00216
00217 private:
00218 friend class boost::serialization::access;
00219 template<class Archive>
00220 void
00221 serialize(Archive & ar, const unsigned int version );
00222 };
00223 }
00224
00225 BOOST_CLASS_EXPORT_KEY(SST::Event)
00226 BOOST_CLASS_EXPORT_KEY(SST::NullEvent)
00227
00228 #endif // SST_CORE_EVENT_H