Re: signal for interface up/down



On Fri, 2016-06-24 at 20:42 +0200, Michael Hirmke wrote:
Hi Thomas,


On Fri, 2016-06-24 at 11:56 +0200, Michael Hirmke wrote:

Hi *,

I'm about to write a script, which should do some actions in a
user
context, whenever an interface is getting active or inactive.
I tried to implement this via the NetworkManager dbus interface
and
the
signals "DeviceNowActive" and "DeviceNoLongerActive".
As it seems, the documentation mentioning these signals is
outdated,
because they don't exist any more. Otherwise I'm doing somtehing
completely wrong.

Can anyone sched some light on this, please?
Do these signals still exist? If so, is there an example on how
to
use
them? At least I found them mentioned in one of the nm libraries.
If theses signals indeed don't exist any more, how is the
preferred
solution for my problem?

Thx a lot!

Bye.
Michael.


Hi Michael,


I think you should listen for the device's "State". Also, as a
device
becomes active, it gets a "ActiveConnection".
Yes, but what I need is to listen for every connection/device
becoming
active or inactive. So I would have to find out, what devices are
present, then listen to the appropriate signals for *each* of them?

Correct.  But in reality you can just watch for all signals coming out
of NetworkManager.  You'd match on the signal (member) name
"StateChanged", and look for object paths starting with
"/org/freedesktop/NetworkManager/Devices/" and an interface of
"org.freedesktop.NetworkManager.Device".

The Device.StateChanged signal arguments are documented in the NM D-Bus 
API; they are new-state (uint), old-state (uint), and reason (uint).

So once you know you've got a device state change signal, you can read
the new-state argument and you'll know when the device is activated or
deactivated.

This all makes it seem more complicated than it is.  In reality you're
just listening for NetworkManager messages of type SIGNAL, checking a
couple standard message attributes (interface, object path, and member
name), and then reading one uint from the message data.

Dan


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