diff options
author | Mike Brady <mikebrady@eircom.net> | 2017-11-19 21:16:36 +0000 |
---|---|---|
committer | Mike Brady <mikebrady@eircom.net> | 2017-11-19 21:16:36 +0000 |
commit | df7c48f0f3d08f5b8e01a97a983c200e5b7b3c22 (patch) | |
tree | c6bede1b6d732781e695fcf449e877a2ad4f325b /shairport-sync-mpris-test-client.c | |
parent | 67dfe591d05b11d16e725e52b4dfa5ec07fa388a (diff) |
Clean up naming of some files, get the 'stop' command working
Diffstat (limited to 'shairport-sync-mpris-test-client.c')
-rw-r--r-- | shairport-sync-mpris-test-client.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/shairport-sync-mpris-test-client.c b/shairport-sync-mpris-test-client.c new file mode 100644 index 0000000..e4418bf --- /dev/null +++ b/shairport-sync-mpris-test-client.c @@ -0,0 +1,81 @@ + +#include "mpris-interface.h" +#include "mpris-player-interface.h" +#include <stdio.h> +#include <unistd.h> + +GMainLoop *loop; + +void on_properties_changed(GDBusProxy *proxy, GVariant *changed_properties, + const gchar *const *invalidated_properties, gpointer user_data) { + /* Note that we are guaranteed that changed_properties and + * invalidated_properties are never NULL + */ + + if (g_variant_n_children(changed_properties) > 0) { + GVariantIter *iter; + const gchar *key; + GVariant *value; + + g_print(" *** Properties Changed:\n"); + g_variant_get(changed_properties, "a{sv}", &iter); + while (g_variant_iter_loop(iter, "{&sv}", &key, &value)) { + gchar *value_str; + value_str = g_variant_print(value, TRUE); + g_print(" %s -> %s\n", key, value_str); + g_free(value_str); + } + g_variant_iter_free(iter); + } + + if (g_strv_length((GStrv)invalidated_properties) > 0) { + guint n; + g_print(" *** Properties Invalidated:\n"); + for (n = 0; invalidated_properties[n] != NULL; n++) { + const gchar *key = invalidated_properties[n]; + g_print(" %s\n", key); + } + } +} + +pthread_t dbus_thread; +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) { + + pthread_create(&dbus_thread, NULL, &dbus_thread_func, NULL); + + MediaPlayer2 *proxy; + MediaPlayer2Player *proxy2; + + GError *error = 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); +*/ + + proxy2 = media_player2_player_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 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_main_loop_quit(loop); + pthread_join(dbus_thread, NULL); + printf("exiting program.\n"); + +// g_object_unref(proxy); + g_object_unref(proxy2); + + return 0; +} |