A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
synchronizer.cc
Go to the documentation of this file.
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 #include "synchronizer.h"
20 
21 namespace ns3 {
22 
23 NS_OBJECT_ENSURE_REGISTERED (Synchronizer);
24 
25 TypeId
27 {
28  static TypeId tid = TypeId ("ns3::Synchronizer")
29  .SetParent<Object> ()
30  ;
31  return tid;
32 }
33 
35  : m_realtimeOriginNano (0), m_simOriginNano (0)
36 {
37 }
38 
40 {
41 }
42 
43 bool
45 {
46  return DoRealtime ();
47 }
48 
49 uint64_t
51 {
53 }
54 
55 void
57 {
60 }
61 
62 uint64_t
64 {
66 }
67 
68 int64_t
70 {
71  int64_t tDrift = DoGetDrift (TimeStepToNanosecond (ts));
72 
73  if (tDrift < 0)
74  {
75  return -NanosecondToTimeStep (-tDrift);
76  } else {
77  return NanosecondToTimeStep (tDrift);
78  }
79 }
80 
81 bool
82 Synchronizer::Synchronize (uint64_t tsCurrent, uint64_t tsDelay)
83 {
84  return DoSynchronize (TimeStepToNanosecond (tsCurrent),
85  TimeStepToNanosecond (tsDelay));
86 }
87 
88 void
90 {
91  DoSignal ();
92 }
93 
94 void
96 {
97  DoSetCondition (cond);
98 }
99 
100 void
102 {
103  DoEventStart ();
104 }
105 
106 uint64_t
108 {
109  return NanosecondToTimeStep (DoEventEnd ());
110 }
111 
112 uint64_t
114 {
115  return TimeStep (ts).GetNanoSeconds ();
116 }
117 
118 uint64_t
120 {
121  return NanoSeconds (ns).GetTimeStep ();
122 }
123 
124 } // namespace ns3
125 
126