Split out the creation of the PA context a little.

This is a precursor to adding reconnection support.
This commit is contained in:
Colin Guthrie 2010-04-20 19:06:01 +01:00
parent 8959744e60
commit cbcdd0f49c
1 changed files with 26 additions and 18 deletions

View File

@ -42,7 +42,8 @@
#include "rolewidget.h"
#include "mainwindow.h"
static pa_context *context = NULL;
static pa_context* context = NULL;
static pa_mainloop_api* api = NULL;
static int n_outstanding = 0;
void show_error(const char *txt) {
@ -386,6 +387,9 @@ void context_state_callback(pa_context *c, void *userdata) {
case PA_CONTEXT_READY: {
pa_operation *o;
/* Create event widget immediately so it's first in the list */
w->createEventRoleWidget();
pa_context_set_subscribe_callback(c, subscribe_cb, w);
if (!(o = pa_context_subscribe(c, (pa_subscription_mask_t)
@ -493,6 +497,25 @@ void context_state_callback(pa_context *c, void *userdata) {
}
}
static pa_context* create_context(MainWindow* w) {
g_assert(api);
pa_proplist *proplist = pa_proplist_new();
pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, _("PulseAudio Volume Control"));
pa_proplist_sets(proplist, PA_PROP_APPLICATION_ID, "org.PulseAudio.pavucontrol");
pa_proplist_sets(proplist, PA_PROP_APPLICATION_ICON_NAME, "audio-card");
pa_proplist_sets(proplist, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION);
pa_context* c = pa_context_new_with_proplist(api, NULL, proplist);
g_assert(c);
pa_proplist_free(proplist);
pa_context_set_state_callback(c, context_state_callback, w);
return c;
}
pa_context* get_context(void) {
return context;
}
@ -512,27 +535,12 @@ int main(int argc, char *argv[]) {
MainWindow* mainWindow = MainWindow::create();
/* Create event widget immediately so it's first in the list */
mainWindow->createEventRoleWidget();
pa_glib_mainloop *m = pa_glib_mainloop_new(g_main_context_default());
g_assert(m);
pa_mainloop_api *api = pa_glib_mainloop_get_api(m);
api = pa_glib_mainloop_get_api(m);
g_assert(api);
pa_proplist *proplist = pa_proplist_new();
pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, _("PulseAudio Volume Control"));
pa_proplist_sets(proplist, PA_PROP_APPLICATION_ID, "org.PulseAudio.pavucontrol");
pa_proplist_sets(proplist, PA_PROP_APPLICATION_ICON_NAME, "audio-card");
pa_proplist_sets(proplist, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION);
context = pa_context_new_with_proplist(api, NULL, proplist);
g_assert(context);
pa_proplist_free(proplist);
pa_context_set_state_callback(context, context_state_callback, mainWindow);
context = create_context(mainWindow);
if (pa_context_connect(context, NULL, (pa_context_flags_t) 0, NULL) < 0)
goto finish;