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
b2d3d15e
Commit
b2d3d15e
authored
Apr 17, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Main: move global variables to struct Instance
More preparations for multi-player support.
parent
08dfd263
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
149 additions
and
38 deletions
+149
-38
Makefile.am
Makefile.am
+1
-0
ClientNew.cxx
src/ClientNew.cxx
+5
-4
Instance.cxx
src/Instance.cxx
+48
-0
Instance.hxx
src/Instance.hxx
+54
-0
Listen.cxx
src/Listen.cxx
+2
-1
Main.cxx
src/Main.cxx
+19
-16
Main.hxx
src/Main.hxx
+2
-3
MessageCommands.cxx
src/MessageCommands.cxx
+3
-2
Partition.hxx
src/Partition.hxx
+7
-2
PlaylistGlobal.cxx
src/PlaylistGlobal.cxx
+3
-3
UpdateGlue.cxx
src/UpdateGlue.cxx
+3
-5
UpdateRemove.cxx
src/UpdateRemove.cxx
+2
-2
No files found.
Makefile.am
View file @
b2d3d15e
...
...
@@ -186,6 +186,7 @@ src_mpd_SOURCES = \
src/io_error.h
\
src/IOThread.cxx src/IOThread.hxx
\
src/Main.cxx src/Main.hxx
\
src/Instance.cxx src/Instance.hxx
\
src/Win32Main.cxx
\
src/GlobalEvents.cxx src/GlobalEvents.hxx
\
src/daemon.c
\
...
...
src/ClientNew.cxx
View file @
b2d3d15e
...
...
@@ -21,7 +21,7 @@
#include "ClientInternal.hxx"
#include "ClientList.hxx"
#include "Partition.hxx"
#include "
Main
.hxx"
#include "
Instance
.hxx"
#include "fd_util.h"
extern
"C"
{
#include "resolver.h"
...
...
@@ -95,7 +95,8 @@ client_new(EventLoop &loop, Partition &partition,
}
#endif
/* HAVE_WRAP */
if
(
client_list
->
IsFull
())
{
ClientList
&
client_list
=
*
partition
.
instance
.
client_list
;
if
(
client_list
.
IsFull
())
{
g_warning
(
"Max Connections Reached!"
);
close_socket
(
fd
);
return
;
...
...
@@ -106,7 +107,7 @@ client_new(EventLoop &loop, Partition &partition,
(
void
)
send
(
fd
,
GREETING
,
sizeof
(
GREETING
)
-
1
,
0
);
client_list
->
Add
(
*
client
);
client_list
.
Add
(
*
client
);
remote
=
sockaddr_to_string
(
sa
,
sa_length
,
NULL
);
g_log
(
G_LOG_DOMAIN
,
LOG_LEVEL_SECURE
,
...
...
@@ -117,7 +118,7 @@ client_new(EventLoop &loop, Partition &partition,
void
Client
::
Close
()
{
client_list
->
Remove
(
*
this
);
partition
.
instance
.
client_list
->
Remove
(
*
this
);
SetExpired
();
...
...
src/Instance.cxx
0 → 100644
View file @
b2d3d15e
/*
* 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 "Instance.hxx"
#include "Partition.hxx"
#include "Idle.hxx"
void
Instance
::
DeleteSong
(
const
song
&
song
)
{
partition
->
DeleteSong
(
song
);
}
void
Instance
::
DatabaseModified
()
{
partition
->
playlist
.
FullIncrementVersions
();
idle_add
(
IDLE_DATABASE
);
}
void
Instance
::
TagModified
()
{
partition
->
playlist
.
TagChanged
();
}
void
Instance
::
SyncWithPlayer
()
{
partition
->
playlist
.
SyncWithPlayer
(
partition
->
pc
);
}
src/Instance.hxx
0 → 100644
View file @
b2d3d15e
/*
* 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_INSTANCE_HXX
#define MPD_INSTANCE_HXX
#include "check.h"
class
ClientList
;
struct
Partition
;
struct
song
;
struct
Instance
{
ClientList
*
client_list
;
Partition
*
partition
;
void
DeleteSong
(
const
song
&
song
);
/**
* The database has been modified. Propagate the change to
* all subsystems.
*/
void
DatabaseModified
();
/**
* A tag in the play queue has been modified. Propagate the
* change to all subsystems.
*/
void
TagModified
();
/**
* Synchronize the player with the play queue.
*/
void
SyncWithPlayer
();
};
#endif
src/Listen.cxx
View file @
b2d3d15e
...
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "Listen.hxx"
#include "Main.hxx"
#include "Instance.hxx"
#include "Client.hxx"
#include "conf.h"
#include "event/ServerSocket.hxx"
...
...
@@ -43,7 +44,7 @@ public:
private
:
virtual
void
OnAccept
(
int
fd
,
const
sockaddr
&
address
,
size_t
address_length
,
int
uid
)
{
client_new
(
*
main_loop
,
*
global_
partition
,
client_new
(
*
main_loop
,
*
instance
->
partition
,
fd
,
&
address
,
address_length
,
uid
);
}
};
...
...
src/Main.cxx
View file @
b2d3d15e
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "Main.hxx"
#include "Instance.hxx"
#include "CommandLine.hxx"
#include "PlaylistFile.hxx"
#include "PlaylistGlobal.hxx"
...
...
@@ -97,9 +98,7 @@ enum {
GThread
*
main_task
;
EventLoop
*
main_loop
;
ClientList
*
client_list
;
Partition
*
global_partition
;
Instance
*
instance
;
static
StateFile
*
state_file
;
...
...
@@ -251,7 +250,7 @@ glue_state_file_init(GError **error_r)
}
state_file
=
new
StateFile
(
std
::
move
(
path_fs
),
path
,
*
global_
partition
,
*
main_loop
);
*
instance
->
partition
,
*
main_loop
);
g_free
(
path
);
state_file
->
Read
();
...
...
@@ -331,9 +330,10 @@ initialize_decoder_and_player(void)
config_get_positive
(
CONF_MAX_PLAYLIST_LENGTH
,
DEFAULT_PLAYLIST_MAX_LENGTH
);
global_partition
=
new
Partition
(
max_length
,
buffered_chunks
,
buffered_before_play
);
instance
->
partition
=
new
Partition
(
*
instance
,
max_length
,
buffered_chunks
,
buffered_before_play
);
}
/**
...
...
@@ -346,7 +346,7 @@ idle_event_emitted(void)
clients */
unsigned
flags
=
idle_get
();
if
(
flags
!=
0
)
client_list
->
IdleAdd
(
flags
);
instance
->
client_list
->
IdleAdd
(
flags
);
if
(
flags
&
(
IDLE_PLAYLIST
|
IDLE_PLAYER
|
IDLE_MIXER
|
IDLE_OUTPUT
))
state_file
->
CheckModified
();
...
...
@@ -421,8 +421,10 @@ int mpd_main(int argc, char *argv[])
main_task
=
g_thread_self
();
main_loop
=
new
EventLoop
(
EventLoop
::
Default
());
instance
=
new
Instance
();
const
unsigned
max_clients
=
config_get_positive
(
CONF_MAX_CONN
,
10
);
client_list
=
new
ClientList
(
max_clients
);
instance
->
client_list
=
new
ClientList
(
max_clients
);
success
=
listen_global_init
(
&
error
);
if
(
!
success
)
{
...
...
@@ -469,7 +471,7 @@ int mpd_main(int argc, char *argv[])
initialize_decoder_and_player
();
volume_init
();
initAudioConfig
();
audio_output_all_init
(
&
global_
partition
->
pc
);
audio_output_all_init
(
&
instance
->
partition
->
pc
);
client_manager_init
();
replay_gain_global_init
();
...
...
@@ -495,7 +497,7 @@ int mpd_main(int argc, char *argv[])
ZeroconfInit
(
*
main_loop
);
player_create
(
&
global_
partition
->
pc
);
player_create
(
&
instance
->
partition
->
pc
);
if
(
create_db
)
{
/* the database failed to load: recreate the
...
...
@@ -511,7 +513,7 @@ int mpd_main(int argc, char *argv[])
return
EXIT_FAILURE
;
}
audio_output_all_set_replay_gain_mode
(
replay_gain_get_real_mode
(
global_
partition
->
playlist
.
queue
.
random
));
audio_output_all_set_replay_gain_mode
(
replay_gain_get_real_mode
(
instance
->
partition
->
playlist
.
queue
.
random
));
success
=
config_get_bool
(
CONF_AUTO_UPDATE
,
false
);
#ifdef ENABLE_INOTIFY
...
...
@@ -527,7 +529,7 @@ int mpd_main(int argc, char *argv[])
/* enable all audio outputs (if not already done by
playlist_state_restore() */
global_
partition
->
pc
.
UpdateAudio
();
instance
->
partition
->
pc
.
UpdateAudio
();
#ifdef WIN32
win32_app_started
();
...
...
@@ -551,10 +553,10 @@ int mpd_main(int argc, char *argv[])
delete
state_file
;
}
global_
partition
->
pc
.
Kill
();
instance
->
partition
->
pc
.
Kill
();
ZeroconfDeinit
();
listen_global_finish
();
delete
client_list
;
delete
instance
->
client_list
;
start
=
clock
();
DatabaseGlobalDeinit
();
...
...
@@ -572,7 +574,7 @@ int mpd_main(int argc, char *argv[])
audio_output_all_finish
();
volume_finish
();
mapper_finish
();
delete
global_
partition
;
delete
instance
->
partition
;
command_finish
();
update_global_finish
();
decoder_plugin_deinit_all
();
...
...
@@ -582,6 +584,7 @@ int mpd_main(int argc, char *argv[])
config_global_finish
();
stats_global_finish
();
io_thread_deinit
();
delete
instance
;
delete
main_loop
;
daemonize_finish
();
#ifdef WIN32
...
...
src/Main.hxx
View file @
b2d3d15e
...
...
@@ -23,14 +23,13 @@
#include <glib.h>
class
EventLoop
;
struct
Instance
;
extern
GThread
*
main_task
;
extern
EventLoop
*
main_loop
;
extern
class
ClientList
*
client_list
;
extern
struct
Partition
*
global_partition
;
extern
Instance
*
instance
;
/**
* A entry point for application.
...
...
src/MessageCommands.cxx
View file @
b2d3d15e
...
...
@@ -22,6 +22,7 @@
#include "ClientSubscribe.hxx"
#include "ClientInternal.hxx"
#include "ClientList.hxx"
#include "Instance.hxx"
#include "Main.hxx"
#include "protocol/Result.hxx"
#include "protocol/ArgParser.hxx"
...
...
@@ -81,7 +82,7 @@ handle_channels(Client *client,
assert
(
argc
==
1
);
std
::
set
<
std
::
string
>
channels
;
for
(
const
auto
&
c
:
*
client_list
)
for
(
const
auto
&
c
:
*
instance
->
client_list
)
channels
.
insert
(
c
->
subscriptions
.
begin
(),
c
->
subscriptions
.
end
());
...
...
@@ -122,7 +123,7 @@ handle_send_message(Client *client,
bool
sent
=
false
;
const
ClientMessage
msg
(
argv
[
1
],
argv
[
2
]);
for
(
const
auto
&
c
:
*
client_list
)
for
(
const
auto
&
c
:
*
instance
->
client_list
)
if
(
client_push_message
(
c
,
msg
))
sent
=
true
;
...
...
src/Partition.hxx
View file @
b2d3d15e
...
...
@@ -23,19 +23,24 @@
#include "Playlist.hxx"
#include "PlayerControl.hxx"
struct
Instance
;
/**
* A partition of the Music Player Daemon. It is a separate unit with
* a playlist, a player, outputs etc.
*/
struct
Partition
{
Instance
&
instance
;
struct
playlist
playlist
;
player_control
pc
;
Partition
(
unsigned
max_length
,
Partition
(
Instance
&
_instance
,
unsigned
max_length
,
unsigned
buffer_chunks
,
unsigned
buffered_before_play
)
:
playlist
(
max_length
),
:
instance
(
_instance
),
playlist
(
max_length
),
pc
(
buffer_chunks
,
buffered_before_play
)
{
}
...
...
src/PlaylistGlobal.cxx
View file @
b2d3d15e
...
...
@@ -26,19 +26,19 @@
#include "PlaylistGlobal.hxx"
#include "Playlist.hxx"
#include "Main.hxx"
#include "
Partition
.hxx"
#include "
Instance
.hxx"
#include "GlobalEvents.hxx"
static
void
playlist_tag_event
(
void
)
{
global_partition
->
playlist
.
TagChang
ed
();
instance
->
TagModifi
ed
();
}
static
void
playlist_event
(
void
)
{
global_partition
->
playlist
.
SyncWithPlayer
(
global_partition
->
pc
);
instance
->
SyncWithPlayer
(
);
}
void
...
...
src/UpdateGlue.cxx
View file @
b2d3d15e
...
...
@@ -32,7 +32,7 @@ extern "C" {
}
#include "Main.hxx"
#include "
Partition
.hxx"
#include "
Instance
.hxx"
#include "mpd_error.h"
#include <glib.h>
...
...
@@ -156,11 +156,9 @@ static void update_finished_event(void)
idle_add
(
IDLE_UPDATE
);
if
(
modified
)
{
if
(
modified
)
/* send "idle" events */
global_partition
->
playlist
.
FullIncrementVersions
();
idle_add
(
IDLE_DATABASE
);
}
instance
->
DatabaseModified
();
path
=
update_queue_shift
(
&
discard
);
if
(
path
!=
NULL
)
{
...
...
src/UpdateRemove.cxx
View file @
b2d3d15e
...
...
@@ -20,13 +20,13 @@
#include "config.h"
/* must be first for large file support */
#include "UpdateRemove.hxx"
#include "Playlist.hxx"
#include "Partition.hxx"
#include "GlobalEvents.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "song.h"
#include "Main.hxx"
#include "Instance.hxx"
#ifdef ENABLE_SQLITE
#include "StickerDatabase.hxx"
...
...
@@ -63,7 +63,7 @@ song_remove_event(void)
sticker_song_delete
(
removed_song
);
#endif
global_partition
->
DeleteSong
(
*
removed_song
);
instance
->
DeleteSong
(
*
removed_song
);
/* clear "removed_song" and send signal to update thread */
remove_mutex
.
lock
();
...
...
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