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
c8b408be
Commit
c8b408be
authored
Jan 14, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InotifyQueue: convert to a class
parent
8e3982dd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
41 deletions
+45
-41
InotifyQueue.cxx
src/InotifyQueue.cxx
+25
-32
InotifyQueue.hxx
src/InotifyQueue.hxx
+16
-6
InotifyUpdate.cxx
src/InotifyUpdate.cxx
+4
-3
No files found.
src/InotifyQueue.cxx
View file @
c8b408be
...
...
@@ -23,9 +23,6 @@
#include "Main.hxx"
#include "event/Loop.hxx"
#include <list>
#include <string>
#include <glib.h>
#include <string.h>
...
...
@@ -42,28 +39,19 @@ enum {
INOTIFY_UPDATE_DELAY_S
=
5
,
};
static
std
::
list
<
std
::
string
>
inotify_queue
;
static
guint
queue_source_id
;
void
mpd_inotify_queue_init
(
void
)
InotifyQueue
::~
InotifyQueue
()
{
if
(
source_id
!=
0
)
g_source_remove
(
source_id
);
}
void
mpd_inotify_queue_finish
(
void
)
{
if
(
queue_source_id
!=
0
)
g_source_remove
(
queue_source_id
);
}
static
gboolean
mpd_inotify_run_update
(
G_GNUC_UNUSED
gpointer
data
)
inline
bool
InotifyQueue
::
Run
()
{
unsigned
id
;
while
(
!
inotify_
queue
.
empty
())
{
const
char
*
uri_utf8
=
inotify_
queue
.
front
().
c_str
();
while
(
!
queue
.
empty
())
{
const
char
*
uri_utf8
=
queue
.
front
().
c_str
();
id
=
update_enqueue
(
uri_utf8
,
false
);
if
(
id
==
0
)
...
...
@@ -72,14 +60,21 @@ mpd_inotify_run_update(G_GNUC_UNUSED gpointer data)
g_debug
(
"updating '%s' job=%u"
,
uri_utf8
,
id
);
inotify_
queue
.
pop_front
();
queue
.
pop_front
();
}
/* done, remove the timer event by returning false */
queue_
source_id
=
0
;
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
)
{
...
...
@@ -91,16 +86,14 @@ path_in(const char *path, const char *possible_parent)
}
void
mpd_inotify_e
nqueue
(
const
char
*
uri_utf8
)
InotifyQueue
::
E
nqueue
(
const
char
*
uri_utf8
)
{
if
(
queue_source_id
!=
0
)
g_source_remove
(
queue_source_id
);
queue_source_id
=
main_loop
->
AddTimeoutSeconds
(
INOTIFY_UPDATE_DELAY_S
,
mpd_inotify_run_update
,
nullptr
);
for
(
auto
i
=
inotify_queue
.
begin
(),
end
=
inotify_queue
.
end
();
i
!=
end
;)
{
if
(
source_id
!=
0
)
g_source_remove
(
source_id
);
source_id
=
main_loop
->
AddTimeoutSeconds
(
INOTIFY_UPDATE_DELAY_S
,
Run
,
nullptr
);
for
(
auto
i
=
queue
.
begin
(),
end
=
queue
.
end
();
i
!=
end
;)
{
const
char
*
current_uri
=
i
->
c_str
();
if
(
path_in
(
uri_utf8
,
current_uri
))
...
...
@@ -111,10 +104,10 @@ mpd_inotify_enqueue(const char *uri_utf8)
/* existing path is a sub-path of the new
path; we can dequeue the existing path and
update the new path instead */
i
=
inotify_
queue
.
erase
(
i
);
i
=
queue
.
erase
(
i
);
else
++
i
;
}
inotify_
queue
.
emplace_back
(
uri_utf8
);
queue
.
emplace_back
(
uri_utf8
);
}
src/InotifyQueue.hxx
View file @
c8b408be
...
...
@@ -20,13 +20,23 @@
#ifndef MPD_INOTIFY_QUEUE_HXX
#define MPD_INOTIFY_QUEUE_HXX
void
mpd_inotify_queue_init
(
void
);
#include <glib.h>
void
mpd_inotify_queue_finish
(
void
);
#include <list>
#include <string>
void
mpd_inotify_enqueue
(
const
char
*
uri_utf8
);
class
InotifyQueue
{
std
::
list
<
std
::
string
>
queue
;
guint
source_id
;
public
:
~
InotifyQueue
();
void
Enqueue
(
const
char
*
uri_utf8
);
private
:
bool
Run
();
static
gboolean
Run
(
gpointer
ctx
);
};
#endif
src/InotifyUpdate.cxx
View file @
c8b408be
...
...
@@ -57,6 +57,7 @@ struct watch_directory {
};
static
InotifySource
*
inotify_source
;
static
InotifyQueue
*
inotify_queue
;
static
unsigned
inotify_max_depth
;
static
struct
watch_directory
inotify_root
;
...
...
@@ -295,7 +296,7 @@ mpd_inotify_callback(int wd, unsigned mask,
:
g_strdup
(
""
);
if
(
uri_utf8
!=
NULL
)
{
mpd_inotify_e
nqueue
(
uri_utf8
);
inotify_queue
->
E
nqueue
(
uri_utf8
);
g_free
(
uri_utf8
);
}
}
...
...
@@ -341,7 +342,7 @@ mpd_inotify_init(unsigned max_depth)
recursive_watch_subdirectories
(
&
inotify_root
,
path
,
0
);
mpd_inotify_queue_init
();
inotify_queue
=
new
InotifyQueue
();
g_debug
(
"watching music directory"
);
}
...
...
@@ -367,7 +368,7 @@ mpd_inotify_finish(void)
if
(
inotify_source
==
NULL
)
return
;
mpd_inotify_queue_finish
()
;
delete
inotify_queue
;
delete
inotify_source
;
g_tree_foreach
(
inotify_directories
,
free_watch_directory
,
NULL
);
...
...
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