aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-30 19:24:39 +0100
committerMax Kellermann <max@duempel.org>2008-12-30 19:24:39 +0100
commit71e7ce5d8e3153342494685d60d7ff16d9b29101 (patch)
treeed9893562c16b7f8ab98a5c97bce79bcf1ae2267 /src/main.c
parent03e650aa9e9a95575fccd51ec9f669abae52fe7e (diff)
downloadmpd-71e7ce5d8e3153342494685d60d7ff16d9b29101.tar.gz
mpd-71e7ce5d8e3153342494685d60d7ff16d9b29101.tar.xz
mpd-71e7ce5d8e3153342494685d60d7ff16d9b29101.zip
main: use the GLib main loop
This is a rather huge patch, which unfortunately cannot be splitted. Instead of using our custom ioops.h library, convert everything to use the GLib main loop.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/src/main.c b/src/main.c
index 580f4bf8b..a33650ae0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -180,9 +180,34 @@ static void killFromPidFile(void)
#endif
}
+static gboolean
+timer_save_state_file(G_GNUC_UNUSED gpointer data)
+{
+ g_debug("Saving state file");
+ write_state_file();
+ return true;
+}
+
+void
+main_notify_triggered(void)
+{
+ unsigned flags;
+
+ syncPlayerAndPlaylist();
+ client_manager_expire();
+ reap_update_task();
+
+ /* send "idle" notificaions to all subscribed
+ clients */
+ flags = idle_get();
+ if (flags != 0)
+ client_manager_idle_add(flags);
+}
+
int main(int argc, char *argv[])
{
Options options;
+ GMainLoop *main_loop;
clock_t start;
GTimer *save_state_timer;
@@ -216,6 +241,8 @@ int main(int argc, char *argv[])
changeToUser();
+ main_loop = g_main_loop_new(NULL, FALSE);
+
path_global_init();
mapper_init();
initPermissions();
@@ -258,26 +285,15 @@ int main(int argc, char *argv[])
save_state_timer = g_timer_new();
- while (COMMAND_RETURN_KILL != client_manager_io() &&
- COMMAND_RETURN_KILL != handlePendingSignals()) {
- unsigned flags;
+ g_timeout_add(5 * 60 * 1000, timer_save_state_file, NULL);
- syncPlayerAndPlaylist();
- client_manager_expire();
- reap_update_task();
+ /* run the main loop */
- /* send "idle" notificaions to all subscribed
- clients */
- flags = idle_get();
- if (flags != 0)
- client_manager_idle_add(flags);
+ g_main_loop_run(main_loop);
- if (g_timer_elapsed(save_state_timer, NULL) >= 5 * 60) {
- g_debug("Saving state file");
- write_state_file();
- g_timer_start(save_state_timer);
- }
- }
+ /* cleanup */
+
+ g_main_loop_unref(main_loop);
g_timer_destroy(save_state_timer);