[rygel] core,plugins: Implement and use MetaConfiguration



commit 98c7a4d5cd3a1bd4662fa4096452533536512355
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Jun 10 17:31:21 2009 +0300

    core,plugins: Implement and use MetaConfiguration
    
    It abstracts Rygel and it's plugins from different Configuration
    implementations. It keeps all real configuration sources in a list and
    returns the value provided by the first one. If none of them provides
    the value, it emits an error.

 .../rygel-media-export-root-container.vala         |    2 +-
 .../mediathek/rygel-mediathek-root-container.vala  |    2 +-
 src/rygel/Makefile.am                              |    3 +
 src/rygel/rygel-meta-config.vala                   |  343 ++++++++++++++++++++
 src/rygel/rygel-root-device-factory.vala           |   21 +-
 src/rygel/rygel-transcode-manager.vala             |    2 +-
 6 files changed, 365 insertions(+), 8 deletions(-)
---
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 1200178..5ac3ad5 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -92,7 +92,7 @@ public class Rygel.MediaExportRootContainer : MediaContainer {
 
         this.children = new ArrayList<MediaExportContainer> ();
 
-        var config = Rygel.UserConfig.get_default ();
+        var config = Rygel.MetaConfig.get_default ();
         var uris = config.get_string_list ("MediaExport", "uris");
 
         // either an error occured or the gconf key is not set
diff --git a/src/plugins/mediathek/rygel-mediathek-root-container.vala b/src/plugins/mediathek/rygel-mediathek-root-container.vala
index 3688755..fdb1f44 100644
--- a/src/plugins/mediathek/rygel-mediathek-root-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-root-container.vala
@@ -100,7 +100,7 @@ public class Rygel.MediathekRootContainer : MediaContainer {
         this.session = new Soup.SessionAsync ();
         this.items = new ArrayList<MediathekRssContainer> ();
 
-        var config = Rygel.UserConfig.get_default ();
+        var config = Rygel.MetaConfig.get_default ();
         var feeds = config.get_int_list ("ZDFMediathek", "rss");
 
         if (feeds.size == 0) {
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index d88c611..6b92166 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -37,6 +37,7 @@ BUILT_SOURCES = rygel-1.0.vapi \
 		rygel-root-device-factory.c \
 		rygel-configuration.c \
 		rygel-user-config.c \
+		rygel-meta-config.c \
 		rygel-main.c \
 		rygel-dbus-service.c \
 		rygel-content-directory.c \
@@ -121,6 +122,7 @@ DEPS_FILES = rygel-1.0.deps
 
 VAPI_SOURCE_FILES = rygel-configuration.vala \
 		    rygel-user-config.vala \
+		    rygel-meta-config.vala \
 		    rygel-content-directory.vala \
 		    rygel-connection-manager.vala \
 		    rygel-transcode-manager.vala \
@@ -159,6 +161,7 @@ noinst_LIBRARIES = librygel-configuration.a
 
 librygel_configuration_a_SOURCES = rygel-configuration.c \
 			           rygel-user-config.c \
+				   rygel-meta-config.c \
 				   cstuff.c \
                                    cstuff.h
 
diff --git a/src/rygel/rygel-meta-config.vala b/src/rygel/rygel-meta-config.vala
new file mode 100644
index 0000000..c8bfe88
--- /dev/null
+++ b/src/rygel/rygel-meta-config.vala
@@ -0,0 +1,343 @@
+/*
+ * Copyright (C) 2008,2009 Nokia Corporation, all rights reserved.
+ * Copyright (C) 2008,2009 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ *
+ * 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 Gee;
+using CStuff;
+
+/**
+ * Manages all the configuration sources for Rygel.
+ *
+ * Abstracts Rygel and it's plugins from Configuration implementations. It keeps
+ * all real configuration sources in a list and returns the value provided by
+ * the first one. If none of them provides the value, it emits an error.
+ */
+public class Rygel.MetaConfig : GLib.Object, Configuration {
+    // Our singleton
+    private static MetaConfig meta_config;
+
+    private ArrayList<Configuration> configs;
+
+    public static MetaConfig get_default () {
+        if (meta_config == null) {
+            meta_config = new MetaConfig ();
+        }
+
+        return meta_config;
+    }
+
+    public MetaConfig () {
+        this.configs = new ArrayList<Configuration> ();
+
+        this.configs.add (UserConfig.get_default ());
+    }
+
+    public bool get_upnp_enabled () throws GLib.Error {
+        bool val = true;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_upnp_enabled ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
+    public string get_host_ip () throws GLib.Error {
+        string val = null;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_host_ip ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
+    public int get_port () throws GLib.Error {
+        int val = 0;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_port ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
+    public bool get_transcoding () throws GLib.Error {
+        bool val = true;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_transcoding ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
+    public bool get_mp3_transcoder () throws GLib.Error {
+        bool val = true;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_mp3_transcoder ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
+    public bool get_mp2ts_transcoder () throws GLib.Error {
+        bool val = true;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_mp2ts_transcoder ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
+    public bool get_lpcm_transcoder () throws GLib.Error {
+        bool val = true;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_lpcm_transcoder ();
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return val;
+    }
+
+    public bool get_enabled (string section) throws GLib.Error {
+        bool val = true;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_enabled (section);
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET (
+                                        "No value available for '%s/enabled'",
+                                        section);
+        }
+
+        return val;
+    }
+
+    public string get_title (string section) throws GLib.Error {
+        string val = null;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_title (section);
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (val == null) {
+            throw new ConfigurationError.NO_VALUE_SET (
+                                        "No value available for '%s/enabled'",
+                                        section);
+        }
+
+        return val;
+    }
+
+    public string get_string (string section,
+                              string key) throws GLib.Error {
+        string val = null;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_string (section, key);
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (val == null) {
+            throw new ConfigurationError.NO_VALUE_SET (
+                                        "No value available for '%s/%s'",
+                                        section,
+                                        key);
+        }
+
+        return val;
+    }
+
+    public Gee.ArrayList<string> get_string_list (string section,
+                                                  string key)
+                                                  throws GLib.Error {
+        Gee.ArrayList<string> val = null;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_string_list (section, key);
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (val == null) {
+            throw new ConfigurationError.NO_VALUE_SET (
+                                        "No value available for '%s/%s'",
+                                        section,
+                                        key);
+        }
+
+        return val;
+    }
+
+    public int get_int (string section,
+                        string key,
+                        int    min,
+                        int    max)
+                        throws GLib.Error {
+        int val = 0;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_int (section, key, min, max);
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET (
+                                        "No value available for '%s/%s'",
+                                        section,
+                                        key);
+        }
+
+        return val;
+    }
+
+    public Gee.ArrayList<int> get_int_list (string section,
+                                            string key)
+                                            throws GLib.Error {
+        Gee.ArrayList<int> val = null;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_int_list (section, key);
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (val == null) {
+            throw new ConfigurationError.NO_VALUE_SET (
+                                        "No value available for '%s/%s'",
+                                        section,
+                                        key);
+        }
+
+        return val;
+    }
+
+    public bool get_bool (string section,
+                          string key)
+                          throws GLib.Error {
+        bool val = false;
+        bool unavailable = true;
+
+        foreach (var config in this.configs) {
+            try {
+                val = config.get_bool (section, key);
+                unavailable = false;
+                break;
+            } catch (GLib.Error err) {}
+        }
+
+        if (unavailable) {
+            throw new ConfigurationError.NO_VALUE_SET (
+                                        "No value available for '%s/%s'",
+                                        section,
+                                        key);
+        }
+
+        return val;
+    }
+}
+
diff --git a/src/rygel/rygel-root-device-factory.vala b/src/rygel/rygel-root-device-factory.vala
index edb99fa..c3ec32c 100644
--- a/src/rygel/rygel-root-device-factory.vala
+++ b/src/rygel/rygel-root-device-factory.vala
@@ -41,14 +41,19 @@ public class Rygel.RootDeviceFactory {
     private GUPnP.Context context;
 
     public RootDeviceFactory () throws GLib.Error {
-        this.config = UserConfig.get_default ();
+        this.config = MetaConfig.get_default ();
 
         /* Set up GUPnP context */
         this.context = create_upnp_context ();
     }
 
     public RootDevice create (Plugin plugin) throws GLib.Error {
-        if (!this.config.get_enabled (plugin.name)) {
+        bool enabled = true;
+        try {
+            enabled = this.config.get_enabled (plugin.name);
+        } catch (GLib.Error err) {}
+
+        if (!enabled) {
             throw new RootDeviceFactoryError.PLUGIN_DISABLED (
                             "Plugin disabled in user configuration.");
         }
@@ -99,9 +104,15 @@ public class Rygel.RootDeviceFactory {
     }
 
     private GUPnP.Context create_upnp_context () throws GLib.Error {
-        GUPnP.Context context = new GUPnP.Context (null,
-                                                   this.config.get_host_ip (),
-                                                   this.config.get_port ());
+        string host_ip = null;
+        int port = 0;
+
+        try {
+            host_ip = this.config.get_host_ip ();
+            port = this.config.get_port ();
+        } catch (GLib.Error err) {}
+
+        GUPnP.Context context = new GUPnP.Context (null, host_ip, port);
 
         /* Host UPnP dir */
         context.host_path (BuildConfig.DATA_DIR, "");
diff --git a/src/rygel/rygel-transcode-manager.vala b/src/rygel/rygel-transcode-manager.vala
index 47e5319..7500522 100644
--- a/src/rygel/rygel-transcode-manager.vala
+++ b/src/rygel/rygel-transcode-manager.vala
@@ -37,7 +37,7 @@ internal abstract class Rygel.TranscodeManager : GLib.Object {
     public TranscodeManager () throws GLib.Error {
         transcoders = new ArrayList<Transcoder> ();
 
-        var config = UserConfig.get_default ();
+        var config = MetaConfig.get_default ();
 
         if (config.get_transcoding ()) {
             if (config.get_lpcm_transcoder ()) {



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