[rygel] media-export: Add simple dbus service
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Add simple dbus service
- Date: Fri, 11 Sep 2009 17:23:35 +0000 (UTC)
commit 3288a75feefc67a8e08743945630abab40f4e4e8
Author: Jens Georg <mail jensge org>
Date: Thu Jul 2 23:16:54 2009 +0200
media-export: Add simple dbus service
src/plugins/media-export/Makefile.am | 2 +
.../rygel-media-export-dbus-service.vala | 60 ++++++++++++++++++++
.../media-export/rygel-media-export-harvester.vala | 1 +
.../rygel-media-export-root-container.vala | 16 +++++
4 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 83045f5..093d516 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -12,11 +12,13 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
librygel_media_export_la_SOURCES = rygel-media-export-plugin.vala \
rygel-media-export-null-container.vala \
rygel-media-export-root-container.vala \
+ rygel-media-export-dbus-service.vala \
rygel-media-export-recursive-file-monitor.vala \
rygel-media-export-harvester.vala \
rygel-media-export-item.vala
librygel_media_export_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \
+ --pkg dbus-glib-1 \
--pkg rygel-1.0 \
--pkg cstuff \
--pkg gupnp-1.0 \
diff --git a/src/plugins/media-export/rygel-media-export-dbus-service.vala b/src/plugins/media-export/rygel-media-export-dbus-service.vala
new file mode 100644
index 0000000..8ba343f
--- /dev/null
+++ b/src/plugins/media-export/rygel-media-export-dbus-service.vala
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 Jens Georg <mail jensge 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.MediaExport1")]
+public class Rygel.MediaExportDBusService : Object {
+ private const string RYGEL_MEDIA_EXPORT_SERVICE =
+ "org.gnome.Rygel.MediaExport1";
+ private const string RYGEL_MEDIA_EXPORT_PATH =
+ "/org/gnome/Rygel/MediaExport1";
+
+ private MediaExportRootContainer root_container;
+
+ public MediaExportDBusService (MediaExportRootContainer root_container)
+ throws GLib.Error {
+ this.root_container = root_container;
+
+ 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_MEDIA_EXPORT_SERVICE,
+ (uint) 0);
+
+ if (request_name_result != DBus.RequestNameReply.PRIMARY_OWNER) {
+ warning ("Failed to start D-Bus service, name '%s' already taken",
+ RYGEL_MEDIA_EXPORT_SERVICE);
+ }
+
+ conn.register_object (RYGEL_MEDIA_EXPORT_PATH, this);
+ }
+
+ public void AddUri (string uri) {
+ this.root_container.add_uri (uri);
+ }
+
+ public void RemoveUri (string uri) {
+ this.root_container.remove_uri (uri);
+ }
+}
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala b/src/plugins/media-export/rygel-media-export-harvester.vala
index 92b06cb..20c533d 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -96,6 +96,7 @@ public class Rygel.MediaExportHarvester : GLib.Object {
if (this.files.get_length() == 0 &&
this.containers.get_length () != 0) {
this.containers.pop_head ();
+ this.containers.peek_head ().updated ();
}
} catch (MediaDBError err) {
warning("Failed to get children of container %s: %s",
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index 3e13e8d..deb056e 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -27,6 +27,7 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
private MetadataExtractor extractor;
private HashMap<File, MediaExportHarvester> harvester;
private MediaExportRecursiveFileMonitor monitor;
+ private MediaExportDBusService service;
private static MediaContainer instance = null;
@@ -75,6 +76,19 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
return MediaExportRootContainer.instance;
}
+ public void add_uri (string uri) {
+ var file = File.new_for_commandline_arg (uri);
+ this.harvest (file);
+ }
+
+ public void remove_uri (string uri) {
+ var file = File.new_for_commandline_arg (uri);
+ var id = Checksum.compute_for_string (ChecksumType.MD5,
+ file.get_uri ());
+ this.media_db.delete_by_id (id);
+ }
+
+
/**
* Create a new root container.
*/
@@ -89,6 +103,8 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
this.monitor = new MediaExportRecursiveFileMonitor (null);
this.monitor.changed.connect (this.on_file_changed);
+ this.service = new MediaExportDBusService (this);
+
try {
media_db.save_object (this);
} catch (Error error) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]