[rygel] core: Provide DBus service



commit c2537d439b23520f2ef05c260ce7be9d5e89970c
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sun Jun 7 00:26:20 2009 +0300

    core: Provide DBus service
    
    Provide DBus service with one method: org.gnome.Rygel.Shutdown.

 src/rygel/Makefile.am             |    3 ++
 src/rygel/rygel-dbus-service.vala |   56 +++++++++++++++++++++++++++++++++++++
 src/rygel/rygel-main.vala         |    2 +
 3 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index c71e06b..b284318 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -33,6 +33,7 @@ BUILT_SOURCES = rygel-1.0.vapi \
 		rygel-root-device-factory.c \
 		rygel-configuration.c \
 		rygel-main.c \
+		rygel-dbus-service.c \
 		rygel-content-directory.c \
 		rygel-browse.c \
 		rygel-didl-lite-writer.c \
@@ -62,6 +63,8 @@ rygel_SOURCES = $(VAPI_SOURCE_FILES) \
 		rygel-root-device-factory.vala \
 		rygel-main.c \
 		rygel-main.vala \
+		rygel-dbus-service.c \
+		rygel-dbus-service.vala \
 		rygel-content-directory.c \
 		rygel-browse.c \
 		rygel-didl-lite-writer.c \
diff --git a/src/rygel/rygel-dbus-service.vala b/src/rygel/rygel-dbus-service.vala
new file mode 100644
index 0000000..a76767a
--- /dev/null
+++ b/src/rygel/rygel-dbus-service.vala
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+[DBus (name = "org.gnome.Rygel")]
+public class Rygel.DBusService : Object {
+    private static string RYGEL_SERVICE = "org.gnome.Rygel";
+    private static string RYGEL_PATH = "/org/gnome/Rygel";
+
+    private Main main;
+
+    public DBusService (Main main) throws GLib.Error {
+        this.main = main;
+
+        var conn = DBus.Bus.get (DBus.BusType. SESSION);
+
+        dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
+                                                   "/org/freedesktop/DBus",
+                                                   "org.freedesktop.DBus");
+
+        // try to register service in session bus
+        uint request_name_result = bus.request_name (RYGEL_SERVICE,
+                                                     (uint) 0);
+
+        if (request_name_result != DBus.RequestNameReply.PRIMARY_OWNER) {
+            warning ("Failed to start D-Bus service, name '%s' already taken",
+                     RYGEL_SERVICE);
+        }
+
+        conn.register_object (RYGEL_PATH, this);
+    }
+
+    public void Shutdown () {
+        this.main.exit (0);
+    }
+}
+
diff --git a/src/rygel/rygel-main.vala b/src/rygel/rygel-main.vala
index 585b939..591d34b 100644
--- a/src/rygel/rygel-main.vala
+++ b/src/rygel/rygel-main.vala
@@ -94,12 +94,14 @@ public class Rygel.Main : Object {
 
     public static int main (string[] args) {
         Main main;
+        DBusService service;
 
         // initialize gstreamer
         Gst.init (ref args);
 
         try {
             main = new Main ();
+            service = new DBusService (main);
         } catch (GLib.Error err) {
             error ("%s", err.message);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]