diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-10-21 13:04:41 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-10-21 23:13:41 +0200 |
commit | 22d5f8ca1afad11f8c9d68d58927d322570655cb (patch) | |
tree | 04d0708b9556c17d26453732029560c1866da4cb /src | |
parent | a32e79764c4f4c7120d5a8537f9e77920f23b5c6 (diff) | |
download | pa-sink-ctl-22d5f8ca1afad11f8c9d68d58927d322570655cb.tar.gz pa-sink-ctl-22d5f8ca1afad11f8c9d68d58927d322570655cb.tar.bz2 pa-sink-ctl-22d5f8ca1afad11f8c9d68d58927d322570655cb.zip |
pa-sink-ctl.h: Remove private functions
This involves moving functions around in pa-sink-ctl.c
so that we dont need to declare them additionally.
Diffstat (limited to 'src')
-rw-r--r-- | src/pa-sink-ctl.c | 174 | ||||
-rw-r--r-- | src/pa-sink-ctl.h | 9 |
2 files changed, 89 insertions, 94 deletions
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index f8a74b8..cd8fbfc 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -12,54 +12,8 @@ g_memdup(&(data), sizeof(data))); \ } while (0) -int -main(int argc, char** argv) -{ - struct context *ctx = g_new0(struct context, 1); - pa_mainloop_api *mainloop_api = NULL; - pa_glib_mainloop *m = NULL; - - ctx->info_callbacks_finished = TRUE; - ctx->info_callbacks_blocked = FALSE; - ctx->sink_list = NULL; - ctx->max_name_len = 0; - ctx->context_ready = FALSE; - - ctx->loop = g_main_loop_new(NULL, FALSE); - - interface_init(ctx); - - if (!(m = pa_glib_mainloop_new(NULL))) { - interface_clear(ctx); - g_printerr("error: pa_glib_mainloop_new() failed.\n"); - return -1; - } - - mainloop_api = pa_glib_mainloop_get_api(m); - - if (!(ctx->context = pa_context_new(mainloop_api, "pa-sink-ctl"))) { - interface_clear(ctx); - g_printerr("error: pa_context_new() failed.\n"); - return -1; - } - - // define callback for connection init - pa_context_set_state_callback(ctx->context, context_state_callback, ctx); - if (pa_context_connect(ctx->context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL)) { - interface_clear(ctx); - g_printerr("error: pa_context_connect() failed.\n"); - } - - g_main_loop_run(ctx->loop); - - interface_clear(ctx); - g_list_free(ctx->sink_list); - - pa_glib_mainloop_free(m); - g_main_loop_unref(ctx->loop); - - return 0; -} +static void +collect_all_info(struct context *ctx); static void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, guint32 idx, gpointer userdata) @@ -75,7 +29,7 @@ subscribe_cb(pa_context *c, pa_subscription_event_type_t t, guint32 idx, gpointe /* * is called after connection */ -void +static void context_state_callback(pa_context *c, gpointer userdata) { struct context *ctx = userdata; @@ -118,44 +72,10 @@ context_state_callback(pa_context *c, gpointer userdata) } } - -/* - * the begin of the callback loops - */ -void -get_sink_info_callback(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata) -{ - g_assert(userdata != NULL); - struct context *ctx = userdata; - - if (is_last < 0) { - g_printerr("Failed to get sink information: %s\n", pa_strerror(pa_context_errno(c))); - quit(ctx); - } - - if (is_last) { - pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, ctx)); - return; - } - - sink_info sink = { - .index = i->index, - .mute = i->mute, - .vol = pa_cvolume_avg(&i->volume), - .channels = i->volume.channels, - .name = g_strdup(i->name), - .device = pa_proplist_contains(i->proplist, "device.product.name") ? - g_strdup(pa_proplist_gets(i->proplist, "device.product.name")) : NULL, - .input_list = NULL - }; - - list_append_struct(ctx->tmp_sinks, sink); -} - /* * is called after sink-input */ -void +static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, gint is_last, gpointer userdata) { g_assert(userdata != NULL); @@ -198,6 +118,40 @@ get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, gint is list_append_struct(sink->input_list, sink_input); } +/* + * the begin of the callback loops + */ +static void +get_sink_info_callback(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata) +{ + g_assert(userdata != NULL); + struct context *ctx = userdata; + + if (is_last < 0) { + g_printerr("Failed to get sink information: %s\n", pa_strerror(pa_context_errno(c))); + quit(ctx); + } + + if (is_last) { + pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, ctx)); + return; + } + + sink_info sink = { + .index = i->index, + .mute = i->mute, + .vol = pa_cvolume_avg(&i->volume), + .channels = i->volume.channels, + .name = g_strdup(i->name), + .device = pa_proplist_contains(i->proplist, "device.product.name") ? + g_strdup(pa_proplist_gets(i->proplist, "device.product.name")) : NULL, + .input_list = NULL + }; + + list_append_struct(ctx->tmp_sinks, sink); +} + + void quit(struct context *ctx) { @@ -216,7 +170,7 @@ change_callback(pa_context* c, gint success, gpointer userdata) return; } -void +static void collect_all_info(struct context *ctx) { if (!ctx->info_callbacks_finished) @@ -225,3 +179,53 @@ collect_all_info(struct context *ctx) ctx->tmp_sinks = NULL; pa_operation_unref(pa_context_get_sink_info_list(ctx->context, get_sink_info_callback, ctx)); } + +int +main(int argc, char** argv) +{ + struct context *ctx = g_new0(struct context, 1); + pa_mainloop_api *mainloop_api = NULL; + pa_glib_mainloop *m = NULL; + + ctx->info_callbacks_finished = TRUE; + ctx->info_callbacks_blocked = FALSE; + ctx->sink_list = NULL; + ctx->max_name_len = 0; + ctx->context_ready = FALSE; + + ctx->loop = g_main_loop_new(NULL, FALSE); + + interface_init(ctx); + + if (!(m = pa_glib_mainloop_new(NULL))) { + interface_clear(ctx); + g_printerr("error: pa_glib_mainloop_new() failed.\n"); + return -1; + } + + mainloop_api = pa_glib_mainloop_get_api(m); + + if (!(ctx->context = pa_context_new(mainloop_api, "pa-sink-ctl"))) { + interface_clear(ctx); + g_printerr("error: pa_context_new() failed.\n"); + return -1; + } + + // define callback for connection init + pa_context_set_state_callback(ctx->context, context_state_callback, ctx); + if (pa_context_connect(ctx->context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL)) { + interface_clear(ctx); + g_printerr("error: pa_context_connect() failed.\n"); + } + + g_main_loop_run(ctx->loop); + + interface_clear(ctx); + g_list_free(ctx->sink_list); + + pa_glib_mainloop_free(m); + g_main_loop_unref(ctx->loop); + + return 0; +} + diff --git a/src/pa-sink-ctl.h b/src/pa-sink-ctl.h index c5bc473..2539ea3 100644 --- a/src/pa-sink-ctl.h +++ b/src/pa-sink-ctl.h @@ -36,18 +36,9 @@ struct context { }; void -collect_all_info(struct context *ctx); - -void quit(struct context *ctx); void -context_state_callback(pa_context*, gpointer); -void -get_sink_info_callback(pa_context *, const pa_sink_info *, gint, gpointer); -void -get_sink_input_info_callback(pa_context *, const pa_sink_input_info*, gint, gpointer); -void change_callback(pa_context* c, gint success, gpointer); #endif |