Re: Tinymail's .NET bindings



On Mon, 2006-10-16 at 11:17 +0200, Philip Van Hoof wrote:

> For people interested in working on the .NET bindings for tinymail:

I have attached a manual version of what I have in mind. A binding
generator should create something like this (which doesn't look
impossible), maybe make xslts of this manual stuff and feed those xslts
the different types, methods, properties and etcetera parsed from the .h
files?

It doesn't look like GAPI generates something that already looks like
this. An open question is whether the interested people are rather
interested in creating a new generator or whether they prefer adapting
gapi?

I prefer generated language bindings. But the quality of the binding
itself is by far more important than its 'generatability'.

I named the files the same as the namespace would be. Per two such
namespaces, a .dll will be created. For example:

Tny and Tny.Proxy will be libtinymail-sharp-1.0.dll
Tny.Ui and Tny.Ui.Proxy will be libtinymailui-sharp-1.0.dll
Tny.Ui.Gtk and Tny.Ui.Gtk.Proxy will be libtinymailui-gtk-sharp-1.0.dll
Tny.Camel and Tny.Camel.Proxy will be libtinymail-camel-sharp-1.0.dll
Tny.Platform and Tny.Platform.Proxy will be libtinymail-platform-sharp-1.0.dll

The types in the Proxy namespaces implement P/Invoke-ing to the GObject
library. The other types, using the Proxy types as the real in a proxy,
implement converting the proxy-calls to whatever is cool in the higher
level programming language. I think those types cannot be 100% generated
whereas the proxy types can (even without any customisation). I would
prefer the generated proxy types to be left untouched (maybe let GAPI
generate them after enhancing GAPI?)

Almost none of the tinymail API isn't suitable for parsing/generating a
language binding for. I have specifically put a lot time in making sure
it's all easy (no typical C types like doubly linked lists, pointers or
other such things are being returned or accepted as a parameter, all
such are converted to full GObject types, except things like "gchar*"
and "gint" of course).

That way it will be possible to have a Tny.List type that implements
IList and IEnumeratable, and a Tny.Iterator that implements IEnumerator
etc etc (or however they are called on .NET today). Those will wrap the
GObject types TnyList and TnyIterator (just examples).

ps. I know at least Bart is working on .NET bindings for tinymail.

-- 
Philip Van Hoof, software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
work: vanhoof at x-tend dot be
blog: http://pvanhoof.be/blog
namespace Tny.Camel
{
  public class Msg : Tny.Msg
  {
	public Msg () 
	{ 
		this.proxy = new Tny.Camel.Proxy.Msg ();
	}

	public Msg (Tny.Proxy.Msg prxy) : base (prxy) { }
  }

  public class Header : Tny.Header
  {
	public Header () 
	{ 
		this.proxy = new Tny.Camel.Proxy.Header ();
	}

	public Msg (Tny.Proxy.Header prxy) : base (prxy) { }
  }
}
namespace Tny.Camel.Proxy
{
  public class Msg : Tny.Proxy.Msg
  {
	[DllImport("libtinymail-camel-1.0.dll")]
        static extern IntPtr tny_camel_msg_new ();

        public Msg ()
        {
                this.real = tny_camel_msg_new ();
        }

	public Msg (IntPtr real) : base (real) { }
  }

  public class Header : Tny.Proxy.Header
  {
	[DllImport("libtinymail-camel-1.0.dll")]
        static extern IntPtr tny_camel_header_new ();

        public Header ()
        {
                this.real = tny_camel_header_new ();
        }

	public Header (IntPtr real) : base (real) { }
  }
}
namespace Tny
{
  public interface IMsg
  {
	Tny.IHeader Header { get; set; }
  }

  public interface IHeader 
  { 
	string Subject { get; set }
  }

  public abstract class Msg : Tny.IMsg
  {
	protected Tny.Proxy.Msg proxy;

	public Tny.IHeader Header
	{
		get { return new Tny.Header (this.proxy.get_header ()); }
		set { this.proxy.set_header (value.proxy); }
	}

	public Msg (Tny.Proxy.Msg prxy) { this.proxy = prxy; }
  }

  public abstract class Header : Tny.IHeader 
  { 
	protected Tny.Proxy.Header proxy;

