Some spring cleaning using clang-format

This commit is contained in:
Mike Brady
2017-10-05 17:48:24 +01:00
parent 87bf5e87ac
commit d343a851c0
12 changed files with 269 additions and 291 deletions
+25 -23
View File
@@ -9,36 +9,36 @@
#include "dbus_service.h"
void notify_loudness_filter_active_callback(ShairportSync *skeleton, gpointer user_data) {
debug(1,"\"notify_loudness_filter_active_callback\" called.");
if (shairport_sync_get_loudness_filter_active (skeleton)) {
debug(1,"activating loudness filter");
debug(1, "\"notify_loudness_filter_active_callback\" called.");
if (shairport_sync_get_loudness_filter_active(skeleton)) {
debug(1, "activating loudness filter");
config.loudness = 1;
} else {
debug(1,"deactivating loudness filter");
debug(1, "deactivating loudness filter");
config.loudness = 0;
}
}
void notify_loudness_threshold_callback(ShairportSync *skeleton, gpointer user_data) {
gdouble th = shairport_sync_get_loudness_threshold (skeleton);
gdouble th = shairport_sync_get_loudness_threshold(skeleton);
if ((th <= 0.0) && (th >= -100.0)) {
debug(1,"Setting loudness threshhold to %f.",th);
debug(1, "Setting loudness threshhold to %f.", th);
config.loudness_reference_volume_db = th;
} else {
debug(1,"Invalid loudness threshhold: %f. Ignored.",th);
debug(1, "Invalid loudness threshhold: %f. Ignored.", th);
}
}
void notify_volume_callback(ShairportSync *skeleton, gpointer user_data) {
gdouble vo = shairport_sync_get_volume (skeleton);
gdouble vo = shairport_sync_get_volume(skeleton);
if (((vo <= 0.0) && (vo >= -30.0)) || (vo == -144.0)) {
debug(1,"Setting volume to %f.",vo);
debug(1, "Setting volume to %f.", vo);
if (playing_conn)
player_volume_without_notification(vo,playing_conn);
player_volume_without_notification(vo, playing_conn);
else
debug(1,"no thread playing -- ignored.");
debug(1, "no thread playing -- ignored.");
} else {
debug(1,"Invalid volume: %f -- ignored.",vo);
debug(1, "Invalid volume: %f -- ignored.", vo);
}
}
@@ -48,22 +48,24 @@ static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpo
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skeleton), connection,
"/org/gnome/ShairportSync", NULL);
shairport_sync_set_loudness_threshold(SHAIRPORT_SYNC(skeleton), config.loudness_reference_volume_db);
debug(1,"Loudness threshold is %f.",config.loudness_reference_volume_db);
if (config.loudness==0) {
shairport_sync_set_loudness_threshold(SHAIRPORT_SYNC(skeleton),
config.loudness_reference_volume_db);
debug(1, "Loudness threshold is %f.", config.loudness_reference_volume_db);
if (config.loudness == 0) {
shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(skeleton), FALSE);
debug(1,"Loudness is off");
debug(1, "Loudness is off");
} else {
shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(skeleton), TRUE);
debug(1,"Loudness is on");
debug(1, "Loudness is on");
}
g_signal_connect(skeleton, "notify::loudness-filter-active", G_CALLBACK(notify_loudness_filter_active_callback), NULL);
g_signal_connect(skeleton, "notify::loudness-threshold", G_CALLBACK(notify_loudness_threshold_callback), NULL);
g_signal_connect(skeleton, "notify::volume", G_CALLBACK(notify_volume_callback), NULL);
g_signal_connect(skeleton, "notify::loudness-filter-active",
G_CALLBACK(notify_loudness_filter_active_callback), NULL);
g_signal_connect(skeleton, "notify::loudness-threshold",
G_CALLBACK(notify_loudness_threshold_callback), NULL);
g_signal_connect(skeleton, "notify::volume", G_CALLBACK(notify_volume_callback), NULL);
}
int start_dbus_service() {
+41 -53
View File
@@ -5,51 +5,42 @@
GMainLoop *loop;
void on_properties_changed (GDBusProxy *proxy,
GVariant *changed_properties,
const gchar* const *invalidated_properties,
gpointer user_data)
{
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;
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);
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);
}
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);
// 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
@@ -57,26 +48,25 @@ void notify_loudness_filter_active_callback(ShairportSync *proxy, gpointer user_
}
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);
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 dB.\n",th);
gdouble th = shairport_sync_get_volume(proxy);
printf("Client reports volume set to %.2f dB.\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
// dbus_service_main(); // let it run inside a thread
}
void main(void) {
pthread_create(&dbus_thread, NULL, &dbus_thread_func, NULL);
@@ -85,21 +75,19 @@ void main(void) {
GError *error = NULL;
proxy = shairport_sync_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
"org.gnome.ShairportSync", "/org/gnome/ShairportSync", NULL, &error);
"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, "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, "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.0);
sleep(10);
shairport_sync_set_volume(SHAIRPORT_SYNC(proxy), -10.0);
@@ -121,8 +109,8 @@ void main(void) {
sleep(15);
g_print("Finished test...\n");
g_main_loop_quit(loop);
pthread_join(dbus_thread,NULL);
pthread_join(dbus_thread, NULL);
printf("exiting program.\n");
g_object_unref(proxy);
}