aboutsummaryrefslogtreecommitdiff
path: root/lib/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-08-22 15:12:38 +0800
committerWilliam Hua <william.hua@canonical.com>2013-08-22 15:12:38 +0800
commit201e48e1b010ebf180034abb8d61cafaba8a08a0 (patch)
tree0607277874705a1a4a5a84086dd56d27a5c7cd72 /lib/main.vala
parente7ef3f36cbce553d8a202c2abca6472797194a6f (diff)
downloadayatana-indicator-keyboard-201e48e1b010ebf180034abb8d61cafaba8a08a0.tar.gz
ayatana-indicator-keyboard-201e48e1b010ebf180034abb8d61cafaba8a08a0.tar.bz2
ayatana-indicator-keyboard-201e48e1b010ebf180034abb8d61cafaba8a08a0.zip
Proper shutdown on SIGTERM.
Diffstat (limited to 'lib/main.vala')
-rw-r--r--lib/main.vala32
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/main.vala b/lib/main.vala
index d601f6f9..073b0588 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -19,6 +19,7 @@
[DBus (name = "com.canonical.indicator.keyboard")]
public class Indicator.Keyboard.Service : Object {
+ private static Service service;
private static IBus.Bus? ibus;
private bool force;
@@ -77,6 +78,22 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
+ public void up () {
+ if (loop == null) {
+ loop = new MainLoop ();
+ ((!) loop).run ();
+ }
+ }
+
+ [DBus (visible = false)]
+ public void down () {
+ if (loop != null) {
+ ((!) loop).quit ();
+ loop = null;
+ }
+ }
+
+ [DBus (visible = false)]
private void acquire_bus_name () {
Bus.own_name (BusType.SESSION,
"com.canonical.indicator.keyboard",
@@ -84,9 +101,6 @@ public class Indicator.Keyboard.Service : Object {
handle_bus_acquired,
null,
handle_name_lost);
-
- loop = new MainLoop ();
- ((!) loop).run ();
}
[DBus (visible = false)]
@@ -428,13 +442,19 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
private void handle_name_lost (DBusConnection? connection, string name) {
- ((!) loop).quit ();
- loop = null;
+ down ();
}
[DBus (visible = false)]
public static int main (string[] args) {
- new Service (ref args);
+ Service.service = new Service (ref args);
+
+ Posix.signal (Posix.SIGTERM, (code) => {
+ Service.service.down ();
+ });
+
+ Service.service.up ();
+
return 0;
}
}