diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ClientNew.cxx | 9 | ||||
-rw-r--r-- | src/Instance.cxx | 48 | ||||
-rw-r--r-- | src/Instance.hxx | 54 | ||||
-rw-r--r-- | src/Listen.cxx | 3 | ||||
-rw-r--r-- | src/Main.cxx | 35 | ||||
-rw-r--r-- | src/Main.hxx | 5 | ||||
-rw-r--r-- | src/MessageCommands.cxx | 5 | ||||
-rw-r--r-- | src/Partition.hxx | 9 | ||||
-rw-r--r-- | src/PlaylistGlobal.cxx | 6 | ||||
-rw-r--r-- | src/UpdateGlue.cxx | 8 | ||||
-rw-r--r-- | src/UpdateRemove.cxx | 4 |
11 files changed, 148 insertions, 38 deletions
diff --git a/src/ClientNew.cxx b/src/ClientNew.cxx index a416c1f83..22127c491 100644 --- a/src/ClientNew.cxx +++ b/src/ClientNew.cxx @@ -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(); diff --git a/src/Instance.cxx b/src/Instance.cxx new file mode 100644 index 000000000..5571155b0 --- /dev/null +++ b/src/Instance.cxx @@ -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); +} diff --git a/src/Instance.hxx b/src/Instance.hxx new file mode 100644 index 000000000..09d9e4465 --- /dev/null +++ b/src/Instance.hxx @@ -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 diff --git a/src/Listen.cxx b/src/Listen.cxx index 26c9e100d..659ed6bdf 100644 --- a/src/Listen.cxx +++ b/src/Listen.cxx @@ -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); } }; diff --git a/src/Main.cxx b/src/Main.cxx index 49f466592..aa0a687fd 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -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 diff --git a/src/Main.hxx b/src/Main.hxx index b2768600c..e403d5669 100644 --- a/src/Main.hxx +++ b/src/Main.hxx @@ -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. diff --git a/src/MessageCommands.cxx b/src/MessageCommands.cxx index f19a1b5d4..4e24a1828 100644 --- a/src/MessageCommands.cxx +++ b/src/MessageCommands.cxx @@ -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; diff --git a/src/Partition.hxx b/src/Partition.hxx index 776f74e2a..6e4230857 100644 --- a/src/Partition.hxx +++ b/src/Partition.hxx @@ -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) { } diff --git a/src/PlaylistGlobal.cxx b/src/PlaylistGlobal.cxx index 9dd971d3f..97902275b 100644 --- a/src/PlaylistGlobal.cxx +++ b/src/PlaylistGlobal.cxx @@ -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.TagChanged(); + instance->TagModified(); } static void playlist_event(void) { - global_partition->playlist.SyncWithPlayer(global_partition->pc); + instance->SyncWithPlayer(); } void diff --git a/src/UpdateGlue.cxx b/src/UpdateGlue.cxx index e9906b84a..5c63efcda 100644 --- a/src/UpdateGlue.cxx +++ b/src/UpdateGlue.cxx @@ -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) { diff --git a/src/UpdateRemove.cxx b/src/UpdateRemove.cxx index acf8bf46c..fa4c8e764 100644 --- a/src/UpdateRemove.cxx +++ b/src/UpdateRemove.cxx @@ -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(); |