blob: 199a8e2c4e9939fd25868c64ebce0e0cc9b5c823 [file] [log] [blame]
Alexander Afanasyev920af2f2014-01-25 22:56:11 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev635bf202017-03-09 21:57:34 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi1e46be32015-01-08 20:18:05 -07004 * 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 Afanasyev4a771362014-04-24 21:29:33 -070030#include <ndn-cxx/util/scheduler.hpp>
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080031
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080032namespace nfd {
Junxiao Shic041ca32014-02-25 20:01:15 -070033namespace scheduler {
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080034
Junxiao Shic041ca32014-02-25 20:01:15 -070035using ndn::Scheduler;
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080036
Junxiao Shic041ca32014-02-25 20:01:15 -070037/** \class EventId
38 * \brief Opaque type (shared_ptr) representing ID of a scheduled event
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080039 */
Junxiao Shic041ca32014-02-25 20:01:15 -070040using ndn::EventId;
41
Alexander Afanasyev635bf202017-03-09 21:57:34 +000042using ndn::util::scheduler::EventCallback;
43
Junxiao Shi98e29f42014-03-31 10:27:26 -070044/** \brief schedule an event
45 */
46EventId
Alexander Afanasyev635bf202017-03-09 21:57:34 +000047schedule(time::nanoseconds after, const EventCallback& event);
Junxiao Shic041ca32014-02-25 20:01:15 -070048
Junxiao Shi98e29f42014-03-31 10:27:26 -070049/** \brief cancel a scheduled event
50 */
51void
52cancel(const EventId& eventId);
53
Junxiao Shi27533da2014-12-15 10:56:20 -070054/** \brief cancels an event automatically upon destruction
55 */
56class ScopedEventId : noncopyable
57{
58public:
59 ScopedEventId();
60
61 /** \brief implicit constructor from EventId
62 * \param event the event to be cancelled upon destruction
63 */
64 ScopedEventId(const EventId& event);
65
66 /** \brief move constructor
67 */
68 ScopedEventId(ScopedEventId&& other);
69
70 /** \brief assigns an event
71 *
72 * If a different event has been assigned to this instance previously,
73 * that event will be cancelled immediately.
74 */
75 ScopedEventId&
76 operator=(const EventId& event);
77
78 /** \brief cancels the event
79 */
80 ~ScopedEventId();
81
82 /** \brief cancels the event manually
83 */
84 void
85 cancel();
86
87 /** \brief releases the event so that it won't be disconnected
88 * when this ScopedEventId is destructed
89 */
90 void
91 release();
92
93private:
94 EventId m_event;
95};
96
Junxiao Shi98e29f42014-03-31 10:27:26 -070097} // namespace scheduler
Junxiao Shic041ca32014-02-25 20:01:15 -070098
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080099} // namespace nfd
Alexander Afanasyev920af2f2014-01-25 22:56:11 -0800100
101#endif // NFD_CORE_SCHEDULER_HPP