00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 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_ID_H 00021 #define EVENT_ID_H 00022 00023 #include <stdint.h> 00024 #include "ns3/ptr.h" 00025 #include "event-impl.h" 00026 00027 namespace ns3 { 00028 00029 class EventImpl; 00030 00031 /** 00032 * \ingroup simulator 00033 * \brief an identifier for simulation events. 00034 * 00035 * Each EventId identifies a unique event scheduled with one 00036 * of the many Simulator::Schedule methods. This EventId can 00037 * be used to Cancel or Remove events after they are scheduled 00038 * with Simulator::Cancel or Simulator::Remove. 00039 * 00040 * The important thing to remember about this class is that 00041 * every variable of this type is _always_ in a valid state, 00042 * even when it has not been assigned an EventId coming from a Schedule 00043 * method: calling Cancel, IsRunning, IsExpired or passing around 00044 * instances of this object will not result in crashes or memory leaks. 00045 */ 00046 class EventId { 00047 public: 00048 EventId (); 00049 // internal. 00050 EventId (const Ptr<EventImpl> &impl, uint64_t ts, uint32_t uid); 00051 /** 00052 * This method is syntactic sugar for the ns3::Simulator::cancel 00053 * method. 00054 */ 00055 void Cancel (void); 00056 /** 00057 * This method is syntactic sugar for the ns3::Simulator::isExpired 00058 * method. 00059 * \returns true if the event has expired, false otherwise. 00060 */ 00061 bool IsExpired (void) const; 00062 /** 00063 * This method is syntactic sugar for the ns3::Simulator::isExpired 00064 * method. 00065 * \returns true if the event has not expired, false otherwise. 00066 */ 00067 bool IsRunning (void) const; 00068 public: 00069 /* The following methods are semi-private 00070 * they are supposed to be invoked only by 00071 * subclasses of the Scheduler base class. 00072 */ 00073 EventImpl *PeekEventImpl (void) const; 00074 uint64_t GetTs (void) const; 00075 uint32_t GetUid (void) const; 00076 private: 00077 friend bool operator == (const EventId &a, const EventId &b); 00078 Ptr<EventImpl> m_eventImpl; 00079 uint64_t m_ts; 00080 uint32_t m_uid; 00081 }; 00082 00083 bool operator == (const EventId &a, const EventId &b); 00084 bool operator != (const EventId &a, const EventId &b); 00085 00086 }; // namespace ns3 00087 00088 #endif /* EVENT_ID_H */