static void app_run(app_t *self) { GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); bot_glib_mainloop_attach_lcm(self->lcm); bot_signal_pipe_glib_quit_on_kill(mainloop); g_main_loop_run(mainloop); printf("main: exiting\n"); g_main_loop_unref(mainloop); }
int main(int argc, char **argv) { state_t *app = calloc(1, sizeof(state_t)); app->lcmurl = strdup(get_default_lcm_url()); if (0 != lcm_parse_url(app->lcmurl, &app->mc_addr, &app->mc_port)) { fprintf (stderr, "invalid URL [%s]\n", app->lcmurl); return 1; } struct in_addr ia; ia = app->mc_addr; printf("MC group: %s port: %d\n", inet_ntoa(ia), app->mc_port); if(0 != setup_socket(app)) { return 1; } app->hosts = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify)host_destroy); app->mainloop = g_main_loop_new(NULL, FALSE); app->ioc = g_io_channel_unix_new(app->recvfd); app->sid = g_io_add_watch(app->ioc, G_IO_IN, (GIOFunc)on_message_ready, app); g_timeout_add(100, on_timer, app); app->report_interval_usec = DEFAULT_REPORT_INTERVAL_SECONDS * 1000000; app->next_report_utime = timestamp_now() + 1000000; bot_signal_pipe_glib_quit_on_kill(app->mainloop); g_main_loop_run(app->mainloop); g_io_channel_unref(app->ioc); g_source_remove(app->sid); shutdown(app->recvfd, SHUT_RDWR); g_hash_table_destroy(app->hosts); free(app->lcmurl); free(app); return 0; }