Re: about DBUS and Qt, implementing 'route' command using DBUS



On 18/11/2009, at 7:23 AM, ext Dan Williams wrote:

> On Mon, 2009-11-16 at 18:42 +0100, Syed Md. Ashraful Karim wrote:
>> Hi Lorn,
>> Thanks your very much for the link on Qt and NM Dbus wrapper
>> implementations. it saved my last weeks attempts to connect NM using
>> Qt. However, still I missed something, like finding routes/ip address
>> in the IP4Config interface, default gateway etc.
>
> There's a few resources that can help you.  The introspection data is
> what the NM DBus interface is directly constructed from.  You can  
> figure
> out the supported properties and methods there.
>
> http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/introspection
>
> The D-Bus specification is also constructed directly from the
> introspection data:
>
> http://projects.gnome.org/NetworkManager/developers/spec-08.html
>
> A description of how NM configuration and settings work is here:
>
> http://live.gnome.org/NetworkManagerConfiguration

 From QNetworkManagerConnectionActive you can get ask if it is the  
defaultRoute.


>
>> Can you please help finding out,
>> - default gateway of each interface
>
> The IP4Config object provides you a list of IP addresses, and each
> address can have a gateway.
>
> For example, lets get the current active connection list:
>
> [dcbw localhost ~]$ dbus-send --system --print-reply -- 
> dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager  
> org.freedesktop.DBus.Properties.Get  
> string:org.freedesktop.NetworkManager string:ActiveConnections
> method return sender=:1.406 -> dest=:1.612 reply_serial=2
>   variant       array [
>         object path "/org/freedesktop/NetworkManager/ 
> ActiveConnection/7"
>         object path "/org/freedesktop/NetworkManager/ 
> ActiveConnection/8"
>      ]
>
> And get the Devices property for the first active connection:
>
> [dcbw localhost ~]$ dbus-send --system --print-reply -- 
> dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/ 
> ActiveConnection/7 org.freedesktop.DBus.Properties.Get  
> string:org.freedesktop.NetworkManager.ActiveConnection string:Devices
> method return sender=:1.406 -> dest=:1.613 reply_serial=2
>   variant       array [
>         object path "/org/freedesktop/NetworkManager/Devices/1"
>      ]
>
> Great, we've got the active hardware device.  Let's get it's  
> IP4Config object:
>
> dcbw localhost ~]$ dbus-send --system --print-reply -- 
> dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/ 
> Devices/1 org.freedesktop.DBus.Properties.Get  
> string:org.freedesktop.NetworkManager.Device string:Ip4Config
> method return sender=:1.406 -> dest=:1.617 reply_serial=2
>   variant       object path "/org/freedesktop/NetworkManager/ 
> IP4Config/4"
>
> Now, lets ask the IP4 config object what IP addresses it has:
>
> [dcbw localhost ~]$ dbus-send --system --print-reply -- 
> dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/ 
> IP4Config/4 org.freedesktop.DBus.Properties.Get  
> string:org.freedesktop.NetworkManager.IP4Config string:Addresses
> method return sender=:1.406 -> dest=:1.621 reply_serial=2
>   variant       array [
>         array [
>            uint32 1711384768
>            uint32 24
>            uint32 16885952
>         ]
>      ]
>
> from the D-Bus specification, we know the format of the reply.  The  
> 3rd
> uint32 is the that addresses gateway in network byte order.  Most
> devices will only have one.   But that is the gateway you're looking
> for.

You will find code that uses the equivalent classes in  
qnmwifiengine_unix.cpp

and then arrive at the QNetworkManagerIp4Config the same way as Dan  
mentioned using the equivalent Qt classes and getting it's  
connectionInterface() to pass to the next "layer".


 From all this, and the Qt classes mentioned previously, you will need  
to add some functions to
QNetworkManagerIp4Config class.



Namely, adding something like (off the top of my head and untested) to  
QNetworkManagerIp4Config

typedef QList < QList < uint32> > QNmAddressesMap; //tricky part
Q_DECLARE_METATYPE(QNmAddressesMap)


  QNmAddressesMap QNetworkManagerIp4Config::addresses()
{
     QVariant prop = d->connectionInterface->property("Addresses");
     return prop.value< QNmAddressesMap >();

}



--
Lorn Potter
Nokia, Qt Development Frameworks / Mobility







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