NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
scheduler.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
#include "common.hpp"
23
24
#include "
scheduler.hpp
"
25
26
namespace
ns3
{
27
29
30
template
<>
31
struct
EventMemberImplObjTraits<
std
::function<void()>> {
32
typedef
std::function<void()> T;
33
static
T&
34
GetReference(T& p)
35
{
36
return
p;
37
}
38
};
39
41
42
}
// namespace ns3
43
44
namespace
ndn
{
45
namespace
util {
46
namespace
scheduler {
47
48
struct
EventIdImpl
49
{
50
EventIdImpl
(
const
Scheduler::EventQueue::iterator
& event)
51
: m_event(event)
52
, m_isValid(true)
53
{
54
}
55
56
void
57
invalidate
()
58
{
59
m_isValid =
false
;
60
}
61
62
bool
63
isValid
()
const
64
{
65
return
m_isValid;
66
}
67
68
operator
const
Scheduler::EventQueue::iterator
&()
const
69
{
70
return
m_event;
71
}
72
73
void
74
reset
(
const
Scheduler::EventQueue::iterator
& newIterator)
75
{
76
m_event = newIterator;
77
m_isValid =
true
;
78
}
79
80
private
:
81
Scheduler::EventQueue::iterator
m_event;
82
bool
m_isValid;
83
};
84
85
Scheduler::EventInfo::EventInfo(
const
time::nanoseconds& after,
86
const
Event& event)
87
: m_scheduledTime(
time::steady_clock::now
() + after)
88
, m_event(event)
89
{
90
}
91
92
Scheduler::EventInfo::EventInfo(
const
time::steady_clock::TimePoint
& when,
93
const
EventInfo& previousEvent)
94
: m_scheduledTime(when)
95
, m_event(previousEvent.m_event)
96
, m_eventId(previousEvent.m_eventId)
97
{
98
}
99
100
time::nanoseconds
101
Scheduler::EventInfo::expiresFromNow()
const
102
{
103
time::steady_clock::TimePoint
now =
time::steady_clock::now
();
104
if
(now > m_scheduledTime)
105
return
time::seconds(0);
// event should be scheduled ASAP
106
else
107
return
m_scheduledTime - now;
108
}
109
110
111
Scheduler::Scheduler(boost::asio::io_service& ioService)
112
: m_scheduledEvent(m_events.end())
113
{
114
}
115
116
EventId
117
Scheduler::scheduleEvent
(
const
time::nanoseconds& after,
118
const
Event
& event)
119
{
120
ns3::EventId
id
= ns3::Simulator::Schedule(ns3::NanoSeconds(after.count()),
121
&std::function<
void
()>::operator(), event);
122
auto
id_ptr = std::make_shared<ns3::EventId>(id);
123
m_events.insert(id_ptr);
124
return
id_ptr;
125
}
126
127
void
128
Scheduler::cancelEvent
(
const
EventId
& eventId)
129
{
130
if
(eventId !=
nullptr
) {
131
ns3::Simulator::Remove(*eventId);
132
const_cast<
EventId
&
>
(eventId).reset();
133
m_events.erase(eventId);
134
}
135
}
136
137
void
138
Scheduler::cancelAllEvents
()
139
{
140
for
(
auto
i = m_events.begin(); i != m_events.end(); i++) {
141
if
((*i) !=
nullptr
) {
142
ns3::Simulator::Remove((**i));
143
const_cast<
EventId
&
>
(*i).reset();
144
}
145
}
146
m_events.clear();
147
}
148
149
}
// namespace scheduler
150
}
// namespace util
151
}
// namespace ndn
ndn::time::steady_clock::TimePoint
time_point TimePoint
Definition:
time.hpp:108
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::util::scheduler::EventIdImpl::invalidate
void invalidate()
Definition:
scheduler.cpp:57
ndn::util::scheduler::EventIdImpl::EventIdImpl
EventIdImpl(const Scheduler::EventQueue::iterator &event)
Definition:
scheduler.cpp:50
ndn::time::steady_clock::now
static time_point now() noexcept
Definition:
time.cpp:79
ndn::util::scheduler::Scheduler::Event
function< void()> Event
Definition:
scheduler.hpp:49
ndn::util::scheduler::EventIdImpl
Definition:
scheduler.cpp:48
std
STL namespace.
ndn::util::scheduler::Scheduler::scheduleEvent
EventId scheduleEvent(const time::nanoseconds &after, const Event &event)
Schedule one time event after the specified delay.
Definition:
scheduler.cpp:117
ndn::util::scheduler::Scheduler::cancelEvent
void cancelEvent(const EventId &eventId)
Cancel scheduled event.
Definition:
scheduler.cpp:128
nfd::scheduler::EventId
std::shared_ptr< ns3::EventId > EventId
Definition:
scheduler.hpp:39
ndn::util::scheduler::Scheduler::cancelAllEvents
void cancelAllEvents()
Cancel all scheduled events.
Definition:
scheduler.cpp:138
nfd::cs::iterator
Table::const_iterator iterator
Definition:
cs-internal.hpp:41
EventId
Private storage of information about the event.
Definition:
scheduler.hpp:36
ndn::util::scheduler::EventIdImpl::isValid
bool isValid() const
Definition:
scheduler.cpp:63
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
content-store-impl.cpp:38
scheduler.hpp
ndn::util::scheduler::EventIdImpl::reset
void reset(const Scheduler::EventQueue::iterator &newIterator)
Definition:
scheduler.cpp:74
ndnSIM
ndn-cxx
src
util
scheduler.cpp
Generated on Tue Feb 23 2016 22:18:44 for ndnSIM by
1.8.11