#include #include #include #include #include #include #include "paman.hh" #include "SinkWindow.hh" #include "MainWindow.hh" MainWindow *mainWindow = NULL; ServerInfoManager *serverInfoManager = NULL; struct pa_context *context = NULL; struct pa_mainloop_api *mainloop_api = NULL; extern "C" static void context_state_callback(struct pa_context *c, void *userdata); static void context_state_callback(struct pa_context *c, void *) { g_assert(c && mainWindow); switch (pa_context_get_state(c)) { case PA_CONTEXT_CONNECTING: mainWindow->showSuccess("Connecting ..."); mainWindow->connectButton->set_sensitive(false); return; case PA_CONTEXT_AUTHORIZING: mainWindow->showSuccess("Authorizing ..."); return; case PA_CONTEXT_SETTING_NAME: mainWindow->showSuccess("Setting name ..."); return; case PA_CONTEXT_READY: mainWindow->showSuccess("Ready"); g_assert(!serverInfoManager); serverInfoManager = new ServerInfoManager(*c); mainWindow->statButton->set_sensitive(true); mainWindow->disconnectButton->set_sensitive(true); return; case PA_CONTEXT_TERMINATED: mainWindow->showSuccess("Disconnected"); break; case PA_CONTEXT_FAILED: default: mainWindow->showFailure(pa_strerror(pa_context_errno(c))); break; } killConnection(); } void createConnection() { if (serverInfoManager) { delete serverInfoManager; serverInfoManager = NULL; } if (context) { pa_context_unref(context); context = NULL; } context = pa_context_new(mainloop_api, "Polypaudio Manager"); g_assert(context); pa_context_set_state_callback(context, context_state_callback, NULL); pa_context_connect(context, NULL, 1, NULL); } void killConnection() { if (serverInfoManager) { delete serverInfoManager; serverInfoManager = NULL; } if (context) { pa_context_unref(context); context = NULL; } mainWindow->connectButton->set_sensitive(true); mainWindow->disconnectButton->set_sensitive(false); mainWindow->statButton->set_sensitive(false); mainWindow->clearAllData(); } int main(int argc, char *argv[]) { struct pa_glib_mainloop *m; signal(SIGPIPE, SIG_IGN); Gtk::Main kit(argc, argv); mainWindow = MainWindow::create(); g_assert(mainWindow); m = pa_glib_mainloop_new(g_main_context_default()); g_assert(m); mainloop_api = pa_glib_mainloop_get_api(m); g_assert(mainloop_api); createConnection(); Gtk::Main::run(*mainWindow); if (serverInfoManager) delete serverInfoManager; if (context) pa_context_unref(context); mainloop_api = NULL; if (mainWindow) delete mainWindow; pa_glib_mainloop_free(m); return 0; }