On Thu, 2007-08-16 at 20:38 +0300, Tadas Dailyda wrote:
> My recommendation would be not to mess with vala when doing D-Bus
> service. It was quiet some pain to do it in C for me and there were
> many
> odd things to figure out about DBus glib bindings. Personally I
> wouldn't
> try doing it with Vala.
I know, writing DBus services using C isn't easy with any existing
binding, sadly enough.
That's why it would be a great addition to Vala, to be able to write
your service/objects in some more "high level" language, which is
compiled to plain C code, using dbus-glib, libdbus or even something
completely else, not sorted out yet. Just like now it's very easy to in
Vala to use an existing object.
It will become something like this:
using DBus;
using Glib;
namespace Foo {
[DBusInterface (name = "org.gnome.Foo.Bar")]
interface Bar {
int GetId();
}
class MyBar : Bar {
public int GetId() {
return 1;
}
public static int main(string[] args) {
var loop = new MainLoop();
var b = new Bar();
var conn = DBus.Bus.get(DBus.BusType.SESSION);
// This registers a new service to the bus
var n = conn.register_service("org.gnome.Foo");
// This registers a new object on the bus on service n
// All interface stuff will be automaticly handled:
// for each DBusInterface the object implements,
// or its parent.
n.register_object(b, "/org/gnome/FooBar");
loop.run();
return 0;
}
}
}
Here's a sample client:
using Foo;
class FooClient {
public static int main(string[] args) {
var conn = DBus.Bus.get(DBus.BusType.SESSION);
var foobar = conn.get_object<Bar>("org.gnome.Foo",
"/org/gnome/FooBar");
try {
return foobar.GetId();
}
catch(DBusError e) {
stdout.print(e.message);
return 1;
}
}
}
So, the goal is not to use dbus-glib from Vala (that's how I started,
but because of bugs like #464988 to include the dbus-binding-tool
generated files, it's not possible now). Vala would get in-language
functionality for DBus services.
Nicolas
Attachment:
signature.asc
Description: This is a digitally signed message part