aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2015-02-11 18:37:51 -0600
committerTed Gould <ted@gould.cx>2015-02-11 18:37:51 -0600
commit180bc45d31558eb19761e07f71beb8d58054c3dc (patch)
tree0e77e09c653ac4d7fe548231c5db722bece7b2a7 /src/main.c
parent10d44ff66a7efb25cd2f69300ed04e97b084034f (diff)
downloadayatana-indicator-sound-180bc45d31558eb19761e07f71beb8d58054c3dc.tar.gz
ayatana-indicator-sound-180bc45d31558eb19761e07f71beb8d58054c3dc.tar.bz2
ayatana-indicator-sound-180bc45d31558eb19761e07f71beb8d58054c3dc.zip
Make it so that Vala stops generating circular references
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 01bc951..516b0c9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,7 +9,7 @@
#include "indicator-sound-service.h"
#include "config.h"
-gboolean
+static gboolean
sigterm_handler (gpointer data)
{
g_debug("Got SIGTERM");
@@ -17,15 +17,32 @@ sigterm_handler (gpointer data)
return G_SOURCE_REMOVE;
}
+static void
+name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data)
+{
+ g_debug("Name lost");
+ g_main_loop_quit((GMainLoop *)user_data);
+}
+
int
main (int argc, char ** argv) {
GMainLoop * loop = NULL;
IndicatorSoundService* service = NULL;
+ GDBusConnection * bus = NULL;
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ /* Grab DBus */
+ GError * error = NULL;
+ bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+ if (error != NULL) {
+ g_error("Unable to get session bus: %s", error->message);
+ g_error_free(error);
+ return -1;
+ }
+
/* Build Mainloop */
loop = g_main_loop_new(NULL, FALSE);
@@ -46,15 +63,23 @@ main (int argc, char ** argv) {
VolumeControlPulse * volume = volume_control_pulse_new();
- service = indicator_sound_service_new (loop, playerlist, volume, accounts);
+ service = indicator_sound_service_new (playerlist, volume, accounts);
+
+ g_bus_own_name_on_connection(bus,
+ "com.canonical.indicator.sound",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, /* acquired */
+ name_lost,
+ loop,
+ NULL);
g_main_loop_run(loop);
- g_object_unref(playerlist);
+ g_clear_object(&playerlist);
g_clear_object(&accounts);
- g_object_unref(service);
+ g_clear_object(&service);
+ g_clear_object(&bus);
return 0;
}
-