Print reason if InitCheck() failed and introduce GError helper functions
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Tue, 7 Apr 2009 09:02:08 +0000 (11:02 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Tue, 7 Apr 2009 09:02:08 +0000 (11:02 +0200)
gstreamer-sharp/Application.cs
gstreamer-sharp/GError.cs [new file with mode: 0644]
gstreamer-sharp/Gstreamer.metadata
gstreamer-sharp/Makefile.am
gstreamer-sharp/glue/Makefile.am
gstreamer-sharp/glue/gerror.c [new file with mode: 0644]

index 8172480..6a8bb78 100644 (file)
@@ -55,16 +55,23 @@ namespace Gst
                 bool result = gst_init_check(ref argc, ref argv_ptr, out error_ptr);
                 
                 if(error_ptr != IntPtr.Zero) {
-                    throw new ApplicationException("gst_init_check set error");
+                   string message = GError.GetMessage (error_ptr);
+
+                   if (message == String.Empty)
+                     message = "Reason unknown";
+
+                   GError.Free (error_ptr);
+
+                    throw new ApplicationException(String.Format ("gst_init_check() failed: {0}", message));
                 } else if(!result) {
-                    throw new ApplicationException("gst_init_check failed, error not set");
+                    throw new ApplicationException("gst_init_check() failed: Reason unknown");
                 }
             } else {
                 gst_init(ref argc, ref argv_ptr);
             }
                 
             if(argv_ptr != argv.Handle) {
-                string init_call = check ? "gst_init_check" : "gst_init";
+                string init_call = check ? "gst_init_check()" : "gst_init()";
                 throw new ApplicationException(init_call + " returned a new argv handle");
             }
             
@@ -76,7 +83,7 @@ namespace Gst
                 Array.Copy(progargs, 1, args, 0, argc - 1);
             }
         }
-        
+
         [DllImport("gstreamer-0.10")]
         private static extern void gst_init(ref int argc, ref IntPtr argv);
 
diff --git a/gstreamer-sharp/GError.cs b/gstreamer-sharp/GError.cs
new file mode 100644 (file)
index 0000000..efaa13f
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// Copyright (c) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+//
+// This class implements some helper functions to handle GError
+//
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Gst {
+    internal static class GError
+    {
+        public static string GetMessage (IntPtr error)
+       {
+           if (error == IntPtr.Zero)
+               return String.Empty;
+
+           IntPtr message = gstsharp_g_error_get_message (error);
+           if (message == IntPtr.Zero)
+             return String.Empty;
+             
+           return GLib.Marshaller.PtrToStringGFree (message);
+       }
+
+       public static void Free (IntPtr error)
+       {
+           if (error != IntPtr.Zero)
+               g_error_free (error);
+       }
+
+       [DllImport("gstreamersharpglue-0.10")]
+       static extern IntPtr gstsharp_g_error_get_message (IntPtr error);
+
+       [DllImport("glib-2.0.dll")]
+       static extern void g_error_free (IntPtr error);
+    }
+}
index 4b00017..7bfbcda 100644 (file)
 
   <attr path="/api/namespace/object[@name='GhostPad']" name="parent">GstPad</attr>
 
+  <remove-node path="/api/namespace/class[@name='Global']/method[@cname='gst_version_string']" />
+
   <attr path="/api/namespace/object[@name='Index']/field[@cname='resolver']" name="hidden">1</attr>
   <attr path="/api/namespace/object[@name='Index']/property[@cname='resolver']" name="hidden">1</attr>
 
   <attr path="/api/namespace/enum[@name='IndexFlags']/member[@cname='GST_INDEX_READABLE']" name="value">ObjectFlags.Last &lt;&lt; 1</attr>
   <attr path="/api/namespace/enum[@name='IndexFlags']/member[@cname='GST_INDEX_FLAG_LAST']" name="value">ObjectFlags.Last &lt;&lt; 8</attr>
 
+  <remove-node path="/api/namespace/class[@name='Init']" />
+
   <attr path="/api/namespace/struct[@name='Iterator']/method[@name='Fold']/parameters/*[@name='ret']" name="name">ret_val</attr>
   <attr path="/api/namespace/struct[@name='Iterator']/field[@name='Next']" name="hidden">1</attr>
   <attr path="/api/namespace/struct[@name='Iterator']/field[@name='Item']" name="hidden">1</attr>
   <attr path="/api/namespace/enum[@name='PadTemplateFlags']/member[@cname='GST_PAD_TEMPLATE_FIXED']" name="value">ObjectFlags.Last &lt;&lt; 0</attr>
   <attr path="/api/namespace/enum[@name='PadTemplateFlags']/member[@cname='GST_PAD_TEMPLATE_FLAG_LAST']" name="value">ObjectFlags.Last &lt;&lt; 4</attr>
 
-  <attr path="/api/namespace/class[@name='Param']" name="hidden">1</attr>
+  <remove-node path="/api/namespace/class[@name='Param']" name="hidden">1</attr>
 
   <attr path="/api/namespace/object[@name='ParamSpecFraction']" name="hidden">1</attr>
   <attr path="/api/namespace/object[@name='ParamSpecMiniObject']" name="hidden">1</attr>
index 446d3cd..cc7f5c6 100644 (file)
@@ -43,6 +43,7 @@ sources = \
        Version.cs \
        AssemblyInfo.cs \
        CommonTags.cs \
+       GError.cs \
        plugins-base/PlayBin.cs \
        plugins-base/DecodeBin.cs \
        plugins-base/TypeFindElement.cs
index 60cecc3..6321e17 100644 (file)
@@ -6,7 +6,8 @@ libgstreamersharpglue_0_10_la_SOURCES = \
        message.c \
        miniobject.c \
        bin.c \
-       dynamicsignal.c
+       dynamicsignal.c \
+       gerror.c
 
 nodist_libgstreamersharpglue_0_10_la_SOURCES = generated.c 
 
diff --git a/gstreamer-sharp/glue/gerror.c b/gstreamer-sharp/glue/gerror.c
new file mode 100644 (file)
index 0000000..d5f64fb
--- /dev/null
@@ -0,0 +1,11 @@
+#include <glib.h>
+
+gchar *
+gstsharp_g_error_get_message (GError * error)
+{
+  if (error->message)
+    return g_strdup (error->message);
+
+  return NULL;
+}
+