blob: c2192f5f0b39df34e77a4b36c8c170b2adb0d675 [file] [log] [blame]
Alexander Afanasyev9a9952f2015-01-28 19:06:48 -08001/* -*- 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
27namespace ndn {
28namespace util {
29namespace scheduler {
30
31/** \brief Event that is automatically cancelled upon destruction
32 */
33class ScopedEventId : noncopyable
34{
35public:
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 */
Junxiao Shi88681402015-06-30 09:58:53 -070045 ScopedEventId(ScopedEventId&& other) noexcept;
Alexander Afanasyev9a9952f2015-01-28 19:06:48 -080046
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 */
Alexander Afanasyevce7b0622016-01-04 10:47:46 -080060 ~ScopedEventId() noexcept;
Alexander Afanasyev9a9952f2015-01-28 19:06:48 -080061
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
Alexander Afanasyevce7b0622016-01-04 10:47:46 -080071 release() noexcept;
Alexander Afanasyev9a9952f2015-01-28 19:06:48 -080072
73private:
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