Mono and XPCOM: Scripting VirtualBox

by Miguel de Icaza

A few weeks ago Thomas introduced me to Achim Hasenmueller from Innotek, the makers of VirtualBox, an open source virtual machine system (similar to VMware and VirtualPC).

It turns out that much of the functionality of VirtualBox is exposed through COM interfaces and at least on Unix they use Mozilla's XPCOM as their COM layer.

Achim wanted to use Mono to script and control VirtualBox through its XPCOM interfaces.

The good news is that for the past few months, Jonathan Chambers has been working on adding COM support to Mono. Jonathan has some software that exposes COM interfaces, and wants to be able to control it from Mono, instantiate COM classes from Mono, consume COM interfaces from Mono and export Mono objects to COM applications.

Jonathan's initial goal was to support COM on Windows, but as the recent testing showed, Mono can use Mozilla's XPCOM to script VirtualBox.

Last time I talked to Jonathan he was putting together a tool that can import type libraries from XPCOM and generate the C# stubs that are necessary to get access to all the APIs exposed by XPCOM instead of having to manually bind each interface.

Hopefully Jonathan will post his sample code for folks that might be interested in using COM with Mono on Unix.

Here is a C# sample that he emailed me recently (for VirtualBox):

        static void listVMs(IVirtualBox virtualBox)
	{
	    IMachineCollection collection;
	    IMachineEnumerator enumerator = null;
	    collection = virtualBox.Machines;

	    if (collection == null) return;
	    enumerator = collection.Enumerate();
	    if (enumerator == null) return;

	    while (enumerator.HasMore)
	    {
	    	IMachine machine = enumerator.Next;
            	if (machine != null){
		    IntPtr ptr;
                    string machineName;
                    ptr = machine.Name;
                    machineName = Marshal.PtrToStringUni(ptr);
                    Console.WriteLine ("\tName:        {0}\n", machineName);
		}
	    }	    
	}
	
	static int Main (string[] args)
	{
                int hr = 0;
                nsIServiceManager sm;
                hr = NativeMethods.NS_InitXPCOM2 (out sm, IntPtr.Zero, IntPtr.Zero);
                IntPtr ptr;

                nsIComponentRegistrar cr = (nsIComponentRegistrar)sm;
                Guid kEventQueueServiceCID = new Guid("be761f00-a3b0-11d2-996c-0080c7cb1080");
                sm.getService(kEventQueueServiceCID, typeof(nsIEventQueueService).GUID, out ptr);

                nsIComponentManager cm = (nsIComponentManager)sm;
                string NS_VIRTUALBOX_CONTRACTID = "@virtualbox.org/VirtualBox;1";
                IVirtualBox virtualBox = (IVirtualBox)cm.createInstanceByContractID(
			NS_VIRTUALBOX_CONTRACTID, null, typeof(IVirtualBox).GUID);

                listVMs(virtualBox);

                Marshal.ReleaseComObject (virtualBox);
                
                NativeMethods.NS_ShutdownXPCOM(sm);
                return 0;
        }

	

The code above would also automatically work with any other .NET language (for scripting purposes, IronPython, and one day IronRuby).

COM on Unix

COM does not exist on Unix as a service that applications can depend on. Developers today have a choice between using Mainsoft's COM runtime or embedding a variation of Mozilla's XPCOM in their application.

For example, VirtualBox today bundles a copy of XPCOM in its source code distribution.

Some folks have a lot of code that has been built with COM in mind and this should open the doors for folks to take advantage of it on Unix with Mono.

Posted on 28 Aug 2007


ASP.NET AJAX in Mono

by Miguel de Icaza

The Mainsoft developers have been busy implementing the core foundation for ASP.NET AJAX. They usually do all their testing on Grasshopper.

Recently System.Web.Extensions got added to the default build in Mono (I do not think this will make it into Mono 1.2.5, you will need to use the code from SVN for that) but we had not really tested it directly with Mono.

Onur Gumus posted a How To: ASP.NET Ajax with Mono document today.

