1/* 2 * Copyright 2011 Julien Lavergne <gilir@ubuntu.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 * MA 02110-1301, USA. 18 */ 19 20namespace Lxsession 21{ 22 23public class SessionObject: Object { 24 25 public ConsoleKitObject dbus_interface; 26 27 public SessionObject() 28 { 29 try 30 { 31 dbus_interface = GLib.Bus.get_proxy_sync( BusType.SYSTEM, 32 "org.freedesktop.ConsoleKit", 33 "/org/freedesktop/ConsoleKit/Manager"); 34 } 35 catch (IOError e) 36 { 37 message ("Could not register service\n"); 38 } 39 } 40 41 public async bool lxsession_can_shutdown() { 42 bool can_shutdown_available = false; 43 try { 44 can_shutdown_available = yield dbus_interface.can_stop (); 45 } 46 catch (IOError err) { 47 warning ("%s", err.message); 48 can_shutdown_available = false; 49 } 50 return can_shutdown_available; 51 52 } 53 54 public void lxsession_shutdown() { 55 try { 56 dbus_interface.stop (); 57 } 58 catch (IOError err) { 59 warning ("%s", err.message); 60 } 61 } 62 63 public void lxsession_restart() { 64 try { 65 dbus_interface.restart (); 66 } 67 catch (IOError err) { 68 warning ("%s", err.message); 69 } 70 } 71 72} 73 74[DBus (name = "org.freedesktop.ConsoleKit.Manager")] 75public interface ConsoleKitObject: Object { 76 public const string UNIQUE_NAME = "org.freedesktop.ConsoleKit"; 77 public const string OBJECT_PATH = "/org/freedesktop/ConsoleKit/Manager"; 78 public const string INTERFACE_NAME = "org.freedesktop.ConsoleKit.Manager"; 79 80 public abstract void restart () throws IOError; 81 public abstract void stop () throws IOError; 82 public abstract async bool can_restart () throws IOError; 83 public abstract async bool can_stop () throws IOError; 84} 85 86void on_bus_aquired (DBusConnection conn) { 87 try { 88 conn.register_object ("/org/lxde/SessionManager", new LxdeSessionServer()); 89 } catch (IOError e) { 90 stderr.printf ("Could not register service\n"); 91 } 92} 93 94void on_gnome_bus_aquired (DBusConnection conn) { 95 try { 96 conn.register_object ("/org/gnome/SessionManager", new GnomeSessionServer()); 97 } catch (IOError e) { 98 stderr.printf ("Could not register service\n"); 99 } 100} 101 102} 103