2009-07-31 08:16:55 +00:00
|
|
|
// ParamSpec.cs - GParamSpec class wrapper implementation
|
|
|
|
//
|
|
|
|
// Authors: Mike Kestner <mkestner@novell.com>
|
|
|
|
//
|
|
|
|
// Copyright (c) 2008 Novell, Inc.
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of version 2 of the Lesser GNU General
|
|
|
|
// Public License as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this program; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
// Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
2009-08-05 14:48:13 +00:00
|
|
|
namespace Gst.GLib {
|
2009-07-31 08:16:55 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
internal enum ParamFlags {
|
2009-09-16 06:38:59 +00:00
|
|
|
None = 0,
|
|
|
|
Readable = 1 << 0,
|
|
|
|
Writable = 1 << 1,
|
|
|
|
Construct = 1 << 2,
|
2009-07-31 08:16:55 +00:00
|
|
|
ConstructOnly = 1 << 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ParamSpec {
|
|
|
|
|
|
|
|
IntPtr handle;
|
|
|
|
|
2009-09-16 06:38:59 +00:00
|
|
|
public ParamSpec (string name, string nick, string blurb, GType type, bool readable, bool writable) : this (name, nick, blurb, type, (readable ? ParamFlags.Readable : ParamFlags.None) | (writable ? ParamFlags.Writable : ParamFlags.None)) {}
|
|
|
|
|
|
|
|
internal ParamSpec (string name, string nick, string blurb, GType type, ParamFlags pflags)
|
|
|
|
{
|
2009-07-31 08:16:55 +00:00
|
|
|
int flags = (int) pflags;
|
|
|
|
|
2009-09-16 06:38:59 +00:00
|
|
|
IntPtr p_name = Gst.GLib.Marshaller.StringToPtrGStrdup (name);
|
|
|
|
IntPtr p_nick = Gst.GLib.Marshaller.StringToPtrGStrdup (nick);
|
|
|
|
IntPtr p_blurb = Gst.GLib.Marshaller.StringToPtrGStrdup (blurb);
|
2009-07-31 08:16:55 +00:00
|
|
|
|
|
|
|
if (type == GType.Char)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_char (p_name, p_nick, p_blurb, SByte.MinValue, SByte.MaxValue, 0, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.UChar)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_uchar (p_name, p_nick, p_blurb, Byte.MinValue, Byte.MaxValue, 0, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.Boolean)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_boolean (p_name, p_nick, p_blurb, false, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.Int)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_int (p_name, p_nick, p_blurb, Int32.MinValue, Int32.MaxValue, 0, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.UInt)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_uint (p_name, p_nick, p_blurb, 0, UInt32.MaxValue, 0, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.Long)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_long (p_name, p_nick, p_blurb, IntPtr.Zero, IntPtr.Size == 4 ? new IntPtr (Int32.MaxValue) : new IntPtr (Int64.MaxValue), IntPtr.Zero, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.ULong)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_ulong (p_name, p_nick, p_blurb, UIntPtr.Zero, UIntPtr.Size == 4 ? new UIntPtr (UInt32.MaxValue) : new UIntPtr (UInt64.MaxValue), UIntPtr.Zero, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.Int64)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_int64 (p_name, p_nick, p_blurb, Int64.MinValue, Int64.MaxValue, 0, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.UInt64)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_uint64 (p_name, p_nick, p_blurb, 0, UInt64.MaxValue, 0, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
/*
|
|
|
|
else if (type == GType.Enum)
|
|
|
|
else if (type == GType.Flags)
|
|
|
|
* TODO:
|
|
|
|
* Both g_param_spec_enum and g_param_spec_flags expect default property values and the members of the enum seemingly cannot be enumerated
|
|
|
|
*/
|
|
|
|
else if (type == GType.Float)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_float (p_name, p_nick, p_blurb, Single.MinValue, Single.MaxValue, 0.0f, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.Double)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_double (p_name, p_nick, p_blurb, Double.MinValue, Double.MaxValue, 0.0, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.String)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_string (p_name, p_nick, p_blurb, IntPtr.Zero, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type == GType.Pointer)
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_pointer (p_name, p_nick, p_blurb, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (type.Val == g_gtype_get_type ())
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_gtype (p_name, p_nick, p_blurb, GType.None.Val, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (g_type_is_a (type.Val, GType.Boxed.Val))
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_boxed (p_name, p_nick, p_blurb, type.Val, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else if (g_type_is_a (type.Val, GType.Object.Val))
|
2009-09-16 06:38:59 +00:00
|
|
|
handle = g_param_spec_object (p_name, p_nick, p_blurb, type.Val, flags);
|
2009-07-31 08:16:55 +00:00
|
|
|
else
|
|
|
|
throw new ArgumentException ("type");
|
|
|
|
|
2009-09-16 06:38:59 +00:00
|
|
|
Gst.GLib.Marshaller.Free (p_name);
|
|
|
|
Gst.GLib.Marshaller.Free (p_nick);
|
|
|
|
Gst.GLib.Marshaller.Free (p_blurb);
|
2009-07-31 08:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public ParamSpec (IntPtr native)
|
|
|
|
{
|
|
|
|
handle = native;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntPtr Handle {
|
|
|
|
get { return handle; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public GType ValueType {
|
|
|
|
get {
|
|
|
|
GParamSpec spec = (GParamSpec) Marshal.PtrToStructure (Handle, typeof (GParamSpec));
|
|
|
|
return new GType (spec.value_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GTypeInstance {
|
|
|
|
IntPtr g_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GParamSpec {
|
|
|
|
GTypeInstance g_type_instance;
|
|
|
|
|
2009-09-16 06:38:59 +00:00
|
|
|
IntPtr name;
|
2009-07-31 08:16:55 +00:00
|
|
|
ParamFlags flags;
|
|
|
|
public IntPtr value_type;
|
|
|
|
IntPtr owner_type;
|
|
|
|
|
|
|
|
IntPtr _nick;
|
|
|
|
IntPtr _blurb;
|
|
|
|
IntPtr qdata;
|
|
|
|
uint ref_count;
|
|
|
|
uint param_id;
|
|
|
|
}
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_char (IntPtr name, IntPtr nick, IntPtr blurb, sbyte min, sbyte max, sbyte dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_uchar (IntPtr name, IntPtr nick, IntPtr blurb, byte min, byte max, byte dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_boolean (IntPtr name, IntPtr nick, IntPtr blurb, bool dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_int (IntPtr name, IntPtr nick, IntPtr blurb, int min, int max, int dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_uint (IntPtr name, IntPtr nick, IntPtr blurb, uint min, uint max, uint dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_long (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr min, IntPtr max, IntPtr dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_ulong (IntPtr name, IntPtr nick, IntPtr blurb, UIntPtr min, UIntPtr max, UIntPtr dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_int64 (IntPtr name, IntPtr nick, IntPtr blurb, long min, long max, long dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_uint64 (IntPtr name, IntPtr nick, IntPtr blurb, ulong min, ulong max, ulong dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_float (IntPtr name, IntPtr nick, IntPtr blurb, float min, float max, float dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_double (IntPtr name, IntPtr nick, IntPtr blurb, double min, double max, double dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_string (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_pointer (IntPtr name, IntPtr nick, IntPtr blurb, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_gtype (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr dval, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_boxed (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr return_type, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_param_spec_object (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr return_type, int flags);
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern IntPtr g_gtype_get_type ();
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern bool g_type_is_a (IntPtr a, IntPtr b);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|