Use new custom GLib.Value support for gtk-sharp trunk

This commit is contained in:
Sebastian Dröge 2009-04-16 21:52:21 +02:00
parent 47fc2f04f6
commit 8e216fcd21
5 changed files with 106 additions and 87 deletions

View file

@ -1,6 +1,8 @@
[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_buffer_try_new_and_alloc (uint size);
public Buffer (GLib.Value val) : base (val) { }
public Buffer (uint size) {
IntPtr raw = gst_buffer_try_new_and_alloc (size);
if (raw == IntPtr.Zero)
@ -195,3 +197,6 @@ public ulong OffsetEnd {
}
}
static Buffer () {
GLib.GType.Register (Buffer.GType, typeof (Buffer));
}

View file

@ -133,12 +133,12 @@ namespace Gst {
static void OnMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
IntPtr ihint, IntPtr data) {
object [] args = new object[argc - 1];
object o = Gst.Value.GetValue ( (GLib.Value) Marshal.PtrToStructure (argsPtr, typeof (GLib.Value)));
object o = ( (GLib.Value) Marshal.PtrToStructure (argsPtr, typeof (GLib.Value))).Val;
for (int i = 1; i < argc; i++) {
IntPtr struct_ptr = (IntPtr) ( (long) argsPtr + (i * gvalue_struct_size));
GLib.Value argument = (GLib.Value) Marshal.PtrToStructure (struct_ptr, typeof (GLib.Value));
args[i - 1] = Gst.Value.GetValue (argument);
args[i - 1] = argument.Val;
}
if (data == IntPtr.Zero) {
@ -256,7 +256,7 @@ namespace Gst {
query = (SignalQuery) SignalEmitInfo[key];
GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1];
signal_parameters[0] = Gst.Value.CreateValue (o);
signal_parameters[0] = new GLib.Value (o);
if (parameters.Length != query.n_params)
throw new ApplicationException (String.Format ("Invalid number of parameters: expected {0}, got {1}", query.n_params, parameters.Length));
@ -268,7 +268,7 @@ namespace Gst {
if (expected_type != given_type && ! given_type.IsSubclassOf (given_type))
throw new ApplicationException (String.Format ("Invalid parameter type: expected {0}, got {1}", expected_type, given_type));
signal_parameters[i + 1] = Gst.Value.CreateValue (parameters[i]);
signal_parameters[i + 1] = new GLib.Value (parameters[i]);
}
GLib.Value return_value = new GLib.Value ();
@ -280,7 +280,7 @@ namespace Gst {
g_signal_emitv (signal_parameters, query.signal_id, signal_detail_quark, ref return_value);
return (query.return_type != GType.Invalid && query.return_type != GType.None) ? Gst.Value.GetValue (return_value) : null;
return (query.return_type != GType.Invalid && query.return_type != GType.None) ? return_value.Val : null;
}
[DllImport ("gstreamersharpglue-0.10") ]

View file

@ -2,11 +2,8 @@ protected MiniObject () : base ()
{
}
public static MiniObject NewFromValue (GLib.Value val) {
IntPtr type = gstsharp_g_value_type (ref val);
GLib.GType gtype = new GLib.GType (type);
return (MiniObject) GLib.Opaque.GetOpaque (gst_value_get_mini_object (ref val), (Type) gtype, false);
public MiniObject (GLib.Value val) : base () {
Raw = gst_value_dup_mini_object (ref val);
}
public static explicit operator GLib.Value (MiniObject o) {
@ -17,12 +14,16 @@ public static explicit operator GLib.Value (MiniObject o) {
return val;
}
public void SetGValue (ref GLib.Value val) {
gst_value_set_mini_object (ref val, Handle);
}
[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_get_mini_object (ref GLib.Value v);
private static extern IntPtr gst_value_dup_mini_object (ref GLib.Value v);
[DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_mini_object (ref GLib.Value v, IntPtr o);

View file

@ -122,11 +122,11 @@ public object Get (string field) {
GLib.Value v;
v = GetValue (field);
return Gst.Value.GetValue (v);
return v.Val;
}
public void Set (string field, object value) {
SetValue (field, Gst.Value.CreateValue (value));
SetValue (field, new GLib.Value (value));
}
public void Set (params object[] fields) {
@ -136,20 +136,16 @@ public void Set (params object[] fields) {
throw new ArgumentException ();
for (i = 0; i < length; i += 2) {
SetValue (fields[i] as string, Gst.Value.CreateValue (fields[i+1]));
SetValue (fields[i] as string, new GLib.Value (fields[i+1]));
}
}
public object this [string field] {
set {
GLib.Value v;
if (field == null)
throw new ArgumentNullException ();
v = Gst.Value.CreateValue (value);
Set (field, v);
Set (field, value);
}
get {
if (field == null)

View file

@ -8,62 +8,6 @@ using GLib;
/* TODO: intersect, compare, substract, .... */
namespace Gst {
public static class Value {
public static object GetValue (GLib.Value val) {
IntPtr type = gstsharp_g_value_type (ref val);
GType gtype = new GType (type);
if (type == Fraction.GType.Val)
return new Fraction (val);
else if (type == DoubleRange.GType.Val)
return new DoubleRange (val);
else if (type == IntRange.GType.Val)
return new IntRange (val);
else if (type == FractionRange.GType.Val)
return new FractionRange (val);
else if (type == Fourcc.GType.Val)
return new Fourcc (val);
else if (type == Date.GType.Val)
return new Date (val);
else if (type == Gst.List.GType.Val)
return new Gst.List (val);
else if (type == Gst.Array.GType.Val)
return new Gst.Array (val);
else if ( ( (Type) gtype).IsSubclassOf (typeof (Gst.MiniObject)))
return MiniObject.NewFromValue (val);
else
return val.Val;
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
private static extern IntPtr gstsharp_g_value_type (ref GLib.Value val);
public static GLib.Value CreateValue (object o) {
if (o.GetType () == typeof (Fraction))
return (GLib.Value) ( (Fraction) o);
else if (o.GetType () == typeof (DoubleRange))
return (GLib.Value) ( (DoubleRange) o);
else if (o.GetType () == typeof (IntRange))
return (GLib.Value) ( (IntRange) o);
else if (o.GetType () == typeof (FractionRange))
return (GLib.Value) ( (FractionRange) o);
else if (o.GetType () == typeof (Fourcc))
return (GLib.Value) ( (Fourcc) o);
else if (o.GetType () == typeof (Date))
return (GLib.Value) ( (Date) o);
else if (o.GetType () == typeof (DateTime))
return (GLib.Value) (new Date ( (DateTime) o));
else if (o.GetType () == typeof (Gst.List))
return (GLib.Value) ( (Gst.List) o);
else if (o.GetType () == typeof (Gst.Array))
return (GLib.Value) ( (Gst.Array) o);
else if (o.GetType ().IsSubclassOf (typeof (Gst.MiniObject)))
return (GLib.Value) ( (MiniObject) o);
else
return new GLib.Value (o);
}
}
public struct Fraction {
public int Numerator {
get {
@ -135,6 +79,10 @@ namespace Gst {
this.denominator = gst_value_get_fraction_denominator (ref val);
}
public void SetGValue (ref GLib.Value val) {
gst_value_set_fraction (ref val, Numerator, Denominator);
}
public override string ToString () {
return String.Format ("{0}/{1}", numerator, denominator);
}
@ -166,6 +114,10 @@ namespace Gst {
return new Fraction (a.Numerator * b.Denominator, a.Denominator * b.Numerator);
}
static Fraction () {
GLib.GType.Register (Fraction.GType, typeof (Fraction));
}
[DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_fraction (ref GLib.Value v, int numerator, int denominator);
[DllImport ("gstreamer-0.10.dll") ]
@ -203,6 +155,10 @@ namespace Gst {
return String.Format ("[{0}, {1}]", Min, Max);
}
public void SetGValue (ref GLib.Value val) {
gst_value_set_double_range (ref val, Min, Max);
}
public static explicit operator GLib.Value (DoubleRange range) {
GLib.Value val = new GLib.Value (DoubleRange.GType);
@ -210,6 +166,10 @@ namespace Gst {
return val;
}
static DoubleRange () {
GLib.GType.Register (DoubleRange.GType, typeof (DoubleRange));
}
[DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_double_range_get_type ();
[DllImport ("gstreamer-0.10.dll") ]
@ -243,6 +203,10 @@ namespace Gst {
this.Max = gst_value_get_int_range_max (ref val);
}
public void SetGValue (ref GLib.Value val) {
gst_value_set_int_range (ref val, Min, Max);
}
public override string ToString () {
return String.Format ("[{0}, {1}]", Min, Max);
}
@ -254,6 +218,10 @@ namespace Gst {
return val;
}
static IntRange () {
GLib.GType.Register (IntRange.GType, typeof (IntRange));
}
[DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_int_range_get_type ();
[DllImport ("gstreamer-0.10.dll") ]
@ -293,8 +261,14 @@ namespace Gst {
min = (GLib.Value) Marshal.PtrToStructure (min_ptr, typeof (GLib.Value));
max = (GLib.Value) Marshal.PtrToStructure (max_ptr, typeof (GLib.Value));
this.Min = (Fraction) Gst.Value.GetValue (min);
this.Max = (Fraction) Gst.Value.GetValue (max);
this.Min = (Fraction) min.Val;
this.Max = (Fraction) max.Val;
}
public void SetGValue (ref GLib.Value val) {
GLib.Value min = new GLib.Value (Min);
GLib.Value max = new GLib.Value (Max);
gst_value_set_fraction_range (ref val, ref min, ref max);
}
public override string ToString () {
@ -304,12 +278,16 @@ namespace Gst {
public static explicit operator GLib.Value (FractionRange range) {
GLib.Value val = new GLib.Value (FractionRange.GType);
GLib.Value min = (GLib.Value) (range.Min);
GLib.Value max = (GLib.Value) (range.Max);
GLib.Value min = new GLib.Value (range.Min);
GLib.Value max = new GLib.Value (range.Max);
gst_value_set_fraction_range (ref val, ref min, ref max);
return val;
}
static FractionRange () {
GLib.GType.Register (FractionRange.GType, typeof (FractionRange));
}
[DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_fraction_range_get_type ();
[DllImport ("gstreamer-0.10.dll") ]
@ -356,6 +334,10 @@ namespace Gst {
public Fourcc (GLib.Value val) : this (gst_value_get_fourcc (ref val)) {
}
public void SetGValue (ref GLib.Value val) {
gst_value_set_fourcc (ref val, Val);
}
public override string ToString () {
return String.Format ("{0}{1}{2}{3}", (char) ( (Val >> 24) & 0xff),
(char) ( (Val >> 16) & 0xff),
@ -382,6 +364,10 @@ namespace Gst {
return fourcc.ToString ();
}
static Fourcc () {
GLib.GType.Register (Fourcc.GType, typeof (Fourcc));
}
[DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_fourcc_get_type ();
[DllImport ("gstreamer-0.10.dll") ]
@ -414,21 +400,30 @@ namespace Gst {
this.Val = new DateTime (g_date_get_year (date), g_date_get_month (date), g_date_get_day (date));
}
public void SetGValue (ref GLib.Value val) {
IntPtr date_ptr = g_date_new_dmy ( (byte) Val.Day, (int) Val.Month, (ushort) Val.Year);
gst_value_set_date (ref val, date_ptr);
GLib.Marshaller.Free (date_ptr);
}
public override string ToString () {
return String.Format ("{0}-{1}-{2}", Val.Year, Val.Month, Val.Day);
}
public static explicit operator GLib.Value (Date date) {
GLib.Value val = new GLib.Value (Date.GType);
IntPtr date_ptr = g_date_new_dmy ( (byte) date.Val.Day, (int) date.Val.Month, (ushort) date.Val.Year);
gst_value_set_date (ref val, date_ptr);
GLib.Marshaller.Free (date_ptr);
date.SetGValue (ref val);
return val;
}
static Date () {
GLib.GType.Register (Date.GType, typeof (Date));
}
[DllImport ("libglib-2.0-0.dll") ]
private static extern byte g_date_get_day (IntPtr date);
[DllImport ("libglib-2.0-0.dll") ]
@ -466,7 +461,14 @@ namespace Gst {
for (uint i = 0; i < n; i++) {
IntPtr v_ptr = gst_value_list_get_value (ref val, i);
GLib.Value v = (GLib.Value) Marshal.PtrToStructure (v_ptr, typeof (GLib.Value));
this.content.Add (Gst.Value.GetValue (v));
this.content.Add (v.Val);
}
}
public void SetGValue (ref GLib.Value val) {
foreach (object o in content) {
GLib.Value v = new GLib.Value (o);
gst_value_list_append_value (ref val, ref v);
}
}
@ -488,7 +490,7 @@ namespace Gst {
GLib.Value val = new GLib.Value (List.GType);
foreach (object o in l.content) {
GLib.Value v = Gst.Value.CreateValue (o);
GLib.Value v = new GLib.Value (o);
gst_value_list_append_value (ref val, ref v);
}
@ -508,6 +510,10 @@ namespace Gst {
}
}
static List () {
GLib.GType.Register (List.GType, typeof (List));
}
[DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_list_get_type ();
[DllImport ("gstreamer-0.10.dll") ]
@ -538,7 +544,14 @@ namespace Gst {
for (uint i = 0; i < n; i++) {
IntPtr v_ptr = gst_value_array_get_value (ref val, i);
GLib.Value v = (GLib.Value) Marshal.PtrToStructure (v_ptr, typeof (GLib.Value));
this.content.Add (Gst.Value.GetValue (v));
this.content.Add (v.Val);
}
}
public void SetGValue (ref GLib.Value val) {
foreach (object o in content) {
GLib.Value v = new GLib.Value (o);
gst_value_array_append_value (ref val, ref v);
}
}
@ -546,7 +559,7 @@ namespace Gst {
GLib.Value val = new GLib.Value (Gst.Array.GType);
foreach (object o in a.content) {
GLib.Value v = Gst.Value.CreateValue (o);
GLib.Value v = new GLib.Value (o);
gst_value_array_append_value (ref val, ref v);
}
@ -580,6 +593,10 @@ namespace Gst {
}
}
static Array () {
GLib.GType.Register (Array.GType, typeof (Array));
}
[DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_array_get_type ();
[DllImport ("gstreamer-0.10.dll") ]