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
0e87ce46
Commit
0e87ce46
authored
Mar 05, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GlobalEvents: expose the internal class
Move the GlobalEvents::Monitor instance into class Instance. Eliminate all global variables.
parent
b4d594ee
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
58 deletions
+38
-58
GlobalEvents.cxx
src/GlobalEvents.cxx
+8
-40
GlobalEvents.hxx
src/GlobalEvents.hxx
+17
-5
Idle.cxx
src/Idle.cxx
+3
-2
Instance.hxx
src/Instance.hxx
+5
-1
Main.cxx
src/Main.cxx
+1
-5
Partition.cxx
src/Partition.cxx
+2
-2
PlaylistGlobal.cxx
src/PlaylistGlobal.cxx
+2
-3
No files found.
src/GlobalEvents.cxx
View file @
0e87ce46
...
@@ -19,35 +19,16 @@
...
@@ -19,35 +19,16 @@
#include "config.h"
#include "config.h"
#include "GlobalEvents.hxx"
#include "GlobalEvents.hxx"
#include "util/Manual.hxx"
#include "event/MaskMonitor.hxx"
#include <assert.h>
#include <assert.h>
namespace
GlobalEvents
{
inline
void
class
Monitor
final
:
public
MaskMonitor
{
GlobalEvents
::
Monitor
::
Invoke
(
Event
event
)
public
:
explicit
Monitor
(
EventLoop
&
_loop
)
:
MaskMonitor
(
_loop
)
{}
protected
:
virtual
void
HandleMask
(
unsigned
mask
)
override
;
};
static
Manual
<
Monitor
>
monitor
;
static
Handler
handlers
[
MAX
];
}
/**
* Invoke the callback for a certain event.
*/
static
void
InvokeGlobalEvent
(
GlobalEvents
::
Event
event
)
{
{
assert
((
unsigned
)
event
<
GlobalEvents
::
MAX
);
assert
((
unsigned
)
event
<
GlobalEvents
::
MAX
);
assert
(
GlobalEvents
::
handlers
[
event
]
!=
nullptr
);
assert
(
handlers
[
event
]
!=
nullptr
);
GlobalEvents
::
handlers
[
event
]();
handlers
[
event
]();
}
}
void
void
...
@@ -56,35 +37,22 @@ GlobalEvents::Monitor::HandleMask(unsigned f)
...
@@ -56,35 +37,22 @@ GlobalEvents::Monitor::HandleMask(unsigned f)
for
(
unsigned
i
=
0
;
i
<
MAX
;
++
i
)
for
(
unsigned
i
=
0
;
i
<
MAX
;
++
i
)
if
(
f
&
(
1u
<<
i
))
if
(
f
&
(
1u
<<
i
))
/* invoke the event handler */
/* invoke the event handler */
InvokeGlobalEvent
(
Event
(
i
));
Invoke
(
Event
(
i
));
}
void
GlobalEvents
::
Initialize
(
EventLoop
&
loop
)
{
monitor
.
Construct
(
loop
);
}
void
GlobalEvents
::
Deinitialize
()
{
monitor
.
Destruct
();
}
}
void
void
GlobalEvents
::
Register
(
Event
event
,
Handler
callback
)
GlobalEvents
::
Monitor
::
Register
(
Event
event
,
Handler
callback
)
{
{
assert
((
unsigned
)
event
<
MAX
);
assert
((
unsigned
)
event
<
MAX
);
assert
(
handlers
[
event
]
==
nullptr
);
handlers
[
event
]
=
callback
;
handlers
[
event
]
=
callback
;
}
}
void
void
GlobalEvents
::
Emit
(
Event
event
)
GlobalEvents
::
Monitor
::
Emit
(
Event
event
)
{
{
assert
((
unsigned
)
event
<
MAX
);
assert
((
unsigned
)
event
<
MAX
);
const
unsigned
mask
=
1u
<<
unsigned
(
event
);
const
unsigned
mask
=
1u
<<
unsigned
(
event
);
monitor
->
OrMask
(
mask
);
OrMask
(
mask
);
}
}
src/GlobalEvents.hxx
View file @
0e87ce46
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#ifndef MPD_GLOBAL_EVENTS_HXX
#ifndef MPD_GLOBAL_EVENTS_HXX
#define MPD_GLOBAL_EVENTS_HXX
#define MPD_GLOBAL_EVENTS_HXX
class
EventLoop
;
#include "event/MaskMonitor.hxx"
namespace
GlobalEvents
{
namespace
GlobalEvents
{
enum
Event
{
enum
Event
{
...
@@ -38,13 +38,25 @@ namespace GlobalEvents {
...
@@ -38,13 +38,25 @@ namespace GlobalEvents {
typedef
void
(
*
Handler
)();
typedef
void
(
*
Handler
)();
void
Initialize
(
EventLoop
&
loop
);
class
Monitor
final
:
MaskMonitor
{
Handler
handlers
[
MAX
];
void
Deinitialize
();
public
:
explicit
Monitor
(
EventLoop
&
_loop
)
:
MaskMonitor
(
_loop
)
{}
void
Register
(
Event
event
,
Handler
handler
);
void
Register
(
Event
event
,
Handler
handler
);
void
Emit
(
Event
event
);
void
Emit
(
Event
event
);
private
:
/**
* Invoke the callback for a certain event.
*/
void
Invoke
(
Event
event
);
protected
:
void
HandleMask
(
unsigned
mask
)
override
;
};
}
}
#endif
/* MAIN_NOTIFY_H */
#endif
/* MAIN_NOTIFY_H */
src/Idle.cxx
View file @
0e87ce46
...
@@ -24,7 +24,8 @@
...
@@ -24,7 +24,8 @@
#include "config.h"
#include "config.h"
#include "Idle.hxx"
#include "Idle.hxx"
#include "GlobalEvents.hxx"
#include "Main.hxx"
#include "Instance.hxx"
#include "util/ASCII.hxx"
#include "util/ASCII.hxx"
#include <atomic>
#include <atomic>
...
@@ -58,7 +59,7 @@ idle_add(unsigned flags)
...
@@ -58,7 +59,7 @@ idle_add(unsigned flags)
unsigned
old_flags
=
idle_flags
.
fetch_or
(
flags
);
unsigned
old_flags
=
idle_flags
.
fetch_or
(
flags
);
if
((
old_flags
&
flags
)
!=
flags
)
if
((
old_flags
&
flags
)
!=
flags
)
GlobalEvents
::
Emit
(
GlobalEvents
::
IDLE
);
instance
->
global_events
.
Emit
(
GlobalEvents
::
IDLE
);
}
}
unsigned
unsigned
...
...
src/Instance.hxx
View file @
0e87ce46
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include "check.h"
#include "check.h"
#include "event/Loop.hxx"
#include "event/Loop.hxx"
#include "GlobalEvents.hxx"
#include "Compiler.h"
#include "Compiler.h"
#ifdef ENABLE_NEIGHBOR_PLUGINS
#ifdef ENABLE_NEIGHBOR_PLUGINS
...
@@ -36,7 +37,6 @@ class Storage;
...
@@ -36,7 +37,6 @@ class Storage;
class
UpdateService
;
class
UpdateService
;
#endif
#endif
class
EventLoop
;
class
Error
;
class
Error
;
class
ClientList
;
class
ClientList
;
struct
Partition
;
struct
Partition
;
...
@@ -57,6 +57,8 @@ struct Instance final
...
@@ -57,6 +57,8 @@ struct Instance final
{
{
EventLoop
event_loop
;
EventLoop
event_loop
;
GlobalEvents
::
Monitor
global_events
;
#ifdef ENABLE_NEIGHBOR_PLUGINS
#ifdef ENABLE_NEIGHBOR_PLUGINS
NeighborGlue
*
neighbors
;
NeighborGlue
*
neighbors
;
#endif
#endif
...
@@ -77,6 +79,8 @@ struct Instance final
...
@@ -77,6 +79,8 @@ struct Instance final
Partition
*
partition
;
Partition
*
partition
;
Instance
()
:
global_events
(
event_loop
)
{}
/**
/**
* Initiate shutdown. Wrapper for EventLoop::Break().
* Initiate shutdown. Wrapper for EventLoop::Break().
*/
*/
...
...
src/Main.cxx
View file @
0e87ce46
...
@@ -38,7 +38,6 @@
...
@@ -38,7 +38,6 @@
#include "Idle.hxx"
#include "Idle.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include "LogInit.hxx"
#include "LogInit.hxx"
#include "GlobalEvents.hxx"
#include "input/Init.hxx"
#include "input/Init.hxx"
#include "event/Loop.hxx"
#include "event/Loop.hxx"
#include "IOThread.hxx"
#include "IOThread.hxx"
...
@@ -520,8 +519,7 @@ static int mpd_main_after_fork(struct options options)
...
@@ -520,8 +519,7 @@ static int mpd_main_after_fork(struct options options)
try
{
try
{
Error
error
;
Error
error
;
GlobalEvents
::
Initialize
(
instance
->
event_loop
);
instance
->
global_events
.
Register
(
GlobalEvents
::
IDLE
,
idle_event_emitted
);
GlobalEvents
::
Register
(
GlobalEvents
::
IDLE
,
idle_event_emitted
);
if
(
!
ConfigureFS
(
error
))
{
if
(
!
ConfigureFS
(
error
))
{
LogError
(
error
);
LogError
(
error
);
...
@@ -689,8 +687,6 @@ try {
...
@@ -689,8 +687,6 @@ try {
sticker_global_finish
();
sticker_global_finish
();
#endif
#endif
GlobalEvents
::
Deinitialize
();
playlist_list_global_finish
();
playlist_list_global_finish
();
input_stream_global_finish
();
input_stream_global_finish
();
...
...
src/Partition.cxx
View file @
0e87ce46
...
@@ -67,13 +67,13 @@ Partition::SyncWithPlayer()
...
@@ -67,13 +67,13 @@ Partition::SyncWithPlayer()
void
void
Partition
::
OnPlayerSync
()
Partition
::
OnPlayerSync
()
{
{
GlobalEvents
::
Emit
(
GlobalEvents
::
PLAYLIST
);
instance
.
global_events
.
Emit
(
GlobalEvents
::
PLAYLIST
);
}
}
void
void
Partition
::
OnPlayerTagModified
()
Partition
::
OnPlayerTagModified
()
{
{
GlobalEvents
::
Emit
(
GlobalEvents
::
TAG
);
instance
.
global_events
.
Emit
(
GlobalEvents
::
TAG
);
}
}
void
void
...
...
src/PlaylistGlobal.cxx
View file @
0e87ce46
...
@@ -26,7 +26,6 @@
...
@@ -26,7 +26,6 @@
#include "PlaylistGlobal.hxx"
#include "PlaylistGlobal.hxx"
#include "Main.hxx"
#include "Main.hxx"
#include "Instance.hxx"
#include "Instance.hxx"
#include "GlobalEvents.hxx"
static
void
static
void
playlist_tag_event
(
void
)
playlist_tag_event
(
void
)
...
@@ -43,6 +42,6 @@ playlist_event(void)
...
@@ -43,6 +42,6 @@ playlist_event(void)
void
void
playlist_global_init
()
playlist_global_init
()
{
{
GlobalEvents
::
Register
(
GlobalEvents
::
TAG
,
playlist_tag_event
);
instance
->
global_events
.
Register
(
GlobalEvents
::
TAG
,
playlist_tag_event
);
GlobalEvents
::
Register
(
GlobalEvents
::
PLAYLIST
,
playlist_event
);
instance
->
global_events
.
Register
(
GlobalEvents
::
PLAYLIST
,
playlist_event
);
}
}
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