Re: Error when trying to access nm with vala and gdbus
- From: Dan Williams <dcbw redhat com>
- To: Florent Thévenet <feuloren free fr>
- Cc: networkmanager-list gnome org
- Subject: Re: Error when trying to access nm with vala and gdbus
- Date: Thu, 12 Jan 2012 19:01:42 -0600
On Thu, 2012-01-12 at 16:35 +0100, Florent Thévenet wrote:
> Hi everyone,
>
> I'm writing a program to change the evolution smtp server according to
> the network I'm connected to, implemented in Vala
>
> The simpler solution I found to talk to networkmanager is over dbus,
> here is the code I use:
>
> """
> [DBus (name = "org.freedesktop.NetworkManager")]
> interface NetworkManager : Object {
> [DBus (name = "state")]
> public abstract uint state () throws IOError;
> public signal void state_changed(uint state);
> }
>
> [DBus (name = "org.freedesktop.NetworkManager.Settings.Connection")]
> interface Connection : Object {
> public abstract HashTable<string, HashTable<string, Variant>>
> get_settings() throws IOError;
> }
>
> [DBus (name = "org.freedesktop.NetworkManager.Connection.Active")]
> interface NetworkManagerActiveConnection : Object {
> }
>
> void main() {
> var loop = new MainLoop();
> //watch state change
>
> //get connection infos
>
> //get active connection
> NetworkManager nm;
> Connection conn;
>
> nm = Bus.get_proxy_sync(BusType.SYSTEM,
> "org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager");
> nm.state_changed.connect((s) => {
> stdout.printf("state changed : %d\n", s);
> });
>
> conn = Bus.get_proxy_sync(BusType.SYSTEM,
> "org.freedesktop.NetworkManager.Settings.Connection",
> "/org/freedesktop/NetworkManager/Settings/15");
Here's the problem: you still need to use the NetworkManager dbus
service name, which is "org.freedesktop.NetworkManager". What you're
passing in here looks like the *interface* name you want to use when
talking to the /org/freedesktop/NetworkManager/Settings/15 object.
So remove the ".Settings.Connection" bit from that and you should get
your proxy. The interface name is already specified at the top where
you define the interface for the Connection object.
Dan
> var result = conn.get_settings();
> var v = result.get("connection").get("id");
> stdout.printf("%u\n%s", nm.state(), v.get_string());
>
> loop.run();
> }
> """
>
> The signal part works great, but I get an error when trying to get a
> proxy for org.freedesktop.NetworkManager.Settings.Connection:
>
> """
> ** (process:4271): CRITICAL **:
> file /home/florent/Projets/smtp_switcher/nm_detection.vala.c: line 747:
> unexpected error: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown:
> The name org.freedesktop.NetworkManager.Settings.Connection was not
> provided by any .service files (g-dbus-error-quark, 2)
> """
>
> I'm using ubuntu 11.10, is there a solution or direct Vala bindings for
> NetworkManager ?
>
> Cheers
> Florent
>
>
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]