用于e NetworkManager VPN连接的dbus信号处理程序

时间:2010-12-09 18:40:58

标签: python linux dbus

我需要开发一些python代码,以便在建立VPN连接时执行,VPN是从NetworkManager控制的,我试图想办法如何使用NM DBUS事件。

使用“dbus-monitor --system”我能够识别连接信号:

signal sender=:1.1 -> dest=(null destination) serial=464 path=/org/freedesktop/NetworkManager/ActiveConnection/3; interface=org.freedesktop.NetworkManager.VPN.Connection; member=PropertiesChanged
   array [
      dict entry(
         string "VpnState"
         variant             uint32 5
      )
      dict entry(
         string "State"
         variant             uint32 2
      )
   ]

现在我需要识别相应的信号处理程序调用签名:

bus.add_signal_receiver(
   handler_name_in_your_program,
   "signal_name",
   "interface_name",
   "connection_name",
   "object_name"

有人可以帮我将dbus-monitor跟踪输出转换为总线sginal处理程序的相应函数值吗?

1 个答案:

答案 0 :(得分:7)

我能够弄清楚:

def vpn_connection_handler(*args, **keywords):
    state = args[0].get('State',0)
    if state == 2:
        # On connect code goes here

system_bus.add_signal_receiver(vpn_connection_handler,
    dbus_interface="org.freedesktop.NetworkManager.VPN.Connection",
        signal_name="PropertiesChanged")