diff options
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/atx/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/plugins/atx/disabled.py | 8 | ||||
-rw-r--r-- | kvmd/plugins/atx/gpio.py | 17 | ||||
-rw-r--r-- | kvmd/plugins/hid/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/plugins/hid/_mcu/__init__.py | 17 | ||||
-rw-r--r-- | kvmd/plugins/hid/bt/__init__.py | 17 | ||||
-rw-r--r-- | kvmd/plugins/hid/ch9329/__init__.py | 17 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/__init__.py | 18 | ||||
-rw-r--r-- | kvmd/plugins/msd/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/plugins/msd/disabled.py | 8 | ||||
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 17 |
11 files changed, 90 insertions, 38 deletions
diff --git a/kvmd/plugins/atx/__init__.py b/kvmd/plugins/atx/__init__.py index e9496a65..7545b030 100644 --- a/kvmd/plugins/atx/__init__.py +++ b/kvmd/plugins/atx/__init__.py @@ -48,6 +48,9 @@ class BaseAtx(BasePlugin): async def get_state(self) -> dict: raise NotImplementedError + async def trigger_state(self) -> None: + raise NotImplementedError + async def poll_state(self) -> AsyncGenerator[dict, None]: yield {} raise NotImplementedError diff --git a/kvmd/plugins/atx/disabled.py b/kvmd/plugins/atx/disabled.py index d9abec00..60c2fa5b 100644 --- a/kvmd/plugins/atx/disabled.py +++ b/kvmd/plugins/atx/disabled.py @@ -36,6 +36,9 @@ class AtxDisabledError(AtxOperationError): # ===== class Plugin(BaseAtx): + def __init__(self) -> None: + self.__notifier = aiotools.AioNotifier() + async def get_state(self) -> dict: return { "enabled": False, @@ -46,10 +49,13 @@ class Plugin(BaseAtx): }, } + async def trigger_state(self) -> None: + self.__notifier.notify() + async def poll_state(self) -> AsyncGenerator[dict, None]: while True: + await self.__notifier.wait() yield (await self.get_state()) - await aiotools.wait_infinite() # ===== diff --git a/kvmd/plugins/atx/gpio.py b/kvmd/plugins/atx/gpio.py index 538aafaf..e42b3959 100644 --- a/kvmd/plugins/atx/gpio.py +++ b/kvmd/plugins/atx/gpio.py @@ -21,6 +21,7 @@ import asyncio +import copy from typing import AsyncGenerator @@ -130,14 +131,18 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes }, } + async def trigger_state(self) -> None: + self.__notifier.notify(1) + async def poll_state(self) -> AsyncGenerator[dict, None]: - prev_state: dict = {} + prev: dict = {} while True: - state = await self.get_state() - if state != prev_state: - yield state - prev_state = state - await self.__notifier.wait() + if (await self.__notifier.wait()) > 0: + prev = {} + new = await self.get_state() + if new != prev: + prev = copy.deepcopy(new) + yield new async def systask(self) -> None: await self.__reader.poll() diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py index 1c2efeec..3cba01f4 100644 --- a/kvmd/plugins/hid/__init__.py +++ b/kvmd/plugins/hid/__init__.py @@ -63,6 +63,9 @@ class BaseHid(BasePlugin): async def get_state(self) -> dict: raise NotImplementedError + async def trigger_state(self) -> None: + raise NotImplementedError + async def poll_state(self) -> AsyncGenerator[dict, None]: yield {} raise NotImplementedError diff --git a/kvmd/plugins/hid/_mcu/__init__.py b/kvmd/plugins/hid/_mcu/__init__.py index 53665fb2..e058fd6c 100644 --- a/kvmd/plugins/hid/_mcu/__init__.py +++ b/kvmd/plugins/hid/_mcu/__init__.py @@ -23,6 +23,7 @@ import multiprocessing import contextlib import queue +import copy import time from typing import Iterable @@ -232,14 +233,18 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many- **self._get_jiggler_state(), } + async def trigger_state(self) -> None: + self.__notifier.notify(1) + async def poll_state(self) -> AsyncGenerator[dict, None]: - prev_state: dict = {} + prev: dict = {} while True: - state = await self.get_state() - if state != prev_state: - yield state - prev_state = state - await self.__notifier.wait() + if (await self.__notifier.wait()) > 0: + prev = {} + new = await self.get_state() + if new != prev: + prev = copy.deepcopy(new) + yield new async def reset(self) -> None: self.__reset_required_event.set() diff --git a/kvmd/plugins/hid/bt/__init__.py b/kvmd/plugins/hid/bt/__init__.py index ece6b59b..bca8f9a5 100644 --- a/kvmd/plugins/hid/bt/__init__.py +++ b/kvmd/plugins/hid/bt/__init__.py @@ -21,6 +21,7 @@ import multiprocessing +import copy import time from typing import Iterable @@ -158,14 +159,18 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes **self._get_jiggler_state(), } + async def trigger_state(self) -> None: + self.__notifier.notify(1) + async def poll_state(self) -> AsyncGenerator[dict, None]: - prev_state: dict = {} + prev: dict = {} while True: - state = await self.get_state() - if state != prev_state: - yield state - prev_state = state - await self.__notifier.wait() + if (await self.__notifier.wait()) > 0: + prev = {} + new = await self.get_state() + if new != prev: + prev = copy.deepcopy(new) + yield new async def reset(self) -> None: self.clear_events() diff --git a/kvmd/plugins/hid/ch9329/__init__.py b/kvmd/plugins/hid/ch9329/__init__.py index 3245505d..f93be95c 100644 --- a/kvmd/plugins/hid/ch9329/__init__.py +++ b/kvmd/plugins/hid/ch9329/__init__.py @@ -22,6 +22,7 @@ import multiprocessing import queue +import copy import time from typing import Iterable @@ -119,14 +120,18 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst **self._get_jiggler_state(), } + async def trigger_state(self) -> None: + self.__notifier.notify(1) + async def poll_state(self) -> AsyncGenerator[dict, None]: - prev_state: dict = {} + prev: dict = {} while True: - state = await self.get_state() - if state != prev_state: - yield state - prev_state = state - await self.__notifier.wait() + if (await self.__notifier.wait()) > 0: + prev = {} + new = await self.get_state() + if new != prev: + prev = copy.deepcopy(new) + yield new async def reset(self) -> None: self.__reset_required_event.set() diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index 3516546d..7686ebdd 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -20,6 +20,8 @@ # ========================================================================== # +import copy + from typing import Iterable from typing import AsyncGenerator from typing import Any @@ -150,14 +152,18 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes **self._get_jiggler_state(), } + async def trigger_state(self) -> None: + self.__notifier.notify(1) + async def poll_state(self) -> AsyncGenerator[dict, None]: - prev_state: dict = {} + prev: dict = {} while True: - state = await self.get_state() - if state != prev_state: - yield state - prev_state = state - await self.__notifier.wait() + if (await self.__notifier.wait()) > 0: + prev = {} + new = await self.get_state() + if new != prev: + prev = copy.deepcopy(new) + yield new async def reset(self) -> None: self.__keyboard_proc.send_reset_event() diff --git a/kvmd/plugins/msd/__init__.py b/kvmd/plugins/msd/__init__.py index e0210921..11cd8be5 100644 --- a/kvmd/plugins/msd/__init__.py +++ b/kvmd/plugins/msd/__init__.py @@ -117,6 +117,9 @@ class BaseMsd(BasePlugin): async def get_state(self) -> dict: raise NotImplementedError() + async def trigger_state(self) -> None: + raise NotImplementedError() + async def poll_state(self) -> AsyncGenerator[dict, None]: if self is not None: # XXX: Vulture and pylint hack raise NotImplementedError() diff --git a/kvmd/plugins/msd/disabled.py b/kvmd/plugins/msd/disabled.py index ad49875e..b9f14f6e 100644 --- a/kvmd/plugins/msd/disabled.py +++ b/kvmd/plugins/msd/disabled.py @@ -40,6 +40,9 @@ class MsdDisabledError(MsdOperationError): # ===== class Plugin(BaseMsd): + def __init__(self) -> None: + self.__notifier = aiotools.AioNotifier() + async def get_state(self) -> dict: return { "enabled": False, @@ -49,10 +52,13 @@ class Plugin(BaseMsd): "drive": None, } + async def trigger_state(self) -> None: + self.__notifier.notify() + async def poll_state(self) -> AsyncGenerator[dict, None]: while True: + await self.__notifier.wait() yield (await self.get_state()) - await aiotools.wait_infinite() async def reset(self) -> None: raise MsdDisabledError() diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index b652cdd0..0bb9f489 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -24,6 +24,7 @@ import asyncio import contextlib import dataclasses import functools +import copy import time from typing import AsyncGenerator @@ -195,14 +196,18 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes "drive": vd, } + async def trigger_state(self) -> None: + self.__notifier.notify(1) + async def poll_state(self) -> AsyncGenerator[dict, None]: - prev_state: dict = {} + prev: dict = {} while True: - state = await self.get_state() - if state != prev_state: - yield state - prev_state = state - await self.__notifier.wait() + if (await self.__notifier.wait()) > 0: + prev = {} + new = await self.get_state() + if new != prev: + prev = copy.deepcopy(new) + yield new async def systask(self) -> None: await self.__watch_inotify() |