rygel r309 - trunk/src/rygel
- From: zeeshanak svn gnome org
- To: svn-commits-list gnome org
- Subject: rygel r309 - trunk/src/rygel
- Date: Wed, 26 Nov 2008 17:00:23 +0000 (UTC)
Author: zeeshanak
Date: Wed Nov 26 17:00:23 2008
New Revision: 309
URL: http://svn.gnome.org/viewvc/rygel?rev=309&view=rev
Log:
Use exceptions rather than returning nulls.
Modified:
trunk/src/rygel/rygel-main.vala
trunk/src/rygel/rygel-media-server-factory.vala
Modified: trunk/src/rygel/rygel-main.vala
==============================================================================
--- trunk/src/rygel/rygel-main.vala (original)
+++ trunk/src/rygel/rygel-main.vala Wed Nov 26 17:00:23 2008
@@ -32,7 +32,7 @@
private MediaServerFactory ms_factory;
private List<MediaServer> media_servers;
- public Main () {
+ public Main () throws GLib.Error {
this.media_servers = new List<MediaServer> ();
this.plugin_loader = new PluginLoader ();
this.ms_factory = new MediaServerFactory ();
@@ -49,18 +49,31 @@
private void on_plugin_loaded (PluginLoader plugin_loader,
Plugin plugin) {
- var server = this.ms_factory.create_media_server (plugin);
+ try {
+ var server = this.ms_factory.create_media_server (plugin);
- /* Make our device available */
- server.available = true;
+ /* Make our device available */
+ server.available = true;
- media_servers.append (server);
+ media_servers.append (server);
+ } catch (GLib.Error error) {
+ warning ("Failed to create MediaServer for %s. Reason: %s\n",
+ plugin.name,
+ error.message);
+ }
}
public static int main (string[] args) {
Main main;
- main = new Main ();
+ try {
+ main = new Main ();
+ } catch (GLib.Error err) {
+ error ("%s", err.message);
+
+ return -1;
+ }
+
main.run ();
return 0;
Modified: trunk/src/rygel/rygel-media-server-factory.vala
==============================================================================
--- trunk/src/rygel/rygel-media-server-factory.vala (original)
+++ trunk/src/rygel/rygel-media-server-factory.vala Wed Nov 26 17:00:23 2008
@@ -28,6 +28,10 @@
using GConf;
using CStuff;
+public errordomain MediaServerFactoryError {
+ XML_PARSE
+}
+
/**
* Factory for MediaServer objects. Give it a plugin and it will create a
* MediaServer device for that.
@@ -41,14 +45,14 @@
private GConf.Client gconf;
private GUPnP.Context context;
- public MediaServerFactory () {
+ public MediaServerFactory () throws GLib.Error {
this.gconf = GConf.Client.get_default ();
/* Set up GUPnP context */
this.context = create_upnp_context ();
}
- public MediaServer? create_media_server (Plugin plugin) {
+ public MediaServer create_media_server (Plugin plugin) throws GLib.Error {
string gconf_path = ROOT_GCONF_PATH + plugin.name + "/";
string modified_desc = DESC_PREFIX + "-" + plugin.name + ".xml";
@@ -75,8 +79,11 @@
DESC_DOC);
Xml.Doc *doc = Xml.Parser.parse_file (orig_desc_path);
- if (doc == null)
- return null;
+ if (doc == null) {
+ string message = "Failed to parse %s".printf (orig_desc_path);
+
+ throw new MediaServerFactoryError.XML_PARSE (message);
+ }
/* Modify description to include Plugin-specific stuff */
this.prepare_desc_for_plugin (doc, plugin, gconf_path);
@@ -95,12 +102,12 @@
res = Xml.Doc.dump (f, doc);
if (f == null || res == -1) {
- critical ("Failed to write modified description.xml to %s.\n",
- desc_path);
+ string message = "Failed to write modified description" +
+ " to %s.\n".printf (desc_path);
delete doc;
- return null;
+ throw new IOError.FAILED (message);
}
/* Host our modified file */
@@ -114,7 +121,7 @@
return server;
}
- private GUPnP.Context? create_upnp_context () {
+ private GUPnP.Context create_upnp_context () throws GLib.Error {
string host_ip;
try {
host_ip = this.gconf.get_string (ROOT_GCONF_PATH + "host-ip");
@@ -133,14 +140,7 @@
port = 0;
}
- GUPnP.Context context;
- try {
- context = new GUPnP.Context (null, host_ip, port);
- } catch (GLib.Error error) {
- warning ("Error setting up GUPnP context: %s", error.message);
-
- return null;
- }
+ GUPnP.Context context = new GUPnP.Context (null, host_ip, port);
/* Host UPnP dir */
context.host_path (BuildConfig.DATA_DIR, "");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]