From e3d8bd27408fbd221b0422ea35325b7251d81e40 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Mon, 4 Oct 2010 11:41:48 +0300 Subject: [PATCH] build,core,plugins: Port to GDBus and GVariant Port from glib-dbus usage to the new awesome D-Bus APIs in gio (2.26). --- configure.ac | 3 - src/plugins/external/Makefile.am | 7 +- .../external/rygel-external-album-art-factory.vala | 23 ++--- src/plugins/external/rygel-external-container.vala | 32 +++---- .../external/rygel-external-icon-factory.vala | 44 ++++----- .../external/rygel-external-interfaces.vala | 24 +++-- .../external/rygel-external-item-factory.vala | 100 +++++++++++---------- .../external/rygel-external-plugin-factory.vala | 71 ++++++++------- src/plugins/external/rygel-external-plugin.vala | 24 +++-- .../external/rygel-external-thumbnail-factory.vala | 32 +++---- src/plugins/gst-launch/Makefile.am | 5 +- src/plugins/media-export/Makefile.am | 3 - .../rygel-media-export-dbus-service.vala | 7 +- src/plugins/mpris/Makefile.am | 2 - src/plugins/mpris/rygel-mpris-interfaces.vala | 20 ++--- src/plugins/mpris/rygel-mpris-player.vala | 6 +- src/plugins/mpris/rygel-mpris-plugin-factory.vala | 60 +++++++------ src/plugins/mpris/rygel-mpris-plugin.vala | 16 ++-- src/plugins/playbin/Makefile.am | 2 - src/plugins/test/Makefile.am | 5 +- src/plugins/tracker/Makefile.am | 6 +- .../tracker/rygel-tracker-insertion-query.vala | 2 +- src/plugins/tracker/rygel-tracker-interfaces.vala | 18 ++-- .../tracker/rygel-tracker-item-creation.vala | 14 +-- .../tracker/rygel-tracker-metadata-values.vala | 20 ++--- .../tracker/rygel-tracker-plugin-factory.vala | 11 ++- src/plugins/tracker/rygel-tracker-query.vala | 2 +- .../tracker/rygel-tracker-root-container.vala | 1 - .../tracker/rygel-tracker-search-container.vala | 14 +-- .../tracker/rygel-tracker-selection-query.vala | 2 +- src/plugins/tracker/rygel-tracker-tags.vala | 1 - src/rygel/Makefile.am | 14 +-- src/rygel/rygel-1.0.deps | 1 - src/rygel/rygel-dbus-interface.vala | 31 +++++++ src/rygel/rygel-dbus-service.vala | 32 ++++--- src/rygel/rygel-free-desktop-interfaces.vala | 34 ++++--- src/rygel/rygel-main.vala | 2 +- src/rygel/rygel-user-config.vala | 49 ++++------ src/ui/Makefile.am | 9 +- 39 files changed, 367 insertions(+), 382 deletions(-) create mode 100644 src/rygel/rygel-dbus-interface.vala diff --git a/configure.ac b/configure.ac index fd0c58b..891fd25 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,6 @@ GUPNP_REQUIRED=0.13.4 GUPNP_AV_REQUIRED=0.5.9 GUPNP_DLNA_REQUIRED=0.3.0 GUPNP_VALA_REQUIRED=0.6.11 -DBUS_GLIB_REQUIRED=0.74 GSTREAMER_REQUIRED=0.10.23 GSTREAMER_TAG_REQUIRED=0.10.28 GSTREAMER_APP_REQUIRED=0.10.28 @@ -38,7 +37,6 @@ LIBSQLITE3_REQUIRED=3.5 PKG_CHECK_MODULES(LIBGUPNP, gupnp-1.0 >= $GUPNP_REQUIRED) PKG_CHECK_MODULES(LIBGUPNP_AV, gupnp-av-1.0 >= $GUPNP_AV_REQUIRED) PKG_CHECK_MODULES(LIBGUPNP_DLNA, gupnp-dlna-1.0 >= $GUPNP_DLNA_REQUIRED) -PKG_CHECK_MODULES(LIBDBUS_GLIB, dbus-glib-1 >= $DBUS_GLIB_REQUIRED) PKG_CHECK_MODULES(LIBGSTREAMER, gstreamer-0.10 >= $GSTREAMER_REQUIRED) PKG_CHECK_MODULES(LIBGIO, gio-2.0 >= $GIO_REQUIRED) PKG_CHECK_MODULES(GEE, gee-1.0 >= $GEE_REQUIRED) @@ -89,7 +87,6 @@ if test x$enable_vala = xyes ; then VALA_CHECK_PACKAGES([gupnp-1.0 gupnp-av-1.0 gupnp-dlna-1.0 - dbus-glib-1 gstreamer-0.10 gstreamer-discoverer-gupnp-dlna-0.10 gio-2.0 diff --git a/src/plugins/external/Makefile.am b/src/plugins/external/Makefile.am index 3bd958f..72a7925 100644 --- a/src/plugins/external/Makefile.am +++ b/src/plugins/external/Makefile.am @@ -10,7 +10,6 @@ plugin_LTLIBRARIES = librygel-external.la AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(LIBGUPNP_AV_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ $(GEE_CFLAGS) \ $(LIBGSTREAMER_CFLAGS) \ $(UUID_FLAGS) \ @@ -30,13 +29,11 @@ librygel_external_la_SOURCES = rygel-external-container.vala \ rygel-external.stamp: $(librygel_external_la_VALASOURCES) librygel_external_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \ --pkg rygel-1.0 --pkg gupnp-1.0 \ - --pkg gupnp-av-1.0 --pkg dbus-glib-1 \ - --pkg gee-1.0 --pkg gstreamer-0.10 \ - --pkg gconf-2.0 -g + --pkg gupnp-av-1.0 --pkg gee-1.0 \ + --pkg gstreamer-0.10 --pkg gconf-2.0 -g librygel_external_la_LIBADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ - $(LIBDBUS_GLIB_LIBS) \ $(LIBGSTREAMER_LIBS) \ $(GEE_LIBS) \ $(UUID_LIBS) diff --git a/src/plugins/external/rygel-external-album-art-factory.vala b/src/plugins/external/rygel-external-album-art-factory.vala index 0608f1c..4d657fe 100644 --- a/src/plugins/external/rygel-external-album-art-factory.vala +++ b/src/plugins/external/rygel-external-album-art-factory.vala @@ -22,7 +22,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using DBus; using FreeDesktop; /** @@ -31,28 +30,30 @@ using FreeDesktop; public class Rygel.External.AlbumArtFactory { public async Thumbnail create (string service_name, string object_path, - string host_ip) - throws GLib.Error { - DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION); - - var props = connection.get_object (service_name, - object_path) - as Properties; + string host_ip) throws IOError { + Properties props = Bus.get_proxy_sync (BusType.SESSION, + service_name, + object_path); var item_props = yield props.get_all (MediaItemProxy.IFACE); + return this.create_from_props (item_props, host_ip); + } + + private Thumbnail create_from_props (HashTable props, + string host_ip) { var thumbnail = new AlbumArt (); - var value = item_props.lookup ("MIMEType"); + var value = props.lookup ("MIMEType"); thumbnail.mime_type = (string) value; - value = item_props.lookup ("URLs"); + value = props.lookup ("URLs"); var uris = (string[]) value; if (uris != null && uris[0] != null) { thumbnail.uri = uris[0].replace ("@ADDRESS@", host_ip); } - value = item_props.lookup ("Size"); + value = props.lookup ("Size"); if (value != null) { thumbnail.size = (int64) value; } diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala index 7dfff0d..9e20ff0 100644 --- a/src/plugins/external/rygel-external-container.vala +++ b/src/plugins/external/rygel-external-container.vala @@ -23,7 +23,6 @@ */ using GUPnP; -using DBus; using Gee; using FreeDesktop; @@ -38,7 +37,6 @@ public class Rygel.External.Container : Rygel.MediaContainer { private ItemFactory item_factory; private ArrayList containers; - private Connection connection; private bool searchable; @@ -49,7 +47,7 @@ public class Rygel.External.Container : Rygel.MediaContainer { string service_name, string path, string host_ip, - Container? parent = null) { + Container? parent = null) throws IOError { base (id, parent, title, (int) child_count); this.service_name = service_name; @@ -57,16 +55,10 @@ public class Rygel.External.Container : Rygel.MediaContainer { this.item_factory = new ItemFactory (); this.containers = new ArrayList (); - try { - this.connection = DBus.Bus.get (DBus.BusType.SESSION); - } catch (GLib.Error err) { - critical ("Failed to connect to session bus: %s", err.message); - } - // Create proxy to MediaContainer iface - this.actual_container = this.connection.get_object (this.service_name, - path) - as MediaContainerProxy; + this.actual_container = Bus.get_proxy_sync (BusType.SESSION, + this.service_name, + path); this.update_container.begin (true); } @@ -138,8 +130,9 @@ public class Rygel.External.Container : Rygel.MediaContainer { MediaObject media_object = null; // Create proxy to MediaObject iface - var actual_object = this.connection.get_object (this.service_name, id) - as MediaObjectProxy; + MediaObjectProxy actual_object = Bus.get_proxy_sync (BusType.SESSION, + this.service_name, + id); if (actual_object.object_type == "container") { media_object = this.find_container_by_id (id); @@ -162,8 +155,9 @@ public class Rygel.External.Container : Rygel.MediaContainer { 0, null); - var props_iface = this.connection.get_object (this.service_name, id) - as Properties; + Properties props_iface = Bus.get_proxy_sync (BusType.SESSION, + this.service_name, + id); var props = yield props_iface.get_all (MediaItemProxy.IFACE); @@ -182,8 +176,8 @@ public class Rygel.External.Container : Rygel.MediaContainer { } private async MediaObjects create_media_objects ( - HashTable[] all_props, - MediaContainer? parent + HashTable[] all_props, + MediaContainer? parent = null) throws GLib.Error { var media_objects = new MediaObjects (); @@ -278,7 +272,7 @@ public class Rygel.External.Container : Rygel.MediaContainer { yield this.refresh_child_containers (); } catch (GLib.Error err) { warning ("Failed to update information about container '%s': %s", - this.actual_container.get_path (), + this.actual_container.get_object_path (), err.message); } diff --git a/src/plugins/external/rygel-external-icon-factory.vala b/src/plugins/external/rygel-external-icon-factory.vala index 5b4d902..9af5884 100644 --- a/src/plugins/external/rygel-external-icon-factory.vala +++ b/src/plugins/external/rygel-external-icon-factory.vala @@ -27,14 +27,9 @@ using FreeDesktop; public class Rygel.External.IconFactory { private static string ITEM_IFACE = "org.gnome.UPnP.MediaItem1"; - DBus.Connection connection; - - public IconFactory (DBus.Connection connection) { - this.connection = connection; - } - - public async IconInfo? create (string service_name, - HashTable container_props) { + public async IconInfo? create (string service_name, + HashTable container_props) + throws IOError { var value = container_props.lookup ("Icon"); if (value == null) { // Seems no icon is provided, nevermind @@ -42,37 +37,32 @@ public class Rygel.External.IconFactory { } var icon_path = (string) value; - var props = this.connection.get_object (service_name, - icon_path) - as Properties; + Properties props = Bus.get_proxy_sync (BusType.SESSION, + service_name, + icon_path); - HashTable item_props; - try { - item_props = yield props.get_all (ITEM_IFACE); - } catch (DBus.Error err) { - warning ("Error fetching icon properties from %s", service_name); + var item_props = yield props.get_all (ITEM_IFACE); - return null; - } + return this.create_from_props (item_props); + } - value = item_props.lookup ("MIMEType"); - var mime_type = (string) value; + private IconInfo? create_from_props (HashTable props) { + var mime_type = (string) props.lookup ("MIMEType"); var icon = new IconInfo (mime_type, this.get_ext_for_mime (mime_type)); - value = item_props.lookup ("URLs"); - var uris = (string[]) value; + var uris = (string[]) props.lookup ("URLs"); if (uris != null && uris[0] != null) { icon.uri = uris[0]; } - value = item_props.lookup ("Size"); + var value = props.lookup ("Size"); if (value != null) { icon.size = (int64) value; } - icon.width = this.get_int (item_props, "Width"); - icon.height = this.get_int (item_props, "Height"); - icon.depth = this.get_int (item_props, "ColorDepth"); + icon.width = this.get_int (props, "Width"); + icon.height = this.get_int (props, "Height"); + icon.depth = this.get_int (props, "ColorDepth"); return icon; } @@ -87,7 +77,7 @@ public class Rygel.External.IconFactory { } } - private int get_int (HashTable props, string prop) { + private int get_int (HashTable props, string prop) { var value = props.lookup (prop); if (value != null) { diff --git a/src/plugins/external/rygel-external-interfaces.vala b/src/plugins/external/rygel-external-interfaces.vala index f8407b9..5b17f91 100644 --- a/src/plugins/external/rygel-external-interfaces.vala +++ b/src/plugins/external/rygel-external-interfaces.vala @@ -21,10 +21,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using DBus; - [DBus (name = "org.gnome.UPnP.MediaObject2")] -public interface Rygel.External.MediaObjectProxy : DBus.Object { +public interface Rygel.External.MediaObjectProxy : DBusProxy { public static const string IFACE = "org.gnome.UPnP.MediaObject2"; public static const string[] PROPERTIES = { "Parent", "Type", @@ -38,7 +36,7 @@ public interface Rygel.External.MediaObjectProxy : DBus.Object { } [DBus (name = "org.gnome.UPnP.MediaContainer2")] -public interface Rygel.External.MediaContainerProxy : DBus.Object, +public interface Rygel.External.MediaContainerProxy : DBusProxy, MediaObjectProxy { public static const string IFACE = "org.gnome.UPnP.MediaContainer2"; public static const string[] PROPERTIES = { "ChildCount", "Searchable" }; @@ -50,31 +48,31 @@ public interface Rygel.External.MediaContainerProxy : DBus.Object, public abstract uint container_count { get; set; } public abstract bool searchable { get; set; } - public abstract async HashTable[] list_children ( + public abstract async HashTable[] list_children ( uint offset, uint max_count, - string[] filter) throws DBus.Error; - public abstract async HashTable[] list_containers ( + string[] filter) throws IOError; + public abstract async HashTable[] list_containers ( uint offset, uint max_count, - string[] filter) throws DBus.Error; - public abstract async HashTable[] list_items ( + string[] filter) throws IOError; + public abstract async HashTable[] list_items ( uint offset, uint max_count, - string[] filter) throws DBus.Error; + string[] filter) throws IOError; // Optional API - public abstract async HashTable[] search_objects ( + public abstract async HashTable[] search_objects ( string query, uint offset, uint max_count, - string[] filter) throws DBus.Error; + string[] filter) throws IOError; public abstract ObjectPath icon { owned get; set; } } [DBus (name = "org.gnome.UPnP.MediaItem2")] -public interface Rygel.External.MediaItemProxy : DBus.Object, MediaObjectProxy { +public interface Rygel.External.MediaItemProxy : DBusProxy, MediaObjectProxy { public static const string IFACE = "org.gnome.UPnP.MediaItem2"; public static const string[] PROPERTIES = { "URLs", "MIMEType", diff --git a/src/plugins/external/rygel-external-item-factory.vala b/src/plugins/external/rygel-external-item-factory.vala index f83bca9..afad6f8 100644 --- a/src/plugins/external/rygel-external-item-factory.vala +++ b/src/plugins/external/rygel-external-item-factory.vala @@ -23,20 +23,19 @@ */ using GUPnP; -using DBus; using FreeDesktop; /** * Creates item for external plugins. */ public class Rygel.External.ItemFactory { - public async MediaItem create (string id, - string type, - string title, - HashTable props, - string service_name, - string host_ip, - MediaContainer parent) + public async MediaItem create (string id, + string type, + string title, + HashTable props, + string service_name, + string host_ip, + MediaContainer parent) throws GLib.Error { MediaItem item; @@ -70,40 +69,20 @@ public class Rygel.External.ItemFactory { host_ip); } + this.set_generic_metadata (item, props, service_name, host_ip); + if (parent is DummyContainer) { item.parent_ref = parent; } - item.mime_type = this.get_string (props, "MIMEType"); - - var value = props.lookup ("URLs"); - var uris = (string[]) value; - - for (var i = 0; uris[i] != null; i++) { - var tmp = uris[i].replace ("@ADDRESS@", host_ip); - - item.add_uri (tmp); - } - - // Optional properties - - item.dlna_profile = this.get_string (props, "DLNAProfile"); - - value = props.lookup ("Size"); - if (value != null) { - item.size = (int64) value; - } - - item.date = this.get_string (props, "Date"); - return item; } private async void set_music_metadata ( - MusicItem music, - HashTable props, - string service_name, - string host_ip) + MusicItem music, + HashTable props, + string service_name, + string host_ip) throws GLib.Error { music.artist = this.get_string (props, "Artist"); music.album = this.get_string (props, "Album"); @@ -121,10 +100,10 @@ public class Rygel.External.ItemFactory { this.set_audio_metadata (music, props, service_name, host_ip); } - private void set_audio_metadata (AudioItem audio, - HashTable props, - string service_name, - string host_ip) + private void set_audio_metadata (AudioItem audio, + HashTable props, + string service_name, + string host_ip) throws GLib.Error { audio.duration = this.get_int (props, "Duration"); audio.bitrate = this.get_int (props, "Bitrate"); @@ -133,10 +112,10 @@ public class Rygel.External.ItemFactory { } private async void set_visual_metadata ( - VisualItem visual, - HashTable props, - string service_name, - string host_ip) + VisualItem visual, + HashTable props, + string service_name, + string host_ip) throws GLib.Error { visual.width = this.get_int (props, "Width"); visual.height = this.get_int (props, "Height"); @@ -155,16 +134,41 @@ public class Rygel.External.ItemFactory { } private async void set_video_metadata ( - VideoItem video, - HashTable props, - string service_name, - string host_ip) + VideoItem video, + HashTable props, + string service_name, + string host_ip) throws GLib.Error { yield this.set_visual_metadata (video, props, service_name, host_ip); this.set_audio_metadata (video, props, service_name, host_ip); } - private string? get_string (HashTable props, string prop) { + private void set_generic_metadata (MediaItem item, + HashTable props, + string service_name, + string host_ip) { + item.mime_type = this.get_string (props, "MIMEType"); + + var uris = (string[]) props.lookup ("URLs"); + if (uris != null) { + for (var i = 0; uris[i] != null; i++) { + item.add_uri (uris[i].replace ("@ADDRESS@", host_ip)); + } + } + + // Optional properties + + item.dlna_profile = this.get_string (props, "DLNAProfile"); + + var value = props.lookup ("Size"); + if (value != null) { + item.size = (int64) value; + } + + item.date = this.get_string (props, "Date"); + } + + private string? get_string (HashTable props, string prop) { var value = props.lookup (prop); if (value != null) { @@ -174,7 +178,7 @@ public class Rygel.External.ItemFactory { } } - private int get_int (HashTable props, string prop) { + private int get_int (HashTable props, string prop) { var value = props.lookup (prop); if (value != null) { diff --git a/src/plugins/external/rygel-external-plugin-factory.vala b/src/plugins/external/rygel-external-plugin-factory.vala index 9d60034..f7683d6 100644 --- a/src/plugins/external/rygel-external-plugin-factory.vala +++ b/src/plugins/external/rygel-external-plugin-factory.vala @@ -31,55 +31,51 @@ private External.PluginFactory plugin_factory; public void module_init (PluginLoader loader) { try { plugin_factory = new External.PluginFactory (loader); - } catch (DBus.Error error) { + } catch (IOError error) { critical ("Failed to fetch list of external services: %s\n", error.message); } } public class Rygel.External.PluginFactory { - private const string DBUS_SERVICE = "org.freedesktop.DBus"; - private const string DBUS_OBJECT = "/org/freedesktop/DBus"; - private const string SERVICE_PREFIX = "org.gnome.UPnP.MediaServer2."; private const string GRILO_UPNP_PREFIX = SERVICE_PREFIX + "grl_upnp"; - DBusObject dbus_obj; - DBus.Connection connection; - PluginLoader loader; - IconFactory icon_factory; + DBusObject dbus_obj; + PluginLoader loader; + IconFactory icon_factory; - public PluginFactory (PluginLoader loader) throws DBus.Error { - this.connection = DBus.Bus.get (DBus.BusType.SESSION); - this.icon_factory = new IconFactory (this.connection); + public PluginFactory (PluginLoader loader) throws IOError { + this.icon_factory = new IconFactory (); - this.dbus_obj = this.connection.get_object (DBUS_SERVICE, DBUS_OBJECT) - as DBusObject; + this.dbus_obj = Bus.get_proxy_sync (BusType.SESSION, + DBUS_SERVICE, + DBUS_OBJECT); this.loader = loader; this.load_plugins.begin (); } - private async void load_plugins () throws DBus.Error { + private async void load_plugins () throws IOError { var services = yield this.dbus_obj.list_names (); foreach (var service in services) { if (service.has_prefix (SERVICE_PREFIX) && this.loader.get_plugin_by_name (service) == null) { - yield this.load_plugin (service); + yield this.load_plugin_n_handle_error (service); } } yield this.load_activatable_plugins (); } - private async void load_activatable_plugins () throws DBus.Error { + private async void load_activatable_plugins () throws IOError { var services = yield this.dbus_obj.list_activatable_names (); foreach (var service in services) { if (service.has_prefix (SERVICE_PREFIX) && this.loader.get_plugin_by_name (service) == null) { - yield this.load_plugin (service); + yield this.load_plugin_n_handle_error (service); } } @@ -102,12 +98,22 @@ public class Rygel.External.PluginFactory { plugin.available = true; } } else if (name.has_prefix (SERVICE_PREFIX)) { - // Ah, new plugin available, lets use it - this.load_plugin.begin (name); + // Ah, new plugin available, lets use it + this.load_plugin_n_handle_error.begin (name); + } + } + + private async void load_plugin_n_handle_error (string service_name) { + try { + yield this.load_plugin (service_name); + } catch (IOError error) { + warning ("Failed to load external plugin '%s': %s", + service_name, + error.message); } } - private async void load_plugin (string service_name) { + private async void load_plugin (string service_name) throws IOError { if (service_name.has_prefix (GRILO_UPNP_PREFIX)) { // We don't entertain UPnP sources return; @@ -117,22 +123,15 @@ public class Rygel.External.PluginFactory { var root_object = "/" + service_name.replace (".", "/"); // Create proxy to MediaObject iface to get the display name through - var props = this.connection.get_object (service_name, root_object) - as Properties; + Properties props = Bus.get_proxy_sync (BusType.SESSION, + service_name, + root_object); - HashTable object_props; - HashTable container_props; + HashTable object_props; + HashTable container_props; - try { - object_props = yield props.get_all (MediaObjectProxy.IFACE); - container_props = yield props.get_all (MediaContainerProxy.IFACE); - } catch (DBus.Error err) { - warning ("Failed to fetch properties of plugin %s: %s.", - service_name, - err.message); - - return; - } + object_props = yield props.get_all (MediaObjectProxy.IFACE); + container_props = yield props.get_all (MediaContainerProxy.IFACE); var icon = yield this.icon_factory.create (service_name, container_props); @@ -145,8 +144,8 @@ public class Rygel.External.PluginFactory { title = service_name; } - var child_count = container_props.lookup ("ChildCount").get_uint (); - var searchable = container_props.lookup ("Searchable").get_boolean (); + var child_count = (uint) container_props.lookup ("ChildCount"); + var searchable = (bool) container_props.lookup ("Searchable"); var plugin = new External.Plugin (service_name, title, diff --git a/src/plugins/external/rygel-external-plugin.vala b/src/plugins/external/rygel-external-plugin.vala index 641985b..2a4ae1b 100644 --- a/src/plugins/external/rygel-external-plugin.vala +++ b/src/plugins/external/rygel-external-plugin.vala @@ -52,13 +52,21 @@ public class Rygel.External.Plugin : Rygel.MediaServerPlugin { } public override MediaContainer? get_root_container (GUPnP.Context context) { - return new Container ("0", - this.title, - this.child_count, - this.searchable, - this.service_name, - this.root_object, - context.host_ip, - null); + Container root_container = null; + + try { + root_container = new Container ("0", + this.title, + this.child_count, + this.searchable, + this.service_name, + this.root_object, + context.host_ip, + null); + } catch (IOError err) { + critical ("Failed to connect to session bus: %s", err.message); + } + + return root_container; } } diff --git a/src/plugins/external/rygel-external-thumbnail-factory.vala b/src/plugins/external/rygel-external-thumbnail-factory.vala index 121340c..eefb2e8 100644 --- a/src/plugins/external/rygel-external-thumbnail-factory.vala +++ b/src/plugins/external/rygel-external-thumbnail-factory.vala @@ -22,7 +22,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using DBus; using FreeDesktop; /** @@ -33,29 +32,32 @@ public class Rygel.External.ThumbnailFactory { string object_path, string host_ip) throws GLib.Error { - DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION); - - var props = connection.get_object (service_name, - object_path) - as Properties; + Properties props = Bus.get_proxy_sync (BusType.SESSION, + service_name, + object_path); var item_props = yield props.get_all (MediaItemProxy.IFACE); + return this.create_from_props (item_props, host_ip); + } + + private Thumbnail create_from_props (HashTable props, + string host_ip) { var thumbnail = new Thumbnail (); - thumbnail.mime_type = this.get_string (item_props, "MIMEType"); - thumbnail.dlna_profile = this.get_string (item_props, "DLNAProfile"); - thumbnail.width = this.get_int (item_props, "Width"); - thumbnail.height = this.get_int (item_props, "Height"); - thumbnail.depth = this.get_int (item_props, "ColorDepth"); + thumbnail.mime_type = this.get_string (props, "MIMEType"); + thumbnail.dlna_profile = this.get_string (props, "DLNAProfile"); + thumbnail.width = this.get_int (props, "Width"); + thumbnail.height = this.get_int (props, "Height"); + thumbnail.depth = this.get_int (props, "ColorDepth"); - var value = item_props.lookup ("URLs"); + var value = props.lookup ("URLs"); var uris = (string[]) value; if (uris != null && uris[0] != null) { thumbnail.uri = uris[0].replace ("@ADDRESS@", host_ip); } - value = item_props.lookup ("Size"); + value = props.lookup ("Size"); if (value != null) { thumbnail.size = (int64) value; } @@ -63,7 +65,7 @@ public class Rygel.External.ThumbnailFactory { return thumbnail; } - private string? get_string (HashTable props, string prop) { + private string? get_string (HashTable props, string prop) { var value = props.lookup (prop); if (value != null) { @@ -73,7 +75,7 @@ public class Rygel.External.ThumbnailFactory { } } - private int get_int (HashTable props, string prop) { + private int get_int (HashTable props, string prop) { var value = props.lookup (prop); if (value != null) { diff --git a/src/plugins/gst-launch/Makefile.am b/src/plugins/gst-launch/Makefile.am index 06312b5..b76cb80 100644 --- a/src/plugins/gst-launch/Makefile.am +++ b/src/plugins/gst-launch/Makefile.am @@ -4,7 +4,6 @@ plugin_LTLIBRARIES = librygel-gst-launch.la AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(LIBGUPNP_AV_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ $(GEE_CFLAGS) \ $(LIBGSTREAMER_CFLAGS) \ $(UUID_FLAGS) \ @@ -21,12 +20,10 @@ librygel_gst_launch_la_SOURCES = rygel-gst-launch-plugin.vala \ librygel_gst_launch_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \ --pkg rygel-1.0 --pkg gconf-2.0 \ --pkg gupnp-1.0 --pkg gupnp-av-1.0 \ - --pkg dbus-glib-1 --pkg gee-1.0 \ - --pkg gstreamer-0.10 -g + --pkg gee-1.0 --pkg gstreamer-0.10 -g librygel_gst_launch_la_LIBADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ - $(LIBDBUS_GLIB_LIBS) \ $(LIBGSTREAMER_LIBS) \ $(GEE_LIBS) \ $(UUID_LIBS) diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am index b2aabbb..05ff906 100644 --- a/src/plugins/media-export/Makefile.am +++ b/src/plugins/media-export/Makefile.am @@ -11,7 +11,6 @@ plugin_LTLIBRARIES = librygel-media-export.la AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(LIBGUPNP_AV_CFLAGS) \ $(LIBGUPNP_DLNA_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ $(LIBSQLITE3_CFLAGS) \ $(GEE_CFLAGS) \ $(UUID_CFLAGS) \ @@ -42,7 +41,6 @@ librygel_media_export_la_SOURCES = rygel-media-export-plugin.vala \ rygel-media-export-object-factory.vala librygel_media_export_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \ - --pkg dbus-glib-1 \ --pkg rygel-1.0 \ --pkg gupnp-1.0 \ --pkg gupnp-av-1.0 \ @@ -57,7 +55,6 @@ librygel_media_export_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \ librygel_media_export_la_LIBADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ $(LIBGUPNP_DLNA_LIBS) \ - $(LIBDBUS_GLIB_LIBS) \ $(LIBGSTREAMER_LIBS) \ $(GSTREAMER_TAG_LIBS) \ $(GSTREAMER_APP_LIBS) \ diff --git a/src/plugins/media-export/rygel-media-export-dbus-service.vala b/src/plugins/media-export/rygel-media-export-dbus-service.vala index 5040018..5c84453 100644 --- a/src/plugins/media-export/rygel-media-export-dbus-service.vala +++ b/src/plugins/media-export/rygel-media-export-dbus-service.vala @@ -29,11 +29,12 @@ public class Rygel.MediaExport.DBusService : Object { this.root_container = root_container; try { - var connection = DBus.Bus.get (DBus.BusType. SESSION); - if (connection != null) { + var connection = Bus.get_sync (BusType.SESSION); + + if (likely (connection != null)) { connection.register_object (RYGEL_MEDIA_EXPORT_PATH, this); } - } catch (DBus.Error err) { + } catch (IOError err) { warning (_("Failed to attach to D-Bus session bus: %s"), err.message); } diff --git a/src/plugins/mpris/Makefile.am b/src/plugins/mpris/Makefile.am index 17a25f6..f889301 100644 --- a/src/plugins/mpris/Makefile.am +++ b/src/plugins/mpris/Makefile.am @@ -12,7 +12,6 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(LIBGUPNP_AV_CFLAGS) \ $(GEE_CFLAGS) \ $(LIBGSTREAMER_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ $(UUID_CFLAGS) \ -I$(top_srcdir)/src/rygel -DDATA_DIR='"$(shareddir)"' \ -include config.h @@ -30,7 +29,6 @@ librygel_mpris_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \ librygel_mpris_la_LIBADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ - $(LIBDBUS_GLIB_LIBS) \ $(GEE_LIBS) \ $(LIBGSTREAMER_LIBS) \ $(UUID_LIBS) diff --git a/src/plugins/mpris/rygel-mpris-interfaces.vala b/src/plugins/mpris/rygel-mpris-interfaces.vala index 407dad8..aa7db0e 100644 --- a/src/plugins/mpris/rygel-mpris-interfaces.vala +++ b/src/plugins/mpris/rygel-mpris-interfaces.vala @@ -21,10 +21,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using DBus; - [DBus (name = "org.mpris.MediaPlayer2")] -public interface Rygel.MPRIS.MediaPlayerProxy : DBus.Object { +public interface Rygel.MPRIS.MediaPlayerProxy : Object { public const string IFACE = "org.mpris.MediaPlayer2"; public abstract string identity { owned get; } @@ -33,18 +31,18 @@ public interface Rygel.MPRIS.MediaPlayerProxy : DBus.Object { } [DBus (name = "org.mpris.MediaPlayer2.Player")] -public interface Rygel.MPRIS.MediaPlayer.PlayerProxy : DBus.Object { +public interface Rygel.MPRIS.MediaPlayer.PlayerProxy : Object { public const string IFACE = "org.mpris.MediaPlayer2.Player"; public abstract string playback_status { owned get; } public abstract double volume { get; set; } public abstract int64 position { get; } - public abstract HashTable metadata { owned get; } + public abstract HashTable metadata { owned get; } - public abstract void pause () throws DBus.Error; - public abstract void play_pause () throws DBus.Error; - public abstract void stop () throws DBus.Error; - public abstract void play () throws DBus.Error; - public abstract void seek (int64 offset) throws DBus.Error; - public abstract void open_uri (string uri) throws DBus.Error; + public abstract void pause () throws IOError; + public abstract void play_pause () throws IOError; + public abstract void stop () throws IOError; + public abstract void play () throws IOError; + public abstract void seek (int64 offset) throws IOError; + public abstract void open_uri (string uri) throws IOError; } diff --git a/src/plugins/mpris/rygel-mpris-player.vala b/src/plugins/mpris/rygel-mpris-player.vala index a55801e..c98fb1f 100644 --- a/src/plugins/mpris/rygel-mpris-player.vala +++ b/src/plugins/mpris/rygel-mpris-player.vala @@ -157,9 +157,9 @@ public class Rygel.MPRIS.Player : GLib.Object, Rygel.MediaPlayer { } } - private void on_properties_changed (string iface, - HashTable changed, - string[] invalidated) { + private void on_properties_changed (string iface, + HashTable changed, + string[] invalidated) { if (changed.lookup ("PlaybackStatus") != null) { this.notify_property ("playback-state"); } diff --git a/src/plugins/mpris/rygel-mpris-plugin-factory.vala b/src/plugins/mpris/rygel-mpris-plugin-factory.vala index 06d8367..cec7f94 100644 --- a/src/plugins/mpris/rygel-mpris-plugin-factory.vala +++ b/src/plugins/mpris/rygel-mpris-plugin-factory.vala @@ -31,7 +31,7 @@ private MPRIS.PluginFactory plugin_factory; public void module_init (PluginLoader loader) { try { plugin_factory = new MPRIS.PluginFactory (loader); - } catch (DBus.Error error) { + } catch (IOError error) { critical ("Failed to fetch list of MPRIS services: %s\n", error.message); } @@ -44,40 +44,38 @@ public class Rygel.MPRIS.PluginFactory { private const string SERVICE_PREFIX = "org.mpris.MediaPlayer2."; private const string MEDIA_PLAYER_PATH = "/org/mpris/MediaPlayer2"; - DBusObject dbus_obj; - DBus.Connection connection; - PluginLoader loader; + DBusObject dbus_obj; + PluginLoader loader; - public PluginFactory (PluginLoader loader) throws DBus.Error { - this.connection = DBus.Bus.get (DBus.BusType.SESSION); - - this.dbus_obj = this.connection.get_object (DBUS_SERVICE, DBUS_OBJECT) - as DBusObject; + public PluginFactory (PluginLoader loader) throws IOError { + this.dbus_obj = Bus.get_proxy_sync (BusType.SESSION, + DBUS_SERVICE, + DBUS_OBJECT); this.loader = loader; this.load_plugins.begin (); } - private async void load_plugins () throws DBus.Error { + private async void load_plugins () throws IOError { var services = yield this.dbus_obj.list_names (); foreach (var service in services) { if (service.has_prefix (SERVICE_PREFIX) && this.loader.get_plugin_by_name (service) == null) { - yield this.load_plugin (service); + yield this.load_plugin_n_handle_error (service); } } yield this.load_activatable_plugins (); } - private async void load_activatable_plugins () throws DBus.Error { + private async void load_activatable_plugins () throws IOError { var services = yield this.dbus_obj.list_activatable_names (); foreach (var service in services) { if (service.has_prefix (SERVICE_PREFIX) && this.loader.get_plugin_by_name (service) == null) { - yield this.load_plugin (service); + yield this.load_plugin_n_handle_error (service); } } @@ -100,28 +98,34 @@ public class Rygel.MPRIS.PluginFactory { plugin.available = true; } } else if (name.has_prefix (SERVICE_PREFIX)) { - // Ah, new plugin available, lets use it - this.load_plugin.begin (name); + // Ah, new plugin available, lets use it + this.load_plugin_n_handle_error.begin (name); } } - private async void load_plugin (string service_name) { - // Create proxy to MediaObject iface to get the display name through - var props = this.connection.get_object (service_name, MEDIA_PLAYER_PATH) - as Properties; - - HashTable props_hash; - + private async void load_plugin_n_handle_error (string service_name) { try { - props_hash = yield props.get_all (MediaPlayerProxy.IFACE); - } catch (DBus.Error err) { - warning ("Failed to fetch properties of plugin %s: %s.", + yield this.load_plugin (service_name); + } catch (IOError error) { + warning ("Failed to load MPRIS2 plugin '%s': %s", service_name, - err.message); - - return; + error.message); } + } + + private async void load_plugin (string service_name) throws IOError { + // Create proxy to MediaObject iface to get the display name through + Properties props = Bus.get_proxy_sync (BusType.SESSION, + service_name, + MEDIA_PLAYER_PATH); + + var props_hash = yield props.get_all (MediaPlayerProxy.IFACE); + + this.load_plugin_from_props (service_name, props_hash); + } + private void load_plugin_from_props (string service_name, + HashTable props_hash) { var title = (string) props_hash.lookup ("Identity"); if (title == null) { title = service_name; diff --git a/src/plugins/mpris/rygel-mpris-plugin.vala b/src/plugins/mpris/rygel-mpris-plugin.vala index 1bc5a4d..3fe912a 100644 --- a/src/plugins/mpris/rygel-mpris-plugin.vala +++ b/src/plugins/mpris/rygel-mpris-plugin.vala @@ -22,9 +22,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using DBus; using Rygel.MPRIS; using Rygel.MPRIS.MediaPlayer; +using FreeDesktop; public class Rygel.MPRIS.Plugin : Rygel.MediaRendererPlugin { private const string MEDIA_PLAYER_PATH = "/org/mpris/MediaPlayer2"; @@ -45,16 +45,14 @@ public class Rygel.MPRIS.Plugin : Rygel.MediaRendererPlugin { this.protocols = this.schemes_to_protocols (schemes); try { - var connection = DBus.Bus.get (DBus.BusType.SESSION); - // Create proxy to MediaPlayer.Player iface - this.actual_player = connection.get_object (service_name, - MEDIA_PLAYER_PATH) - as PlayerProxy; + this.actual_player = Bus.get_proxy_sync (BusType.SESSION, + DBUS_SERVICE, + MEDIA_PLAYER_PATH); // Create proxy to FreeDesktop.Properties iface - this.properties = connection.get_object (service_name, - MEDIA_PLAYER_PATH) - as FreeDesktop.Properties; + this.properties = Bus.get_proxy_sync (BusType.SESSION, + service_name, + MEDIA_PLAYER_PATH); } catch (GLib.Error err) { critical ("Failed to connect to session bus: %s", err.message); } diff --git a/src/plugins/playbin/Makefile.am b/src/plugins/playbin/Makefile.am index 74d0abc..be23645 100644 --- a/src/plugins/playbin/Makefile.am +++ b/src/plugins/playbin/Makefile.am @@ -11,7 +11,6 @@ plugin_LTLIBRARIES = librygel-playbin.la AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(LIBGUPNP_AV_CFLAGS) \ $(GEE_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ $(LIBGSTREAMER_CFLAGS) \ $(UUID_CFLAGS) \ -I$(top_srcdir)/src/rygel -DDATA_DIR='"$(shareddir)"' \ @@ -29,7 +28,6 @@ librygel_playbin_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \ librygel_playbin_la_LIBADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ $(LIBGSTREAMER_LIBS) \ - $(LIBDBUS_GLIB_LIBS) \ $(GEE_LIBS) \ $(UUID_LIBS) librygel_playbin_la_LDFLAGS = -shared -fPIC -module -avoid-version diff --git a/src/plugins/test/Makefile.am b/src/plugins/test/Makefile.am index 581d772..481bb8a 100644 --- a/src/plugins/test/Makefile.am +++ b/src/plugins/test/Makefile.am @@ -10,7 +10,6 @@ plugin_LTLIBRARIES = librygel-test.la AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(LIBGUPNP_AV_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ $(GEE_CFLAGS) \ $(LIBGSTREAMER_CFLAGS) \ $(UUID_CFLAGS) \ @@ -25,12 +24,10 @@ librygel_test_la_SOURCES = rygel-test-root-container.vala \ librygel_test_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \ --pkg rygel-1.0 --pkg gconf-2.0 \ --pkg gupnp-1.0 --pkg gupnp-av-1.0 \ - --pkg dbus-glib-1 --pkg gee-1.0 \ - --pkg gstreamer-0.10 -g + --pkg gee-1.0 --pkg gstreamer-0.10 -g librygel_test_la_LIBADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ - $(LIBDBUS_GLIB_LIBS) \ $(LIBGSTREAMER_LIBS) \ $(UUID_LIBS) \ $(GEE_LIBS) diff --git a/src/plugins/tracker/Makefile.am b/src/plugins/tracker/Makefile.am index 77be9ae..a6233cf 100644 --- a/src/plugins/tracker/Makefile.am +++ b/src/plugins/tracker/Makefile.am @@ -40,13 +40,11 @@ librygel_media_tracker_la_SOURCES = rygel-tracker-root-container.vala \ librygel_media_tracker_la_VALAFLAGS = \ --vapidir=$(top_srcdir)/src/rygel \ - --pkg rygel-1.0 --pkg rygel-build-config --pkg gconf-2.0 \ - --pkg gupnp-1.0 --pkg gupnp-av-1.0 --pkg posix \ - --pkg dbus-glib-1 --pkg gee-1.0 --pkg gstreamer-0.10 -g + --pkg rygel-1.0 --pkg rygel-build-config --pkg gupnp-1.0 \ + --pkg gupnp-av-1.0 --pkg posix --pkg gee-1.0 --pkg gstreamer-0.10 -g librygel_media_tracker_la_LIBADD = $(LIBGUPNP_LIBS) \ $(LIBGUPNP_AV_LIBS) \ - $(LIBDBUS_GLIB_LIBS) \ $(LIBGSTREAMER_LIBS) \ $(GEE_LIBS) \ $(UUID_LIBS) diff --git a/src/plugins/tracker/rygel-tracker-insertion-query.vala b/src/plugins/tracker/rygel-tracker-insertion-query.vala index 5b61bd6..c8452ab 100644 --- a/src/plugins/tracker/rygel-tracker-insertion-query.vala +++ b/src/plugins/tracker/rygel-tracker-insertion-query.vala @@ -60,7 +60,7 @@ public class Rygel.Tracker.InsertionQuery : Query { } public override async void execute (ResourcesIface resources) - throws DBus.Error { + throws IOError { var str = this.to_string (); debug ("Executing SPARQL query: %s", str); diff --git a/src/plugins/tracker/rygel-tracker-interfaces.vala b/src/plugins/tracker/rygel-tracker-interfaces.vala index dfc7fcc..972a342 100644 --- a/src/plugins/tracker/rygel-tracker-interfaces.vala +++ b/src/plugins/tracker/rygel-tracker-interfaces.vala @@ -21,23 +21,21 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using DBus; - [DBus (name = "org.freedesktop.Tracker1.Statistics")] -public interface Rygel.Tracker.StatsIface : DBus.Object { - public abstract async string[,] get_statistics () throws DBus.Error; +public interface Rygel.Tracker.StatsIface : DBusProxy { + public abstract async string[,] get_statistics () throws IOError; } [DBus (name = "org.freedesktop.Tracker1.Resources")] -public interface Rygel.Tracker.ResourcesIface: DBus.Object { +public interface Rygel.Tracker.ResourcesIface: DBusProxy { public abstract async string[,] sparql_query (string query) - throws DBus.Error; + throws IOError; public abstract async HashTable[,] sparql_update_blank ( - string query) throws DBus.Error; + string query) throws IOError; } [DBus (name = "org.freedesktop.Tracker1.Resources.Class")] -public interface Rygel.Tracker.ResourcesClassIface: DBus.Object { +public interface Rygel.Tracker.ResourcesClassIface: DBusProxy { public abstract signal void subjects_added (string[] subjects); public abstract signal void subjects_removed (string[] subjects); public abstract signal void subjects_changed (string[] before, @@ -45,9 +43,9 @@ public interface Rygel.Tracker.ResourcesClassIface: DBus.Object { } [DBus (name = "org.freedesktop.Tracker1.Miner")] -public interface Rygel.Tracker.MinerIface : DBus.Object { +public interface Rygel.Tracker.MinerIface : DBusProxy { public abstract async void ignore_next_update (string[] urls) - throws DBus.Error; + throws IOError; } namespace Rygel { diff --git a/src/plugins/tracker/rygel-tracker-item-creation.vala b/src/plugins/tracker/rygel-tracker-item-creation.vala index 39f9c22..5fd97fe 100644 --- a/src/plugins/tracker/rygel-tracker-item-creation.vala +++ b/src/plugins/tracker/rygel-tracker-item-creation.vala @@ -90,13 +90,13 @@ public class Rygel.Tracker.ItemCreation : GLib.Object, Rygel.StateMachine { return query.id; } - private void create_proxies () throws DBus.Error { - DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION); - - this.resources = connection.get_object (TRACKER_SERVICE, RESOURCES_PATH) - as ResourcesIface; - this.miner = connection.get_object (MINER_SERVICE, MINER_PATH) - as MinerIface; + private void create_proxies () throws IOError { + this.resources = Bus.get_proxy_sync (BusType.SESSION, + TRACKER_SERVICE, + RESOURCES_PATH); + this.miner = Bus.get_proxy_sync (BusType.SESSION, + MINER_SERVICE, + MINER_PATH); } } diff --git a/src/plugins/tracker/rygel-tracker-metadata-values.vala b/src/plugins/tracker/rygel-tracker-metadata-values.vala index 4a6ff61..aee2df1 100644 --- a/src/plugins/tracker/rygel-tracker-metadata-values.vala +++ b/src/plugins/tracker/rygel-tracker-metadata-values.vala @@ -22,7 +22,6 @@ */ using GUPnP; -using DBus; using Gee; /** @@ -60,7 +59,7 @@ public abstract class Rygel.Tracker.MetadataValues : Rygel.SimpleContainer { try { this.create_proxies (); - } catch (DBus.Error error) { + } catch (IOError error) { critical (_("Failed to connect to session bus: %s"), error.message); return; @@ -113,7 +112,7 @@ public abstract class Rygel.Tracker.MetadataValues : Rygel.SimpleContainer { try { yield query.execute (this.resources); - } catch (DBus.Error error) { + } catch (IOError error) { critical (_("Error getting all values for '%s': %s"), string.joinv (" -> ", this.key_chain), error.message); @@ -186,15 +185,14 @@ public abstract class Rygel.Tracker.MetadataValues : Rygel.SimpleContainer { return id.has_prefix (this.id + ":"); } - private void create_proxies () throws DBus.Error { - DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION); - - this.resources = connection.get_object (TRACKER_SERVICE, RESOURCES_PATH) - as ResourcesIface; - this.resources_class = connection.get_object ( + private void create_proxies () throws IOError { + this.resources = Bus.get_proxy_sync (BusType.SESSION, + TRACKER_SERVICE, + RESOURCES_PATH); + this.resources_class = Bus.get_proxy_sync ( + BusType.SESSION, TRACKER_SERVICE, - this.item_factory.resources_class_path) - as ResourcesClassIface; + this.item_factory.resources_class_path); } private void hook_to_changes () { diff --git a/src/plugins/tracker/rygel-tracker-plugin-factory.vala b/src/plugins/tracker/rygel-tracker-plugin-factory.vala index c2083b9..db5d57e 100644 --- a/src/plugins/tracker/rygel-tracker-plugin-factory.vala +++ b/src/plugins/tracker/rygel-tracker-plugin-factory.vala @@ -30,7 +30,7 @@ private Tracker.PluginFactory plugin_factory; public void module_init (PluginLoader loader) { try { plugin_factory = new Tracker.PluginFactory (loader); - } catch (DBus.Error err) { + } catch (IOError err) { warning (_("Failed to start Tracker service: %s. Plugin disabled.") + err.message); } @@ -44,11 +44,10 @@ public class Rygel.Tracker.PluginFactory { StatsIface stats; PluginLoader loader; - public PluginFactory (PluginLoader loader) throws DBus.Error { - var connection = DBus.Bus.get (DBus.BusType.SESSION); - - this.stats = connection.get_object (TRACKER_SERVICE, STATISTICS_OBJECT) - as StatsIface; + public PluginFactory (PluginLoader loader) throws IOError { + this.stats = Bus.get_proxy_sync (BusType.SESSION, + TRACKER_SERVICE, + STATISTICS_OBJECT); this.loader = loader; this.stats.get_statistics (); diff --git a/src/plugins/tracker/rygel-tracker-query.vala b/src/plugins/tracker/rygel-tracker-query.vala index 16ab833..81cb22e 100644 --- a/src/plugins/tracker/rygel-tracker-query.vala +++ b/src/plugins/tracker/rygel-tracker-query.vala @@ -33,7 +33,7 @@ public abstract class Rygel.Tracker.Query { } public abstract async void execute (ResourcesIface resources) - throws DBus.Error; + throws IOError; // Deriving classes should override this method and complete it by // adding the first part of the query diff --git a/src/plugins/tracker/rygel-tracker-root-container.vala b/src/plugins/tracker/rygel-tracker-root-container.vala index 7662b67..6410447 100644 --- a/src/plugins/tracker/rygel-tracker-root-container.vala +++ b/src/plugins/tracker/rygel-tracker-root-container.vala @@ -23,7 +23,6 @@ */ using GUPnP; -using DBus; using Gee; /** diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala index c94de34..a0c1029 100644 --- a/src/plugins/tracker/rygel-tracker-search-container.vala +++ b/src/plugins/tracker/rygel-tracker-search-container.vala @@ -23,7 +23,6 @@ */ using GUPnP; -using DBus; using Gee; /** @@ -92,10 +91,12 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer { MODIFIED_VARIABLE); try { - this.create_proxies (); + this.resources = Bus.get_proxy_sync (BusType.SESSION, + TRACKER_SERVICE, + RESOURCES_PATH); this.get_children_count.begin (); - } catch (DBus.Error error) { + } catch (IOError error) { critical (_("Failed to connect to session bus: %s"), error.message); } } @@ -282,13 +283,6 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer { } } - private void create_proxies () throws DBus.Error { - DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION); - - this.resources = connection.get_object (TRACKER_SERVICE, RESOURCES_PATH) - as ResourcesIface; - } - /** * Chops the tail of a particular row in a 2-dimensional string array. * diff --git a/src/plugins/tracker/rygel-tracker-selection-query.vala b/src/plugins/tracker/rygel-tracker-selection-query.vala index c35fc4c..d23084f 100644 --- a/src/plugins/tracker/rygel-tracker-selection-query.vala +++ b/src/plugins/tracker/rygel-tracker-selection-query.vala @@ -65,7 +65,7 @@ public class Rygel.Tracker.SelectionQuery : Query { } public override async void execute (ResourcesIface resources) - throws DBus.Error { + throws IOError { var str = this.to_string (); debug ("Executing SPARQL query: %s", str); diff --git a/src/plugins/tracker/rygel-tracker-tags.vala b/src/plugins/tracker/rygel-tracker-tags.vala index 2b2ebe9..0f8d2e5 100644 --- a/src/plugins/tracker/rygel-tracker-tags.vala +++ b/src/plugins/tracker/rygel-tracker-tags.vala @@ -22,7 +22,6 @@ */ using GUPnP; -using DBus; using Gee; /** diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am index 49a2712..751f786 100644 --- a/src/rygel/Makefile.am +++ b/src/rygel/Makefile.am @@ -20,7 +20,6 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(GEE_CFLAGS) \ $(UUID_CFLAGS) \ $(LIBSOUP_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ -I$(top_srcdir) \ -DDATA_DIR='"$(shareddir)"' -DSYS_CONFIG_DIR='"$(sysconfdir)"'\ -DPLUGIN_DIR='"$(plugindir)"' -DDESKTOP_DIR='"$(desktopdir)"'\ @@ -122,13 +121,14 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \ rygel-media-player.vala \ rygel-changelog.vala \ rygel-volume.vala \ - rygel-free-desktop-interfaces.vala + rygel-free-desktop-interfaces.vala \ + rygel-dbus-interface.vala rygel_VALAFLAGS = \ -H rygel.h -C --library=rygel-1.0 --vapidir=$(srcdir) --thread \ --pkg rygel-build-config --pkg rygel-misc --pkg gupnp-1.0 \ - --pkg gupnp-av-1.0 --pkg gupnp-dlna-1.0 --pkg dbus-glib-1 \ - --pkg gstreamer-0.10 --pkg gio-2.0 --pkg gee-1.0 --pkg posix -g + --pkg gupnp-av-1.0 --pkg gupnp-dlna-1.0 --pkg gstreamer-0.10 \ + --pkg gio-2.0 --pkg gee-1.0 --pkg posix -g # Note: `-- the -g needs to be at the end of VALAFLAGS to not break make dist rygel_LDADD = librygel-configuration.a \ @@ -139,8 +139,7 @@ rygel_LDADD = librygel-configuration.a \ $(GIO_LIBS) \ $(GEE_LIBS) \ $(UUID_LIBS) \ - $(LIBSOUP_LIBS) \ - $(LIBDBUS_GLIB_LIBS) + $(LIBSOUP_LIBS) rygel_LDFLAGS = -export-dynamic @@ -157,7 +156,8 @@ librygel_configuration_a_SOURCES = rygel-configuration.c \ rygel-user-config.c \ rygel-meta-config.c \ rygel-cmdline-config.c \ - rygel-environment-config.c + rygel-environment-config.c \ + rygel-dbus-interface.c MAINTAINERCLEANFILES = Makefile.in $(BUILT_SOURCES) EXTRA_DIST = rygel-build-config.vapi \ diff --git a/src/rygel/rygel-1.0.deps b/src/rygel/rygel-1.0.deps index 907bfa9..080d2af 100644 --- a/src/rygel/rygel-1.0.deps +++ b/src/rygel/rygel-1.0.deps @@ -2,4 +2,3 @@ gupnp-1.0 gupnp-av-1.0 gstreamer-0.10 gee-1.0 -dbus-glib-1 diff --git a/src/rygel/rygel-dbus-interface.vala b/src/rygel/rygel-dbus-interface.vala new file mode 100644 index 0000000..83434b9 --- /dev/null +++ b/src/rygel/rygel-dbus-interface.vala @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008,2010 Nokia Corporation. + * Copyright (C) 2008 Zeeshan Ali (Khattak) . + * + * Author: Zeeshan Ali (Khattak) + * + * 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.Rygel1")] +public interface Rygel.DBusInterface : DBusProxy { + public const string SERVICE_NAME = "org.gnome.Rygel1"; + public const string OBJECT_PATH = "/org/gnome/Rygel1"; + + public abstract void shutdown () throws IOError; +} + diff --git a/src/rygel/rygel-dbus-service.vala b/src/rygel/rygel-dbus-service.vala index 2a0118b..3498d1b 100644 --- a/src/rygel/rygel-dbus-service.vala +++ b/src/rygel/rygel-dbus-service.vala @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Nokia Corporation. + * Copyright (C) 2008,2010 Nokia Corporation. * Copyright (C) 2008 Zeeshan Ali (Khattak) . * * Author: Zeeshan Ali (Khattak) @@ -21,35 +21,33 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +using FreeDesktop; + +// FIXME: Declare that we implement DBusInterface once bug#631044 is fixed. [DBus (name = "org.gnome.Rygel1")] public class Rygel.DBusService : Object { - private static string RYGEL_SERVICE = "org.gnome.Rygel1"; - private static string RYGEL_PATH = "/org/gnome/Rygel1"; - private Main main; - public DBusService (Main main) throws DBus.Error { + public DBusService (Main main) throws IOError { 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"); + DBusObject bus = Bus.get_proxy_sync (BusType.SESSION, + DBUS_SERVICE, + DBUS_OBJECT); // 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) { + if (bus.request_name (DBusInterface.SERVICE_NAME, 0) != + DBusRequestNameReply.PRIMARY_OWNER) { warning ("Failed to start D-Bus service name '%s' already taken", - RYGEL_SERVICE); + DBusInterface.SERVICE_NAME); } else { - conn.register_object (RYGEL_PATH, this); + var conn = Bus.get_sync (BusType.SESSION); + + conn.register_object (DBusInterface.OBJECT_PATH, this); } } - public void Shutdown () { + public void shutdown () throws IOError { this.main.exit (0); } } diff --git a/src/rygel/rygel-free-desktop-interfaces.vala b/src/rygel/rygel-free-desktop-interfaces.vala index cf56590..7f3eabf 100644 --- a/src/rygel/rygel-free-desktop-interfaces.vala +++ b/src/rygel/rygel-free-desktop-interfaces.vala @@ -21,25 +21,39 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using DBus; +namespace FreeDesktop { + public const string DBUS_SERVICE = "org.freedesktop.DBus"; + public const string DBUS_OBJECT = "/org/freedesktop/DBus"; +} + +public enum FreeDesktop.DBusRequestNameReply { + PRIMARY_OWNER = 1, + IN_QUEUE, + EXISTS, + ALREADY_OWNER +} [DBus (name = "org.freedesktop.DBus")] -public interface FreeDesktop.DBusObject: DBus.Object { +public interface FreeDesktop.DBusObject: Object { public abstract signal void name_owner_changed (string name, string old_owner, string new_owner); - public abstract async string[] list_names () throws DBus.Error; - public abstract async string[] list_activatable_names () throws DBus.Error; + // FIXME: This method should be async + public abstract uint32 request_name (string name, uint32 flags) + throws IOError; + public abstract async string[] list_names () throws IOError; + public abstract async string[] list_activatable_names () throws IOError; } [DBus (name = "org.freedesktop.DBus.Properties")] -public interface FreeDesktop.Properties: DBus.Object { - public abstract async HashTable get_all (string iface) - throws DBus.Error; +public interface FreeDesktop.Properties: Object { + public abstract async HashTable get_all (string iface) + throws IOError; public abstract signal void properties_changed - (string iface, - HashTable changed, - string[] invalidated); + (string iface, + HashTable changed, + string[] + invalidated); } diff --git a/src/rygel/rygel-main.vala b/src/rygel/rygel-main.vala index 772ffa4..f35a730 100644 --- a/src/rygel/rygel-main.vala +++ b/src/rygel/rygel-main.vala @@ -228,7 +228,7 @@ public class Rygel.Main : Object { main = new Main (); service = new DBusService (main); - } catch (DBus.Error err) { + } catch (IOError err) { warning (_("Failed to start D-Bus service: %s"), err.message); } catch (CmdlineConfigError.VERSION_ONLY err) { return 0; diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala index c634701..4394d2f 100644 --- a/src/rygel/rygel-user-config.vala +++ b/src/rygel/rygel-user-config.vala @@ -41,10 +41,6 @@ public class Rygel.UserConfig : GLib.Object, Configuration { protected static const string LOG_LEVEL_KEY = "log-level"; protected static const string PLUGIN_PATH_KEY = "plugin-path"; - private const string DBUS_SERVICE = "org.freedesktop.DBus"; - private const string DBUS_PATH = "/org/freedesktop/DBus"; - private const string DBUS_INTERFACE = "org.freedesktop.DBus"; - private const string RYGEL_SERVICE = "org.gnome.Rygel1"; private const string RYGEL_PATH = "/org/gnome/Rygel1"; private const string RYGEL_INTERFACE = "org.gnome.Rygel1"; @@ -55,9 +51,6 @@ public class Rygel.UserConfig : GLib.Object, Configuration { protected KeyFile key_file; private bool read_only; - private dynamic DBus.Object dbus_obj; - private dynamic DBus.Object rygel_obj; - public bool get_upnp_enabled () throws GLib.Error { return this.get_bool ("general", ENABLED_KEY); } @@ -164,21 +157,6 @@ public class Rygel.UserConfig : GLib.Object, Configuration { KeyFileFlags.KEEP_COMMENTS | KeyFileFlags.KEEP_TRANSLATIONS); debug ("Loaded user configuration from file '%s'", path); - - try { - DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION); - - // Create proxy to Rygel - this.rygel_obj = connection.get_object (RYGEL_SERVICE, - RYGEL_PATH, - RYGEL_INTERFACE); - // and DBus - this.dbus_obj = connection.get_object (DBUS_SERVICE, - DBUS_PATH, - DBUS_INTERFACE); - } catch (DBus.Error err) { - debug ("Failed to connect to session bus: %s", err.message); - } } public void save () { @@ -313,14 +291,13 @@ public class Rygel.UserConfig : GLib.Object, Configuration { var dest = File.new_for_path (dest_path); if (enable) { - uint32 res; - - // Start service first - if (this.dbus_obj != null) { - this.dbus_obj.StartServiceByName (RYGEL_SERVICE, - (uint32) 0, - out res); - } + // Creating the proxy starts the service + DBusInterface rygel_proxy = Bus.get_proxy_sync + (BusType.SESSION, + DBusInterface.SERVICE_NAME, + DBusInterface.OBJECT_PATH); + // Just to satisfy valac + rygel_proxy.get_object_path (); // Then symlink the desktop file to user's autostart dir var source_path = Path.build_filename (BuildConfig.DESKTOP_DIR, @@ -331,9 +308,15 @@ public class Rygel.UserConfig : GLib.Object, Configuration { this.set_bool ("general", ENABLED_KEY, true); } else { - // Stop service first - if (this.rygel_obj != null) { - this.rygel_obj.Shutdown (); + // Stop service only if already running + if (this.get_enabled ("general")) { + // Create proxy to Rygel + DBusInterface rygel_proxy = Bus.get_proxy_sync + (BusType.SESSION, + DBusInterface.SERVICE_NAME, + DBusInterface.OBJECT_PATH); + + rygel_proxy.shutdown (); } // Then delete the symlink from user's autostart dir diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 8500acf..7f315dc 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -16,7 +16,6 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ $(GEE_CFLAGS) \ $(UUID_CFLAGS) \ $(LIBSOUP_CFLAGS) \ - $(LIBDBUS_GLIB_CFLAGS) \ -I$(top_srcdir) -I$(rygeldir) -DDATA_DIR='"$(shareddir)"' \ -DSMALL_ICON_DIR='"$(icondir)"' -include config.h \ -DLOCALEDIR=\""$(datadir)/locale"\" @@ -35,9 +34,8 @@ rygel.stamp: $(rygel_preferences_VALASOURCES) rygel_preferences_VALAFLAGS = \ --vapidir=$(rygeldir) --thread \ --pkg rygel-1.0 --pkg rygel-build-config --pkg gupnp-1.0 \ - --pkg gupnp-av-1.0 --pkg dbus-glib-1 --pkg gconf-2.0 \ - --pkg gstreamer-0.10 --pkg gio-2.0 --pkg gee-1.0 \ - --pkg gtk+-$(GTK_VAPI_VERSION) -g + --pkg gupnp-av-1.0 --pkg gconf-2.0 --pkg gstreamer-0.10 --pkg gio-2.0 \ + --pkg gee-1.0 --pkg gtk+-$(GTK_VAPI_VERSION) -g rygel_preferences_LDADD = \ $(abs_top_builddir)/src/rygel/librygel-configuration.a \ @@ -48,8 +46,7 @@ rygel_preferences_LDADD = \ $(GEE_LIBS) \ $(UUID_LIBS) \ $(LIBSOUP_LIBS) \ - $(GTK_LIBS) \ - $(LIBDBUS_GLIB_LIBS) + $(GTK_LIBS) rygel_preferences_LDFLAGS = -export-dynamic MAINTAINERCLEANFILES = Makefile.in -- 2.7.4