blob: 4ef124c617fcc93c912e9a4c8023162197463dbc [file] [log] [blame]
Alexander Afanasyev920af2f2014-01-25 22:56:11 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi27533da2014-12-15 10:56:20 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi27533da2014-12-15 10:56:20 -070024 */
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080025
26#ifndef NFD_CORE_SCHEDULER_HPP
27#define NFD_CORE_SCHEDULER_HPP
28
Junxiao Shi98e29f42014-03-31 10:27:26 -070029#include "common.hpp"
Alexander Afanasyev1de5da62014-11-14 17:11:41 -080030
31#include "ns3/simulator.h"
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080032
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080033namespace nfd {
Junxiao Shic041ca32014-02-25 20:01:15 -070034namespace scheduler {
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080035
Junxiao Shic041ca32014-02-25 20:01:15 -070036/** \class EventId
37 * \brief Opaque type (shared_ptr) representing ID of a scheduled event
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080038 */
Alexander Afanasyev1de5da62014-11-14 17:11:41 -080039typedef std::shared_ptr<ns3::EventId> EventId;
Junxiao Shic041ca32014-02-25 20:01:15 -070040
Junxiao Shi98e29f42014-03-31 10:27:26 -070041/** \brief schedule an event
42 */
43EventId
Alexander Afanasyev1de5da62014-11-14 17:11:41 -080044schedule(const time::nanoseconds& after, const std::function<void()>& event);
Junxiao Shic041ca32014-02-25 20:01:15 -070045
Junxiao Shi98e29f42014-03-31 10:27:26 -070046/** \brief cancel a scheduled event
47 */
48void
49cancel(const EventId& eventId);
50
Junxiao Shi27533da2014-12-15 10:56:20 -070051/** \brief cancels an event automatically upon destruction
52 */
53class ScopedEventId : noncopyable
54{
55public:
56 ScopedEventId();
57
58 /** \brief implicit constructor from EventId
59 * \param event the event to be cancelled upon destruction
60 */
61 ScopedEventId(const EventId& event);
62
63 /** \brief move constructor
64 */
65 ScopedEventId(ScopedEventId&& other);
66
67 /** \brief assigns an event
68 *
69 * If a different event has been assigned to this instance previously,
70 * that event will be cancelled immediately.
71 */
72 ScopedEventId&
73 operator=(const EventId& event);
74
75 /** \brief cancels the event
76 */
77 ~ScopedEventId();
78
79 /** \brief cancels the event manually
80 */
81 void
82 cancel();
83
84 /** \brief releases the event so that it won't be disconnected
85 * when this ScopedEventId is destructed
86 */
87 void
88 release();
89
90private:
91 EventId m_event;
92};
93
Junxiao Shi98e29f42014-03-31 10:27:26 -070094} // namespace scheduler
Junxiao Shic041ca32014-02-25 20:01:15 -070095
96using scheduler::EventId;
97
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080098} // namespace nfd
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080099
100#endif // NFD_CORE_SCHEDULER_HPP