| 32 | return callback |
| 33 | |
| 34 | class NetworkManagerEvents(threading.Thread): |
| 35 | def __init__(self, manager): |
| 36 | super(NetworkManagerEvents, self).__init__() |
| 37 | self.daemon = True |
| 38 | self._stopped = False |
| 39 | self._manager = manager |
| 40 | self._online = None |
| 41 | self._currentIpv4Address = None |
| 42 | self._activeDevice = None |
| 43 | self._activatingConnection = None |
| 44 | self._setOnlineCondition = threading.Condition() |
| 45 | self._justActivatedConnection = False |
| 46 | |
| 47 | #listeners |
| 48 | self._propertiesListener = None |
| 49 | self._stateChangeListener = None |
| 50 | self._devicePropertiesListener = None |
| 51 | self._monitorActivatingListener = None |
| 52 | |
| 53 | def getActiveConnectionDevice(self, connection=None): |
| 54 | if connection: |
| 55 | settings = connection.GetSettings() |
| 56 | uuid = settings['connection']['uuid'] |
| 57 | |
| 58 | connections = NetworkManager.NetworkManager.ActiveConnections |
| 59 | for c in connections: |
| 60 | |
| 61 | if connection and not c.Uuid == uuid: |
| 62 | continue |
| 63 | |
| 64 | try: |
| 65 | if hasattr(c, 'State') and c.State == NetworkManager.NM_ACTIVE_CONNECTION_STATE_ACTIVATED: |
| 66 | d = c.Devices[0] |
| 67 | return d |
| 68 | except: |
| 69 | #ignore errors, some connections are stale and give dbus exceptions |
| 70 | pass |
| 71 | |
| 72 | return None |
| 73 | |
| 74 | def run(self): |
| 75 | self._stopped = False |
| 76 | self._loop = GObject.MainLoop() |
| 77 | |
| 78 | self._propertiesListener = NetworkManager.NetworkManager.OnPropertiesChanged(self.propertiesChanged) |
| 79 | self._stateChangeListener = NetworkManager.NetworkManager.OnStateChanged(self.globalStateChanged) |
| 80 | |
| 81 | connectionState = NetworkManager.NetworkManager.State |
| 82 | logger.info('Network Manager reports state: *[%s]*' % NetworkManager.const('state', connectionState)) |
| 83 | if connectionState == NetworkManager.NM_STATE_CONNECTED_GLOBAL: |
| 84 | self._setOnline(True) |
| 85 | |
| 86 | #d = self.getActiveConnectionDevice() |
| 87 | #if d: |
| 88 | # self._devicePropertiesListener = d.Dhcp4Config.connect_to_signal('PropertiesChanged', self.activeDeviceConfigChanged) |
| 89 | # self._currentIpv4Address = d.Ip4Address |
| 90 | # self._activeDevice = d |
| 91 | # self._online = True |