[rygel] Put PluginFactory in a separate file
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Subject: [rygel] Put PluginFactory in a separate file
- Date: Fri, 22 May 2009 11:14:35 -0400 (EDT)
commit 97f47230111d0f413f73283b11c93b5183eddf83
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed May 13 16:06:56 2009 +0300
Put PluginFactory in a separate file
---
src/plugins/external/Makefile.am | 7 +-
.../external/rygel-external-plugin-factory.vala | 104 ++++++++++++++++++++
src/plugins/external/rygel-external-plugin.vala | 78 ---------------
3 files changed, 109 insertions(+), 80 deletions(-)
diff --git a/src/plugins/external/Makefile.am b/src/plugins/external/Makefile.am
index dfa31aa..4316946 100644
--- a/src/plugins/external/Makefile.am
+++ b/src/plugins/external/Makefile.am
@@ -14,7 +14,8 @@ BUILT_SOURCES = rygel-external.stamp \
rygel-external-content-dir.c \
rygel-external-container.c \
rygel-external-item.c \
- rygel-external-plugin.c
+ rygel-external-plugin.c \
+ rygel-external-plugin-factory.c
librygel_external_la_SOURCES = rygel-external-content-dir.c \
rygel-external-content-dir.vala \
@@ -23,7 +24,9 @@ librygel_external_la_SOURCES = rygel-external-content-dir.c \
rygel-external-item.c \
rygel-external-item.vala \
rygel-external-plugin.c \
- rygel-external-plugin.vala
+ rygel-external-plugin.vala \
+ rygel-external-plugin-factory.c \
+ rygel-external-plugin-factory.vala
rygel-external.stamp: $(filter %.vala,$(librygel_external_la_SOURCES))
$(VALAC) -C --vapidir=$(top_srcdir)/src/rygel \
diff --git a/src/plugins/external/rygel-external-plugin-factory.vala b/src/plugins/external/rygel-external-plugin-factory.vala
new file mode 100644
index 0000000..4539fcf
--- /dev/null
+++ b/src/plugins/external/rygel-external-plugin-factory.vala
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2009 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * <zeeshan ali nokia com>
+ *
+ * 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.
+ */
+
+using Rygel;
+using Gee;
+using CStuff;
+
+private const string DBUS_SERVICE = "org.freedesktop.DBus";
+private const string DBUS_OBJECT = "/org/freedesktop/DBus";
+private const string DBUS_IFACE = "org.freedesktop.DBus";
+
+private const string SERVICE_PREFIX = "org.Rygel.MediaServer1.";
+
+private ExternalPluginFactory plugin_factory;
+
+[ModuleInit]
+public void module_init (PluginLoader loader) {
+ try {
+ plugin_factory = new ExternalPluginFactory (loader);
+ } catch (DBus.Error error) {
+ critical ("Failed to fetch list of external services: %s\n",
+ error.message);
+ }
+}
+
+public class ExternalPluginFactory {
+ dynamic DBus.Object dbus_obj;
+ DBus.Connection connection;
+ PluginLoader loader;
+
+ public ExternalPluginFactory (PluginLoader loader) throws DBus.Error {
+ this.connection = DBus.Bus.get (DBus.BusType.SESSION);
+
+ this.dbus_obj = connection.get_object (DBUS_SERVICE,
+ DBUS_OBJECT,
+ DBUS_IFACE);
+ this.loader = loader;
+
+ dbus_obj.ListNames (this.list_names_cb);
+ }
+
+ private void list_names_cb (string[] services,
+ GLib.Error err) {
+ if (err != null) {
+ critical ("Failed to fetch list of external services: %s\n",
+ err.message);
+
+ return;
+ }
+
+ foreach (var service in services) {
+ if (service.has_prefix (SERVICE_PREFIX)) {
+ this.loader.add_plugin (new ExternalPlugin (this.connection,
+ service));
+ }
+ }
+
+ dbus_obj.NameOwnerChanged += this.name_owner_changed;
+ }
+
+ private void name_owner_changed (dynamic DBus.Object dbus_obj,
+ string name,
+ string old_owner,
+ string new_owner) {
+ var plugin = this.loader.get_plugin_by_name (name);
+
+ if (plugin != null) {
+ if (old_owner != "" && new_owner == "") {
+ debug ("Service '%s' going down, marking it as unavailable",
+ name);
+ plugin.available = false;
+ } else if (old_owner == "" && new_owner != "") {
+ debug ("Service '%s' up again, marking it as available",
+ name);
+ plugin.available = true;
+ }
+ } else if (name.has_prefix (SERVICE_PREFIX)) {
+ // Ah, new plugin available, lets use it
+ this.loader.add_plugin (new ExternalPlugin (this.connection,
+ name));
+ }
+ }
+}
diff --git a/src/plugins/external/rygel-external-plugin.vala b/src/plugins/external/rygel-external-plugin.vala
index 6e5cf6d..83b5d38 100644
--- a/src/plugins/external/rygel-external-plugin.vala
+++ b/src/plugins/external/rygel-external-plugin.vala
@@ -23,87 +23,9 @@
*/
using Rygel;
-using Gee;
-using CStuff;
-private const string DBUS_SERVICE = "org.freedesktop.DBus";
-private const string DBUS_OBJECT = "/org/freedesktop/DBus";
-private const string DBUS_IFACE = "org.freedesktop.DBus";
private const string PROPS_IFACE = "org.freedesktop.DBus.Properties";
-
private const string OBJECT_IFACE = "org.Rygel.MediaObject1";
-private const string SERVICE_PREFIX = "org.Rygel.MediaServer1.";
-
-private ExternalPluginFactory plugin_factory;
-
-[ModuleInit]
-public void module_init (PluginLoader loader) {
- try {
- plugin_factory = new ExternalPluginFactory (loader);
- } catch (DBus.Error error) {
- critical ("Failed to fetch list of external services: %s\n",
- error.message);
- }
-}
-
-public class ExternalPluginFactory {
- dynamic DBus.Object dbus_obj;
- DBus.Connection connection;
- PluginLoader loader;
-
- public ExternalPluginFactory (PluginLoader loader) throws DBus.Error {
- this.connection = DBus.Bus.get (DBus.BusType.SESSION);
-
- this.dbus_obj = connection.get_object (DBUS_SERVICE,
- DBUS_OBJECT,
- DBUS_IFACE);
- this.loader = loader;
-
- dbus_obj.ListNames (this.list_names_cb);
- }
-
- private void list_names_cb (string[] services,
- GLib.Error err) {
- if (err != null) {
- critical ("Failed to fetch list of external services: %s\n",
- err.message);
-
- return;
- }
-
- foreach (var service in services) {
- if (service.has_prefix (SERVICE_PREFIX)) {
- this.loader.add_plugin (new ExternalPlugin (this.connection,
- service));
- }
- }
-
- dbus_obj.NameOwnerChanged += this.name_owner_changed;
- }
-
- private void name_owner_changed (dynamic DBus.Object dbus_obj,
- string name,
- string old_owner,
- string new_owner) {
- var plugin = this.loader.get_plugin_by_name (name);
-
- if (plugin != null) {
- if (old_owner != "" && new_owner == "") {
- debug ("Service '%s' going down, marking it as unavailable",
- name);
- plugin.available = false;
- } else if (old_owner == "" && new_owner != "") {
- debug ("Service '%s' up again, marking it as available",
- name);
- plugin.available = true;
- }
- } else if (name.has_prefix (SERVICE_PREFIX)) {
- // Ah, new plugin available, lets use it
- this.loader.add_plugin (new ExternalPlugin (this.connection,
- name));
- }
- }
-}
public class ExternalPlugin : Plugin {
// class-wide constants
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]