dbus signal handler for e NetworkManager VPN connection

浪子不回头ぞ 提交于 2019-12-06 02:28:23

问题


I need to develop some python code to be executed when a VPN connection is established, the VPN is controlled from NetworkManager, I am trying to figure how to use an NM DBUS event for this.

Using "dbus-monitor --system" I was able to identify the connect signal:

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
      )
   ]

Now I need to identify the corresponding signal handler calling signature:

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

)

Can someone help me translating the dbus-monitor trace output into the corresponding function values for the bus sginal handler ?


回答1:


I was able to figure it out:

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")


来源:https://stackoverflow.com/questions/4401851/dbus-signal-handler-for-e-networkmanager-vpn-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!