aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2015-02-11 15:47:12 -0600
committerTed Gould <ted@gould.cx>2015-02-11 15:47:12 -0600
commit10d44ff66a7efb25cd2f69300ed04e97b084034f (patch)
treeb8298900d2d72ead4471ba9a32abd2e2af9beb20 /src
parent48117fc3ea085d123567ccb621809f43a4358938 (diff)
downloadayatana-indicator-sound-10d44ff66a7efb25cd2f69300ed04e97b084034f.tar.gz
ayatana-indicator-sound-10d44ff66a7efb25cd2f69300ed04e97b084034f.tar.bz2
ayatana-indicator-sound-10d44ff66a7efb25cd2f69300ed04e97b084034f.zip
Pulling the mainloop out of the service object
Diffstat (limited to 'src')
-rw-r--r--src/main.c22
-rw-r--r--src/service.vala50
2 files changed, 39 insertions, 33 deletions
diff --git a/src/main.c b/src/main.c
index 6cc3b13..01bc951 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,15 +9,28 @@
#include "indicator-sound-service.h"
#include "config.h"
+gboolean
+sigterm_handler (gpointer data)
+{
+ g_debug("Got SIGTERM");
+ g_main_loop_quit((GMainLoop *)data);
+ return G_SOURCE_REMOVE;
+}
+
int
main (int argc, char ** argv) {
- gint result = 0;
+ GMainLoop * loop = NULL;
IndicatorSoundService* service = NULL;
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ /* Build Mainloop */
+ loop = g_main_loop_new(NULL, FALSE);
+
+ g_unix_signal_add(SIGTERM, sigterm_handler, loop);
+
/* Initialize libnotify */
notify_init ("indicator-sound");
@@ -33,14 +46,15 @@ main (int argc, char ** argv) {
VolumeControlPulse * volume = volume_control_pulse_new();
- service = indicator_sound_service_new (playerlist, volume, accounts);
- result = indicator_sound_service_run (service);
+ service = indicator_sound_service_new (loop, playerlist, volume, accounts);
+
+ g_main_loop_run(loop);
g_object_unref(playerlist);
g_clear_object(&accounts);
g_object_unref(service);
- return result;
+ return 0;
}
diff --git a/src/service.vala b/src/service.vala
index da3bf09..4711867 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -18,7 +18,11 @@
*/
public class IndicatorSound.Service: Object {
- public Service (MediaPlayerList playerlist, VolumeControl volume, AccountsServiceUser? accounts) {
+ Cancellable cancel;
+
+ public Service (MainLoop inloop, MediaPlayerList playerlist, VolumeControl volume, AccountsServiceUser? accounts) {
+ loop = inloop;
+
sync_notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted");
this.notification_server_watch = GLib.Bus.watch_name(GLib.BusType.SESSION,
"org.freedesktop.Notifications",
@@ -89,9 +93,17 @@ public class IndicatorSound.Service: Object {
}
}
});
+
+ Bus.own_name (BusType.SESSION, "com.canonical.indicator.sound", BusNameOwnerFlags.NONE,
+ this.bus_acquired, null, this.name_lost);
}
~Service() {
+ debug("Destroying Service Object");
+
+ cancel.cancel();
+ clear_acts_player();
+
if (this.sound_was_blocked_timeout_id > 0) {
Source.remove (this.sound_was_blocked_timeout_id);
this.sound_was_blocked_timeout_id = 0;
@@ -119,30 +131,6 @@ public class IndicatorSound.Service: Object {
this.accounts_service.player = null;
}
- public int run () {
- if (this.loop != null) {
- warning ("service is already running");
- return 1;
- }
-
- Bus.own_name (BusType.SESSION, "com.canonical.indicator.sound", BusNameOwnerFlags.NONE,
- this.bus_acquired, null, this.name_lost);
-
- this.loop = new MainLoop (null, false);
-
- GLib.Unix.signal_add(GLib.ProcessSignal.TERM, () => {
- debug("SIGTERM recieved, stopping our mainloop");
- this.loop.quit();
- return false;
- });
-
- this.loop.run ();
-
- clear_acts_player();
-
- return 0;
- }
-
public bool visible { get; set; }
public bool allow_amplified_volume {
@@ -488,19 +476,23 @@ public class IndicatorSound.Service: Object {
DBusConnection? bus = null;
uint export_actions = 0;
- void bus_acquired (DBusConnection connection, string name) {
+ void bus_acquired (DBusConnection? connection, string name) {
+ if (connection == null)
+ return;
+
bus = connection;
try {
- export_actions = connection.export_action_group ("/com/canonical/indicator/sound", this.actions);
+ export_actions = bus.export_action_group ("/com/canonical/indicator/sound", this.actions);
} catch (Error e) {
critical ("%s", e.message);
}
- this.menus.@foreach ( (profile, menu) => menu.export (connection, @"/com/canonical/indicator/sound/$profile"));
+ return;
+ this.menus.@foreach ( (profile, menu) => menu.export (bus, @"/com/canonical/indicator/sound/$profile"));
}
- void name_lost (DBusConnection connection, string name) {
+ void name_lost (DBusConnection? connection, string name) {
this.loop.quit ();
}