summaryrefslogtreecommitdiffstats
path: root/src/paman.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/paman.cc')
-rw-r--r--src/paman.cc117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/paman.cc b/src/paman.cc
new file mode 100644
index 0000000..0c1741d
--- /dev/null
+++ b/src/paman.cc
@@ -0,0 +1,117 @@
+#include <signal.h>
+
+#include <gtkmm.h>
+#include <libglademm.h>
+
+#include <polyp/polyplib.h>
+#include <polyp/glib-mainloop.h>
+#include <polyp/polyplib-error.h>
+
+#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;
+
+static void context_state_callback(struct pa_context *c, void *userdata) {
+ 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);
+ return;
+
+ case PA_CONTEXT_TERMINATED:
+ mainWindow->showSuccess("Disconnected");
+ break;
+
+ case PA_CONTEXT_FAILED:
+ default:
+ mainWindow->showFailure(pa_strerror(pa_context_errno(c)));
+ break;
+
+ }
+
+ if (context) {
+ pa_context_unref(context);
+ context = NULL;
+ }
+
+ if (serverInfoManager) {
+ delete serverInfoManager;
+ serverInfoManager = NULL;
+ }
+
+ mainWindow->connectButton->set_sensitive(true);
+ mainWindow->clearAllData();
+}
+
+void create_connection() {
+ 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);
+}
+
+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);
+
+ create_connection();
+
+ Gtk::Main::run(*mainWindow);
+
+quit:
+ if (serverInfoManager)
+ delete serverInfoManager;
+
+ if (context)
+ pa_context_unref(context);
+
+ mainloop_api = NULL;
+ if (mainWindow)
+ delete mainWindow;
+
+ pa_glib_mainloop_free(m);
+
+ return 0;
+}