aboutsummaryrefslogtreecommitdiffstats
path: root/src/Main.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Main.cxx (renamed from src/main.c)176
1 files changed, 104 insertions, 72 deletions
diff --git a/src/main.c b/src/Main.cxx
index 12f8d86f6..917d89457 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,62 @@
*/
#include "config.h"
-#include "main.h"
-#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 "Main.hxx"
+#include "CommandLine.hxx"
+#include "PlaylistFile.hxx"
+#include "PlaylistGlobal.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"
+#include "Volume.hxx"
+#include "OutputAll.hxx"
+#include "tag.h"
#include "conf.h"
+#include "replay_gain_config.h"
+#include "Idle.hxx"
+#include "SignalHandlers.hxx"
+#include "Log.hxx"
+#include "GlobalEvents.hxx"
+#include "InputInit.hxx"
+#include "event/Loop.hxx"
+#include "IOThread.hxx"
+
+extern "C" {
+#include "daemon.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>
@@ -91,11 +97,11 @@ enum {
};
GThread *main_task;
-GMainLoop *main_loop;
+EventLoop *main_loop;
-GCond *main_cond;
+Partition *global_partition;
-struct player_control *global_player_control;
+static StateFile *state_file;
static bool
glue_daemonize_init(const struct options *options, GError **error_r)
@@ -153,31 +159,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();
}
/**
@@ -205,14 +227,18 @@ glue_state_file_init(GError **error_r)
GError *error = NULL;
char *path = config_dup_path(CONF_STATE_FILE, &error);
- if (path == NULL && error != NULL) {
- g_propagate_error(error_r, error);
- return false;
+ if (path == nullptr) {
+ if (error != nullptr) {
+ g_propagate_error(error_r, error);
+ return false;
+ }
+
+ return true;
}
- state_file_init(path, global_player_control);
+ state_file = new StateFile(path, *global_partition, *main_loop);
g_free(path);
-
+ state_file->Read();
return true;
}
@@ -285,11 +311,17 @@ 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);
}
/**
- * event_pipe callback function for PIPE_EVENT_IDLE
+ * Handler for GlobalEvents::IDLE.
*/
static void
idle_event_emitted(void)
@@ -302,12 +334,12 @@ idle_event_emitted(void)
}
/**
- * event_pipe callback function for PIPE_EVENT_SHUTDOWN
+ * Handler for GlobalEvents::SHUTDOWN.
*/
static void
shutdown_event_emitted(void)
{
- g_main_loop_quit(main_loop);
+ main_loop->Break();
}
int main(int argc, char *argv[])
@@ -342,7 +374,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);
@@ -367,6 +398,9 @@ int mpd_main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ main_task = g_thread_self();
+ main_loop = new EventLoop(EventLoop::Default());
+
success = listen_global_init(&error);
if (!success) {
g_warning("%s", error->message);
@@ -376,13 +410,9 @@ int mpd_main(int argc, char *argv[])
daemonize_set_user();
- main_task = g_thread_self();
- main_loop = g_main_loop_new(NULL, FALSE);
- main_cond = g_cond_new();
-
- event_pipe_init();
- event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted);
- event_pipe_register(PIPE_EVENT_SHUTDOWN, shutdown_event_emitted);
+ GlobalEvents::Initialize();
+ GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted);
+ GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
path_global_init();
@@ -416,7 +446,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 +472,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 +488,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,14 +504,14 @@ 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();
#endif
/* run the main loop */
- g_main_loop_run(main_loop);
+ main_loop->Run();
#ifdef WIN32
win32_app_stopping();
@@ -487,21 +519,24 @@ int mpd_main(int argc, char *argv[])
/* cleanup */
- g_main_loop_unref(main_loop);
+ delete main_loop;
#ifdef ENABLE_INOTIFY
mpd_inotify_finish();
#endif
- state_file_finish(global_player_control);
- pc_kill(global_player_control);
+ if (state_file != nullptr) {
+ state_file->Write();
+ delete state_file;
+ }
+
+ 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);
@@ -509,8 +544,7 @@ int mpd_main(int argc, char *argv[])
sticker_global_finish();
#endif
- g_cond_free(main_cond);
- event_pipe_deinit();
+ GlobalEvents::Deinitialize();
playlist_list_global_finish();
input_stream_global_finish();
@@ -518,8 +552,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 +560,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();