A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
model
list-scheduler.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2005 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
#include "
list-scheduler.h
"
22
#include "
event-impl.h
"
23
#include "
log.h
"
24
#include <utility>
25
#include <string>
26
#include "
assert.h
"
27
34
namespace
ns3
{
35
36
NS_LOG_COMPONENT_DEFINE
(
"ListScheduler"
);
37
38
NS_OBJECT_ENSURE_REGISTERED
(ListScheduler);
39
40
TypeId
41
ListScheduler::GetTypeId
(
void
)
42
{
43
static
TypeId
tid =
TypeId
(
"ns3::ListScheduler"
)
44
.
SetParent
<
Scheduler
> ()
45
.SetGroupName (
"Core"
)
46
.AddConstructor<
ListScheduler
> ()
47
;
48
return
tid;
49
}
50
51
ListScheduler::ListScheduler
()
52
{
53
NS_LOG_FUNCTION
(
this
);
54
}
55
ListScheduler::~ListScheduler
()
56
{
57
}
58
59
void
60
ListScheduler::Insert
(
const
Event
&ev)
61
{
62
NS_LOG_FUNCTION
(
this
<< &ev);
63
for
(
EventsI
i =
m_events
.begin (); i !=
m_events
.end (); i++)
64
{
65
if
(ev.
key
< i->key)
66
{
67
m_events
.insert (i, ev);
68
return
;
69
}
70
}
71
m_events
.push_back (ev);
72
}
73
bool
74
ListScheduler::IsEmpty
(
void
)
const
75
{
76
NS_LOG_FUNCTION
(
this
);
77
return
m_events
.empty ();
78
}
79
Scheduler::Event
80
ListScheduler::PeekNext
(
void
)
const
81
{
82
NS_LOG_FUNCTION
(
this
);
83
return
m_events
.front ();
84
}
85
86
Scheduler::Event
87
ListScheduler::RemoveNext
(
void
)
88
{
89
NS_LOG_FUNCTION
(
this
);
90
Event
next =
m_events
.front ();
91
m_events
.pop_front ();
92
return
next;
93
}
94
95
void
96
ListScheduler::Remove
(
const
Event
&ev)
97
{
98
NS_LOG_FUNCTION
(
this
<< &ev);
99
for
(
EventsI
i =
m_events
.begin (); i !=
m_events
.end (); i++)
100
{
101
if
(i->key.m_uid == ev.
key
.
m_uid
)
102
{
103
NS_ASSERT
(ev.
impl
== i->impl);
104
m_events
.erase (i);
105
return
;
106
}
107
}
108
NS_ASSERT
(
false
);
109
}
110
111
}
// namespace ns3
ns3::ListScheduler::IsEmpty
virtual bool IsEmpty(void) const
Test if the schedule is empty.
Definition:
list-scheduler.cc:74
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Definition:
log-macros-enabled.h:213
event-impl.h
ns3::EventImpl declarations.
ns3::ListScheduler::RemoveNext
virtual Scheduler::Event RemoveNext(void)
Remove the earliest event from the event list.
Definition:
list-scheduler.cc:87
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
ns3::Scheduler::Event::impl
EventImpl * impl
Pointer to the event implementation.
Definition:
scheduler.h:94
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition:
assert.h:67
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::ListScheduler::Insert
virtual void Insert(const Scheduler::Event &ev)
Insert a new Event in the schedule.
Definition:
list-scheduler.cc:60
list-scheduler.h
ns3::ListScheduler declaration.
ns3::Scheduler::Event::key
EventKey key
Key for sorting and ordering Events.
Definition:
scheduler.h:95
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Event unique id.
Definition:
scheduler.h:82
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::Scheduler
Maintain the event list.
Definition:
scheduler.h:66
ns3::Scheduler::Event
Scheduler event.
Definition:
scheduler.h:92
ns3::ListScheduler::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition:
list-scheduler.cc:41
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ListScheduler::~ListScheduler
virtual ~ListScheduler()
Destructor.
Definition:
list-scheduler.cc:55
ns3::ListScheduler::PeekNext
virtual Scheduler::Event PeekNext(void) const
Get a pointer to the next event.
Definition:
list-scheduler.cc:80
ns3::ListScheduler::Remove
virtual void Remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
Definition:
list-scheduler.cc:96
ns3::ListScheduler::m_events
Events m_events
The event list.
Definition:
list-scheduler.h:74
ns3::ListScheduler::EventsI
std::list< Scheduler::Event >::iterator EventsI
Events iterator.
Definition:
list-scheduler.h:71
log.h
Debug message logging.
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:58
ns3::ListScheduler
a std::list event scheduler
Definition:
list-scheduler.h:46
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:915
ns3::ListScheduler::ListScheduler
ListScheduler()
Constructor.
Definition:
list-scheduler.cc:51
Generated on Wed Nov 7 2018 10:01:49 for ns-3 by
1.8.14