173 lines
5.9 KiB
C
173 lines
5.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <popt.h>
|
|
#include "dbus-interface.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);
|
|
}
|
|
}
|
|
}
|
|
|
|
void notify_loudness_filter_active_callback(ShairportSync *proxy, gpointer user_data) {
|
|
// printf("\"notify_loudness_filter_active_callback\" called with a gpointer of
|
|
// %lx.\n",(int64_t)user_data);
|
|
gboolean ebl = shairport_sync_get_loudness_filter_active(proxy);
|
|
if (ebl == TRUE)
|
|
printf("Client reports loudness is enabled.\n");
|
|
else
|
|
printf("Client reports loudness is disabled.\n");
|
|
}
|
|
|
|
void notify_loudness_threshold_callback(ShairportSync *proxy, gpointer user_data) {
|
|
gdouble th = shairport_sync_get_loudness_threshold(proxy);
|
|
printf("Client reports loudness threshold set to %.2f dB.\n", th);
|
|
}
|
|
|
|
void notify_volume_callback(ShairportSync *proxy, gpointer user_data) {
|
|
gdouble th = shairport_sync_get_volume(proxy);
|
|
printf("Client reports volume set to %.2f.\n", th);
|
|
}
|
|
|
|
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(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);
|
|
}
|
|
|
|
|
|
/* Now do options processing */
|
|
while ((c = poptGetNextOpt(optCon)) >= 0) {
|
|
}
|
|
|
|
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);
|
|
|
|
ShairportSync *proxy;
|
|
GError *error = NULL;
|
|
|
|
proxy = shairport_sync_proxy_new_for_bus_sync(gbus_type_selected, G_DBUS_PROXY_FLAGS_NONE,
|
|
"org.gnome.ShairportSync",
|
|
"/org/gnome/ShairportSync", NULL, &error);
|
|
|
|
// g_signal_connect(proxy, "notify::loudness-filter-active",
|
|
// G_CALLBACK(notify_loudness_filter_active_callback), NULL);
|
|
|
|
g_signal_connect(proxy, "g-properties-changed", G_CALLBACK(on_properties_changed), NULL);
|
|
g_signal_connect(proxy, "notify::loudness-threshold",
|
|
G_CALLBACK(notify_loudness_threshold_callback), NULL);
|
|
g_signal_connect(proxy, "notify::volume", G_CALLBACK(notify_volume_callback), NULL);
|
|
|
|
g_print("Starting test...\n");
|
|
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 20);
|
|
sleep(5);
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 100);
|
|
sleep(5);
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 40);
|
|
sleep(5);
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 60);
|
|
// sleep(1);
|
|
/*
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 10);
|
|
sleep(1);
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 0);
|
|
sleep(1);
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 25);
|
|
sleep(1);
|
|
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), 100);
|
|
sleep(1);
|
|
shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(proxy), TRUE);
|
|
sleep(10);
|
|
shairport_sync_set_loudness_threshold(SHAIRPORT_SYNC(proxy), -20.0);
|
|
sleep(5);
|
|
shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(proxy), FALSE);
|
|
sleep(5);
|
|
shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(proxy), TRUE);
|
|
sleep(5);
|
|
shairport_sync_set_loudness_threshold(SHAIRPORT_SYNC(proxy), -10.0);
|
|
sleep(10);
|
|
shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(proxy), FALSE);
|
|
sleep(1);
|
|
|
|
shairport_sync_call_remote_command(SHAIRPORT_SYNC(proxy), "string",NULL,NULL,NULL);
|
|
*/
|
|
g_print("Finished test. Waiting for property changes...\n");
|
|
// g_main_loop_quit(loop);
|
|
pthread_join(dbus_thread, NULL);
|
|
printf("exiting program.\n");
|
|
|
|
g_object_unref(proxy);
|
|
|
|
return 0;
|
|
}
|