diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-08-13 06:14:51 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-08-13 06:16:37 -0400 |
commit | 3b286de6104fb4a4a0c2d6dfc8910cfc957f51b2 (patch) | |
tree | e70dea722c867460ebba932648544772cd115384 | |
parent | d55f646008c104c61c9ca35724bf2a8710675c97 (diff) | |
download | mirror-ponymix-3b286de6104fb4a4a0c2d6dfc8910cfc957f51b2.tar.gz mirror-ponymix-3b286de6104fb4a4a0c2d6dfc8910cfc957f51b2.tar.bz2 mirror-ponymix-3b286de6104fb4a4a0c2d6dfc8910cfc957f51b2.zip |
fold connection into pulse_init
-rw-r--r-- | pulsemix.c | 39 |
1 files changed, 19 insertions, 20 deletions
@@ -561,15 +561,31 @@ static int set_default(struct pulseaudio_t *pulse, struct io_t *dev) return !pulse->success; } -static void pulse_init(struct pulseaudio_t *pulse) +static int pulse_connect(struct pulseaudio_t *pulse) +{ + pa_context_connect(pulse->cxt, NULL, PA_CONTEXT_NOFLAGS, NULL); + while (pulse->state == STATE_CONNECTING) + pa_mainloop_iterate(pulse->mainloop, 1, NULL); + + if (pulse->state == STATE_ERROR) { + int r = pa_context_errno(pulse->cxt); + fprintf(stderr, "failed to connect to pulse daemon: %s\n", + pa_strerror(r)); + return 1; + } + + return 0; +} + +static int pulse_init(struct pulseaudio_t *pulse) { pulse->mainloop = pa_mainloop_new(); pulse->cxt = pa_context_new(pa_mainloop_get_api(pulse->mainloop), "lolpulse"); pulse->state = STATE_CONNECTING; pulse->head = NULL; - /* set state callback for connection */ pa_context_set_state_callback(pulse->cxt, state_cb, pulse); + return pulse_connect(pulse); } static void pulse_deinit(struct pulseaudio_t *pulse) @@ -588,22 +604,6 @@ static void pulse_deinit(struct pulseaudio_t *pulse) } } -static int pulse_connect(struct pulseaudio_t *pulse) -{ - pa_context_connect(pulse->cxt, NULL, PA_CONTEXT_NOFLAGS, NULL); - while (pulse->state == STATE_CONNECTING) - pa_mainloop_iterate(pulse->mainloop, 1, NULL); - - if (pulse->state == STATE_ERROR) { - int r = pa_context_errno(pulse->cxt); - fprintf(stderr, "failed to connect to pulse daemon: %s\n", - pa_strerror(r)); - return 1; - } - - return 0; -} - static void __attribute__((__noreturn__)) usage(FILE *out) { fprintf(out, "usage: %s [options] <command>...\n", program_invocation_short_name); @@ -760,8 +760,7 @@ int main(int argc, char *argv[]) } /* initialize connection */ - pulse_init(&pulse); - if (pulse_connect(&pulse) != 0) + if (pulse_init(&pulse) != 0) return 1; if (verb == ACTION_DEFAULTS) { |