Add a Shairport Sync Diagnostics DBus Onject, only part working

This commit is contained in:
Mike Brady
2018-03-10 17:01:42 +00:00
parent 39f159bf9e
commit 9d9b0a1824
11 changed files with 140 additions and 15 deletions
+1
View File
@@ -33,6 +33,7 @@ shairport-sync.core
/dbus-interface.*
/mpris-interface.*
/mpris-player-interface.*
/dbus-diagnostics-interface.*
# Some eclipse project files
.cproject
+19 -5
View File
@@ -75,6 +75,14 @@ if USE_DNS_SD
shairport_sync_SOURCES += mdns_dns_sd.c
endif
if USE_METADATA_HUB
shairport_sync_SOURCES += metadata_hub.c
endif
if USE_DACP_CLIENT
shairport_sync_SOURCES += dacp.c tinyhttp/chunk.c tinyhttp/header.c tinyhttp/http.c
endif
BUILT_SOURCES =
noinst_HEADERS =
CLEANFILES =
@@ -91,13 +99,19 @@ 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_METADATA_HUB
shairport_sync_SOURCES += metadata_hub.c
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_DACP_CLIENT
shairport_sync_SOURCES += dacp.c tinyhttp/chunk.c tinyhttp/header.c tinyhttp/http.c
endif
if USE_MPRIS
shairport_sync_SOURCES += mpris-service.c mpris-interface.c mpris-player-interface.c
+8
View File
@@ -976,3 +976,11 @@ uint32_t nctohl(const uint8_t *p) { // read 4 characters from the p and do ntohl
memcpy(&holder, p, sizeof(holder));
return ntohl(holder);
}
static pthread_mutex_t barrier_mutex = PTHREAD_MUTEX_INITIALIZER;
void memory_barrier() {
pthread_mutex_lock(&barrier_mutex);
pthread_mutex_unlock(&barrier_mutex);
}
+2
View File
@@ -178,6 +178,8 @@ typedef struct {
} shairport_cfg;
uint32_t nctohl(const uint8_t *p); // read 4 characters from the p and do ntohl on them
void memory_barrier();
// true if Shairport Sync is supposed to be sending output to the output device, false otherwise
+3
View File
@@ -279,9 +279,12 @@ AC_ARG_WITH(dbus, [ --with-dbus-interface = include support for a native Shairp
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.])
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"])
# Look for dbus test client flag
AC_ARG_WITH(dbus-test-client, [ --with-dbus-test-client = compile dbus test client], [
+75
View File
@@ -0,0 +1,75 @@
#include <stdio.h>
#include <string.h>
#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_include_statistics_in_log_callback(ShairportSyncDiagnostics *skeleton,
__attribute__((unused)) gpointer user_data) {
debug(1, "\"notify_include_statistics_in_log_callback\" called.");
if (shairport_sync_diagnostics_get_include_statistics_in_log(skeleton)) {
debug(1, ">> start logging statistics");
config.statistics_requested = 1;
} else {
debug(1, ">> stop logging statistics");
config.statistics_requested = 0;
}
return TRUE;
}
gboolean notify_log_verbosity_callback(ShairportSyncDiagnostics *skeleton,
__attribute__((unused)) gpointer user_data) {
gint th = shairport_sync_diagnostics_get_log_verbosity(skeleton);
if ((th >= 0) && (th <= 3)) {
debug(1, "Setting log verbosity to %d.", th);
debuglev = 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/Diagnostics", NULL);
shairport_sync_diagnostics_set_log_verbosity(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton),
debuglev);
debug(1,"Log verbosity is %d.",debuglev);
if (config.statistics_requested == 0) {
shairport_sync_diagnostics_set_include_statistics_in_log(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), FALSE);
debug(1, "Statistics Logging is off");
} else {
shairport_sync_diagnostics_set_include_statistics_in_log(SHAIRPORT_SYNC_DIAGNOSTICS(shairportSyncDiagnosticsSkeleton), TRUE);
debug(1, "Statistics Logging is on");
}
g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::log-verbosity",
G_CALLBACK(notify_log_verbosity_callback), NULL);
g_signal_connect(shairportSyncDiagnosticsSkeleton, "notify::include-statistics-in-log",
G_CALLBACK(notify_include_statistics_in_log_callback), NULL);
}
+10
View File
@@ -0,0 +1,10 @@
#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 */
+12 -4
View File
@@ -10,9 +10,14 @@
#include "rtp.h"
#include "dacp.h"
#include "metadata_hub.h"
#include "dbus-service.h"
#include "metadata_hub.h"
#ifdef HAVE_DBUS_DIAGNOSTICS
#include "dbus-diagnostics.h"
#endif
void dbus_metadata_watcher(struct metadata_bundle *argc, __attribute__((unused)) void *userdata) {
// debug(1, "DBUS metadata watcher called");
@@ -62,8 +67,7 @@ static gboolean on_handle_remote_command(ShairportSync *skeleton, GDBusMethodInv
return TRUE;
}
static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name,
__attribute__((unused)) gpointer user_data) {
static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) {
// debug(1, "Shairport Sync native D-Bus interface \"%s\" acquired on the %s bus.", name,
// (config.dbus_service_bus_type == DBT_session) ? "session" : "system");
@@ -94,6 +98,10 @@ static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name
NULL);
add_metadata_watcher(dbus_metadata_watcher, NULL);
#ifdef HAVE_DBUS_DIAGNOSTICS
dbus_diagnostics_on_dbus_name_acquired(connection,name,user_data);
#endif
debug(1, "Shairport Sync native D-Bus service started at \"%s\" on the %s bus.", name,
(config.dbus_service_bus_type == DBT_session) ? "session" : "system");
@@ -126,7 +134,7 @@ static void on_dbus_name_lost(__attribute__((unused)) GDBusConnection *connectio
}
int start_dbus_service() {
shairportSyncSkeleton = NULL;
// shairportSyncSkeleton = NULL;
GBusType dbus_bus_type = G_BUS_TYPE_SYSTEM;
if (config.dbus_service_bus_type == DBT_session)
dbus_bus_type = G_BUS_TYPE_SESSION;
-1
View File
@@ -3,7 +3,6 @@
#define DBUS_SERVICE_H
#include "dbus-interface.h"
ShairportSync *shairportSyncSkeleton;
int start_dbus_service();
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name="org.gnome.ShairportSync.Diagnostics">
<property name="LogVerbosity" type="i" access="readwrite" />
<property name="IncludeStatisticsInLog" type="b" access="readwrite" />
<property name="IncludeElapsedTimeInLog" type="b" access="readwrite" />
<property name="IncludeDeltaTimeInLog" type="b" access="readwrite" />
<property name="DisableResendRequests" type="b" access="readwrite" />
</interface>
</node>
-5
View File
@@ -85,7 +85,6 @@ enum rtsp_read_request_response {
};
// Mike Brady's part...
static pthread_mutex_t barrier_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t play_lock = PTHREAD_MUTEX_INITIALIZER;
// every time we want to retain or release a reference count, lock it with this
@@ -102,10 +101,6 @@ static rtsp_conn_info **conns = NULL;
int RTSP_connection_index = 0;
void memory_barrier() {
pthread_mutex_lock(&barrier_mutex);
pthread_mutex_unlock(&barrier_mutex);
}
#ifdef CONFIG_METADATA
typedef struct {