diff options
author | Max Kellermann <max@duempel.org> | 2014-02-04 23:58:03 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-05 00:09:36 +0100 |
commit | d380db25be3a37666d1c908343115ed5490db968 (patch) | |
tree | b65cf15deff49441f779d4e951d11a88e584a75f /src | |
parent | e8938b1069739eca2bd2f27705c1c7783e834e59 (diff) |
Instance: add attribute "event_loop"
Replaces global variable "main_loop".
Diffstat (limited to 'src')
-rw-r--r-- | src/Instance.hxx | 3 | ||||
-rw-r--r-- | src/Main.cxx | 30 | ||||
-rw-r--r-- | src/Main.hxx | 2 | ||||
-rw-r--r-- | src/client/ClientRead.cxx | 5 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/Instance.hxx b/src/Instance.hxx index df5fdfbc4..52b137ab6 100644 --- a/src/Instance.hxx +++ b/src/Instance.hxx @@ -34,6 +34,7 @@ class Database; class UpdateService; #endif +class EventLoop; class Error; class ClientList; struct Partition; @@ -52,6 +53,8 @@ struct Instance final public NeighborListener #endif { + EventLoop *event_loop; + #ifdef ENABLE_NEIGHBOR_PLUGINS NeighborGlue *neighbors; #endif diff --git a/src/Main.cxx b/src/Main.cxx index a4f01dba8..2b64142cf 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -110,7 +110,6 @@ static constexpr unsigned DEFAULT_BUFFER_BEFORE_PLAY = 10; static constexpr Domain main_domain("main"); ThreadId main_thread; -EventLoop *main_loop; Instance *instance; @@ -197,7 +196,8 @@ glue_db_init_and_load(void) bool is_simple; Error error; - instance->database = DatabaseGlobalInit(*main_loop, *instance, *param, + instance->database = DatabaseGlobalInit(*instance->event_loop, + *instance, *param, is_simple, error); if (instance->database == nullptr) FatalError(error); @@ -211,7 +211,8 @@ glue_db_init_and_load(void) return true; SimpleDatabase &db = *(SimpleDatabase *)instance->database; - instance->update = new UpdateService(*main_loop, db, *instance); + instance->update = new UpdateService(*instance->event_loop, db, + *instance); /* run database update after daemonization? */ return db.FileExists(); @@ -247,7 +248,8 @@ glue_state_file_init(Error &error) return !error.IsDefined(); state_file = new StateFile(std::move(path_fs), - *instance->partition, *main_loop); + *instance->partition, + *instance->event_loop); state_file->Read(); return true; } @@ -353,7 +355,7 @@ idle_event_emitted(void) static void shutdown_event_emitted(void) { - main_loop->Break(); + instance->event_loop->Break(); } #endif @@ -411,9 +413,9 @@ int mpd_main(int argc, char *argv[]) } main_thread = ThreadId::GetCurrent(); - main_loop = new EventLoop(); instance = new Instance(); + instance->event_loop = new EventLoop(); #ifdef ENABLE_NEIGHBOR_PLUGINS instance->neighbors = new NeighborGlue(); @@ -431,7 +433,7 @@ int mpd_main(int argc, char *argv[]) const unsigned max_clients = config_get_positive(CONF_MAX_CONN, 10); instance->client_list = new ClientList(max_clients); - if (!listen_global_init(*main_loop, error)) { + if (!listen_global_init(*instance->event_loop, error)) { LogError(error); return EXIT_FAILURE; } @@ -439,7 +441,7 @@ int mpd_main(int argc, char *argv[]) daemonize_set_user(); daemonize_begin(options.daemon); - GlobalEvents::Initialize(*main_loop); + GlobalEvents::Initialize(*instance->event_loop); GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted); #ifdef WIN32 GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted); @@ -476,7 +478,7 @@ int mpd_main(int argc, char *argv[]) initialize_decoder_and_player(); volume_init(); initAudioConfig(); - instance->partition->outputs.Configure(*main_loop, + instance->partition->outputs.Configure(*instance->event_loop, instance->partition->pc); client_manager_init(); replay_gain_global_init(); @@ -492,7 +494,7 @@ int mpd_main(int argc, char *argv[]) setup_log_output(options.log_stderr); - SignalHandlersInit(*main_loop); + SignalHandlersInit(*instance->event_loop); io_thread_start(); @@ -502,7 +504,7 @@ int mpd_main(int argc, char *argv[]) FatalError(error); #endif - ZeroconfInit(*main_loop); + ZeroconfInit(*instance->event_loop); player_create(instance->partition->pc); @@ -527,7 +529,7 @@ int mpd_main(int argc, char *argv[]) #ifdef ENABLE_INOTIFY if (mapper_has_music_directory() && instance->update != nullptr) - mpd_inotify_init(*main_loop, *instance->update, + mpd_inotify_init(*instance->event_loop, *instance->update, config_get_unsigned(CONF_AUTO_UPDATE_DEPTH, G_MAXUINT)); #else @@ -551,7 +553,7 @@ int mpd_main(int argc, char *argv[]) SetThreadTimerSlackMS(100); /* run the main loop */ - main_loop->Run(); + instance->event_loop->Run(); #ifdef WIN32 win32_app_stopping(); @@ -608,8 +610,8 @@ int mpd_main(int argc, char *argv[]) config_global_finish(); io_thread_deinit(); SignalHandlersFinish(); + delete instance->event_loop; delete instance; - delete main_loop; daemonize_finish(); #ifdef WIN32 WSACleanup(); diff --git a/src/Main.hxx b/src/Main.hxx index 454519f46..08f24ec96 100644 --- a/src/Main.hxx +++ b/src/Main.hxx @@ -26,8 +26,6 @@ struct Instance; extern ThreadId main_thread; -extern EventLoop *main_loop; - extern Instance *instance; /** diff --git a/src/client/ClientRead.cxx b/src/client/ClientRead.cxx index 19deebd52..1ec6d29d5 100644 --- a/src/client/ClientRead.cxx +++ b/src/client/ClientRead.cxx @@ -19,7 +19,8 @@ #include "config.h" #include "ClientInternal.hxx" -#include "Main.hxx" +#include "Partition.hxx" +#include "Instance.hxx" #include "event/Loop.hxx" #include "util/CharUtil.hxx" @@ -53,7 +54,7 @@ Client::OnSocketInput(void *data, size_t length) case CommandResult::KILL: Close(); - main_loop->Break(); + partition.instance.event_loop->Break(); return InputResult::CLOSED; case CommandResult::FINISH: |