From: Mike Brady Date: Sun, 4 Mar 2018 15:30:06 +0000 (+0000) Subject: Allow the mpris test client to take an option to listen on the system bus (default... X-Git-Tag: 3.2d29~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0388f0419ffdfdd2248bc9c30fd1edbcb9afde87;p=thirdparty%2Fshairport-sync.git Allow the mpris test client to take an option to listen on the system bus (default) or the session bus --session --- diff --git a/shairport-sync-mpris-test-client.c b/shairport-sync-mpris-test-client.c index 310ffe23..35ef85d3 100644 --- a/shairport-sync-mpris-test-client.c +++ b/shairport-sync-mpris-test-client.c @@ -1,8 +1,9 @@ - -#include "mpris-interface.h" -#include "mpris-player-interface.h" #include +#include #include +#include +#include "mpris-interface.h" +#include "mpris-player-interface.h" GMainLoop *loop; @@ -44,38 +45,64 @@ void *dbus_thread_func(void *arg) { loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(loop); - - // dbus_service_main(); // let it run inside a thread return NULL; // this is just to quieten a compiler warning. } -int main(void) { +int main(int argc, char *argv[]) { + GBusType gbus_type_selected = G_BUS_TYPE_SYSTEM; // set default + // get the options --system or --session for system bus or session bus + char c; /* used for argument parsing */ + poptContext optCon; /* context for parsing command-line options */ + + struct poptOption optionsTable[] = { + { "system", '\0', POPT_ARG_VAL, &gbus_type_selected, G_BUS_TYPE_SYSTEM, + "Listen on the D-Bus system bus -- pick this option or the \'--session\' option, but not both. This is the default if no option is chosen.", NULL }, + { "session", '\0', POPT_ARG_VAL, &gbus_type_selected, G_BUS_TYPE_SESSION, + "Listen on the D-Bus session bus -- pick this option or the \'--system\' option, but not both.", NULL }, + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0 } + }; + + optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0); + poptSetOtherOptionHelp(optCon, "[--system | --session]"); + + if (argc > 2) { + poptPrintHelp(optCon, stderr, 0); + exit(1); + } - pthread_create(&dbus_thread, NULL, &dbus_thread_func, NULL); - MediaPlayer2 *proxy; - MediaPlayer2Player *proxy2; + /* Now do options processing */ + while ((c = poptGetNextOpt(optCon)) >= 0) { + } - GError *error = NULL; + if (c < -1) { + /* an error occurred during option processing */ + fprintf(stderr, "%s: %s\n", + poptBadOption(optCon, POPT_BADOPTION_NOALIAS), + poptStrerror(c)); + return 1; + } + + poptFreeContext(optCon); + + printf( "Listening on the D-Bus %s bus...\n", (gbus_type_selected == G_BUS_TYPE_SYSTEM) ? "system" : "session"); + + pthread_create(&dbus_thread, NULL, &dbus_thread_func, NULL); - /* - proxy = media_player2_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, - "org.mpris.MediaPlayer2.ShairportSync", - "/org/mpris/MediaPlayer2", NULL, &error); - g_signal_connect(proxy, "g-properties-changed", G_CALLBACK(on_properties_changed), NULL); - */ + MediaPlayer2Player *proxy; - proxy2 = media_player2_player_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, + GError *error = NULL; + + proxy = media_player2_player_proxy_new_for_bus_sync(gbus_type_selected, G_DBUS_PROXY_FLAGS_NONE, "org.mpris.MediaPlayer2.ShairportSync", "/org/mpris/MediaPlayer2", NULL, &error); - g_signal_connect(proxy2, "g-properties-changed", G_CALLBACK(on_properties_changed), NULL); - // sleep(120); + g_signal_connect(proxy, "g-properties-changed", G_CALLBACK(on_properties_changed), NULL); // g_main_loop_quit(loop); pthread_join(dbus_thread, NULL); printf("exiting program.\n"); - // g_object_unref(proxy); - g_object_unref(proxy2); + g_object_unref(proxy); return 0; }