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.
This commit is contained in:
Max Kellermann
2008-12-30 19:24:39 +01:00
parent 03e650aa9e
commit 71e7ce5d8e
13 changed files with 182 additions and 576 deletions

View File

@@ -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);