A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
default-simulator-impl.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef DEFAULT_SIMULATOR_IMPL_H
22 #define DEFAULT_SIMULATOR_IMPL_H
23 
24 #include "simulator-impl.h"
25 #include "scheduler.h"
26 #include "event-impl.h"
27 #include "system-thread.h"
28 #include "ns3/system-mutex.h"
29 
30 #include "ptr.h"
31 
32 #include <list>
33 
34 namespace ns3 {
35 
37 {
38 public:
39  static TypeId GetTypeId (void);
40 
43 
44  virtual void Destroy ();
45  virtual bool IsFinished (void) const;
46  virtual void Stop (void);
47  virtual void Stop (Time const &time);
48  virtual EventId Schedule (Time const &time, EventImpl *event);
49  virtual void ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event);
50  virtual EventId ScheduleNow (EventImpl *event);
51  virtual EventId ScheduleDestroy (EventImpl *event);
52  virtual void Remove (const EventId &ev);
53  virtual void Cancel (const EventId &ev);
54  virtual bool IsExpired (const EventId &ev) const;
55  virtual void Run (void);
56  virtual Time Now (void) const;
57  virtual Time GetDelayLeft (const EventId &id) const;
58  virtual Time GetMaximumSimulationTime (void) const;
59  virtual void SetScheduler (ObjectFactory schedulerFactory);
60  virtual uint32_t GetSystemId (void) const;
61  virtual uint32_t GetContext (void) const;
62 
63 private:
64  virtual void DoDispose (void);
65  void ProcessOneEvent (void);
66  void ProcessEventsWithContext (void);
67 
69  uint32_t context;
70  uint64_t timestamp;
71  EventImpl *event;
72  };
73  typedef std::list<struct EventWithContext> EventsWithContext;
74  EventsWithContext m_eventsWithContext;
75  bool m_eventsWithContextEmpty;
76  SystemMutex m_eventsWithContextMutex;
77 
78  typedef std::list<EventId> DestroyEvents;
79  DestroyEvents m_destroyEvents;
80  bool m_stop;
81  Ptr<Scheduler> m_events;
82 
83  uint32_t m_uid;
84  uint32_t m_currentUid;
85  uint64_t m_currentTs;
86  uint32_t m_currentContext;
87  // number of events that have been inserted but not yet scheduled,
88  // not counting the "destroy" events; this is used for validation
89  int m_unscheduledEvents;
90 
91  SystemThread::ThreadId m_main;
92 };
93 
94 } // namespace ns3
95 
96 #endif /* DEFAULT_SIMULATOR_IMPL_H */
keep track of time unit.
Definition: nstime.h:149
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
virtual Time GetMaximumSimulationTime(void) const
virtual void SetScheduler(ObjectFactory schedulerFactory)
virtual EventId ScheduleNow(EventImpl *event)
virtual uint32_t GetSystemId(void) const
virtual void Remove(const EventId &ev)
virtual Time Now(void) const
virtual bool IsExpired(const EventId &ev) const
virtual Time GetDelayLeft(const EventId &id) const
virtual EventId ScheduleDestroy(EventImpl *event)
virtual void Cancel(const EventId &ev)
virtual uint32_t GetContext(void) const
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:50
virtual void ScheduleWithContext(uint32_t context, Time const &time, EventImpl *event)
virtual EventId Schedule(Time const &time, EventImpl *event)
instantiate subclasses of ns3::Object.
a simulation event
Definition: event-impl.h:39
virtual bool IsFinished(void) const
an identifier for simulation events.
Definition: event-id.h:46
a unique identifier for an interface.
Definition: type-id.h:44