Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 25 | |
| 26 | #ifndef NFD_CORE_SCHEDULER_HPP |
| 27 | #define NFD_CORE_SCHEDULER_HPP |
| 28 | |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 29 | #include "common.hpp" |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 30 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 31 | #include <ndn-cxx/util/scheduler.hpp> |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 33 | namespace nfd { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 34 | namespace scheduler { |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 35 | |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 36 | using ndn::Scheduler; |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 37 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 38 | /** \class nfd::scheduler::EventId |
| 39 | * \brief Opaque handle for a scheduled event. |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 40 | */ |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 41 | using ndn::EventId; |
| 42 | |
Alexander Afanasyev | 635bf20 | 2017-03-09 21:57:34 +0000 | [diff] [blame] | 43 | using ndn::util::scheduler::EventCallback; |
| 44 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 45 | /** \brief Schedule an event. |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 46 | */ |
| 47 | EventId |
Alexander Afanasyev | 635bf20 | 2017-03-09 21:57:34 +0000 | [diff] [blame] | 48 | schedule(time::nanoseconds after, const EventCallback& event); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 49 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 50 | /** \brief Cancel a scheduled event. |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 51 | */ |
| 52 | void |
| 53 | cancel(const EventId& eventId); |
| 54 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 55 | /** \brief Cancels an event automatically upon destruction. |
Junxiao Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 56 | */ |
| 57 | class ScopedEventId : noncopyable |
| 58 | { |
| 59 | public: |
| 60 | ScopedEventId(); |
| 61 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 62 | /** \brief Implicit constructor from EventId. |
Junxiao Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 63 | * \param event the event to be cancelled upon destruction |
| 64 | */ |
| 65 | ScopedEventId(const EventId& event); |
| 66 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 67 | /** \brief Move constructor. |
Junxiao Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 68 | */ |
| 69 | ScopedEventId(ScopedEventId&& other); |
| 70 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 71 | /** \brief Assigns an event. |
Junxiao Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 72 | * |
| 73 | * If a different event has been assigned to this instance previously, |
| 74 | * that event will be cancelled immediately. |
| 75 | */ |
| 76 | ScopedEventId& |
| 77 | operator=(const EventId& event); |
| 78 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 79 | /** \brief Cancels the event. |
Junxiao Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 80 | */ |
| 81 | ~ScopedEventId(); |
| 82 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 83 | /** \brief Cancels the event manually. |
Junxiao Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 84 | */ |
| 85 | void |
| 86 | cancel(); |
| 87 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 88 | /** \brief Releases the event so that it won't be cancelled when this ScopedEventId is destructed. |
Junxiao Shi | 27533da | 2014-12-15 10:56:20 -0700 | [diff] [blame] | 89 | */ |
| 90 | void |
| 91 | release(); |
| 92 | |
| 93 | private: |
| 94 | EventId m_event; |
| 95 | }; |
| 96 | |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 97 | } // namespace scheduler |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 98 | } // namespace nfd |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 99 | |
| 100 | #endif // NFD_CORE_SCHEDULER_HPP |