00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005,2006 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef EVENT_IMPL_H 00021 #define EVENT_IMPL_H 00022 00023 #include <stdint.h> 00024 00025 namespace ns3 { 00026 00027 /** 00028 * \ingroup simulator 00029 * \brief a simulation event 00030 * 00031 * Each subclass of this base class represents a simulation event. The 00032 * EventImpl::Invoke method will be invoked by the simulation engine 00033 * when the time associated to this event expires. This class is 00034 * obviously (there are Ref and Unref methods) reference-counted and 00035 * most subclasses are usually created by one of the many Simulator::Schedule 00036 * methods. 00037 */ 00038 class EventImpl 00039 { 00040 public: 00041 EventImpl (); 00042 inline void Ref (void) const; 00043 inline void Unref (void) const; 00044 virtual ~EventImpl () = 0; 00045 /** 00046 * Called by the simulation engine to notify the event that it has expired. 00047 */ 00048 void Invoke (void); 00049 /** 00050 * Marks the event as 'canceled'. The event will not be removed from 00051 * the event list but the simulation engine will check its canceled status 00052 * before calling Invoke. 00053 */ 00054 void Cancel (void); 00055 /** 00056 * \returns true if the event has been canceled. 00057 * 00058 * Invoked by the simulation engine before calling Invoke. 00059 */ 00060 bool IsCancelled (void); 00061 00062 protected: 00063 virtual void Notify (void) = 0; 00064 00065 private: 00066 bool m_cancel; 00067 mutable uint32_t m_count; 00068 }; 00069 00070 }; // namespace ns3 00071 00072 namespace ns3 { 00073 00074 void 00075 EventImpl::Ref (void) const 00076 { 00077 m_count++; 00078 } 00079 00080 void 00081 EventImpl::Unref (void) const 00082 { 00083 uint32_t c; 00084 c = --m_count; 00085 if (c == 0) 00086 { 00087 delete this; 00088 } 00089 } 00090 00091 } // namespace ns3 00092 00093 #endif /* EVENT_IMPL_H */