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