	public string Subject 
	{ 
		get { return this.proxy.get_subject (); }
		set { this.proxy.set_subject (value); }
	}

	public Header (Tny.Proxy.Header prxy) { this.proxy = prxy; }
  }
}
namespace Tny.Proxy
{
   public abstract class Header 
   {
	protected IntPtr real;

        [DllImport("libtinymail-1.0.dll")]
        static extern IntPtr tny_header_get_subject (IntPtr self);

	public string get_subject ()
	{
		IntPtr cstr = tny_header_get_subject (this.real);
		return Tool.GCharToString (cstr);
	}

        [DllImport("libtinymail-1.0.dll")]
        static extern void tny_header_set_subject (IntPtr self, IntPtr str);

	public void set_subject (string sbj)
	{
		IntPtr cstr = Tool.StringToGChar (str);
		tny_header_set_subject (this.real, cstr);
		Tool.FreeGChar (cstr);
	}

	public Header (IntPtr r)
	{
		this.real = r;
	}
   }

   public abstract class Msg
   {
        protected IntPtr real;

        [DllImport("libtinymail-1.0.dll")]
        static extern IntPtr tny_msg_get_header (IntPtr self);

	public Tny.Proxy.Header get_header ()
	{
		IntPtr real = tny_msg_get_header (this.real);
		Tny.Proxy.Header h = new Tny.Proxy.Header (real);
		return h;
	}

        [DllImport("libtinymail-1.0.dll")]
        static extern void tny_msg_set_header (IntPtr self, IntPtr hdr);

	public void set_header (Tny.Proxy.Header h)
	{
		tny_msg_set_header (self.real, h.real);
	}


        public Msg (IntPtr real)
        {
                this.real = real;
        }
   }
}
namespace Tny.Ui
{
  public interface IMsgView
  {
        Tny.IMsg Msg { get; set; }
        void Clear ();
  }

  public abstract class MsgView : Tny.Ui.IMsgView
  {
	protected Tny.Ui.Proxy.MsgView proxy;


	public Tny.IMsg Message
	{
                get { return new Tny.Msg (this.proxy.get_msg ()); }
                set { this.proxy.set_msg (value.proxy); }
        }

	public void Clear ()
	{
		this.proxy.clear ();
	}

	public MsgView (Tny.Ui.Proxy.MsgView prxy) { this.proxy = prxy; }
  }
}
namespace Tny.Ui.Gtk
{
  public class MsgView : Tny.Ui.MsgView
  {
	public MsgView () 
	{ 
		this.proxy = new Tny.Ui.Gtk.Proxy.MsgView ();
	}

	public MsgView (Tny.Ui.Proxy.MsgView prxy) : base (prxy) { }
  }
}

namespace Tny.Ui.Gtk.Proxy
{
  public class MsgView : Tny.Ui.Proxy.MsgView
  {
	[DllImport("libtinymailui-gtk-1.0.dll")]
        static extern IntPtr tny_gtk_msg_view_new ();

        public MsgView ()
        {
                this.real = tny_gtk_msg_view_new ();
        }

	public MsgView (IntPtr real) : base (real) { }

  }
}
namespace Tny.Ui.Proxy
{
   public abstract class MsgView
   {
	protected IntPtr real;

        [DllImport("libtinymailui-1.0.dll")]
        static extern IntPtr tny_msg_view_get_msg (IntPtr real);

        public Tny.Proxy.Msg get_msg ()
        {
                IntPtr real = tny_msg_view_get_msg (this.real);
                Tny.Proxy.Msg h = new Tny.Proxy.Msg (real)
                return h;
        }

        [DllImport("libtinymailui-1.0.dll")]
        static extern void tny_msg_view_set_msg (IntPtr real, IntPtr s);

        public void set_msg (Tny.Proxy.Msg s)
        {
                tny_msg_view_set_msg (this.real, s.real);
        }

        [DllImport("libtinymailui-1.0.dll")]
        static extern void tny_msg_view_clear (IntPtr real);

        public void clear ()
        {
                tny_msg_view_clear (this.real);
        }

        public MsgView (IntPtr real)
        {
                this.real = real;
        }
   }

}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]