blob: 5bdcf223756cccf616fe8a2fd41c48ca89c0d17e [file] [log] [blame]
Alexander Afanasyev920af2f2014-01-25 22:56:11 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento1cb619e2018-04-10 17:13:53 -04002/*
3 * Copyright (c) 2014-2018, 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"
Davide Pesavento1cb619e2018-04-10 17:13:53 -040030
Alexander Afanasyev4a771362014-04-24 21:29:33 -070031#include <ndn-cxx/util/scheduler.hpp>
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 -070036using ndn::Scheduler;
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080037
Davide Pesavento1cb619e2018-04-10 17:13:53 -040038/** \class nfd::scheduler::EventId
39 * \brief Opaque handle for a scheduled event.
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080040 */
Junxiao Shic041ca32014-02-25 20:01:15 -070041using ndn::EventId;
42
Alexander Afanasyev635bf202017-03-09 21:57:34 +000043using ndn::util::scheduler::EventCallback;
44
Davide Pesavento1cb619e2018-04-10 17:13:53 -040045/** \brief Schedule an event.
Junxiao Shi98e29f42014-03-31 10:27:26 -070046 */
47EventId
Alexander Afanasyev635bf202017-03-09 21:57:34 +000048schedule(time::nanoseconds after, const EventCallback& event);
Junxiao Shic041ca32014-02-25 20:01:15 -070049
Davide Pesavento1cb619e2018-04-10 17:13:53 -040050/** \brief Cancel a scheduled event.
Junxiao Shi98e29f42014-03-31 10:27:26 -070051 */
52void
53cancel(const EventId& eventId);
54
Alexander Afanasyevbf9945d2014-11-14 17:11:41 -080055Scheduler&
56getGlobalScheduler();
57
Davide Pesavento1cb619e2018-04-10 17:13:53 -040058/** \brief Cancels an event automatically upon destruction.
Junxiao Shi27533da2014-12-15 10:56:20 -070059 */
60class ScopedEventId : noncopyable
61{
62public:
63 ScopedEventId();
64
Davide Pesavento1cb619e2018-04-10 17:13:53 -040065 /** \brief Implicit constructor from EventId.
Junxiao Shi27533da2014-12-15 10:56:20 -070066 * \param event the event to be cancelled upon destruction
67 */
68 ScopedEventId(const EventId& event);
69
Davide Pesavento1cb619e2018-04-10 17:13:53 -040070 /** \brief Move constructor.
Junxiao Shi27533da2014-12-15 10:56:20 -070071 */
72 ScopedEventId(ScopedEventId&& other);
73
Davide Pesavento1cb619e2018-04-10 17:13:53 -040074 /** \brief Assigns an event.
Junxiao Shi27533da2014-12-15 10:56:20 -070075 *
76 * If a different event has been assigned to this instance previously,
77 * that event will be cancelled immediately.
78 */
79 ScopedEventId&
80 operator=(const EventId& event);
81
Davide Pesavento1cb619e2018-04-10 17:13:53 -040082 /** \brief Cancels the event.
Junxiao Shi27533da2014-12-15 10:56:20 -070083 */
84 ~ScopedEventId();
85
Davide Pesavento1cb619e2018-04-10 17:13:53 -040086 /** \brief Cancels the event manually.
Junxiao Shi27533da2014-12-15 10:56:20 -070087 */
88 void
89 cancel();
90
Davide Pesavento1cb619e2018-04-10 17:13:53 -040091 /** \brief Releases the event so that it won't be cancelled when this ScopedEventId is destructed.
Junxiao Shi27533da2014-12-15 10:56:20 -070092 */
93 void
94 release();
95
96private:
97 EventId m_event;
98};
99
Junxiao Shi98e29f42014-03-31 10:27:26 -0700100} // namespace scheduler
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800101} // namespace nfd
Alexander Afanasyev920af2f2014-01-25 22:56:11 -0800102
103#endif // NFD_CORE_SCHEDULER_HPP