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