2007-01-09 Mike Kestner <mkestner@novell.com>

* generator/CallbackGen.cs : add PersistUntilCalled method generation
	to the wrapper class.  Holds a GCHandle for the wrapper which is Freed
	when the delegate is invoked.
	* generator/MethodBody.cs : add "async" case for delegate scope.  Use
	this scope to identify a callback parameter that needs to persist 
	until the native side calls back.  Only valid for single-invoke
	callbacks.
	* gtk/Gtk.metadata : mark Print.RunPageSetupDialogAsync done_cb param
	with the new async scope.

svn path=/trunk/gtk-sharp/; revision=71767
This commit is contained in:
Mike Kestner 2007-01-26 20:46:09 +00:00
parent 6844495fce
commit 1d105a960b
4 changed files with 31 additions and 7 deletions

View file

@ -1,3 +1,15 @@
2007-01-09 Mike Kestner <mkestner@novell.com>
* generator/CallbackGen.cs : add PersistUntilCalled method generation
to the wrapper class. Holds a GCHandle for the wrapper which is Freed
when the delegate is invoked.
* generator/MethodBody.cs : add "async" case for delegate scope. Use
this scope to identify a callback parameter that needs to persist
until the native side calls back. Only valid for single-invoke
callbacks.
* gtk/Gtk.metadata : mark Print.RunPageSetupDialogAsync done_cb param
with the new async scope.
2007-01-09 Mike Kestner <mkestner@novell.com>
* sample/GtkDemo/DemoPixbuf.cs : use Marshal.Copy properly

View file

@ -98,6 +98,7 @@ namespace GtkSharp.Generation {
sw.WriteLine ("namespace " + NS + "Sharp {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
sw.WriteLine ();
sw.WriteLine ("#region Autogenerated code");
sw.WriteLine ("\t[GLib.CDeclCallback]");
@ -138,15 +139,13 @@ namespace GtkSharp.Generation {
idx++;
}
cleanup_str += "\t\t\tif (release_on_call)\n\t\t\t\tgch.Free ();\n";
sw.Write ("\t\t\t");
string invoke = "managed (" + call_str + ")";
if (retval.MarshalType != "void") {
if (cleanup_str == "")
sw.Write ("return ");
else {
sw.Write (retval.MarshalType + " ret = ");
cleanup_str += "\t\t\treturn ret;\n";
}
sw.Write (retval.MarshalType + " ret = ");
cleanup_str += "\t\t\treturn ret;\n";
SymbolTable table = SymbolTable.Table;
ClassBase ret_wrapper = table.GetClassGen (retval.CType);
@ -167,7 +166,15 @@ namespace GtkSharp.Generation {
sw.Write (cleanup_str);
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tbool release_on_call = false;");
sw.WriteLine ("\t\tGCHandle gch;");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic void PersistUntilCalled ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\trelease_on_call = true;");
sw.WriteLine ("\t\t\tgch = GCHandle.Alloc (this);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tinternal " + wrapper + " NativeDelegate;");
sw.WriteLine ("\t\t" + NS + "." + Name + " managed;");
sw.WriteLine ();

View file

@ -155,6 +155,10 @@ namespace GtkSharp.Generation {
sw.WriteLine (indent + "\t\t\t}");
break;
case "async":
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
sw.WriteLine (indent + "\t\t\t{0}_wrapper.PersistUntilCalled ();", name);
break;
case "call":
default:
if (p.Scope == String.Empty)

View file

@ -93,6 +93,7 @@
<attr path="/api/namespace/class[@cname='GtkInit_']/method[@name='CheckAbiCheck']" name="hidden">1</attr>
<attr path="/api/namespace/class[@cname='GtkInit_']/method[@name='AbiCheck']" name="hidden">1</attr>
<attr path="/api/namespace/class[@cname='GtkInput_']/method[@name='AddFull']" name="hidden">1</attr>
<attr path="/api/namespace/class[@cname='GtkPrint_']/method[@name='RunPageSetupDialogAsync']/*/*[@name='done_cb']" name="scope">async</attr>
<attr path="/api/namespace/class[@cname='GtkQuit_']/method[@name='Add']" name="hidden">1</attr>
<attr path="/api/namespace/class[@cname='GtkQuit_']/method[@name='AddFull']" name="hidden">1</attr>
<attr path="/api/namespace/class[@cname='GtkSignal_']" name="hidden">1</attr>