Mono Developer Room for FOSDEM 2010!

on Wednesday, December 02, 2009

Some excellent news out of Brussels today, there is going to be a Mono Developer Room at FOSDEM 2010! Call for participation is now open, so come and join us put together an awesome Mono day at FOSDEM! 

Thank you so much to Ruben Vermeersch for spearheading this effort, together with Stéphane Delcroix. You guys rock!

Don't forget, send in your talk!

New phone, Moonlight almost upon us and other little tidbits from the week

on Saturday, November 21, 2009
First off, Moonlight news: 2.0 is almost upon us (or upon you, in any case). The official release date is not set yet, but it is going to be in the next two weeks, so if you have bugs that need fixing for the release, speak now or forever hold your peace. Well, not forever forever... you know what I mean :)

A simple phone

This week I got supremely frustrated with my phone(s). I have a very friendly Nokia 6288 which is unfortunately locked-in to Vodafone, and as some of you might know, I got a new phone number from a different operator, which means I can't use my Nokia until I unlock it... and in this country, it's not an easy thing to do. In the meantime, I have some unlocked phones, but they're for emergencies only, really, when I'm travelling and just need to use a local card for a bit, not at all something that I would like to use on a regular basis. And I did try to use them, but it turns out I need a little more from a phone than what a Nokia Prism can provide... boy oh boy is that thing slow :P

Choosing a new phone for me is always hard... it beats clothes shopping in difficulty level/time spent hands down. I take *months* to make up my mind, and of course, by that time they're deprecated and new models are out, so I can never decide :P So this week I was stuck in a shopping center, getting frustrated with my crappy phone yet again, and I happen to walk in to a Fnac store, which the mobile phone section right in front of me. They always say you shouldn't shop for food when you're hungry... well, it turns out that applies to looking at pretty gadgets while being frustrated with your own gadgets, too.

I started browsing, not very impressed by the selection, and I come to a corner with a pretty litte thing called HTC Tattoo. I don't know if it was the name, or the silly android logo on the silvery back of the display model or what, but before I realized it, I was walking out with a new phone.

I love it, it's everything I needed and a ton more. The only gripe I have with it is lack of a foldout keyboard, but the touch keypad is surprisingly accurate for it's small size, so I'm not missing it too much. The parts I like best are having mp3 and ogg as my morning alarm and ringtones, the twitter/facebook/gtalk/gmail/imap/flickr integration with everything and the gorgeous display. Oh yes, it makes calls, too :)

Two seconds into playing with it I found a bug in the messaging software, where when you send an sms, it gives you the option to send more by having an empty box and a send button, and if you hit the send button, it will send an empty sms without any confirmation :P That was pretty much the only hiccup I've had with it so far, it's been a pretty smooth ride. I'm sure I'll have a lot more problems once I start hacking on it though :D


Thursday Google released the source of ChromiumOS. That evening I basically couldn't get to sleep, so I figured I might as well go do something boring like trying it out on my EeePC - watching stuff build usually does wonders for my sleeplessness.

Building the thing was pretty straightforward, and in a short while I had it running from USB on the Eee 901. But, alas, no wireless - the 901 comes with a ralink, whose drivers are still relegated to the staging area of the kernel, and it turns out ChromiumOS doesn't include those in the build. So I had to go back, reconfigure the kernel to add the ralink drivers and build again, then build the image, load it on the stick, and boot again - et voilà, wireless was up and running.

Next problem... how to get it to connect to a secure AP - it's not like you can login without network on ChromiumOS (well, yes, you can, but I'm stubborn and don't wanna), and there's no way to configure anything from the login screen... fortunately, wpa_cli was available from the terminal, so after a few choice commands, it connected to the AP.

But still, no login. For some reason the connman DNS proxy refused to talk to the DNS on the router, so it wouldn't resolve any hosts (and it doesn't log anything! there's no docs for it, nothing... essential system-level software that fails without telling me anything is annoying!).

At this point I decided to get it running from the HD, to make it easier to configure stuff, and the installation of the system to HD was completely painless and fast. Another reboot, and we're up and running from HD. Still no DNS, so terminal again to hack up resolv.conf and set up nameservers. ChromiumOS doesn't save wireless configurations, so every reboot means another set of wpa_cli commands, which is annoying. But hey, I have a lot of patience. Or I'm masochistic... one of those.

Finally, net was running, tried to login and... no dice. A quick look at the logs reveals that curl is failing trying to load security certificates :/ At this point I gave in a bit and connected the eee to the ethernet, just to make sure. Same thing. Looks like it's either trying to connect to a stale server, or there's something wrong with my build. So I've seen the login screen (very blue), but nothing else. Maybe tomorrow I'll take another stab at it - I'm curious how the desktop is done.

Didn't help much with the sleep thing, but it was fun. :)

Doing the Wave

on Tuesday, October 20, 2009
For the past week I've been doing the Google Wave dance. First impressions are, it's a really interesting mashup of different messaging/content concepts - Wiki meets IM meets Email threading - but it's way too cluttered. The social web evolution tells us that simpler is better, services tend to be straightforward, simple, uncluttered, fast. Google's own web page was a hit precisely because it was simple, clean and to the point, Twitter and all related services are the same thing. Having a huge chunk of my desktop space occupied by one browser window with a bunch of stuff because that's what it takes to be able to interact with Google Wave is way too intrusive. And of course, the fact that it can literally bring the browser to it's knees tells me that it might be a bit too much for a web app.

I'm looking forward to seeing how it evolves, I'm sure a lot of people are getting ideas for better ways to do it... I've had a bunch already. In the meantime, I'm on it as, feel free to add me to waves, I want to see what people are doing with that thing.

Binding C++ APIs, the COM way

on Monday, August 03, 2009

A couple of days ago, during a routine "aaagh, we still don't have a nice way to do C# bindings for C++ APIs" discussion, Miguel asked me how hard would it be to leverage COM to bind C++ APIs. I've been known to mess around with COM, as when I did Mono.WebBrowser/Gecko C# bindings, but I never did get around to do little test apps to try and streamline the whole process of using COM to bind a C++ API, so I jumped at the chance and got some interesting results.

COM, despite all the bad connotations surrounding it, is actually really simple: it is just a contract stating that any COM-conforming C++ class has at least 3 methods: QueryInterface, AddRef and Release. No matter how many members the class might have, those 3 are always present at the top of the class' vtable, so Mono's COM interop layer always knows where they are and can invoke them directly. And since the vtable layout for the class is known, any other method on that class can also be invoked in this way, bypassing name-mangling and other issues.

COM-comforming C++ classes can be described in C# via interfaces that have the same layout as the C++ class, so Mono knows exactly where the methods are in the vtable when invoking. Furthermore, COM support is pretty much transparent in C# - once you've defined your interfaces, you don't even realize you're using a COM object, it's just another object that you invoke methods on. Mono does all the marshalling for you, so you don't have to pass IntPtrs around, you just use the types you defined and everything will be marshalled for you behind the scenes.

Show me the code!

Let's say you have a little C++ library you'd like to use from C#:

class File {
int Open();
int Close();

The C++ COM class

The first thing you need to do is create a COM class which will serve as a proxy between C# and your nice little library.

class COMFile {
virtual int QueryInterface (void* id, void** result) {
*result = this;
return 0;
virtual int AddRef () { return 1; }
virtual int Release () { return 0; }

virtual int Open () { return file->Open(); }
virtual int Close () { return file->Close(); }

COMFile (File* f) : file(f) {}

File* file;

All methods that need to be "exported" are marked as virtual, and the layout is what you would expect: the 3 methods on top that make this a COM class, plus the 2 methods that are proxying the calls to the library's File class.

AddRef and Release are standard refcounting methods - these will be called by Mono as needed when you invoke things that end up creating objects of this type. I'm just returning fixed values here, but it's important to note that when Release makes the refcount go to 0, the object should be released.

QueryInterface allows Mono's COM interop layer to figure out if a pointer can be cast to a specified type - via behind the scenes magic (and a little code), it enables a dynamic type system. This example is very simple and doesn't use inheritance, but with a complex binding you'll certainly have inheritance, and there is where QueryInterface comes in, for instance allowing for upcasts if your COM class inherits from several different classes.

You'll notice in the C# interface below that it is marked with a Guid - this id is unique to every class, and your C++ class definition should also have the same id. When QueryInterface is invoked, the id argument is the Guid of the type you want to cast to, so you can check if your C++ class is of the correct type by comparing ids, or if it is a subclass and you need to cast the result (or you don't support it at all, in which case you'd return null).

The C# interface

[Guid ("00000000-0000-0000-0000-000000001111")]
[InterfaceType (ComInterfaceType.InterfaceIsUnknown)]
public interface COMFile {
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
int Open();

[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
int Close();

"Wait a minute... where are the 3 methods?", I can hear you thinking. Well, on the C# side you don't need them. The interface is marked ComImport(), so Mono already knows it's a COM class and it will add them for you, no questions asked. The C# interface only needs the definitions of the methods you want to access, and nothing else.

Putting it all together

Now that you have all your definitions in place, the only thing you need is to get a reference to a COMFile object. For this you're going to need to add a P/Invoke call to a C function on your proxy code that gives you a pointer to an instance of that class. You only need to do that for top level objects, because any objects that are returned via COM calls are directly available to you.

C++ proxy library

extern "C" {
COMFile* getptr() {
return new COMFile (new File ());

C# test app

[DllImport ("myglue")]
static extern COMFile getptr();

public static void Main() {
COMFile file = getptr();
int return = file.Open();

And there you go, the "file" variable is now talking to your COM class which is proxying all calls directly to your library. The glue code is very straightforward and can be easily autogenerated.

You can download a complete working sample here:

Build and install both packages to the same prefix, then go to $prefix/lib/ and do " ln -s comtestsharp/* . ". Then just do"mono comtestsharp.exe" and you should see the output of the Open and Close calls.

Update: BTW, neither QI nor AddRef/Release are actually implemented properly in this little sample. The unused parameter "id" is the Guid that is getting requested, and QI should always check it against the current instance.

Book memes for a monday morning

on Monday, May 18, 2009

* Grab the nearest book.
* Open it to page 56.
* Find the fifth sentence.
* Post the text of the sentence in your journal along with these instructions.
* Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.

"I was chewing on the peculiar fact that both these photographs were pointing outwards from the desk, when a connecting door opened, and I was suddenly in the presence of Spencer."

Note to self: when I eventually get down to writing a book, remember to collect all the memes flying around and place interestingly exotic and/or misterious phrases in all the right spots.

Extra cookies if anyone can guess what book it is.

Update: No cookies for all you guys looking up the book on Google! As penitence you now have to go and read the book! Tssk tssk

Gtk# on Windows - now with more Tomboy flavour!

on Thursday, April 23, 2009
If anyone missed it, a new shiny Gtk# 2.12.8 installer for Windows is available. As Miguel noted yesterday, it's a nice small package with the full stack so you have everything you need to develop in an awesome cross-platform way.

And speaking of cross-platform development, in case you missed that one as well, a new version of Tomboy is out now, with full Windows and Mac OSX support, for your note-taking pleasure! I've been using Tomboy forever, and it's one of those little apps that you just can't go without once you have it!

Google Summer of Code with Mono!

on Wednesday, April 01, 2009
Calling all students!

Google Summer of Code is here, and this is the week where you do your proposals to spend the next few months working on awesome projects on Mono!

Our ideas page is here, and the soc page is here. There is a #monosoc channel on dedicated to everything Soc, do don't delay, do it now!

RIP Mário Gamito

on Monday, March 23, 2009
Nem sei o que dizer...

Moonlight shining on Ubuntu

on Thursday, February 19, 2009
This morning the first thing on the channel was the following excellent news, that I shall now reproduce directly as-read:

<directhex> it's official, moon binaries are now trivially installable on any ubuntu 9.04 system
<directhex> the 1-click url is apt:moonlight-plugin-mozilla

Awesome stuff directhex, many thanks ot you and everyone else that helped shine a bit of moonlight on jaunty!

PS: directhex also noted that the build servers are busy building, so not all architectures might be available right now, just give it a bit of time :)