Re: Glib Dbus Types for object paths

On Mon, 2010-12-06 at 17:05 +0100, Maxime Boure wrote:
> Hello everybody,
> I am developing an application using dbus to control Network Manager.
> The only problem I encounter is how to get the properties of type "- o
> -"

Right.  So 'o' (object path) is the type of the property you're looking
for, but the way to access that property is the D-Bus Properties
interface, which NM objects implement:

in which the Get() call does return an VARIANT.

> for example the property of 
> org.freedesktop.NetworkManager.Connection.Active 
> Connection - o - (read)
> The path of the connection.
> I use the glib library.
> I tried 
> if (!dbus_g_proxy_call (proxy_props, "Get", &error,
> G_TYPE_STRING, "org.freedesktop.NetworkManager.Connection.Active",
> G_TYPE_STRING, "Connection",
>                                         DBUS_TYPE_G_OBJECT_PATH,
> &conn,
> {
> ERROR ("Error getting device's connection name : %s", error->message);
> g_error_free (error);
> }
> Which through the error : Error getting device's connection name :
> Expected D-BUS object path, got type code 'v'
> I replaced the DBUS_TYPE_G_OBJECT_PATH by G_TYPE_VALUE, the error
> disappear but I can't find the good g_value_get_xxx that can get me
> this value.

GValue is just a container type which can create and free various other
types of values.  So it "wraps" the real type that gets returned.  So if
you get a GValue back, you can do something like this to see what's in
it, if you don't already know:

GValue value = { 0 };
GError *error = NULL;

if (!dbus_g_proxy_call (proxy, "Get", &error,
                        G_TYPE_STRING, NM_DBUS_INTERFACE,
                        G_TYPE_STRING, "ActiveConnections",
                        G_TYPE_VALUE, &value,
                        G_TYPE_INVALID)) {
	g_warning ("Failed to get property: %s", error->message);
	g_error_free (error);

g_message ("value type %s", G_VALUE_TYPE_NAME (&value));
g_value_unset (&value);

In the case of an object path, you would do this:

const char *path;

path = g_value_get_boxed (&value);

since you know that DBUS_TYPE_G_OBJECT_PATH is actually a string

In any case, I've posted an example here:

that should show you what needs to get done.  Let me know if you have
any further questions or comments!


> Does anyone has succeeded that ?
> Many thanks
> -- 
> Maxime Bouré
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org

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