build,core,plugins: Port to GDBus and GVariant
[profile/ivi/rygel.git] / src / rygel / rygel-dbus-service.vala
1 /*
2  * Copyright (C) 2008,2010 Nokia Corporation.
3  * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
4  *
5  * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
6  *
7  * This file is part of Rygel.
8  *
9  * Rygel is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Rygel is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  */
23
24 using FreeDesktop;
25
26 // FIXME: Declare that we implement DBusInterface once bug#631044 is fixed.
27 [DBus (name = "org.gnome.Rygel1")]
28 public class Rygel.DBusService : Object {
29     private Main main;
30
31     public DBusService (Main main) throws IOError {
32         this.main = main;
33
34         DBusObject bus = Bus.get_proxy_sync (BusType.SESSION,
35                                              DBUS_SERVICE,
36                                              DBUS_OBJECT);
37
38         // try to register service in session bus
39         if (bus.request_name (DBusInterface.SERVICE_NAME, 0) !=
40             DBusRequestNameReply.PRIMARY_OWNER) {
41             warning ("Failed to start D-Bus service  name '%s' already taken",
42                      DBusInterface.SERVICE_NAME);
43         } else {
44             var conn = Bus.get_sync (BusType.SESSION);
45
46             conn.register_object (DBusInterface.OBJECT_PATH, this);
47         }
48     }
49
50     public void shutdown () throws IOError {
51         this.main.exit (0);
52     }
53 }
54