示例#1
0
def device_state_change(*args, **kwargs):
    global __devices
    global __network_status

    msg = kwargs['d_member']
    path = kwargs['d_path']
    device = NetworkManager.Device(path)
    newState = NetworkManager.const('device_state', args[0])

    try:
        if device.DeviceType == NetworkManager.NM_DEVICE_TYPE_ETHERNET:
            connectionType = "Ethernet"
        elif device.DeviceType == NetworkManager.NM_DEVICE_TYPE_WIFI:
            connectionType = "Wifi"
    except:
        # D-Bus likely doesn't know about the device any longer,
        # this is typically a removable Wifi stick
        path = kwargs['d_path']
        if path in __devices:
            connectionType = __devices[path]["type"]

    if newState == "activated":
        path = kwargs['d_path']
        __devices[path] = {"type": connectionType, "active": True}
        if connectionType == "Ethernet":
            __network_status.ethernet = True
        if connectionType == "Wifi":
            __network_status.wifi = True
        send_unsent_batch()
    else:
        if connectionType == "Ethernet":
            __network_status.ethernet = False
        if connectionType == "Wifi":
            __network_status.wifi = False