From: Mike Brady Date: Tue, 20 Mar 2018 16:28:06 +0000 (+0000) Subject: Rationalise all the native dbus intefaces files down to just three. X-Git-Tag: 3.2RC1~7^2~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0b1dc542ac15083ac0329b962aed3870bf36250;p=thirdparty%2Fshairport-sync.git Rationalise all the native dbus intefaces files down to just three. --- diff --git a/Makefile.am b/Makefile.am index 3627d54c..26bc7fa5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -99,30 +99,6 @@ dbus-interface.h dbus-interface.c: org.gnome.ShairportSync.xml gdbus-codegen --interface-prefix org.gnome --generate-c-code dbus-interface org.gnome.ShairportSync.xml endif -if USE_DBUS_DIAGNOSTICS -shairport_sync_SOURCES += dbus-diagnostics.c dbus-diagnostics-interface.c -BUILT_SOURCES += dbus-diagnostics-interface.h dbus-diagnostics-interface.c -# We don't want to install this header -noinst_HEADERS += $(BUILT_SOURCES) -# Correctly clean the generated headers, but keep the xml description -CLEANFILES += $(BUILT_SOURCES) - -dbus-diagnostics-interface.h dbus-diagnostics-interface.c: org.gnome.ShairportSync.Diagnostics.xml - gdbus-codegen --interface-prefix org.gnome --generate-c-code dbus-diagnostics-interface org.gnome.ShairportSync.Diagnostics.xml -endif - -if USE_DBUS_BASIC_REMOTE_CONTROL -shairport_sync_SOURCES += dbus-basic-remote-control.c dbus-basic-remote-control-interface.c -BUILT_SOURCES += dbus-basic-remote-control-interface.h dbus-basic-remote-control-interface.c -# We don't want to install this header -noinst_HEADERS += $(BUILT_SOURCES) -# Correctly clean the generated headers, but keep the xml description -CLEANFILES += $(BUILT_SOURCES) - -dbus-basic-remote-control-interface.h dbus-basic-remote-control-interface.c: org.gnome.ShairportSync.Basic.Remote.Control.xml - gdbus-codegen --interface-prefix org.gnome --generate-c-code dbus-basic-remote-control-interface org.gnome.ShairportSync.Basic.Remote.Control.xml -endif - if USE_MPRIS shairport_sync_SOURCES += mpris-service.c mpris-interface.c mpris-player-interface.c BUILT_SOURCES += mpris-interface.h mpris-interface.c mpris-player-interface.h mpris-player-interface.c diff --git a/configure.ac b/configure.ac index 2c2950bb..8a4d6fa5 100644 --- a/configure.ac +++ b/configure.ac @@ -275,19 +275,13 @@ AC_ARG_WITH(dns_sd, [ --with-dns_sd = choose dns_sd mDNS support], [ AM_CONDITIONAL([USE_DNS_SD], [test "x$HAS_DNS_SD" = "x1"]) # Look for dbus flag -AC_ARG_WITH(dbus, [ --with-dbus-interface = include support for a native Shairport Sync D-Bus interface], [ +AC_ARG_WITH(dbus, [ --with-dbus-interface = include support for the native Shairport Sync D-Bus interface], [ AC_MSG_RESULT(>>Including dbus support) HAS_DBUS=1 AC_DEFINE([HAVE_DBUS], 1, [Needed by the compiler.]) - AC_DEFINE([HAVE_DBUS_DIAGNOSTICS], 1, [Needed by the compiler.]) - AC_DEFINE([HAVE_DBUS_BASIC_REMOTE_CONTROL], 1, [Needed by the compiler.]) PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= 2.30.0],[CFLAGS="${GIO_UNIX_CFLAGS} ${CFLAGS}" LIBS="${GIO_UNIX_LIBS} ${LIBS}"],[AC_MSG_ERROR(dbus messaging support requires the glib 2.0 library -- libglib2.0-dev suggested!)]) ], ) AM_CONDITIONAL([USE_DBUS], [test "x$HAS_DBUS" = "x1"]) -# Automatically include the diagnostics interface -AM_CONDITIONAL([USE_DBUS_DIAGNOSTICS], [test "x$HAS_DBUS" = "x1"]) -# Automatically include the basic remote control interface -AM_CONDITIONAL([USE_DBUS_BASIC_REMOTE_CONTROL], [test "x$HAS_DBUS" = "x1"]) # Look for dbus test client flag AC_ARG_WITH(dbus-test-client, [ --with-dbus-test-client = compile dbus test client], [ diff --git a/dbus-basic-remote-control.c b/dbus-basic-remote-control.c deleted file mode 100644 index d64cd509..00000000 --- a/dbus-basic-remote-control.c +++ /dev/null @@ -1,315 +0,0 @@ -#include -#include - -#include "config.h" - -#include "common.h" -#include "player.h" -#include "rtsp.h" - -#include "rtp.h" - -#include "dacp.h" -#include "metadata_hub.h" - -#include "dbus-basic-remote-control.h" -#include "dbus-basic-remote-control-interface.h" - -ShairportSyncBasicRemoteControl *shairportSyncBasicRemoteControlSkeleton; - - -void dbus_basic_remote_control_metadata_watcher(struct metadata_bundle *argc, __attribute__((unused)) void *userdata) { - // debug(1, "DBUS basic remote control watcher called"); - - shairport_sync_basic_remote_control_set_airplay_volume(shairportSyncBasicRemoteControlSkeleton, argc->airplay_volume); - - if (argc->dacp_server_active) - shairport_sync_basic_remote_control_set_server(shairportSyncBasicRemoteControlSkeleton, argc->client_ip); - else - shairport_sync_basic_remote_control_set_server(shairportSyncBasicRemoteControlSkeleton, ""); - - GVariantBuilder *dict_builder, *aa; - - /* Build the metadata array */ - // debug(1,"Build metadata"); - dict_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - - // Make up the artwork URI if we have one - if (argc->cover_art_pathname) { - char artURIstring[1024]; - sprintf(artURIstring, "file://%s", argc->cover_art_pathname); - // sprintf(artURIstring,""); - // debug(1,"artURI String: \"%s\".",artURIstring); - GVariant *artUrl = g_variant_new("s", artURIstring); - g_variant_builder_add(dict_builder, "{sv}", "mpris:artUrl", artUrl); - } - - // Add the TrackID if we have one - if (argc->item_id) { - char trackidstring[128]; - // debug(1, "Set ID using mper ID: \"%u\".",argc->item_id); - sprintf(trackidstring, "/org/gnome/ShairportSync/mper_%u", argc->item_id); - GVariant *trackid = g_variant_new("o", trackidstring); - g_variant_builder_add(dict_builder, "{sv}", "mpris:trackid", trackid); - } - - // Add the track name if there is one - if (argc->track_name) { - // debug(1, "Track name set to \"%s\".", argc->track_name); - GVariant *trackname = g_variant_new("s", argc->track_name); - g_variant_builder_add(dict_builder, "{sv}", "xesam:title", trackname); - } - - // Add the album name if there is one - if (argc->album_name) { - // debug(1, "Album name set to \"%s\".", argc->album_name); - GVariant *albumname = g_variant_new("s", argc->album_name); - g_variant_builder_add(dict_builder, "{sv}", "xesam:album", albumname); - } - - // Add the artists if there are any (actually there will be at most one, but put it in an array) - if (argc->artist_name) { - /* Build the artists array */ - // debug(1,"Build artist array"); - aa = g_variant_builder_new(G_VARIANT_TYPE("as")); - g_variant_builder_add(aa, "s", argc->artist_name); - GVariant *artists = g_variant_builder_end(aa); - g_variant_builder_unref(aa); - g_variant_builder_add(dict_builder, "{sv}", "xesam:artist", artists); - } - - // Add the genres if there are any (actually there will be at most one, but put it in an array) - if (argc->genre) { - // debug(1,"Build genre"); - aa = g_variant_builder_new(G_VARIANT_TYPE("as")); - g_variant_builder_add(aa, "s", argc->genre); - GVariant *genres = g_variant_builder_end(aa); - g_variant_builder_unref(aa); - g_variant_builder_add(dict_builder, "{sv}", "xesam:genre", genres); - } - - GVariant *dict = g_variant_builder_end(dict_builder); - g_variant_builder_unref(dict_builder); - - // debug(1,"Set metadata"); - shairport_sync_basic_remote_control_set_metadata(shairportSyncBasicRemoteControlSkeleton, dict); -} - - - -static gboolean on_handle_fast_forward(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("beginff"); - shairport_sync_basic_remote_control_complete_fast_forward(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_rewind(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("beginrew"); - shairport_sync_basic_remote_control_complete_rewind(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_toggle_mute(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("mutetoggle"); - shairport_sync_basic_remote_control_complete_toggle_mute(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_next(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("nextitem"); - shairport_sync_basic_remote_control_complete_next(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_previous(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("previtem"); - shairport_sync_basic_remote_control_complete_previous(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_pause(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("pause"); - shairport_sync_basic_remote_control_complete_pause(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_play_pause(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("playpause"); - shairport_sync_basic_remote_control_complete_play_pause(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_play(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("play"); - shairport_sync_basic_remote_control_complete_play(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_stop(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("stop"); - shairport_sync_basic_remote_control_complete_stop(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_resume(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("playresume"); - shairport_sync_basic_remote_control_complete_resume(skeleton, invocation); - return TRUE; -} - - -static gboolean on_handle_shuffle_songs(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("shuffle_songs"); - shairport_sync_basic_remote_control_complete_shuffle_songs(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_volume_up(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("volumeup"); - shairport_sync_basic_remote_control_complete_volume_up(skeleton, invocation); - return TRUE; -} - -static gboolean on_handle_volume_down(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, - __attribute__((unused)) gpointer user_data) { - send_simple_dacp_command("volumedown"); - shairport_sync_basic_remote_control_complete_volume_down(skeleton, invocation); - return TRUE; -} - - -/* -gboolean notify_elapsed_time_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - // debug(1, "\"notify_elapsed_time_callback\" called."); - if (shairport_sync_diagnostics_get_elapsed_time(skeleton)) { - config.debugger_show_elapsed_time = 1; - debug(1, ">> start including elapsed time in logs"); - } else { - config.debugger_show_elapsed_time = 0; - debug(1, ">> stop including elapsed time in logs"); - } - return TRUE; -} - -gboolean notify_delta_time_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - // debug(1, "\"notify_delta_time_callback\" called."); - if (shairport_sync_diagnostics_get_delta_time(skeleton)) { - config.debugger_show_relative_time = 1; - debug(1, ">> start including delta time in logs"); - } else { - config.debugger_show_relative_time = 0; - debug(1, ">> stop including delta time in logs"); - } - return TRUE; -} - -gboolean notify_statistics_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - // debug(1, "\"notify_statistics_callback\" called."); - if (shairport_sync_diagnostics_get_statistics(skeleton)) { - debug(1, ">> start logging statistics"); - config.statistics_requested = 1; - } else { - debug(1, ">> stop logging statistics"); - config.statistics_requested = 0; - } - return TRUE; -} - -gboolean notify_verbosity_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - gint th = shairport_sync_diagnostics_get_verbosity(skeleton); - if ((th >= 0) && (th <= 3)) { - if (th==0) - debug(1, ">> log verbosity set to %d.", th); - debuglev = th; - debug(1, ">> log verbosity set to %d.", th); - } else { - debug(1, ">> invalid log verbosity: %d. Ignored.", th); - } - return TRUE; -} -*/ - -void dbus_basic_remote_control_on_dbus_name_acquired(GDBusConnection *connection, - __attribute__((unused)) const gchar *name, - __attribute__((unused)) gpointer user_data) { - debug(1,"dbus_basic_remote_control_on_dbus_name_acquired"); - shairportSyncBasicRemoteControlSkeleton = shairport_sync_basic_remote_control_skeleton_new(); - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(shairportSyncBasicRemoteControlSkeleton), connection, - "/org/gnome/ShairportSync", NULL); - - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-fast-forward", G_CALLBACK(on_handle_fast_forward), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-rewind", G_CALLBACK(on_handle_rewind), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-toggle-mute", G_CALLBACK(on_handle_toggle_mute), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-next", G_CALLBACK(on_handle_next), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-previous", G_CALLBACK(on_handle_previous), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-pause", G_CALLBACK(on_handle_pause), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-play-pause", G_CALLBACK(on_handle_play_pause), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-play", G_CALLBACK(on_handle_play), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-stop", G_CALLBACK(on_handle_stop), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-resume", G_CALLBACK(on_handle_resume), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-shuffle-songs", G_CALLBACK(on_handle_shuffle_songs), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-volume-up", G_CALLBACK(on_handle_volume_up), NULL); - g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-volume-down", G_CALLBACK(on_handle_volume_down), NULL); - - add_metadata_watcher(dbus_basic_remote_control_metadata_watcher, NULL); - - /* - shairport_sync_diagnostics_set_verbosity(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), - debuglev); - - // debug(2,">> log verbosity is %d.",debuglev); - - if (config.statistics_requested == 0) { - shairport_sync_diagnostics_set_statistics(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); - // debug(1, ">> statistics logging is off"); - } else { - shairport_sync_diagnostics_set_statistics(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); - // debug(1, ">> statistics logging is on"); - } - - if (config.debugger_show_elapsed_time == 0) { - shairport_sync_diagnostics_set_elapsed_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); - // debug(1, ">> elapsed time is included in log entries"); - } else { - shairport_sync_diagnostics_set_elapsed_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); - // debug(1, ">> elapsed time is not included in log entries"); - } - - if (config.debugger_show_relative_time == 0) { - shairport_sync_diagnostics_set_delta_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); - // debug(1, ">> delta time is included in log entries"); - } else { - shairport_sync_diagnostics_set_delta_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); - // debug(1, ">> delta time is not included in log entries"); - } - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::verbosity", - G_CALLBACK(notify_verbosity_callback), NULL); - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::statistics", - G_CALLBACK(notify_statistics_callback), NULL); - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::elapsed-time", - G_CALLBACK(notify_elapsed_time_callback), NULL); - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::delta-time", - G_CALLBACK(notify_delta_time_callback), NULL); - */ -} - diff --git a/dbus-basic-remote-control.h b/dbus-basic-remote-control.h deleted file mode 100644 index e96c90f7..00000000 --- a/dbus-basic-remote-control.h +++ /dev/null @@ -1,10 +0,0 @@ - -#ifndef DBUS_BASIC_REMOTE_CONTROL_H -#define DBUS_BASIC_REMOTE_CONTROL_H - -#include "dbus-basic-remote-control-interface.h" -ShairportSyncBasicRemoteControl *shairportSyncBasicRemoteControlSkeleton; - -void dbus_basic_remote_control_on_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data); - -#endif /* #ifndef DBUS_BASIC_REMOTE_CONTROL_ */ diff --git a/dbus-diagnostics.c b/dbus-diagnostics.c deleted file mode 100644 index db872daf..00000000 --- a/dbus-diagnostics.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include - -#include "config.h" - -#include "common.h" -#include "player.h" -#include "rtsp.h" - -#include "rtp.h" - -#include "dacp.h" -#include "metadata_hub.h" - -#include "dbus-diagnostics.h" -#include "dbus-diagnostics-interface.h" - -ShairportSyncDiagnostics *shairportSyncDiagnosticsSkeleton; - -gboolean notify_elapsed_time_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - // debug(1, "\"notify_elapsed_time_callback\" called."); - if (shairport_sync_diagnostics_get_elapsed_time(skeleton)) { - config.debugger_show_elapsed_time = 1; - debug(1, ">> start including elapsed time in logs"); - } else { - config.debugger_show_elapsed_time = 0; - debug(1, ">> stop including elapsed time in logs"); - } - return TRUE; -} - -gboolean notify_delta_time_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - // debug(1, "\"notify_delta_time_callback\" called."); - if (shairport_sync_diagnostics_get_delta_time(skeleton)) { - config.debugger_show_relative_time = 1; - debug(1, ">> start including delta time in logs"); - } else { - config.debugger_show_relative_time = 0; - debug(1, ">> stop including delta time in logs"); - } - return TRUE; -} - -gboolean notify_statistics_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - // debug(1, "\"notify_statistics_callback\" called."); - if (shairport_sync_diagnostics_get_statistics(skeleton)) { - debug(1, ">> start logging statistics"); - config.statistics_requested = 1; - } else { - debug(1, ">> stop logging statistics"); - config.statistics_requested = 0; - } - return TRUE; -} - -gboolean notify_verbosity_callback(ShairportSyncDiagnostics *skeleton, - __attribute__((unused)) gpointer user_data) { - gint th = shairport_sync_diagnostics_get_verbosity(skeleton); - if ((th >= 0) && (th <= 3)) { - if (th==0) - debug(1, ">> log verbosity set to %d.", th); - debuglev = th; - debug(1, ">> log verbosity set to %d.", th); - } else { - debug(1, ">> invalid log verbosity: %d. Ignored.", th); - } - return TRUE; -} - -void dbus_diagnostics_on_dbus_name_acquired(GDBusConnection *connection, - __attribute__((unused)) const gchar *name, - __attribute__((unused)) gpointer user_data) { - // debug(1,"dbus_diagnostics_on_dbus_name_acquired"); - shairportSyncDiagnosticsSkeleton = shairport_sync_diagnostics_skeleton_new(); - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(shairportSyncDiagnosticsSkeleton), connection, - "/org/gnome/ShairportSync", NULL); - - shairport_sync_diagnostics_set_verbosity(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), - debuglev); - - // debug(2,">> log verbosity is %d.",debuglev); - - if (config.statistics_requested == 0) { - shairport_sync_diagnostics_set_statistics(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); - // debug(1, ">> statistics logging is off"); - } else { - shairport_sync_diagnostics_set_statistics(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); - // debug(1, ">> statistics logging is on"); - } - - if (config.debugger_show_elapsed_time == 0) { - shairport_sync_diagnostics_set_elapsed_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); - // debug(1, ">> elapsed time is included in log entries"); - } else { - shairport_sync_diagnostics_set_elapsed_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); - // debug(1, ">> elapsed time is not included in log entries"); - } - - if (config.debugger_show_relative_time == 0) { - shairport_sync_diagnostics_set_delta_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); - // debug(1, ">> delta time is included in log entries"); - } else { - shairport_sync_diagnostics_set_delta_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); - // debug(1, ">> delta time is not included in log entries"); - } - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::verbosity", - G_CALLBACK(notify_verbosity_callback), NULL); - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::statistics", - G_CALLBACK(notify_statistics_callback), NULL); - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::elapsed-time", - G_CALLBACK(notify_elapsed_time_callback), NULL); - - g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::delta-time", - G_CALLBACK(notify_delta_time_callback), NULL); - -} - diff --git a/dbus-diagnostics.h b/dbus-diagnostics.h deleted file mode 100644 index acfa8793..00000000 --- a/dbus-diagnostics.h +++ /dev/null @@ -1,10 +0,0 @@ - -#ifndef DBUS_DIAGNOSTICS_H -#define DBUS_DIAGNOSTICS_H - -#include "dbus-diagnostics-interface.h" -ShairportSyncDiagnostics *shairportSyncDiagnosticsSkeleton; - -void dbus_diagnostics_on_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data); - -#endif /* #ifndef DBUS_SERVICE_H */ diff --git a/dbus-service.c b/dbus-service.c index 8a497a65..dea98cfa 100644 --- a/dbus-service.c +++ b/dbus-service.c @@ -14,17 +14,236 @@ #include "dbus-service.h" -#ifdef HAVE_DBUS_DIAGNOSTICS - #include "dbus-diagnostics.h" -#endif - -#ifdef HAVE_DBUS_BASIC_REMOTE_CONTROL - #include "dbus-basic-remote-control.h" -#endif +ShairportSyncDiagnostics *shairportSyncDiagnosticsSkeleton; +ShairportSyncBasicRemoteControl *shairportSyncBasicRemoteControlSkeleton; void dbus_metadata_watcher(struct metadata_bundle *argc, __attribute__((unused)) void *userdata) { // debug(1, "DBUS metadata watcher called"); shairport_sync_set_volume(shairportSyncSkeleton, argc->speaker_volume); + + // debug(1, "No diagnostics watcher required"); + + // debug(1, "DBUS basic remote control watcher called"); + + shairport_sync_basic_remote_control_set_airplay_volume(shairportSyncBasicRemoteControlSkeleton, argc->airplay_volume); + + if (argc->dacp_server_active) + shairport_sync_basic_remote_control_set_server(shairportSyncBasicRemoteControlSkeleton, argc->client_ip); + else + shairport_sync_basic_remote_control_set_server(shairportSyncBasicRemoteControlSkeleton, ""); + + GVariantBuilder *dict_builder, *aa; + + /* Build the metadata array */ + // debug(1,"Build metadata"); + dict_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + // Make up the artwork URI if we have one + if (argc->cover_art_pathname) { + char artURIstring[1024]; + sprintf(artURIstring, "file://%s", argc->cover_art_pathname); + // sprintf(artURIstring,""); + // debug(1,"artURI String: \"%s\".",artURIstring); + GVariant *artUrl = g_variant_new("s", artURIstring); + g_variant_builder_add(dict_builder, "{sv}", "mpris:artUrl", artUrl); + } + + // Add the TrackID if we have one + if (argc->item_id) { + char trackidstring[128]; + // debug(1, "Set ID using mper ID: \"%u\".",argc->item_id); + sprintf(trackidstring, "/org/gnome/ShairportSync/mper_%u", argc->item_id); + GVariant *trackid = g_variant_new("o", trackidstring); + g_variant_builder_add(dict_builder, "{sv}", "mpris:trackid", trackid); + } + + // Add the track name if there is one + if (argc->track_name) { + // debug(1, "Track name set to \"%s\".", argc->track_name); + GVariant *trackname = g_variant_new("s", argc->track_name); + g_variant_builder_add(dict_builder, "{sv}", "xesam:title", trackname); + } + + // Add the album name if there is one + if (argc->album_name) { + // debug(1, "Album name set to \"%s\".", argc->album_name); + GVariant *albumname = g_variant_new("s", argc->album_name); + g_variant_builder_add(dict_builder, "{sv}", "xesam:album", albumname); + } + + // Add the artists if there are any (actually there will be at most one, but put it in an array) + if (argc->artist_name) { + /* Build the artists array */ + // debug(1,"Build artist array"); + aa = g_variant_builder_new(G_VARIANT_TYPE("as")); + g_variant_builder_add(aa, "s", argc->artist_name); + GVariant *artists = g_variant_builder_end(aa); + g_variant_builder_unref(aa); + g_variant_builder_add(dict_builder, "{sv}", "xesam:artist", artists); + } + + // Add the genres if there are any (actually there will be at most one, but put it in an array) + if (argc->genre) { + // debug(1,"Build genre"); + aa = g_variant_builder_new(G_VARIANT_TYPE("as")); + g_variant_builder_add(aa, "s", argc->genre); + GVariant *genres = g_variant_builder_end(aa); + g_variant_builder_unref(aa); + g_variant_builder_add(dict_builder, "{sv}", "xesam:genre", genres); + } + + GVariant *dict = g_variant_builder_end(dict_builder); + g_variant_builder_unref(dict_builder); + + // debug(1,"Set metadata"); + shairport_sync_basic_remote_control_set_metadata(shairportSyncBasicRemoteControlSkeleton, dict); + + +} + +static gboolean on_handle_fast_forward(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("beginff"); + shairport_sync_basic_remote_control_complete_fast_forward(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_rewind(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("beginrew"); + shairport_sync_basic_remote_control_complete_rewind(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_toggle_mute(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("mutetoggle"); + shairport_sync_basic_remote_control_complete_toggle_mute(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_next(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("nextitem"); + shairport_sync_basic_remote_control_complete_next(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_previous(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("previtem"); + shairport_sync_basic_remote_control_complete_previous(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_pause(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("pause"); + shairport_sync_basic_remote_control_complete_pause(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_play_pause(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("playpause"); + shairport_sync_basic_remote_control_complete_play_pause(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_play(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("play"); + shairport_sync_basic_remote_control_complete_play(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_stop(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("stop"); + shairport_sync_basic_remote_control_complete_stop(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_resume(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("playresume"); + shairport_sync_basic_remote_control_complete_resume(skeleton, invocation); + return TRUE; +} + + +static gboolean on_handle_shuffle_songs(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("shuffle_songs"); + shairport_sync_basic_remote_control_complete_shuffle_songs(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_volume_up(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("volumeup"); + shairport_sync_basic_remote_control_complete_volume_up(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_volume_down(ShairportSyncBasicRemoteControl *skeleton, GDBusMethodInvocation *invocation, + __attribute__((unused)) gpointer user_data) { + send_simple_dacp_command("volumedown"); + shairport_sync_basic_remote_control_complete_volume_down(skeleton, invocation); + return TRUE; +} + +gboolean notify_elapsed_time_callback(ShairportSyncDiagnostics *skeleton, + __attribute__((unused)) gpointer user_data) { + // debug(1, "\"notify_elapsed_time_callback\" called."); + if (shairport_sync_diagnostics_get_elapsed_time(skeleton)) { + config.debugger_show_elapsed_time = 1; + debug(1, ">> start including elapsed time in logs"); + } else { + config.debugger_show_elapsed_time = 0; + debug(1, ">> stop including elapsed time in logs"); + } + return TRUE; +} + +gboolean notify_delta_time_callback(ShairportSyncDiagnostics *skeleton, + __attribute__((unused)) gpointer user_data) { + // debug(1, "\"notify_delta_time_callback\" called."); + if (shairport_sync_diagnostics_get_delta_time(skeleton)) { + config.debugger_show_relative_time = 1; + debug(1, ">> start including delta time in logs"); + } else { + config.debugger_show_relative_time = 0; + debug(1, ">> stop including delta time in logs"); + } + return TRUE; +} + +gboolean notify_statistics_callback(ShairportSyncDiagnostics *skeleton, + __attribute__((unused)) gpointer user_data) { + // debug(1, "\"notify_statistics_callback\" called."); + if (shairport_sync_diagnostics_get_statistics(skeleton)) { + debug(1, ">> start logging statistics"); + config.statistics_requested = 1; + } else { + debug(1, ">> stop logging statistics"); + config.statistics_requested = 0; + } + return TRUE; +} + +gboolean notify_verbosity_callback(ShairportSyncDiagnostics *skeleton, + __attribute__((unused)) gpointer user_data) { + gint th = shairport_sync_diagnostics_get_verbosity(skeleton); + if ((th >= 0) && (th <= 3)) { + if (th==0) + debug(1, ">> log verbosity set to %d.", th); + debuglev = th; + debug(1, ">> log verbosity set to %d.", th); + } else { + debug(1, ">> invalid log verbosity: %d. Ignored.", th); + } + return TRUE; } gboolean notify_loudness_filter_active_callback(ShairportSync *skeleton, @@ -100,11 +319,74 @@ static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name g_signal_connect(shairportSyncSkeleton, "handle-set-volume", G_CALLBACK(on_handle_set_volume), NULL); - add_metadata_watcher(dbus_metadata_watcher, NULL); + // debug(1,"dbus_diagnostics_on_dbus_name_acquired"); + shairportSyncDiagnosticsSkeleton = shairport_sync_diagnostics_skeleton_new(); + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(shairportSyncDiagnosticsSkeleton), connection, + "/org/gnome/ShairportSync", NULL); + + shairport_sync_diagnostics_set_verbosity(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), + debuglev); + + // debug(2,">> log verbosity is %d.",debuglev); + + if (config.statistics_requested == 0) { + shairport_sync_diagnostics_set_statistics(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); + // debug(1, ">> statistics logging is off"); + } else { + shairport_sync_diagnostics_set_statistics(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); + // debug(1, ">> statistics logging is on"); + } -#ifdef HAVE_DBUS_DIAGNOSTICS - dbus_diagnostics_on_dbus_name_acquired(connection,name,user_data); -#endif + if (config.debugger_show_elapsed_time == 0) { + shairport_sync_diagnostics_set_elapsed_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); + // debug(1, ">> elapsed time is included in log entries"); + } else { + shairport_sync_diagnostics_set_elapsed_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); + // debug(1, ">> elapsed time is not included in log entries"); + } + + if (config.debugger_show_relative_time == 0) { + shairport_sync_diagnostics_set_delta_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE); + // debug(1, ">> delta time is included in log entries"); + } else { + shairport_sync_diagnostics_set_delta_time(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE); + // debug(1, ">> delta time is not included in log entries"); + } + + g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::verbosity", + G_CALLBACK(notify_verbosity_callback), NULL); + + g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::statistics", + G_CALLBACK(notify_statistics_callback), NULL); + + g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::elapsed-time", + G_CALLBACK(notify_elapsed_time_callback), NULL); + + g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::delta-time", + G_CALLBACK(notify_delta_time_callback), NULL); + + // debug(1,"dbus_basic_remote_control_on_dbus_name_acquired"); + shairportSyncBasicRemoteControlSkeleton = shairport_sync_basic_remote_control_skeleton_new(); + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(shairportSyncBasicRemoteControlSkeleton), connection, + "/org/gnome/ShairportSync", NULL); + + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-fast-forward", G_CALLBACK(on_handle_fast_forward), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-rewind", G_CALLBACK(on_handle_rewind), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-toggle-mute", G_CALLBACK(on_handle_toggle_mute), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-next", G_CALLBACK(on_handle_next), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-previous", G_CALLBACK(on_handle_previous), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-pause", G_CALLBACK(on_handle_pause), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-play-pause", G_CALLBACK(on_handle_play_pause), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-play", G_CALLBACK(on_handle_play), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-stop", G_CALLBACK(on_handle_stop), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-resume", G_CALLBACK(on_handle_resume), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-shuffle-songs", G_CALLBACK(on_handle_shuffle_songs), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-volume-up", G_CALLBACK(on_handle_volume_up), NULL); + g_signal_connect(shairportSyncBasicRemoteControlSkeleton, "handle-volume-down", G_CALLBACK(on_handle_volume_down), NULL); + + + + add_metadata_watcher(dbus_metadata_watcher, NULL); #ifdef HAVE_DBUS_BASIC_REMOTE_CONTROL dbus_basic_remote_control_on_dbus_name_acquired(connection,name,user_data); diff --git a/org.gnome.ShairportSync.Basic.Remote.Control.xml b/org.gnome.ShairportSync.Basic.Remote.Control.xml deleted file mode 100644 index d968d2e3..00000000 --- a/org.gnome.ShairportSync.Basic.Remote.Control.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.gnome.ShairportSync.Diagnostics.xml b/org.gnome.ShairportSync.Diagnostics.xml deleted file mode 100644 index fed5c4b9..00000000 --- a/org.gnome.ShairportSync.Diagnostics.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/org.gnome.ShairportSync.xml b/org.gnome.ShairportSync.xml index 5d5da742..7a9c8663 100644 --- a/org.gnome.ShairportSync.xml +++ b/org.gnome.ShairportSync.xml @@ -11,4 +11,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +