diff options
author | Devaev Maxim <[email protected]> | 2020-10-03 09:58:15 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-10-03 09:58:15 +0300 |
commit | 877a0b844100c51ff96f19f4a00abed02dadec89 (patch) | |
tree | 0c4b068707931926ecdaab6a9563be9330616b34 /kvmd/plugins/hid/otg/device.py | |
parent | 971eb1c203e5dfacd55b7c1e215071b3ebd0c153 (diff) |
processing udc state
Diffstat (limited to 'kvmd/plugins/hid/otg/device.py')
-rw-r--r-- | kvmd/plugins/hid/otg/device.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py index e44efd5e..08777293 100644 --- a/kvmd/plugins/hid/otg/device.py +++ b/kvmd/plugins/hid/otg/device.py @@ -35,6 +35,8 @@ from ....logging import get_logger from .... import aiomulti from .... import aioproc +from .usb import UsbDeviceController + # ===== class BaseEvent: @@ -42,13 +44,15 @@ class BaseEvent: class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-instance-attributes - def __init__( + def __init__( # pylint: disable=too-many-arguments self, name: str, read_size: int, initial_state: Dict, notifier: aiomulti.AioProcessNotifier, + udc: UsbDeviceController, + device_path: str, select_timeout: float, write_retries: int, @@ -61,6 +65,8 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in self.__name = name self.__read_size = read_size + self.__udc = udc + self.__device_path = device_path self.__select_timeout = select_timeout self.__write_retries = write_retries @@ -87,7 +93,8 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in try: event: BaseEvent = self.__events_queue.get(timeout=0.1) except queue.Empty: - pass + if not self.__udc.can_operate(): + self.__close_device() else: self._process_event(event) except Exception: @@ -216,16 +223,19 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in logger = get_logger() if self.__fd < 0: - try: - flags = os.O_NONBLOCK - flags |= (os.O_RDWR if self.__read_size else os.O_WRONLY) - self.__fd = os.open(self.__device_path, flags) - except FileNotFoundError: - logger.error("Missing HID-%s device: %s", self.__name, self.__device_path) - time.sleep(self.__select_timeout) - except Exception as err: - logger.error("Can't open HID-%s device: %s: %s: %s", - self.__name, self.__device_path, type(err).__name__, err) + if self.__udc.can_operate(): + try: + flags = os.O_NONBLOCK + flags |= (os.O_RDWR if self.__read_size else os.O_WRONLY) + self.__fd = os.open(self.__device_path, flags) + except FileNotFoundError: + logger.error("Missing HID-%s device: %s", self.__name, self.__device_path) + time.sleep(self.__select_timeout) + except Exception as err: + logger.error("Can't open HID-%s device: %s: %s: %s", + self.__name, self.__device_path, type(err).__name__, err) + time.sleep(self.__select_timeout) + else: time.sleep(self.__select_timeout) if self.__fd >= 0: |