Cleanup glue and GError handling

This commit is contained in:
Sebastian Dröge 2009-04-16 22:19:59 +02:00
parent 6b4fc89778
commit a97db534ed
7 changed files with 39 additions and 63 deletions

View file

@ -48,14 +48,7 @@ namespace Gst {
bool result = gst_init_check (ref argc, ref argv_ptr, out error_ptr);
if (error_ptr != IntPtr.Zero) {
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));
throw new GLib.GException (error_ptr);
} else if (!result) {
throw new ApplicationException ("gst_init_check() failed: Reason unknown");
}

View file

@ -8,26 +8,51 @@ 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);
[StructLayout (LayoutKind.Sequential) ]
internal struct GError {
uint domain_quark;
int code;
IntPtr message;
public uint Domain {
get {
return domain_quark;
}
set {
domain_quark = value;
}
}
public int Code {
get {
return code;
}
set {
code = value;
}
}
public string Message {
get {
if (message == IntPtr.Zero)
return String.Empty;
return GLib.Marshaller.PtrToStringGFree (message);
return null;
return GLib.Marshaller.Utf8PtrToString (message);
}
set {
if (message != IntPtr.Zero)
GLib.Marshaller.Free (message);
message = GLib.Marshaller.StringToPtrGStrdup (value);
}
}
public static void Free (IntPtr error) {
if (error != IntPtr.Zero)
g_error_free (error);
public void Unset () {
GLib.Marshaller.Free (message);
message = IntPtr.Zero;
code = 0;
domain_quark = 0;
}
[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);
}

View file

@ -20,8 +20,6 @@ public void SetGValue (ref GLib.Value val) {
[DllImport ("gstreamersharpglue-0.10.dll") ]
private static extern IntPtr gstsharp_g_type_from_instance (IntPtr o);
[DllImport ("gstreamersharpglue-0.10.dll") ]
private static extern IntPtr gstsharp_g_value_type (ref GLib.Value val);
[DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_dup_mini_object (ref GLib.Value v);
[DllImport ("gstreamer-0.10.dll") ]

View file

@ -7,7 +7,6 @@ libgstreamersharpglue_0_10_la_SOURCES = \
message.c \
bin.c \
structure.c \
gerror.c \
gobject.c
nodist_libgstreamersharpglue_0_10_la_SOURCES = generated.c

View file

@ -1,10 +0,0 @@
#include <glib.h>
gchar *
gstsharp_g_error_get_message (GError * error)
{
if (error->message)
return g_strdup (error->message);
return NULL;
}

View file

@ -12,8 +12,3 @@ gstsharp_g_type_from_instance (GTypeInstance * instance)
return G_TYPE_FROM_INSTANCE (instance);
}
GType
gstsharp_g_value_type (const GValue * val)
{
return G_VALUE_TYPE (val);
}

View file

@ -1,24 +0,0 @@
#include <glib/gerror.h>
#include <gst/gstmessage.h>
#include <glib/gquark.h>
gchar *
gstsharp_message_parse_error (GstMessage * message)
{
GError *gerror;
gchar *error;
gst_message_parse_error (message, &gerror, NULL);
error = g_strdup (gerror->message);
g_error_free (gerror);
return error;
}
GError *
gstsharp_message_error_new ()
{
GQuark domain = g_quark_from_string ("test");
return g_error_new (domain, 10, "test error");
}