[Vala] connecting non-gobject callbacks



Hi,
I'm trying to write a client for XMMS2 in Vala.
XMMS2 doesn't use GObjects, but it uses callbacks in various places,
which makes it hard to use it in Vala.

XMMS2 uses a struct called xmmsc_result_t, to which you can connect a
callback like this:

  static void handler(xmmsc_result_t *res, void *user_data) {...}

  xmmsc_result_t *res;
  xmmsc_result_notifier_set (res, handler, NULL);

So eventually "handler" will be called with res and NULL. The straight
forward Vala bindings make it impossible to connect an instance method
as a notifier for a Xmms.Result, since the callback is always passed a
xmmsc_result_t* as the first argument, but Vala needs the first argument
to be a Vala object resp gobject. Connecting to class methods/static
methods works just fine, but it's just not sufficient.

Did anyone solve this problem before? We don't want to touch XMMS2, but
we'd like to solve this on the Vala side only :)

We tried to write a wrapper function in Vala that would allow us to pass
a Vala instance pointer around, too, but the problem is that you cannot
extend Vala classes (that are wrapping C structs) with Vala code.

ie if my vapi has this: "public class Xmms.Result" then you cannot
reopen the class in Vala and attach another method like this:
  public class Xmms.Result {
    public void new_method () { ... }
  }

This last point might actually be what bug #480253 is about, but I'm not
sure (http://bugzilla.gnome.org/show_bug.cgi?id=480253#c2).

Any hints are appreciated, I hope this mail isn't too confusing :)

Regards,
Tilman

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Attachment: pgpoKwa35AmHW.pgp
Description: PGP signature



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