NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
scheduler.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "scheduler.hpp"
27 
28 namespace ns3 {
29 
31 
32 template<>
33 struct EventMemberImplObjTraits<std::function<void()>> {
34  typedef std::function<void()> T;
35  static T&
36  GetReference(T& p)
37  {
38  return p;
39  }
40 };
41 
43 
44 } // namespace ns3
45 
46 namespace nfd {
47 namespace scheduler {
48 
49 EventId
50 schedule(const time::nanoseconds& after, const std::function<void()>& event)
51 {
52  ns3::EventId id = ns3::Simulator::Schedule(ns3::NanoSeconds(after.count()),
53  &std::function<void()>::operator(), event);
54  return std::make_shared<ns3::EventId>(id);
55 }
56 
57 void
58 cancel(const EventId& eventId)
59 {
60  if (eventId != nullptr) {
61  ns3::Simulator::Remove(*eventId);
62  const_cast<EventId&>(eventId).reset();
63  }
64 }
65 
66 ScopedEventId::ScopedEventId()
67 {
68 }
69 
70 ScopedEventId::ScopedEventId(const EventId& event)
71  : m_event(event)
72 {
73 }
74 
76  : m_event(other.m_event)
77 {
78  other.release();
79 }
80 
83 {
84  if (m_event != event) {
85  scheduler::cancel(m_event);
86  m_event = event;
87  }
88  return *this;
89 }
90 
92 {
93  scheduler::cancel(m_event);
94 }
95 
96 void
98 {
99  scheduler::cancel(m_event);
100 }
101 
102 void
104 {
105  m_event.reset();
106 }
107 
108 } // namespace scheduler
109 } // namespace nfd
void cancel()
cancels the event manually
Definition: scheduler.cpp:97
ScopedEventId & operator=(const EventId &event)
assigns an event
Definition: scheduler.cpp:82
void cancel(const EventId &eventId)
cancel a scheduled event
Definition: scheduler.cpp:58
~ScopedEventId()
cancels the event
Definition: scheduler.cpp:91
STL namespace.
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:39
Private storage of information about the event.
Definition: scheduler.hpp:36
void release()
releases the event so that it won&#39;t be disconnected when this ScopedEventId is destructed ...
Definition: scheduler.cpp:103
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
Copyright (c) 2011-2015 Regents of the University of California.
cancels an event automatically upon destruction
Definition: scheduler.hpp:53
EventId schedule(const time::nanoseconds &after, const std::function< void()> &event)
schedule an event
Definition: scheduler.cpp:50