A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
visual-simulator-impl.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 Gustavo Carneiro
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: Gustavo Carneiro <gjcarneiro@gmail.com> <gjc@inescporto.pt>
19
*/
20
#include <Python.h>
21
#include "
visual-simulator-impl.h
"
22
#include "ns3/default-simulator-impl.h"
23
#include "ns3/log.h"
24
25
NS_LOG_COMPONENT_DEFINE
(
"VisualSimulatorImpl"
);
26
27
namespace
ns3 {
28
29
30
31
NS_OBJECT_ENSURE_REGISTERED
(VisualSimulatorImpl);
32
33
namespace
34
{
35
ObjectFactory
36
GetDefaultSimulatorImplFactory
()
37
{
38
ObjectFactory
factory;
39
factory.
SetTypeId
(
DefaultSimulatorImpl::GetTypeId
());
40
return
factory;
41
}
42
}
43
44
45
TypeId
46
VisualSimulatorImpl::GetTypeId
(
void
)
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::VisualSimulatorImpl"
)
49
.
SetParent
<
SimulatorImpl
> ()
50
.AddConstructor<VisualSimulatorImpl> ()
51
.AddAttribute (
"SimulatorImplFactory"
,
52
"Factory for the underlying simulator implementation used by the visualizer."
,
53
ObjectFactoryValue
(
GetDefaultSimulatorImplFactory
()),
54
MakeObjectFactoryAccessor (&
VisualSimulatorImpl::m_simulatorImplFactory
),
55
MakeObjectFactoryChecker ())
56
;
57
return
tid;
58
}
59
60
61
VisualSimulatorImpl::VisualSimulatorImpl
()
62
{
63
}
64
65
VisualSimulatorImpl::~VisualSimulatorImpl
()
66
{
67
}
68
69
void
70
VisualSimulatorImpl::DoDispose
(
void
)
71
{
72
if
(
m_simulator
)
73
{
74
m_simulator
->
Dispose
();
75
m_simulator
= NULL;
76
}
77
SimulatorImpl::DoDispose
();
78
}
79
80
void
81
VisualSimulatorImpl::NotifyConstructionCompleted
()
82
{
83
m_simulator
=
m_simulatorImplFactory
.
Create
<
SimulatorImpl
> ();
84
}
85
86
87
void
88
VisualSimulatorImpl::Destroy
()
89
{
90
m_simulator
->
Destroy
();
91
}
92
93
void
94
VisualSimulatorImpl::SetScheduler
(
ObjectFactory
schedulerFactory)
95
{
96
m_simulator
->
SetScheduler
(schedulerFactory);
97
}
98
99
// System ID for non-distributed simulation is always zero
100
uint32_t
101
VisualSimulatorImpl::GetSystemId
(
void
)
const
102
{
103
return
m_simulator
->
GetSystemId
();
104
}
105
106
bool
107
VisualSimulatorImpl::IsFinished
(
void
)
const
108
{
109
return
m_simulator
->
IsFinished
();
110
}
111
112
void
113
VisualSimulatorImpl::Run
(
void
)
114
{
115
if
(!Py_IsInitialized ())
116
{
117
const
char
*argv[] = {
"python"
, NULL};
118
Py_Initialize ();
119
PySys_SetArgv (1, (
char
**) argv);
120
PyRun_SimpleString (
121
"import visualizer\n"
122
"visualizer.start();\n"
123
);
124
}
125
else
126
{
127
PyGILState_STATE __py_gil_state = PyGILState_Ensure ();
128
129
PyRun_SimpleString (
130
"import visualizer\n"
131
"visualizer.start();\n"
132
);
133
134
PyGILState_Release (__py_gil_state);
135
}
136
}
137
138
void
139
VisualSimulatorImpl::Stop
(
void
)
140
{
141
m_simulator
->
Stop
();
142
}
143
144
void
145
VisualSimulatorImpl::Stop
(
Time
const
&time)
146
{
147
m_simulator
->
Stop
(time);
148
}
149
150
//
151
// Schedule an event for a _relative_ time in the future.
152
//
153
EventId
154
VisualSimulatorImpl::Schedule
(
Time
const
&time,
EventImpl
*event)
155
{
156
return
m_simulator
->
Schedule
(time, event);
157
}
158
159
void
160
VisualSimulatorImpl::ScheduleWithContext
(uint32_t context,
Time
const
&time,
EventImpl
*event)
161
{
162
m_simulator
->
ScheduleWithContext
(context, time, event);
163
}
164
165
EventId
166
VisualSimulatorImpl::ScheduleNow
(
EventImpl
*event)
167
{
168
return
m_simulator
->
ScheduleNow
(event);
169
}
170
171
EventId
172
VisualSimulatorImpl::ScheduleDestroy
(
EventImpl
*event)
173
{
174
return
m_simulator
->
ScheduleDestroy
(event);
175
}
176
177
Time
178
VisualSimulatorImpl::Now
(
void
)
const
179
{
180
return
m_simulator
->
Now
();
181
}
182
183
Time
184
VisualSimulatorImpl::GetDelayLeft
(
const
EventId
&
id
)
const
185
{
186
return
m_simulator
->
GetDelayLeft
(
id
);
187
}
188
189
void
190
VisualSimulatorImpl::Remove
(
const
EventId
&
id
)
191
{
192
m_simulator
->
Remove
(
id
);
193
}
194
195
void
196
VisualSimulatorImpl::Cancel
(
const
EventId
&
id
)
197
{
198
m_simulator
->
Cancel
(
id
);
199
}
200
201
bool
202
VisualSimulatorImpl::IsExpired
(
const
EventId
&ev)
const
203
{
204
return
m_simulator
->
IsExpired
(ev);
205
}
206
207
Time
208
VisualSimulatorImpl::GetMaximumSimulationTime
(
void
)
const
209
{
210
return
m_simulator
->
GetMaximumSimulationTime
();
211
}
212
213
uint32_t
214
VisualSimulatorImpl::GetContext
(
void
)
const
215
{
216
return
m_simulator
->
GetContext
();
217
}
218
219
void
220
VisualSimulatorImpl::RunRealSimulator
(
void
)
221
{
222
m_simulator
->
Run
();
223
}
224
225
226
}
// namespace ns3
227
228
src
visualizer
model
visual-simulator-impl.cc
Generated on Fri Dec 21 2012 19:00:48 for ns-3 by
1.8.1.2