diff options
Diffstat (limited to '')
-rw-r--r-- | src/Main.cxx (renamed from src/main.c) | 106 |
1 files changed, 65 insertions, 41 deletions
diff --git a/src/main.c b/src/Main.cxx index 12f8d86f6..371602247 100644 --- a/src/main.c +++ b/src/Main.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * 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 @@ -18,56 +18,60 @@ */ #include "config.h" -#include "main.h" +#include "Main.hxx" +#include "CommandLine.hxx" +#include "PlaylistFile.hxx" +#include "UpdateGlue.hxx" +#include "MusicChunk.hxx" +#include "StateFile.hxx" +#include "PlayerThread.hxx" +#include "Mapper.hxx" +#include "DatabaseGlue.hxx" +#include "DatabaseSimple.hxx" +#include "Permission.hxx" +#include "Listen.hxx" +#include "ClientIdle.hxx" +#include "Client.hxx" +#include "AllCommands.hxx" +#include "Partition.hxx" + +extern "C" { #include "daemon.h" #include "io_thread.h" -#include "client.h" -#include "client_idle.h" #include "idle.h" -#include "command.h" -#include "playlist.h" -#include "stored_playlist.h" -#include "database.h" -#include "update.h" -#include "player_thread.h" -#include "listen.h" -#include "cmdline.h" #include "conf.h" #include "path.h" -#include "mapper.h" -#include "chunk.h" -#include "player_control.h" #include "stats.h" #include "sig_handlers.h" #include "audio_config.h" #include "output_all.h" #include "volume.h" #include "log.h" -#include "permission.h" #include "pcm_resample.h" #include "replay_gain_config.h" #include "decoder_list.h" #include "input_init.h" #include "playlist_list.h" -#include "state_file.h" #include "tag.h" -#include "dbUtils.h" #include "zeroconf.h" #include "event_pipe.h" -#include "tag_pool.h" +} + #include "mpd_error.h" #ifdef ENABLE_INOTIFY -#include "inotify_update.h" +#include "InotifyUpdate.hxx" #endif #ifdef ENABLE_SQLITE -#include "sticker.h" +#include "StickerDatabase.hxx" #endif +extern "C" { #ifdef ENABLE_ARCHIVE #include "archive_list.h" #endif +} #include <glib.h> @@ -95,7 +99,7 @@ GMainLoop *main_loop; GCond *main_cond; -struct player_control *global_player_control; +Partition *global_partition; static bool glue_daemonize_init(const struct options *options, GError **error_r) @@ -153,31 +157,47 @@ glue_mapper_init(GError **error_r) static bool glue_db_init_and_load(void) { + const struct config_param *param = config_get_param("database"); const struct config_param *path = config_get_param(CONF_DB_FILE); + if (param != NULL && path != NULL) + g_message("Found both 'database' and '" CONF_DB_FILE + "' setting - ignoring the latter"); + GError *error = NULL; bool ret; if (!mapper_has_music_directory()) { + if (param != NULL) + g_message("Found database setting without " + CONF_MUSIC_DIR " - disabling database"); if (path != NULL) g_message("Found " CONF_DB_FILE " setting without " CONF_MUSIC_DIR " - disabling database"); - db_init(NULL, NULL); return true; } - if (path == NULL) - MPD_ERROR(CONF_DB_FILE " setting missing"); + struct config_param *allocated = NULL; - if (!db_init(path, &error)) + if (param == NULL && path != NULL) { + allocated = config_new_param("database", path->line); + config_add_block_param(allocated, "path", + path->value, path->line); + param = allocated; + } + + if (!DatabaseGlobalInit(param, &error)) MPD_ERROR("%s", error->message); - ret = db_load(&error); + if (allocated != NULL) + config_param_free(allocated); + + ret = DatabaseGlobalOpen(&error); if (!ret) MPD_ERROR("%s", error->message); /* run database update after daemonization? */ - return db_exists(); + return !db_is_simple() || db_exists(); } /** @@ -210,7 +230,7 @@ glue_state_file_init(GError **error_r) return false; } - state_file_init(path, global_player_control); + state_file_init(path, *global_partition); g_free(path); return true; @@ -285,7 +305,13 @@ initialize_decoder_and_player(void) if (buffered_before_play > buffered_chunks) buffered_before_play = buffered_chunks; - global_player_control = pc_new(buffered_chunks, buffered_before_play); + const unsigned max_length = + config_get_positive(CONF_MAX_PLAYLIST_LENGTH, + DEFAULT_PLAYLIST_MAX_LENGTH); + + global_partition = new Partition(max_length, + buffered_chunks, + buffered_before_play); } /** @@ -342,7 +368,6 @@ int mpd_main(int argc, char *argv[]) io_thread_init(); winsock_init(); idle_init(); - tag_pool_init(); config_global_init(); success = parse_cmdline(argc, argv, &options, &error); @@ -416,7 +441,7 @@ int mpd_main(int argc, char *argv[]) initialize_decoder_and_player(); volume_init(); initAudioConfig(); - audio_output_all_init(global_player_control); + audio_output_all_init(&global_partition->pc); client_manager_init(); replay_gain_global_init(); @@ -442,7 +467,7 @@ int mpd_main(int argc, char *argv[]) initZeroconf(); - player_create(global_player_control); + player_create(&global_partition->pc); if (create_db) { /* the database failed to load: recreate the @@ -458,6 +483,8 @@ 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)); + success = config_get_bool(CONF_AUTO_UPDATE, false); #ifdef ENABLE_INOTIFY if (success && mapper_has_music_directory()) @@ -472,7 +499,7 @@ int mpd_main(int argc, char *argv[]) /* enable all audio outputs (if not already done by playlist_state_restore() */ - pc_update_audio(global_player_control); + pc_update_audio(&global_partition->pc); #ifdef WIN32 win32_app_started(); @@ -493,15 +520,14 @@ int mpd_main(int argc, char *argv[]) mpd_inotify_finish(); #endif - state_file_finish(global_player_control); - pc_kill(global_player_control); + state_file_finish(*global_partition); + pc_kill(&global_partition->pc); finishZeroconf(); client_manager_deinit(); listen_global_finish(); - playlist_global_finish(); start = clock(); - db_finish(); + DatabaseGlobalDeinit(); g_debug("db_finish took %f seconds", ((float)(clock()-start))/CLOCKS_PER_SEC); @@ -518,8 +544,7 @@ int mpd_main(int argc, char *argv[]) volume_finish(); mapper_finish(); path_global_finish(); - finishPermissions(); - pc_free(global_player_control); + delete global_partition; command_finish(); update_global_finish(); decoder_plugin_deinit_all(); @@ -527,7 +552,6 @@ int mpd_main(int argc, char *argv[]) archive_plugin_deinit_all(); #endif config_global_finish(); - tag_pool_deinit(); idle_deinit(); stats_global_finish(); io_thread_deinit(); |