• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/event.h

00001 // Copyright 2009-2010 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2009-2010, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
00011 
00012 
00013 #ifndef SST_CORE_EVENT_H
00014 #define SST_CORE_EVENT_H
00015 
00016 //#include <sst/core/eventFunctor.h>
00017 #include <sst/core/sst_types.h>
00018 #include <sst/core/debug.h>
00019 #include <sst/core/activity.h>
00020 
00021 namespace SST {
00022 
00023 class Link;
00024 
00025 class Event : public Activity {
00026 public:
00027     Event() : Activity() {
00028         setPriority(50);
00029     }
00030     virtual ~Event() = 0;
00031 
00032     void execute(void);
00033 
00034     inline void setDeliveryLink(LinkId_t id, Link *link) {
00035         link_id = id;
00036         delivery_link = link;
00037     }
00038 
00039     inline void setRemoteEvent() {
00040         delivery_link = NULL;
00041     }
00042 
00043     inline LinkId_t getLinkId(void) const { return link_id; }
00044 
00045 
00046     // Functor classes for Event handling
00047     class HandlerBase {
00048     public:
00049         virtual void operator()(Event*) = 0;
00050         virtual ~HandlerBase() {}
00051     };
00052     
00053 
00054     template <typename classT, typename argT = void>
00055     class Handler : public HandlerBase {
00056     private:
00057         typedef void (classT::*PtrMember)(Event*, argT);
00058         classT* object;
00059         const PtrMember member;
00060         argT data;
00061         
00062     public:
00063         Handler( classT* const object, PtrMember member, argT data ) :
00064             object(object),
00065             member(member),
00066             data(data)
00067         {}
00068 
00069             void operator()(Event* event) {
00070                 (object->*member)(event,data);
00071             }
00072     };
00073     
00074     template <typename classT>
00075     class Handler<classT, void> : public HandlerBase {
00076     private:
00077         typedef void (classT::*PtrMember)(Event*);
00078         const PtrMember member;
00079         classT* object;
00080         
00081     public:
00082         Handler( classT* const object, PtrMember member ) :
00083           member(member),
00084           object(object)
00085         {}
00086 
00087             void operator()(Event* event) {
00088                 (object->*member)(event);
00089             }
00090     };
00091     
00092 protected:
00093     Link* delivery_link;
00094     
00095 private:
00096     LinkId_t link_id;
00097 
00098     friend class boost::serialization::access;
00099     template<class Archive>
00100     void
00101     serialize(Archive & ar, const unsigned int version );
00102 };
00103 
00104 
00105 class NullEvent : public Event {
00106 public:
00107     NullEvent() : Event() {}
00108     ~NullEvent() {}
00109 
00110     void execute(void);
00111 
00112 private:
00113     friend class boost::serialization::access;
00114     template<class Archive>
00115     void
00116     serialize(Archive & ar, const unsigned int version );
00117 };
00118 }
00119 
00120 BOOST_CLASS_EXPORT_KEY(SST::Event)
00121 BOOST_CLASS_EXPORT_KEY(SST::NullEvent)
00122 
00123 #endif // SST_EVENT_H

Generated on Fri Oct 22 2010 11:02:13 for SST by  doxygen 1.7.1