A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
realtime-simulator-impl.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 University of Washington
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 
19 #ifndef REALTIME_SIMULATOR_IMPL_H
20 #define REALTIME_SIMULATOR_IMPL_H
21 
22 #include "simulator-impl.h"
23 #include "system-thread.h"
24 
25 #include "scheduler.h"
26 #include "synchronizer.h"
27 #include "event-impl.h"
28 
29 #include "ptr.h"
30 #include "assert.h"
31 #include "log.h"
32 #include "system-mutex.h"
33 
34 #include <list>
35 
36 namespace ns3 {
37 
39 {
40 public:
41  static TypeId GetTypeId (void);
42 
48  SYNC_BEST_EFFORT,
50  };
51 
54 
55  virtual void Destroy ();
56  virtual bool IsFinished (void) const;
57  virtual void Stop (void);
58  virtual void Stop (Time const &time);
59  virtual EventId Schedule (Time const &time, EventImpl *event);
60  virtual void ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event);
61  virtual EventId ScheduleNow (EventImpl *event);
62  virtual EventId ScheduleDestroy (EventImpl *event);
63  virtual void Remove (const EventId &ev);
64  virtual void Cancel (const EventId &ev);
65  virtual bool IsExpired (const EventId &ev) const;
66  virtual void Run (void);
67  virtual Time Now (void) const;
68  virtual Time GetDelayLeft (const EventId &id) const;
69  virtual Time GetMaximumSimulationTime (void) const;
70  virtual void SetScheduler (ObjectFactory schedulerFactory);
71  virtual uint32_t GetSystemId (void) const;
72  virtual uint32_t GetContext (void) const;
73 
74  void ScheduleRealtimeWithContext (uint32_t context, Time const &time, EventImpl *event);
75  void ScheduleRealtime (Time const &time, EventImpl *event);
76  void ScheduleRealtimeNowWithContext (uint32_t context, EventImpl *event);
77  void ScheduleRealtimeNow (EventImpl *event);
78  Time RealtimeNow (void) const;
79 
80  void SetSynchronizationMode (RealtimeSimulatorImpl::SynchronizationMode mode);
81  RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode (void) const;
82 
83  void SetHardLimit (Time limit);
84  Time GetHardLimit (void) const;
85 
86 private:
87  bool Running (void) const;
88  bool Realtime (void) const;
89  uint64_t NextTs (void) const;
90  void ProcessOneEvent (void);
91  virtual void DoDispose (void);
92 
93  typedef std::list<EventId> DestroyEvents;
94  DestroyEvents m_destroyEvents;
95  bool m_stop;
96  bool m_running;
97 
98  // The following variables are protected using the m_mutex
99  Ptr<Scheduler> m_events;
100  int m_unscheduledEvents;
101  uint32_t m_uid;
102  uint32_t m_currentUid;
103  uint64_t m_currentTs;
104  uint32_t m_currentContext;
105 
106  mutable SystemMutex m_mutex;
107 
108  Ptr<Synchronizer> m_synchronizer;
109 
114 
119 
120  SystemThread::ThreadId m_main;
121 };
122 
123 } // namespace ns3
124 
125 #endif /* REALTIME_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 EventId ScheduleNow(EventImpl *event)
virtual EventId Schedule(Time const &time, EventImpl *event)
virtual Time GetMaximumSimulationTime(void) const
SynchronizationMode m_synchronizationMode
virtual EventId ScheduleDestroy(EventImpl *event)
virtual void ScheduleWithContext(uint32_t context, Time const &time, EventImpl *event)
virtual Time Now(void) const
virtual void Remove(const EventId &ev)
virtual void Cancel(const EventId &ev)
virtual Time GetDelayLeft(const EventId &id) const
virtual uint32_t GetSystemId(void) const
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:50
virtual bool IsExpired(const EventId &ev) const
virtual void SetScheduler(ObjectFactory schedulerFactory)
instantiate subclasses of ns3::Object.
a simulation event
Definition: event-impl.h:39
an identifier for simulation events.
Definition: event-id.h:46
virtual uint32_t GetContext(void) const
virtual bool IsFinished(void) const
a unique identifier for an interface.
Definition: type-id.h:44