[rygel] core: Basic implementation of CmdlineConfig



commit 3a9f24c4c3b332235a2e88d67fffc36e2a7f1c88
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Jun 11 17:15:07 2009 +0300

    core: Basic implementation of CmdlineConfig
    
    An implementation of Configuration that gets it's options from commandline
    arguments.

 src/rygel/Makefile.am               |    3 +
 src/rygel/rygel-cmdline-config.vala |  162 +++++++++++++++++++++++++++++++++++
 src/rygel/rygel-main.vala           |   12 ++-
 src/rygel/rygel-meta-config.vala    |    1 +
 4 files changed, 175 insertions(+), 3 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index a2efa79..54c76d6 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -38,6 +38,7 @@ BUILT_SOURCES = rygel-1.0.vapi \
 		rygel-configuration.c \
 		rygel-user-config.c \
 		rygel-meta-config.c \
+		rygel-cmdline-config.c \
 		rygel-main.c \
 		rygel-dbus-service.c \
 		rygel-content-directory.c \
@@ -123,6 +124,7 @@ DEPS_FILES = rygel-1.0.deps
 VAPI_SOURCE_FILES = rygel-configuration.vala \
 		    rygel-user-config.vala \
 		    rygel-meta-config.vala \
+		    rygel-cmdline-config.vala \
 		    rygel-content-directory.vala \
 		    rygel-connection-manager.vala \
 		    rygel-transcode-manager.vala \
@@ -162,6 +164,7 @@ noinst_LIBRARIES = librygel-configuration.a
 librygel_configuration_a_SOURCES = rygel-configuration.c \
 			           rygel-user-config.c \
 				   rygel-meta-config.c \
+				   rygel-cmdline-config.c \
 				   cstuff.c \
                                    cstuff.h
 
diff --git a/src/rygel/rygel-cmdline-config.vala b/src/rygel/rygel-cmdline-config.vala
new file mode 100644
index 0000000..edbdade
--- /dev/null
+++ b/src/rygel/rygel-cmdline-config.vala
@@ -0,0 +1,162 @@
+/*
+ * 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 CStuff;
+
+public errordomain Rygel.CmdlineConfigError {
+    VERSION_ONLY
+}
+
+/**
+ * Manages configuration from Commandline arguments.
+ */
+public class Rygel.CmdlineConfig : GLib.Object, Configuration {
+    private static string host_ip;
+    private static int port;
+
+    private static bool no_transcoding;
+    private static bool no_mp3_trans;
+    private static bool no_mp2ts_trans;
+    private static bool no_lpcm_trans;
+
+    private static bool version;
+
+    // Our singleton
+    private static CmdlineConfig config;
+
+    // Command-line options
+	const OptionEntry[] options = {
+		{ "version", 0, 0, OptionArg.NONE, ref version,
+          "Display version number", null },
+		{ "host-ip", 'H', 0, OptionArg.STRING, ref host_ip,
+          "IP address", "IP" },
+		{ "port", 'p', 0, OptionArg.INT, ref port,
+          "Port", "PORT" },
+		{ "disable-transcoding", 't', 0, OptionArg.NONE, ref no_transcoding,
+          "Disable transcoding", null },
+		{ "disable-mp3-transcoder", 'm', 0, OptionArg.NONE, ref no_mp3_trans,
+          "Disable MP3 transcoder", null },
+		{ "disable-mp2ts-transcoder", 'p', 0, OptionArg.NONE,
+          ref no_mp2ts_trans,
+          "Disable mpeg2 transport stream transcoder", null },
+		{ "disable-lpcm-transcoder", 'l', 0, OptionArg.NONE, ref no_lpcm_trans,
+          "Disable Linear PCM transcoder", null },
+		{ null }
+	};
+
+    public static CmdlineConfig get_default () {
+        if (config == null) {
+            config = new CmdlineConfig ();
+        }
+
+        return config;
+    }
+
+    public static void parse_args (ref unowned string[] args)
+                                   throws CmdlineConfigError.VERSION_ONLY,
+                                          OptionError {
+        var parameter_string = "- " + BuildConfig.PACKAGE_NAME;
+        var opt_context = new OptionContext (parameter_string);
+        opt_context.set_help_enabled (true);
+        opt_context.add_main_entries (options, null);
+        opt_context.add_group (Gst.init_get_option_group ());
+        opt_context.parse (ref args);
+
+		if (version) {
+			stdout.printf ("%s\n", BuildConfig.PACKAGE_STRING);
+			throw new CmdlineConfigError.VERSION_ONLY ("");
+		}
+    }
+
+    // Why would someone lauch rygel to kill itself?
+    public bool get_upnp_enabled () throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+
+    public string get_host_ip () throws GLib.Error {
+        return host_ip;
+    }
+
+    public int get_port () throws GLib.Error {
+        return port;
+    }
+
+    public bool get_transcoding () throws GLib.Error {
+        return !no_transcoding;
+    }
+
+    public bool get_mp3_transcoder () throws GLib.Error {
+        return !no_mp3_trans;
+    }
+
+    public bool get_mp2ts_transcoder () throws GLib.Error {
+        return !no_mp2ts_trans;
+    }
+
+    public bool get_lpcm_transcoder () throws GLib.Error {
+        return !no_lpcm_trans;
+    }
+
+    // Dynamic options
+    // FIXME: How to handle them?
+    public bool get_enabled (string section) throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+
+    public string get_title (string section) throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+
+    public string get_string (string section,
+                              string key) throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+
+    public Gee.ArrayList<string> get_string_list (string section,
+                                                  string key)
+                                                  throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+
+    public int get_int (string section,
+                        string key,
+                        int    min,
+                        int    max)
+                        throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+
+    public Gee.ArrayList<int> get_int_list (string section,
+                                            string key)
+                                            throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+
+    public bool get_bool (string section,
+                          string key)
+                          throws GLib.Error {
+        throw new ConfigurationError.NO_VALUE_SET ("No value available");
+    }
+}
+
diff --git a/src/rygel/rygel-main.vala b/src/rygel/rygel-main.vala
index 591d34b..983ddf7 100644
--- a/src/rygel/rygel-main.vala
+++ b/src/rygel/rygel-main.vala
@@ -96,12 +96,18 @@ public class Rygel.Main : Object {
         Main main;
         DBusService service;
 
-        // initialize gstreamer
-        Gst.init (ref args);
-
         try {
+            // Parse commandline options
+            CmdlineConfig.parse_args (ref args);
+
+            // initialize gstreamer
+            var dummy_args = new string[0];
+            Gst.init (ref dummy_args);
+
             main = new Main ();
             service = new DBusService (main);
+        } catch (CmdlineConfigError.VERSION_ONLY err) {
+            return 0;
         } catch (GLib.Error err) {
             error ("%s", err.message);
 
diff --git a/src/rygel/rygel-meta-config.vala b/src/rygel/rygel-meta-config.vala
index c8bfe88..b9a64bd 100644
--- a/src/rygel/rygel-meta-config.vala
+++ b/src/rygel/rygel-meta-config.vala
@@ -49,6 +49,7 @@ public class Rygel.MetaConfig : GLib.Object, Configuration {
     public MetaConfig () {
         this.configs = new ArrayList<Configuration> ();
 
+        this.configs.add (CmdlineConfig.get_default ());
         this.configs.add (UserConfig.get_default ());
     }
 



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