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
5ffb8299
Commit
5ffb8299
authored
Mar 10, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IdleMonitor: new class to replace GlobalEvents::IDLE
Use MaskMonitor to eliminate duplicate code.
parent
07add0bd
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
37 deletions
+60
-37
Makefile.am
Makefile.am
+1
-0
GlobalEvents.hxx
src/GlobalEvents.hxx
+0
-3
Idle.cxx
src/Idle.cxx
+1
-14
Idle.hxx
src/Idle.hxx
+0
-6
IdleMaskMonitor.hxx
src/IdleMaskMonitor.hxx
+44
-0
Instance.hxx
src/Instance.hxx
+9
-2
Main.cxx
src/Main.cxx
+5
-12
No files found.
Makefile.am
View file @
5ffb8299
...
...
@@ -95,6 +95,7 @@ libmpd_a_SOURCES = \
src/command/OtherCommands.cxx src/command/OtherCommands.hxx
\
src/command/CommandListBuilder.cxx src/command/CommandListBuilder.hxx
\
src/Idle.cxx src/Idle.hxx
\
src/IdleMaskMonitor.hxx
\
src/IdleFlags.cxx src/IdleFlags.hxx
\
src/decoder/DecoderError.cxx src/decoder/DecoderError.hxx
\
src/decoder/DecoderThread.cxx src/decoder/DecoderThread.hxx
\
...
...
src/GlobalEvents.hxx
View file @
5ffb8299
...
...
@@ -24,9 +24,6 @@
namespace
GlobalEvents
{
enum
Event
{
/** an idle event was emitted */
IDLE
,
/** must call playlist_sync() */
PLAYLIST
,
...
...
src/Idle.cxx
View file @
5ffb8299
...
...
@@ -27,25 +27,12 @@
#include "Main.hxx"
#include "Instance.hxx"
#include <atomic>
#include <assert.h>
static
std
::
atomic_uint
idle_flags
;
void
idle_add
(
unsigned
flags
)
{
assert
(
flags
!=
0
);
unsigned
old_flags
=
idle_flags
.
fetch_or
(
flags
);
if
((
old_flags
&
flags
)
!=
flags
)
instance
->
global_events
.
Emit
(
GlobalEvents
::
IDLE
);
}
unsigned
idle_get
(
void
)
{
return
idle_flags
.
exchange
(
0
);
instance
->
EmitIdle
(
flags
);
}
src/Idle.hxx
View file @
5ffb8299
...
...
@@ -34,10 +34,4 @@
void
idle_add
(
unsigned
flags
);
/**
* Atomically reads and resets the global idle flags value.
*/
unsigned
idle_get
();
#endif
src/IdleMaskMonitor.hxx
0 → 100644
View file @
5ffb8299
/*
* Copyright 2003-2016 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_IDLE_MONITOR_HXX
#define MPD_IDLE_MONITOR_HXX
#include "event/MaskMonitor.hxx"
class
IdleMaskMonitor
:
MaskMonitor
{
public
:
explicit
IdleMaskMonitor
(
EventLoop
&
_loop
)
:
MaskMonitor
(
_loop
)
{}
void
EmitIdle
(
unsigned
mask
)
{
OrMask
(
mask
);
}
protected
:
virtual
void
OnIdle
(
unsigned
mask
)
=
0
;
private
:
/* virtual methods from class MaskMonitor */
void
HandleMask
(
unsigned
mask
)
final
{
OnIdle
(
mask
);
}
};
#endif
src/Instance.hxx
View file @
5ffb8299
...
...
@@ -22,6 +22,7 @@
#include "check.h"
#include "event/Loop.hxx"
#include "IdleMaskMonitor.hxx"
#include "GlobalEvents.hxx"
#include "Compiler.h"
...
...
@@ -51,7 +52,8 @@ struct EventLoopHolder {
};
struct
Instance
final
:
EventLoopHolder
:
EventLoopHolder
,
IdleMaskMonitor
#if defined(ENABLE_DATABASE) || defined(ENABLE_NEIGHBOR_PLUGINS)
,
#endif
...
...
@@ -89,7 +91,9 @@ struct Instance final
StateFile
*
state_file
;
Instance
()
:
global_events
(
event_loop
)
{}
Instance
()
:
IdleMaskMonitor
(
event_loop
),
global_events
(
event_loop
)
{}
/**
* Initiate shutdown. Wrapper for EventLoop::Break().
...
...
@@ -129,6 +133,9 @@ private:
virtual
void
FoundNeighbor
(
const
NeighborInfo
&
info
)
override
;
virtual
void
LostNeighbor
(
const
NeighborInfo
&
info
)
override
;
#endif
/* virtual methods from class IdleMaskMonitor */
void
OnIdle
(
unsigned
mask
)
override
;
};
#endif
src/Main.cxx
View file @
5ffb8299
...
...
@@ -365,21 +365,16 @@ initialize_decoder_and_player(void)
buffered_before_play
);
}
/**
* Handler for GlobalEvents::IDLE.
*/
static
void
idle_event_emitted
(
void
)
void
Instance
::
OnIdle
(
unsigned
flags
)
{
/* send "idle" notifications to all subscribed
clients */
unsigned
flags
=
idle_get
();
if
(
flags
!=
0
)
instance
->
client_list
->
IdleAdd
(
flags
);
client_list
->
IdleAdd
(
flags
);
if
(
flags
&
(
IDLE_PLAYLIST
|
IDLE_PLAYER
|
IDLE_MIXER
|
IDLE_OUTPUT
)
&&
instance
->
state_file
!=
nullptr
)
instance
->
state_file
->
CheckModified
();
state_file
!=
nullptr
)
state_file
->
CheckModified
();
}
#ifndef ANDROID
...
...
@@ -517,8 +512,6 @@ static int mpd_main_after_fork(struct options options)
try
{
Error
error
;
instance
->
global_events
.
Register
(
GlobalEvents
::
IDLE
,
idle_event_emitted
);
if
(
!
ConfigureFS
(
error
))
{
LogError
(
error
);
return
EXIT_FAILURE
;
...
...
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