For doing native development in Unix this is a bit cumbersome (due to all the new stuff that needs to be added to the Web.config file; Should we put most of this in the standard machine.config?) but if you are moving an application, the Web.config should have been produced by Visual Studio already.

Konstantin Triger reports that the open source ASP.NET AJAX Toolkit works on Grasshopper, we have not tested this directly with Mono and XSP, but hopefully someone will try it soon.

Posted on 28 Aug 2007


Election Money

by Miguel de Icaza

A useful Flash interactive application to browse how much money candidates have raised, how much they have spent and who are their major donors.

Three folks that have impressed me (Dennis Kucinich, Mike Gravel and Ron Paul Gravel) have raised very little money compared to the multi-million juggernauts in the mainstream.

Electability seems to be highly correlated to how much money these folks are raising and spending.

Posted on 27 Aug 2007


Libros Educativos

by Miguel de Icaza

Cuando era niño, era fan de esta colección de libros de Pemsa que tristemente ya no están a la venta.

Ahora un esfuerzo está tratando de digitalizar libros de segunda mano y completar un acervo histórico en línea (por Barrapunto).

Posted on 27 Aug 2007


Silverlight and Moonlight: A Summary.

by Miguel de Icaza

Edd Dumbill has authored a superb summary on where Moonlight is.

He has put together a great description that pulls information from multiple sources to put together a really nice story and give a good idea of where we are headed to.

Posted on 23 Aug 2007


Google Summer of Code: Windows.Forms Designer

by Miguel de Icaza

Ivan has posted the final status report for his Mono.Design work for the summer:

During the summer Ivan worked on implementing a Windows.Forms designer surface and various pieces of the infrastructure to load and save designs. He also worked on integrating Windows.Forms with Gtk# to enable the designer to be used from within MonoDevelop.

Read his entire report here and you can comment on his blog.

Posted on 23 Aug 2007


OMG2 OMG2 OMG2 OMG2 OMG2

by Miguel de Icaza

OMG2 OMG2 OMG2 OMG2 OMG2 Mark Probst pointed me out to the announcement of Canon's 40D camera. I skipped over the 30D, so this is my opportunity to continue shopping until I drop.

OMG3 OMG3: it can do Wifi file transfers and hook up to a GPS.

Posted on 22 Aug 2007


OMG OMG OMG OMG OMG

by Miguel de Icaza

As a very happy Rhapsody customer, the news that Rhapsody will start selling DRM-less music at 0.89 cents a pop is ubertastic.

If I was European or Canadian I would be 30% more excited -- considering the falling dollar.

I have been using it mostly as a radio so far, and avoided purchasing music because it would be DRMed, but there are a bunch of titles that I would like to own.

Let the double-click all-amateur shopping begin!

Posted on 22 Aug 2007


Annotated C# Standard

by Miguel de Icaza

Today I received my copy of the Annotated C# Standard that Jon Jagger, Nigel Perry and Peter Sestoft put together.

This book is an annotated version of the C# specification that comes with plenty of comments and contributions from people that have implemented the language (It has contributions from Mono's Marek Safar, Martin Baulig, Paolo Molaro, Raja Harinath and myself, but also from the C# team at Microsoft, contributors to ECMA and some universities that researched C#).

Jon has been passionate about C# for a long time. The C# specification that we distribute as part of Monodoc was based on his hyperlinked version of the standard.

Nigel contributed to both the CLI and C# standards over the years and recently joined Microsoft.

Peter has written a number of books (Java Precisely, C# Precisely) and is also behind the implementation of C5 a Generic Collection Library (this was a great test case for Mono's C# compiler: it was quite a challenge).

Congratulations to Jon, Nigel and Peter. They have been working on this project for a long time.

Posted on 22 Aug 2007


Rafi on Grasshopper

by Miguel de Icaza

A few years ago we met Rafi at one of our Mono summits in Boston, he works for Mainsoft and he has always been amazing.

Watch his interview on what he is doing with Grasshopper here and here.

He talks about Mainsoft's contributions to Mono, about his testing procedures and the kind of things that are possible with Grasshopper when integrating ASP.NET applications when running on J2EE servers.

Posted on 16 Aug 2007


« Newer entries | Older entries »