Ejemplo n.º 1
0
	def monitorActivatingConnection(self, nm, new_state, old_state, reason, interface, signal):
		try:
			logger.info('Activating State Change %s -> %s' % (NetworkManager.const('device_state', old_state),NetworkManager.const('device_state', new_state)))
			if self._activatingConnection:
				if new_state == NetworkManager.NM_DEVICE_STATE_ACTIVATED:
					if self._monitorActivatingListener:
						NetworkManager.SignalDispatcher.remove_signal_receiver(self._monitorActivatingListener)
						self._monitorActivatingListener = None

					d = self.getActiveConnectionDevice(self._activatingConnection)
					if isinstance(d, NetworkManager.Wired):
						eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {
							'status': 'connected',
							'info': {
								'type': 'ethernet',
								'ip': self._manager._getIpAddress(d)
							}
						})
					else:
						ap = d.ActiveAccessPoint
						eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {
							'status': 'connected',
							'info': {
								'type': 'wifi',
								'signal': ap.Strength,
								'name': ap.Ssid,
								'ip': self._manager._getIpAddress(d)
							}
						})

					self._activatingConnection = None
					self._justActivatedConnection = True
					self._setOnline(True)

				elif new_state in [NetworkManager.NM_DEVICE_STATE_FAILED, NetworkManager.NM_DEVICE_STATE_UNKNOWN]:
					logger.warn('Connection reached state %s, reason: %s' % (NetworkManager.const('device_state', new_state), NetworkManager.const('device_state_reason', reason) ) )

					#It has reached and end state.
					self._activatingConnection = None
					if self._monitorActivatingListener:
						NetworkManager.SignalDispatcher.remove_signal_receiver(self._monitorActivatingListener)
						self._monitorActivatingListener = None

					eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {'status': 'failed', 'reason': NetworkManager.const('device_state_reason', reason)})

				elif new_state == NetworkManager.NM_DEVICE_STATE_DISCONNECTED:
					if self._monitorActivatingListener:
						NetworkManager.SignalDispatcher.remove_signal_receiver(self._monitorActivatingListener)
						self._monitorActivatingListener = None

					eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {'status': 'disconnected'})

					self._activatingConnection = None

					#check the global connection status before setting it to false
					#if NetworkManager.NetworkManager.state() != NetworkManager.NM_STATE_CONNECTED_GLOBAL:
					#	self._setOnline(False)
		except Exception, e:
			logger.error(e, exc_info= True)
Ejemplo n.º 2
0
	def run(self):
		self._stopped = False
		self._loop = GObject.MainLoop()

		self._propertiesListener = NetworkManager.NetworkManager.OnPropertiesChanged(self.propertiesChanged)
		self._stateChangeListener = NetworkManager.NetworkManager.OnStateChanged(self.globalStateChanged)

		connectionState = NetworkManager.NetworkManager.State
		logger.info('Network Manager reports state: *[%s]*' % NetworkManager.const('state', connectionState))
		if connectionState == NetworkManager.NM_STATE_CONNECTED_GLOBAL:
			self._setOnline(True)

		#d = self.getActiveConnectionDevice()
		#if d:
		#	self._devicePropertiesListener = d.Dhcp4Config.connect_to_signal('PropertiesChanged', self.activeDeviceConfigChanged)
		#	self._currentIpv4Address = d.Ip4Address
		#	self._activeDevice = d
		#	self._online = True
		#	logger.info('Active Connection found at %s (%s)' % (d.IpInterface, d.Ip4Address))

		while not self._stopped:
			try:
				self._loop.run()

			except KeyboardInterrupt:
				#kill the main process too
				from octoprint import astrobox
				astrobox.stop()

			except DBusException as e:
				#GObject.idle_add(logger.error, 'Exception during NetworkManagerEvents: %s' % e)
				logger.error('Exception during NetworkManagerEvents: %s' % e)

			finally:
				self.stop()
Ejemplo n.º 3
0
	def globalStateChanged(self, nm, state, interface, signal):
		#uncomment for debugging only
		logger.info('Network Global State Changed, new(%s)' % NetworkManager.const('state', state))
		if state == NetworkManager.NM_STATE_CONNECTED_GLOBAL:
			self._setOnline(True)

		elif self._justActivatedConnection and state == NetworkManager.NM_STATE_CONNECTED_LOCAL:
			#local is a transition state when we have just activated a connection, so do nothing
			self._justActivatedConnection = False

		elif state != NetworkManager.NM_STATE_CONNECTING:
			self._setOnline(False)
Ejemplo n.º 4
0
    def globalStateChanged(self, nm, state, interface, signal):
        #uncomment for debugging only
        logger.info('Network Global State Changed, new(%s)' %
                    NetworkManager.const('state', state))
        if state == NetworkManager.NM_STATE_CONNECTED_GLOBAL:
            self._setOnline(True)

        elif self._justActivatedConnection and state == NetworkManager.NM_STATE_CONNECTED_LOCAL:
            #local is a transition state when we have just activated a connection, so do nothing
            self._justActivatedConnection = False

        elif state != NetworkManager.NM_STATE_CONNECTING:
            self._setOnline(False)
Ejemplo n.º 5
0
    def run(self):
        self._stopped = False
        self._loop = GObject.MainLoop()

        self._propertiesListener = NetworkManager.NetworkManager.OnPropertiesChanged(
            self.propertiesChanged)
        self._stateChangeListener = NetworkManager.NetworkManager.OnStateChanged(
            self.globalStateChanged)

        connectionState = NetworkManager.NetworkManager.State
        logger.info('Network Manager reports state: *[%s]*' %
                    NetworkManager.const('state', connectionState))
        if connectionState == NetworkManager.NM_STATE_CONNECTED_GLOBAL:
            self._setOnline(True)

        #d = self.getActiveConnectionDevice()
        #if d:
        #	self._devicePropertiesListener = d.Dhcp4Config.connect_to_signal('PropertiesChanged', self.activeDeviceConfigChanged)
        #	self._currentIpv4Address = d.Ip4Address
        #	self._activeDevice = d
        #	self._online = True
        #	logger.info('Active Connection found at %s (%s)' % (d.IpInterface, d.Ip4Address))

        while not self._stopped:
            try:
                self._loop.run()

            except KeyboardInterrupt:
                #kill the main process too
                from octoprint import astrobox
                astrobox.stop()

            except DBusException as e:
                #GObject.idle_add(logger.error, 'Exception during NetworkManagerEvents: %s' % e)
                logger.error('Exception during NetworkManagerEvents: %s' % e)

            finally:
                self.stop()
Ejemplo n.º 6
0
    def monitorActivatingConnection(self, nm, new_state, old_state, reason,
                                    interface, signal):
        try:
            logger.info('Activating State Change %s -> %s' %
                        (NetworkManager.const('device_state', old_state),
                         NetworkManager.const('device_state', new_state)))
            if self._activatingConnection:
                if new_state == NetworkManager.NM_DEVICE_STATE_ACTIVATED:
                    if self._monitorActivatingListener:
                        NetworkManager.SignalDispatcher.remove_signal_receiver(
                            self._monitorActivatingListener)
                        self._monitorActivatingListener = None

                    d = self.getActiveConnectionDevice(
                        self._activatingConnection)
                    if isinstance(d, NetworkManager.Wired):
                        eventManager.fire(
                            Events.INTERNET_CONNECTING_STATUS, {
                                'status': 'connected',
                                'info': {
                                    'type': 'ethernet',
                                    'ip': self._manager._getIpAddress(d)
                                }
                            })
                    else:
                        ap = d.ActiveAccessPoint
                        eventManager.fire(
                            Events.INTERNET_CONNECTING_STATUS, {
                                'status': 'connected',
                                'info': {
                                    'type': 'wifi',
                                    'signal': ap.Strength,
                                    'name': ap.Ssid,
                                    'ip': self._manager._getIpAddress(d)
                                }
                            })

                    self._activatingConnection = None
                    self._justActivatedConnection = True
                    self._setOnline(True)

                elif new_state in [
                        NetworkManager.NM_DEVICE_STATE_FAILED,
                        NetworkManager.NM_DEVICE_STATE_UNKNOWN
                ]:
                    logger.warn(
                        'Connection reached state %s, reason: %s' %
                        (NetworkManager.const('device_state', new_state),
                         NetworkManager.const('device_state_reason', reason)))

                    #It has reached and end state.
                    self._activatingConnection = None
                    if self._monitorActivatingListener:
                        NetworkManager.SignalDispatcher.remove_signal_receiver(
                            self._monitorActivatingListener)
                        self._monitorActivatingListener = None

                    eventManager.fire(
                        Events.INTERNET_CONNECTING_STATUS, {
                            'status':
                            'failed',
                            'reason':
                            NetworkManager.const('device_state_reason', reason)
                        })

                elif new_state == NetworkManager.NM_DEVICE_STATE_DISCONNECTED:
                    if self._monitorActivatingListener:
                        NetworkManager.SignalDispatcher.remove_signal_receiver(
                            self._monitorActivatingListener)
                        self._monitorActivatingListener = None

                    eventManager.fire(Events.INTERNET_CONNECTING_STATUS,
                                      {'status': 'disconnected'})

                    self._activatingConnection = None

                    #check the global connection status before setting it to false
                    #if NetworkManager.NetworkManager.state() != NetworkManager.NM_STATE_CONNECTED_GLOBAL:
                    #	self._setOnline(False)
        except Exception, e:
            logger.error(e, exc_info=True)
Ejemplo n.º 7
0
    def monitorActivatingConnection(self, nm, new_state, old_state, reason,
                                    interface, signal):
        logger.info('Activating State Change %s -> %s' %
                    (NetworkManager.const('device_state', old_state),
                     NetworkManager.const('device_state', new_state)))
        if self._activatingConnection:
            if new_state == NetworkManager.NM_DEVICE_STATE_ACTIVATED:
                if self._monitorActivatingListener:
                    NetworkManager.SignalDispatcher.remove_signal_receiver(
                        self._monitorActivatingListener)
                    self._monitorActivatingListener = None

                d = self.getActiveConnectionDevice()
                if d.DeviceType == NetworkManager.NM_DEVICE_TYPE_ETHERNET:
                    eventManager.fire(
                        Events.INTERNET_CONNECTING_STATUS, {
                            'status': 'connected',
                            'info': {
                                'type': 'ethernet',
                                'ip': self._manager._getIpAddress(d)
                            }
                        })
                else:
                    ap = d.SpecificDevice().ActiveAccessPoint
                    eventManager.fire(
                        Events.INTERNET_CONNECTING_STATUS, {
                            'status': 'connected',
                            'info': {
                                'type': 'wifi',
                                'signal': ap.Strength,
                                'name': ap.Ssid,
                                'ip': self._manager._getIpAddress(d)
                            }
                        })

                self._activatingConnection = None
                self._justActivatedConnection = True
                self._setOnline(True)

            elif new_state in [
                    NetworkManager.NM_DEVICE_STATE_FAILED,
                    NetworkManager.NM_DEVICE_STATE_UNKNOWN
            ]:
                logger.warn(
                    'Connection reached state %s, reason: %s' %
                    (NetworkManager.const('device_state', new_state),
                     NetworkManager.const('device_state_reason', reason)))

                #It has reached and end state.
                self._activatingConnection = None
                if self._monitorActivatingListener:
                    NetworkManager.SignalDispatcher.remove_signal_receiver(
                        self._monitorActivatingListener)
                    self._monitorActivatingListener = None

                eventManager.fire(
                    Events.INTERNET_CONNECTING_STATUS, {
                        'status':
                        'failed',
                        'reason':
                        NetworkManager.const('device_state_reason', reason)
                    })

            elif new_state == NetworkManager.NM_DEVICE_STATE_DISCONNECTED:
                if self._monitorActivatingListener:
                    NetworkManager.SignalDispatcher.remove_signal_receiver(
                        self._monitorActivatingListener)
                    self._monitorActivatingListener = None

                eventManager.fire(Events.INTERNET_CONNECTING_STATUS,
                                  {'status': 'disconnected'})

                self._activatingConnection = None