コード例 #1
0
ファイル: NetworkManager.py プロジェクト: 5l1v3r1/blueman-1
    def _on_device_state_changed(self, device, new_state, old_state, reason):
        new = NM.DeviceState(new_state)
        old = NM.DeviceState(old_state)
        state_reason = NM.DeviceStateReason(reason)
        logging.debug(
            'New: %s Old: %s Reason: %s' %
            (new.value_nick, old.value_nick, state_reason.value_nick))

        error_msg = None
        reply_msg = None

        if new == NM.DeviceState.FAILED:
            error_msg = 'Connection failed with reason: %s' % state_reason.value_nick
        elif new == NM.DeviceState.ACTIVATED:
            reply_msg = 'Connection sucesfully activated'
        elif (new <= NM.DeviceState.DISCONNECTED or new == NM.DeviceState.DEACTIVATING) and \
                (NM.DeviceState.DISCONNECTED < old <= NM.DeviceState.ACTIVATED):
            error_msg = 'Connection disconnected with reason %s' % state_reason.value_nick
        else:
            return  # Keep checking the state changes

        # We are done with state changes
        device.disconnect(self._statehandler)
        if error_msg is None:
            self._return_or_reply_handler(reply_msg)
        else:
            logging.debug(error_msg)
            self._raise_or_error_handler(NMConnectionError(error_msg))
コード例 #2
0
    def _on_device_state_changed(self, device: NM.Device, new_state: int,
                                 old_state: int, reason: int) -> None:
        new = NM.DeviceState(new_state)
        old = NM.DeviceState(old_state)
        state_reason = NM.DeviceStateReason(reason)
        logging.debug(
            f"New: {new.value_nick} Old: {old.value_nick} Reason: {state_reason.value_nick}"
        )

        error_msg = None

        if new == NM.DeviceState.FAILED:
            error_msg = f"Connection failed with reason: {state_reason.value_nick}"
        elif new == NM.DeviceState.ACTIVATED:
            logging.debug("Connection successfully activated")
        elif (new <= NM.DeviceState.DISCONNECTED or new == NM.DeviceState.DEACTIVATING) and \
                (NM.DeviceState.DISCONNECTED < old <= NM.DeviceState.ACTIVATED):
            error_msg = f"Connection disconnected with reason {state_reason.value_nick}"
        else:
            return  # Keep checking the state changes

        # We are done with state changes
        assert self._statehandler is not None
        GObject.signal_handler_disconnect(device, self._statehandler)
        if error_msg is None:
            self.reply_handler()
        else:
            logging.debug(error_msg)
            self.error_handler(NMConnectionError(error_msg))
コード例 #3
0
    def wait_state(self, expected, timeout):
        res, out_value, _ = NM.utils_enum_from_str(NM.DeviceState, expected)
        if not res:
            raise ValueError("invalid state '{}'".format(expected))
        expected = NM.DeviceState(out_value)

        timeout = monotonic() + timeout
        while monotonic() < timeout:
            sleep(0.25)
            if self._nm_dev.get_state() == expected:
                break
        else:
            raise TimeoutError("state is '{}' instead of '{}'".format(
                self._nm_dev.get_state().value_nick, expected.value_nick))
コード例 #4
0
    def wait_state(self, expected, timeout):
        res, out_value, _ = NM.utils_enum_from_str(NM.DeviceState, expected)
        if not res:
            raise ValueError(f"invalid state '{expected}'")
        expected = NM.DeviceState(out_value)

        timeout = monotonic() + timeout
        while monotonic() < timeout:
            sleep(0.25)
            if self._nm_dev.get_state() == expected:
                break
        else:
            raise TimeoutError(
                f"state is '{self._nm_dev.get_state().value_nick}' instead of '{expected.value_nick}'"  # pylint: disable=line-too-long
            )