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
d3a479b7
Commit
d3a479b7
authored
Jan 10, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/TimeoutMonitor: wrapper for g_timeout_source_new()
parent
92fb0e82
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
153 additions
and
60 deletions
+153
-60
Makefile.am
Makefile.am
+1
-0
InotifyQueue.cxx
src/InotifyQueue.cxx
+3
-21
InotifyQueue.hxx
src/InotifyQueue.hxx
+5
-6
InotifyUpdate.cxx
src/InotifyUpdate.cxx
+2
-1
StateFile.cxx
src/StateFile.cxx
+5
-13
StateFile.hxx
src/StateFile.hxx
+4
-9
Loop.hxx
src/event/Loop.hxx
+8
-10
TimeoutMonitor.cxx
src/event/TimeoutMonitor.cxx
+65
-0
TimeoutMonitor.hxx
src/event/TimeoutMonitor.hxx
+60
-0
No files found.
Makefile.am
View file @
d3a479b7
...
...
@@ -354,6 +354,7 @@ libutil_a_SOURCES = \
libevent_a_SOURCES
=
\
src/event/WakeFD.cxx src/event/WakeFD.hxx
\
src/event/TimeoutMonitor.hxx src/event/TimeoutMonitor.cxx
\
src/event/Loop.hxx
# PCM library
...
...
src/InotifyQueue.cxx
View file @
d3a479b7
...
...
@@ -20,7 +20,6 @@
#include "config.h"
#include "InotifyQueue.hxx"
#include "UpdateGlue.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
#include <glib.h>
...
...
@@ -39,14 +38,8 @@ enum {
INOTIFY_UPDATE_DELAY_S
=
5
,
};
InotifyQueue
::~
InotifyQueue
()
{
if
(
source_id
!=
0
)
g_source_remove
(
source_id
);
}
inline
bool
InotifyQueue
::
Run
()
bool
InotifyQueue
::
OnTimeout
()
{
unsigned
id
;
...
...
@@ -64,17 +57,9 @@ InotifyQueue::Run()
}
/* done, remove the timer event by returning false */
source_id
=
0
;
return
false
;
}
gboolean
InotifyQueue
::
Run
(
gpointer
data
)
{
InotifyQueue
&
queue
=
*
(
InotifyQueue
*
)
data
;
return
queue
.
Run
();
}
static
bool
path_in
(
const
char
*
path
,
const
char
*
possible_parent
)
{
...
...
@@ -88,10 +73,7 @@ path_in(const char *path, const char *possible_parent)
void
InotifyQueue
::
Enqueue
(
const
char
*
uri_utf8
)
{
if
(
source_id
!=
0
)
g_source_remove
(
source_id
);
source_id
=
main_loop
->
AddTimeoutSeconds
(
INOTIFY_UPDATE_DELAY_S
,
Run
,
nullptr
);
ScheduleSeconds
(
INOTIFY_UPDATE_DELAY_S
);
for
(
auto
i
=
queue
.
begin
(),
end
=
queue
.
end
();
i
!=
end
;)
{
const
char
*
current_uri
=
i
->
c_str
();
...
...
src/InotifyQueue.hxx
View file @
d3a479b7
...
...
@@ -20,23 +20,22 @@
#ifndef MPD_INOTIFY_QUEUE_HXX
#define MPD_INOTIFY_QUEUE_HXX
#include <glib.h>
#include "event/TimeoutMonitor.hxx"
#include "gcc.h"
#include <list>
#include <string>
class
InotifyQueue
{
class
InotifyQueue
final
:
private
TimeoutMonitor
{
std
::
list
<
std
::
string
>
queue
;
guint
source_id
;
public
:
~
InotifyQueue
();
InotifyQueue
(
EventLoop
&
_loop
)
:
TimeoutMonitor
(
_loop
)
{}
void
Enqueue
(
const
char
*
uri_utf8
);
private
:
bool
Run
();
static
gboolean
Run
(
gpointer
ctx
);
virtual
bool
OnTimeout
()
override
;
};
#endif
src/InotifyUpdate.cxx
View file @
d3a479b7
...
...
@@ -22,6 +22,7 @@
#include "InotifySource.hxx"
#include "InotifyQueue.hxx"
#include "Mapper.hxx"
#include "Main.hxx"
extern
"C"
{
#include "path.h"
...
...
@@ -342,7 +343,7 @@ mpd_inotify_init(unsigned max_depth)
recursive_watch_subdirectories
(
&
inotify_root
,
path
,
0
);
inotify_queue
=
new
InotifyQueue
();
inotify_queue
=
new
InotifyQueue
(
*
main_loop
);
g_debug
(
"watching music directory"
);
}
...
...
src/StateFile.cxx
View file @
d3a479b7
...
...
@@ -35,17 +35,11 @@
#define G_LOG_DOMAIN "state_file"
StateFile
::
StateFile
(
const
char
*
_path
,
Partition
&
_partition
,
EventLoop
&
_loop
)
:
path
(
_path
),
partition
(
_partition
),
loop
(
_loop
),
source_id
(
0
),
:
TimeoutMonitor
(
_loop
),
path
(
_path
),
partition
(
_partition
),
prev_volume_version
(
0
),
prev_output_version
(
0
),
prev_playlist_version
(
0
)
{
source_id
=
loop
.
AddTimeoutSeconds
(
5
*
60
,
TimerCallback
,
this
);
}
StateFile
::~
StateFile
()
{
g_source_remove
(
source_id
);
ScheduleSeconds
(
5
*
60
);
}
void
...
...
@@ -120,11 +114,9 @@ StateFile::AutoWrite()
* This function is called every 5 minutes by the GLib main loop, and
* saves the state file.
*/
gboolean
StateFile
::
TimerCallback
(
gpointer
data
)
bool
StateFile
::
OnTimeout
(
)
{
StateFile
&
state_file
=
*
(
StateFile
*
)
data
;
state_file
.
AutoWrite
();
AutoWrite
();
return
true
;
}
src/StateFile.hxx
View file @
d3a479b7
...
...
@@ -20,21 +20,17 @@
#ifndef MPD_STATE_FILE_HXX
#define MPD_STATE_FILE_HXX
#include <glib.h>
#include "event/TimeoutMonitor.hxx"
#include "gcc.h"
#include <string>
struct
Partition
;
class
EventLoop
;
class
StateFile
{
class
StateFile
final
:
private
TimeoutMonitor
{
std
::
string
path
;
Partition
&
partition
;
EventLoop
&
loop
;
/** the GLib source id for the save timer */
guint
source_id
;
/**
* These version numbers determine whether we need to save the state
...
...
@@ -45,14 +41,13 @@ class StateFile {
public
:
StateFile
(
const
char
*
path
,
Partition
&
partition
,
EventLoop
&
loop
);
~
StateFile
();
void
Read
();
void
Write
();
void
AutoWrite
();
private
:
static
gboolean
TimerCallback
(
gpointer
data
)
;
virtual
bool
OnTimeout
()
override
;
};
#endif
/* STATE_FILE_H */
src/event/Loop.hxx
View file @
d3a479b7
...
...
@@ -64,22 +64,20 @@ public:
return
id
;
}
guint
AddTimeout
(
guint
interval_ms
,
GSourceFunc
function
,
gpointer
data
)
{
GSource
*
AddTimeout
(
guint
interval_ms
,
GSourceFunc
function
,
gpointer
data
)
{
GSource
*
source
=
g_timeout_source_new
(
interval_ms
);
g_source_set_callback
(
source
,
function
,
data
,
nullptr
);
guint
id
=
g_source_attach
(
source
,
GetContext
());
g_source_unref
(
source
);
return
id
;
g_source_attach
(
source
,
GetContext
());
return
source
;
}
guint
AddTimeoutSeconds
(
guint
interval_s
,
GSourceFunc
function
,
gpointer
data
)
{
GSource
*
AddTimeoutSeconds
(
guint
interval_s
,
GSourceFunc
function
,
gpointer
data
)
{
GSource
*
source
=
g_timeout_source_new_seconds
(
interval_s
);
g_source_set_callback
(
source
,
function
,
data
,
nullptr
);
guint
id
=
g_source_attach
(
source
,
GetContext
());
g_source_unref
(
source
);
return
id
;
g_source_attach
(
source
,
GetContext
());
return
source
;
}
};
...
...
src/event/TimeoutMonitor.cxx
0 → 100644
View file @
d3a479b7
/*
* 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 "TimeoutMonitor.hxx"
#include "Loop.hxx"
void
TimeoutMonitor
::
Cancel
()
{
if
(
source
!=
nullptr
)
{
g_source_destroy
(
source
);
g_source_unref
(
source
);
source
=
nullptr
;
}
}
void
TimeoutMonitor
::
Schedule
(
unsigned
ms
)
{
Cancel
();
source
=
loop
.
AddTimeout
(
ms
,
Callback
,
this
);
}
void
TimeoutMonitor
::
ScheduleSeconds
(
unsigned
s
)
{
Cancel
();
source
=
loop
.
AddTimeoutSeconds
(
s
,
Callback
,
this
);
}
bool
TimeoutMonitor
::
Run
()
{
bool
result
=
OnTimeout
();
if
(
!
result
&&
source
!=
nullptr
)
{
g_source_unref
(
source
);
source
=
nullptr
;
}
return
result
;
}
gboolean
TimeoutMonitor
::
Callback
(
gpointer
data
)
{
TimeoutMonitor
&
monitor
=
*
(
TimeoutMonitor
*
)
data
;
return
monitor
.
Run
();
}
src/event/TimeoutMonitor.hxx
0 → 100644
View file @
d3a479b7
/*
* 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_TIMEOUT_MONITOR_HXX
#define MPD_SOCKET_TIMEOUT_MONITOR_HXX
#include "check.h"
#include <glib.h>
class
EventLoop
;
class
TimeoutMonitor
{
EventLoop
&
loop
;
GSource
*
source
;
public
:
TimeoutMonitor
(
EventLoop
&
_loop
)
:
loop
(
_loop
),
source
(
nullptr
)
{}
~
TimeoutMonitor
()
{
Cancel
();
}
bool
IsActive
()
const
{
return
source
!=
nullptr
;
}
void
Schedule
(
unsigned
ms
);
void
ScheduleSeconds
(
unsigned
s
);
void
Cancel
();
protected
:
/**
* @return true reschedules the timeout again
*/
virtual
bool
OnTimeout
()
=
0
;
private
:
bool
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