MPD  0.20.18
IdleMonitor.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_SOCKET_IDLE_MONITOR_HXX
21 #define MPD_SOCKET_IDLE_MONITOR_HXX
22 
23 #include "check.h"
24 
25 class EventLoop;
26 
35 class IdleMonitor {
36  friend class EventLoop;
37 
38  EventLoop &loop;
39 
40  bool active;
41 
42 public:
44  :loop(_loop), active(false) {}
45 
47 #ifndef NDEBUG
48  /* this check is redundant, it is only here to avoid
49  the assertion in Cancel() */
50  if (IsActive())
51 #endif
52  Cancel();
53  }
54 
56  return loop;
57  }
58 
59  bool IsActive() const {
60  return active;
61  }
62 
63  void Schedule();
64  void Cancel();
65 
66 protected:
67  virtual void OnIdle() = 0;
68 
69 private:
70  void Run();
71 };
72 
73 #endif /* MAIN_NOTIFY_H */
virtual void OnIdle()=0
IdleMonitor(EventLoop &_loop)
Definition: IdleMonitor.hxx:43
An event that runs when the EventLoop has become idle, before waiting for more events.
Definition: IdleMonitor.hxx:35
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:52
bool IsActive() const
Definition: IdleMonitor.hxx:59
void Run()
The main function of this class.
void Cancel()
EventLoop & GetEventLoop() const
Definition: IdleMonitor.hxx:55
void Schedule()