Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
cc511e7b
Commit
cc511e7b
authored
Aug 10, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/IdleMonitor: new monitor class
parent
bb2af791
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
0 deletions
+131
-0
Makefile.am
Makefile.am
+1
-0
IdleMonitor.cxx
src/event/IdleMonitor.cxx
+64
-0
IdleMonitor.hxx
src/event/IdleMonitor.hxx
+66
-0
No files found.
Makefile.am
View file @
cc511e7b
...
...
@@ -299,6 +299,7 @@ libevent_a_SOURCES = \
src/event/WakeFD.hxx
\
src/event/SignalMonitor.hxx src/event/SignalMonitor.cxx
\
src/event/TimeoutMonitor.hxx src/event/TimeoutMonitor.cxx
\
src/event/IdleMonitor.hxx src/event/IdleMonitor.cxx
\
src/event/DeferredMonitor.hxx src/event/DeferredMonitor.cxx
\
src/event/SocketMonitor.cxx src/event/SocketMonitor.hxx
\
src/event/BufferedSocket.cxx src/event/BufferedSocket.hxx
\
...
...
src/event/IdleMonitor.cxx
0 → 100644
View file @
cc511e7b
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "IdleMonitor.hxx"
#include "Loop.hxx"
void
IdleMonitor
::
Cancel
()
{
assert
(
loop
.
IsInside
());
if
(
!
IsActive
())
return
;
g_source_remove
(
source_id
);
source_id
=
0
;
}
void
IdleMonitor
::
Schedule
()
{
assert
(
loop
.
IsInside
());
if
(
IsActive
())
/* already scheduled */
return
;
source_id
=
loop
.
AddIdle
(
Callback
,
this
);
}
void
IdleMonitor
::
Run
()
{
assert
(
loop
.
IsInside
());
assert
(
source_id
!=
0
);
source_id
=
0
;
OnIdle
();
}
gboolean
IdleMonitor
::
Callback
(
gpointer
data
)
{
IdleMonitor
&
monitor
=
*
(
IdleMonitor
*
)
data
;
monitor
.
Run
();
return
false
;
}
src/event/IdleMonitor.hxx
0 → 100644
View file @
cc511e7b
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_SOCKET_IDLE_MONITOR_HXX
#define MPD_SOCKET_IDLE_MONITOR_HXX
#include "check.h"
#include <glib.h>
class
EventLoop
;
/**
* An event that runs when the EventLoop has become idle, before
* waiting for more events. This class is not thread-safe; all
* methods must be run from EventLoop's thread.
*/
class
IdleMonitor
{
EventLoop
&
loop
;
guint
source_id
;
public
:
IdleMonitor
(
EventLoop
&
_loop
)
:
loop
(
_loop
),
source_id
(
0
)
{}
~
IdleMonitor
()
{
Cancel
();
}
EventLoop
&
GetEventLoop
()
const
{
return
loop
;
}
bool
IsActive
()
const
{
return
source_id
!=
0
;
}
void
Schedule
();
void
Cancel
();
protected
:
virtual
void
OnIdle
()
=
0
;
private
:
void
Run
();
static
gboolean
Callback
(
gpointer
data
);
};
#endif
/* MAIN_NOTIFY_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment