Alexander Afanasyev | 9a9952f | 2015-01-28 19:06:48 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #ifndef NDN_UTIL_SCHEDULER_SCOPED_EVENT_ID_HPP |
| 23 | #define NDN_UTIL_SCHEDULER_SCOPED_EVENT_ID_HPP |
| 24 | |
| 25 | #include "scheduler.hpp" |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace util { |
| 29 | namespace scheduler { |
| 30 | |
| 31 | /** \brief Event that is automatically cancelled upon destruction |
| 32 | */ |
| 33 | class ScopedEventId : noncopyable |
| 34 | { |
| 35 | public: |
| 36 | /** \brief Construct ScopedEventId tied to the specified scheduler |
| 37 | * \param scheduler Scheduler to which the event is tied. Behavior is undefined if |
| 38 | * scheduler is destructed before an uncanceled ScopedEventId. |
| 39 | */ |
| 40 | explicit |
| 41 | ScopedEventId(Scheduler& scheduler); |
| 42 | |
| 43 | /** \brief move constructor |
| 44 | */ |
| 45 | ScopedEventId(ScopedEventId&& other); |
| 46 | |
| 47 | /** \brief assigns an event |
| 48 | * |
| 49 | * If a different event has been assigned to this instance previously, |
| 50 | * that event will be cancelled immediately. |
| 51 | * |
| 52 | * \note The caller should ensure that ScopedEventId is tied to a correct scheduler. |
| 53 | * Behavior is undefined when assigning event scheduled in another scheduler instance. |
| 54 | */ |
| 55 | ScopedEventId& |
| 56 | operator=(const EventId& event); |
| 57 | |
| 58 | /** \brief cancels the event |
| 59 | */ |
| 60 | ~ScopedEventId(); |
| 61 | |
| 62 | /** \brief cancels the event manually |
| 63 | */ |
| 64 | void |
| 65 | cancel(); |
| 66 | |
| 67 | /** \brief releases the event so that it won't be canceled |
| 68 | * when this ScopedEventId is destructed |
| 69 | */ |
| 70 | void |
| 71 | release(); |
| 72 | |
| 73 | private: |
| 74 | Scheduler* m_scheduler; // pointer to allow move semantics |
| 75 | EventId m_event; |
| 76 | }; |
| 77 | |
| 78 | } // namespace scheduler |
| 79 | } // namespace util |
| 80 | } // namespace ndn |
| 81 | |
| 82 | #endif // NDN_UTIL_SCHEDULER_SCOPED_EVENT_ID_HPP |