generator,glib: added GPollFD and GSource types

GSource type was already there (but was not mapped by
the generator yet) so then the autogenerated methods
have been added manually inside the class after the
custom methods.

Other Source-related class are also generated and added
(but not mapped in the SymbolTable) to glib.
This commit is contained in:
Stephan Sundermann 2013-10-09 19:41:21 +02:00 committed by Andrés G. Aragoneses
parent 139479036b
commit 6ab620d689
10 changed files with 719 additions and 5 deletions

View file

@ -132,6 +132,8 @@ namespace GtkSharp.Generation {
AddType (new ManualGen ("GCond", "GLib.Cond"));
AddType (new ManualGen ("GDateTime", "GLib.DateTime"));
AddType (new ManualGen ("GDate", "GLib.Date"));
AddType (new ManualGen ("GSource", "GLib.Source"));
AddType (new SimpleGen ("GPollFD", "GLib.PollFD", "GLib.PollFD.Zero"));
AddType (new MarshalGen ("gunichar", "char", "uint", "GLib.Marshaller.CharToGUnichar ({0})", "GLib.Marshaller.GUnicharToChar ({0})"));
AddType (new MarshalGen ("time_t", "System.DateTime", "IntPtr", "GLib.Marshaller.DateTimeTotime_t ({0})", "GLib.Marshaller.time_tToDateTime ({0})"));
AddType (new MarshalGen ("GString", "string", "IntPtr", "new GLib.GString ({0}).Handle", "GLib.GString.PtrToString ({0})"));

View file

@ -0,0 +1,92 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace GLibSharp {
using System;
using System.Runtime.InteropServices;
#region Autogenerated code
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate void SourceDummyMarshalNative();
internal class SourceDummyMarshalInvoker {
SourceDummyMarshalNative native_cb;
IntPtr __data;
GLib.DestroyNotify __notify;
~SourceDummyMarshalInvoker ()
{
if (__notify == null)
return;
__notify (__data);
}
internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb) : this (native_cb, IntPtr.Zero, null) {}
internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb, IntPtr data) : this (native_cb, data, null) {}
internal SourceDummyMarshalInvoker (SourceDummyMarshalNative native_cb, IntPtr data, GLib.DestroyNotify notify)
{
this.native_cb = native_cb;
__data = data;
__notify = notify;
}
internal GLib.SourceDummyMarshal Handler {
get {
return new GLib.SourceDummyMarshal(InvokeNative);
}
}
void InvokeNative ()
{
native_cb ();
}
}
internal class SourceDummyMarshalWrapper {
public void NativeCallback ()
{
try {
managed ();
if (release_on_call)
gch.Free ();
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
bool release_on_call = false;
GCHandle gch;
public void PersistUntilCalled ()
{
release_on_call = true;
gch = GCHandle.Alloc (this);
}
internal SourceDummyMarshalNative NativeDelegate;
GLib.SourceDummyMarshal managed;
public SourceDummyMarshalWrapper (GLib.SourceDummyMarshal managed)
{
this.managed = managed;
if (managed != null)
NativeDelegate = new SourceDummyMarshalNative (NativeCallback);
}
public static GLib.SourceDummyMarshal GetManagedDelegate (SourceDummyMarshalNative native)
{
if (native == null)
return null;
SourceDummyMarshalWrapper wrapper = (SourceDummyMarshalWrapper) native.Target;
if (wrapper == null)
return null;
return wrapper.managed;
}
}
#endregion
}

View file

@ -0,0 +1,95 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace GLibSharp {
using System;
using System.Runtime.InteropServices;
#region Autogenerated code
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate bool SourceFuncNative(IntPtr user_data);
internal class SourceFuncInvoker {
SourceFuncNative native_cb;
IntPtr __data;
GLib.DestroyNotify __notify;
~SourceFuncInvoker ()
{
if (__notify == null)
return;
__notify (__data);
}
internal SourceFuncInvoker (SourceFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}
internal SourceFuncInvoker (SourceFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}
internal SourceFuncInvoker (SourceFuncNative native_cb, IntPtr data, GLib.DestroyNotify notify)
{
this.native_cb = native_cb;
__data = data;
__notify = notify;
}
internal GLib.SourceFunc Handler {
get {
return new GLib.SourceFunc(InvokeNative);
}
}
bool InvokeNative (IntPtr user_data)
{
bool __result = native_cb (__data);
return __result;
}
}
internal class SourceFuncWrapper {
public bool NativeCallback (IntPtr user_data)
{
try {
bool __ret = managed (user_data);
if (release_on_call)
gch.Free ();
return __ret;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
return false;
}
}
bool release_on_call = false;
GCHandle gch;
public void PersistUntilCalled ()
{
release_on_call = true;
gch = GCHandle.Alloc (this);
}
internal SourceFuncNative NativeDelegate;
GLib.SourceFunc managed;
public SourceFuncWrapper (GLib.SourceFunc managed)
{
this.managed = managed;
if (managed != null)
NativeDelegate = new SourceFuncNative (NativeCallback);
}
public static GLib.SourceFunc GetManagedDelegate (SourceFuncNative native)
{
if (native == null)
return null;
SourceFuncWrapper wrapper = (SourceFuncWrapper) native.Target;
if (wrapper == null)
return null;
return wrapper.managed;
}
}
#endregion
}

View file

@ -20,7 +20,9 @@ POLICY_CONFIGS = $(addsuffix .config, $(addprefix policy., $(POLICY_VERSIONS)))
references =
# TODO: auto-generate at compile time the following classes:
# Cond, Date, DateTime, Mutex, RecMutex, TimeVal, TimeZone
# Cond, Date, DateTime, Mutex, PollFD, RecMutex, (half)Source,
# SourceCallbackFuncs, SourceDummyMarshal, SourceFunc,
# SourceFuncNative, SourceFuncs, TimeVal, TimeZone
# (to do that, we need to fill missing pieces in glib's
# gobject-introspection metadata upstream)
@ -62,6 +64,7 @@ sources = \
ObjectManager.cs \
Opaque.cs \
ParamSpec.cs \
PollFD.cs \
Priority.cs \
PropertyAttribute.cs \
PtrArray.cs \
@ -72,6 +75,12 @@ sources = \
SignalClosure.cs \
SList.cs \
Source.cs \
SourceFunc.cs \
SourceFuncs.cs \
SourceDummyMarshal.cs \
GLibSharp.SourceFuncNative.cs \
GLibSharp.SourceDummyMarshalNative.cs \
SourceCallbackFuncs.cs \
Spawn.cs \
Thread.cs \
Timeout.cs \

67
glib/PollFD.cs Normal file
View file

@ -0,0 +1,67 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace GLib {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
#region Autogenerated code
[StructLayout(LayoutKind.Sequential)]
public partial struct PollFD : IEquatable<PollFD> {
public int Fd;
public ushort Events;
public ushort Revents;
public static GLib.PollFD Zero = new GLib.PollFD ();
public static GLib.PollFD New(IntPtr raw) {
if (raw == IntPtr.Zero)
return GLib.PollFD.Zero;
return (GLib.PollFD) Marshal.PtrToStructure (raw, typeof (GLib.PollFD));
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_pollfd_get_type();
public static GLib.GType GType {
get {
IntPtr raw_ret = g_pollfd_get_type();
GLib.GType ret = new GLib.GType(raw_ret);
return ret;
}
}
public bool Equals (PollFD other)
{
return true && Fd.Equals (other.Fd) && Events.Equals (other.Events) && Revents.Equals (other.Revents);
}
public override bool Equals (object other)
{
return other is PollFD && Equals ((PollFD) other);
}
public override int GetHashCode ()
{
return this.GetType().FullName.GetHashCode() ^ Fd.GetHashCode () ^ Events.GetHashCode () ^ Revents.GetHashCode ();
}
public static explicit operator GLib.Value (GLib.PollFD boxed)
{
GLib.Value val = GLib.Value.Empty;
val.Init (GLib.PollFD.GType);
val.Val = boxed;
return val;
}
public static explicit operator GLib.PollFD (GLib.Value val)
{
return (GLib.PollFD) val.Val;
}
#endregion
}
}

View file

@ -44,7 +44,8 @@ namespace GLib {
}
}
public class Source {
public partial class Source : GLib.Opaque {
private Source () {}
internal static Hashtable source_handlers = new Hashtable ();
@ -58,5 +59,343 @@ namespace GLib {
source_handlers.Remove (tag);
return g_source_remove (tag);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_source_get_context(IntPtr raw);
public GLib.MainContext Context {
get {
IntPtr raw_ret = g_source_get_context(Handle);
GLib.MainContext ret = raw_ret == IntPtr.Zero ? null : new MainContext (raw_ret);
return ret;
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int g_source_get_priority(IntPtr raw);
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_set_priority(IntPtr raw, int priority);
public int Priority {
get {
int raw_ret = g_source_get_priority(Handle);
int ret = raw_ret;
return ret;
}
set {
g_source_set_priority(Handle, value);
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_source_get_name(IntPtr raw);
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_set_name(IntPtr raw, IntPtr name);
public string Name {
get {
IntPtr raw_ret = g_source_get_name(Handle);
string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
return ret;
}
set {
IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value);
g_source_set_name(Handle, native_value);
GLib.Marshaller.Free (native_value);
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_source_get_type();
public static GLib.GType GType {
get {
IntPtr raw_ret = g_source_get_type();
GLib.GType ret = new GLib.GType(raw_ret);
return ret;
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_add_child_source(IntPtr raw, IntPtr child_source);
public void AddChildSource(GLib.Source child_source) {
g_source_add_child_source(Handle, child_source == null ? IntPtr.Zero : child_source.Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_add_poll(IntPtr raw, IntPtr fd);
public void AddPoll(GLib.PollFD fd) {
IntPtr native_fd = GLib.Marshaller.StructureToPtrAlloc (fd);
g_source_add_poll(Handle, native_fd);
fd = GLib.PollFD.New (native_fd);
Marshal.FreeHGlobal (native_fd);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern uint g_source_attach(IntPtr raw, IntPtr context);
public uint Attach(GLib.MainContext context) {
uint raw_ret = g_source_attach(Handle, context == null ? IntPtr.Zero : context.Handle);
uint ret = raw_ret;
return ret;
}
uint Attach() {
return Attach (null);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_source_get_can_recurse(IntPtr raw);
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_set_can_recurse(IntPtr raw, bool can_recurse);
public bool CanRecurse {
get {
bool raw_ret = g_source_get_can_recurse(Handle);
bool ret = raw_ret;
return ret;
}
set {
g_source_set_can_recurse(Handle, value);
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_get_current_time(IntPtr raw, IntPtr timeval);
[Obsolete]
public void GetCurrentTime(GLib.TimeVal timeval) {
IntPtr native_timeval = GLib.Marshaller.StructureToPtrAlloc (timeval);
g_source_get_current_time(Handle, native_timeval);
timeval = GLib.TimeVal.New (native_timeval);
Marshal.FreeHGlobal (native_timeval);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern uint g_source_get_id(IntPtr raw);
public uint Id {
get {
uint raw_ret = g_source_get_id(Handle);
uint ret = raw_ret;
return ret;
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern long g_source_get_ready_time(IntPtr raw);
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_set_ready_time(IntPtr raw, long ready_time);
public long ReadyTime {
get {
long raw_ret = g_source_get_ready_time(Handle);
long ret = raw_ret;
return ret;
}
set {
g_source_set_ready_time(Handle, value);
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern long g_source_get_time(IntPtr raw);
public long Time {
get {
long raw_ret = g_source_get_time(Handle);
long ret = raw_ret;
return ret;
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_source_is_destroyed(IntPtr raw);
public bool IsDestroyed {
get {
bool raw_ret = g_source_is_destroyed(Handle);
bool ret = raw_ret;
return ret;
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_modify_unix_fd(IntPtr raw, IntPtr tag, int new_events);
public void ModifyUnixFd(IntPtr tag, GLib.IOCondition new_events) {
g_source_modify_unix_fd(Handle, tag, (int) new_events);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int g_source_query_unix_fd(IntPtr raw, IntPtr tag);
public GLib.IOCondition QueryUnixFd(IntPtr tag) {
int raw_ret = g_source_query_unix_fd(Handle, tag);
GLib.IOCondition ret = (GLib.IOCondition) raw_ret;
return ret;
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_remove_child_source(IntPtr raw, IntPtr child_source);
public void RemoveChildSource(GLib.Source child_source) {
g_source_remove_child_source(Handle, child_source == null ? IntPtr.Zero : child_source.Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_remove_poll(IntPtr raw, IntPtr fd);
public void RemovePoll(GLib.PollFD fd) {
IntPtr native_fd = GLib.Marshaller.StructureToPtrAlloc (fd);
g_source_remove_poll(Handle, native_fd);
fd = GLib.PollFD.New (native_fd);
Marshal.FreeHGlobal (native_fd);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_remove_unix_fd(IntPtr raw, IntPtr tag);
public void RemoveUnixFd(IntPtr tag) {
g_source_remove_unix_fd(Handle, tag);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_set_callback_indirect(IntPtr raw, IntPtr callback_data, IntPtr callback_funcs);
public void SetCallbackIndirect(IntPtr callback_data, GLib.SourceCallbackFuncs callback_funcs) {
IntPtr native_callback_funcs = GLib.Marshaller.StructureToPtrAlloc (callback_funcs);
g_source_set_callback_indirect(Handle, callback_data, native_callback_funcs);
callback_funcs = GLib.SourceCallbackFuncs.New (native_callback_funcs);
Marshal.FreeHGlobal (native_callback_funcs);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_set_funcs(IntPtr raw, IntPtr value);
public GLib.SourceFuncs Funcs {
set {
IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value);
g_source_set_funcs(Handle, native_value);
value = GLib.SourceFuncs.New (native_value);
Marshal.FreeHGlobal (native_value);
}
}
/*
* commented out because there is already a custom implementation for Remove
*
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_source_remove(uint tag);
public static bool Remove(uint tag) {
bool raw_ret = g_source_remove(tag);
bool ret = raw_ret;
return ret;
}
*/
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_source_remove_by_funcs_user_data(IntPtr funcs, IntPtr user_data);
public static bool RemoveByFuncsUserData(GLib.SourceFuncs funcs, IntPtr user_data) {
IntPtr native_funcs = GLib.Marshaller.StructureToPtrAlloc (funcs);
bool raw_ret = g_source_remove_by_funcs_user_data(native_funcs, user_data);
bool ret = raw_ret;
funcs = GLib.SourceFuncs.New (native_funcs);
Marshal.FreeHGlobal (native_funcs);
return ret;
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_source_remove_by_user_data(IntPtr user_data);
public static bool RemoveByUserData(IntPtr user_data) {
bool raw_ret = g_source_remove_by_user_data(user_data);
bool ret = raw_ret;
return ret;
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_set_name_by_id(uint tag, IntPtr name);
public static void SetNameById(uint tag, string name) {
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
g_source_set_name_by_id(tag, native_name);
GLib.Marshaller.Free (native_name);
}
public Source(IntPtr raw) : base(raw) {}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_source_new(IntPtr source_funcs, uint struct_size);
public Source (GLib.SourceFuncs source_funcs, uint struct_size)
{
IntPtr native_source_funcs = GLib.Marshaller.StructureToPtrAlloc (source_funcs);
Raw = g_source_new(native_source_funcs, struct_size);
source_funcs = GLib.SourceFuncs.New (native_source_funcs);
Marshal.FreeHGlobal (native_source_funcs);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_source_ref(IntPtr raw);
protected override void Ref (IntPtr raw)
{
if (!Owned) {
g_source_ref (raw);
Owned = true;
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_unref(IntPtr raw);
protected override void Unref (IntPtr raw)
{
if (Owned) {
g_source_unref (raw);
Owned = false;
}
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_source_destroy(IntPtr raw);
protected override void Free (IntPtr raw)
{
g_source_destroy (raw);
}
class FinalizerInfo {
IntPtr handle;
public FinalizerInfo (IntPtr handle)
{
this.handle = handle;
}
public bool Handler ()
{
g_source_destroy (handle);
return false;
}
}
~Source ()
{
if (!Owned)
return;
FinalizerInfo info = new FinalizerInfo (Handle);
GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
}
}
}

View file

@ -0,0 +1,44 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace GLib {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
#region Autogenerated code
[StructLayout(LayoutKind.Sequential)]
public partial struct SourceCallbackFuncs : IEquatable<SourceCallbackFuncs> {
public static GLib.SourceCallbackFuncs Zero = new GLib.SourceCallbackFuncs ();
public static GLib.SourceCallbackFuncs New(IntPtr raw) {
if (raw == IntPtr.Zero)
return GLib.SourceCallbackFuncs.Zero;
return (GLib.SourceCallbackFuncs) Marshal.PtrToStructure (raw, typeof (GLib.SourceCallbackFuncs));
}
public bool Equals (SourceCallbackFuncs other)
{
return true;
}
public override bool Equals (object other)
{
return other is SourceCallbackFuncs && Equals ((SourceCallbackFuncs) other);
}
public override int GetHashCode ()
{
return this.GetType().FullName.GetHashCode();
}
private static GLib.GType GType {
get { return GLib.GType.Pointer; }
}
#endregion
}
}

View file

@ -0,0 +1,10 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace GLib {
using System;
public delegate void SourceDummyMarshal();
}

10
glib/SourceFunc.cs Normal file
View file

@ -0,0 +1,10 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace GLib {
using System;
public delegate bool SourceFunc(IntPtr user_data);
}

46
glib/SourceFuncs.cs Normal file
View file

@ -0,0 +1,46 @@
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace GLib {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
#region Autogenerated code
[StructLayout(LayoutKind.Sequential)]
public partial struct SourceFuncs : IEquatable<SourceFuncs> {
internal GLibSharp.SourceFuncNative closure_callback;
internal GLibSharp.SourceDummyMarshalNative closure_marshal;
public static GLib.SourceFuncs Zero = new GLib.SourceFuncs ();
public static GLib.SourceFuncs New(IntPtr raw) {
if (raw == IntPtr.Zero)
return GLib.SourceFuncs.Zero;
return (GLib.SourceFuncs) Marshal.PtrToStructure (raw, typeof (GLib.SourceFuncs));
}
public bool Equals (SourceFuncs other)
{
return true && closure_callback.Equals (other.closure_callback) && closure_callback.Equals (other.closure_callback);
}
public override bool Equals (object other)
{
return other is SourceFuncs && Equals ((SourceFuncs) other);
}
public override int GetHashCode ()
{
return this.GetType().FullName.GetHashCode() ^ closure_marshal.GetHashCode () ^ closure_marshal.GetHashCode ();
}
private static GLib.GType GType {
get { return GLib.GType.Pointer; }
}
#endregion
}
}