mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:06:12 +00:00
Cleanup glue and GError handling
This commit is contained in:
parent
6b4fc89778
commit
a97db534ed
7 changed files with 39 additions and 63 deletions
|
@ -48,14 +48,7 @@ namespace Gst {
|
||||||
bool result = gst_init_check (ref argc, ref argv_ptr, out error_ptr);
|
bool result = gst_init_check (ref argc, ref argv_ptr, out error_ptr);
|
||||||
|
|
||||||
if (error_ptr != IntPtr.Zero) {
|
if (error_ptr != IntPtr.Zero) {
|
||||||
string message = GError.GetMessage (error_ptr);
|
throw new GLib.GException (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) {
|
} else if (!result) {
|
||||||
throw new ApplicationException ("gst_init_check() failed: Reason unknown");
|
throw new ApplicationException ("gst_init_check() failed: Reason unknown");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,25 +8,50 @@ using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Gst {
|
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) ]
|
||||||
if (message == IntPtr.Zero)
|
internal struct GError {
|
||||||
return String.Empty;
|
uint domain_quark;
|
||||||
|
int code;
|
||||||
|
IntPtr message;
|
||||||
|
|
||||||
return GLib.Marshaller.PtrToStringGFree (message);
|
public uint Domain {
|
||||||
|
get {
|
||||||
|
return domain_quark;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
domain_quark = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Free (IntPtr error) {
|
public int Code {
|
||||||
if (error != IntPtr.Zero)
|
get {
|
||||||
g_error_free (error);
|
return code;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
code = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport ("gstreamersharpglue-0.10") ]
|
public string Message {
|
||||||
static extern IntPtr gstsharp_g_error_get_message (IntPtr error);
|
get {
|
||||||
|
if (message == IntPtr.Zero)
|
||||||
|
return null;
|
||||||
|
return GLib.Marshaller.Utf8PtrToString (message);
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (message != IntPtr.Zero)
|
||||||
|
GLib.Marshaller.Free (message);
|
||||||
|
message = GLib.Marshaller.StringToPtrGStrdup (value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unset () {
|
||||||
|
GLib.Marshaller.Free (message);
|
||||||
|
message = IntPtr.Zero;
|
||||||
|
code = 0;
|
||||||
|
domain_quark = 0;
|
||||||
|
}
|
||||||
|
|
||||||
[DllImport ("glib-2.0.dll") ]
|
[DllImport ("glib-2.0.dll") ]
|
||||||
static extern void g_error_free (IntPtr error);
|
static extern void g_error_free (IntPtr error);
|
||||||
|
|
|
@ -20,8 +20,6 @@ public void SetGValue (ref GLib.Value val) {
|
||||||
|
|
||||||
[DllImport ("gstreamersharpglue-0.10.dll") ]
|
[DllImport ("gstreamersharpglue-0.10.dll") ]
|
||||||
private static extern IntPtr gstsharp_g_type_from_instance (IntPtr o);
|
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") ]
|
[DllImport ("gstreamer-0.10.dll") ]
|
||||||
private static extern IntPtr gst_value_dup_mini_object (ref GLib.Value v);
|
private static extern IntPtr gst_value_dup_mini_object (ref GLib.Value v);
|
||||||
[DllImport ("gstreamer-0.10.dll") ]
|
[DllImport ("gstreamer-0.10.dll") ]
|
||||||
|
|
|
@ -7,7 +7,6 @@ libgstreamersharpglue_0_10_la_SOURCES = \
|
||||||
message.c \
|
message.c \
|
||||||
bin.c \
|
bin.c \
|
||||||
structure.c \
|
structure.c \
|
||||||
gerror.c \
|
|
||||||
gobject.c
|
gobject.c
|
||||||
|
|
||||||
nodist_libgstreamersharpglue_0_10_la_SOURCES = generated.c
|
nodist_libgstreamersharpglue_0_10_la_SOURCES = generated.c
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -12,8 +12,3 @@ gstsharp_g_type_from_instance (GTypeInstance * instance)
|
||||||
return G_TYPE_FROM_INSTANCE (instance);
|
return G_TYPE_FROM_INSTANCE (instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
GType
|
|
||||||
gstsharp_g_value_type (const GValue * val)
|
|
||||||
{
|
|
||||||
return G_VALUE_TYPE (val);
|
|
||||||
}
|
|
||||||
|
|
|
@ -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");
|
|
||||||
}
|
|
Loading…
Reference in a new issue