summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-03-27 06:57:43 +0300
committerDevaev Maxim <[email protected]>2019-03-27 06:57:43 +0300
commit2acec3f229070539e1c199977d4ad5e19af76075 (patch)
tree8e1e800dfb55a701143eba7bdcd25eddd41c4f0f
parent68f28c69f30b1289ff55963d056c8baa232136b1 (diff)
api refactoring
-rw-r--r--kvmd/apps/kvmd/hid.py12
-rw-r--r--kvmd/apps/kvmd/msd.py13
-rw-r--r--kvmd/apps/kvmd/server.py4
-rw-r--r--web/share/js/kvm/keyboard.js6
-rw-r--r--web/share/js/kvm/mouse.js6
5 files changed, 23 insertions, 18 deletions
diff --git a/kvmd/apps/kvmd/hid.py b/kvmd/apps/kvmd/hid.py
index adf4f743..22d4acf3 100644
--- a/kvmd/apps/kvmd/hid.py
+++ b/kvmd/apps/kvmd/hid.py
@@ -141,7 +141,7 @@ class Hid(multiprocessing.Process): # pylint: disable=too-many-instance-attribu
self.__lock = asyncio.Lock()
self.__events_queue: multiprocessing.queues.Queue = multiprocessing.Queue()
- self.__ok_shared = multiprocessing.Value("i", 1)
+ self.__online_shared = multiprocessing.Value("i", 1)
self.__stop_event = multiprocessing.Event()
@@ -150,7 +150,7 @@ class Hid(multiprocessing.Process): # pylint: disable=too-many-instance-attribu
super().start()
def get_state(self) -> Dict:
- return {"ok": bool(self.__ok_shared.value)}
+ return {"online": bool(self.__online_shared.value)}
async def poll_state(self) -> AsyncGenerator[Dict, None]:
while self.is_alive():
@@ -290,23 +290,23 @@ class Hid(multiprocessing.Process): # pylint: disable=too-many-instance-attribu
logger.error("Got CRC error of request from HID: request=%r", request)
elif code == 0x45: # Unknown command
logger.error("HID did not recognize the request=%r", request)
- self.__ok_shared.value = 1
+ self.__online_shared.value = 1
return
elif code == 0x24: # Rebooted?
logger.error("No previous command state inside HID, seems it was rebooted")
- self.__ok_shared.value = 1
+ self.__online_shared.value = 1
return
elif code == 0x20: # Done
if error_occured:
logger.info("Success!")
- self.__ok_shared.value = 1
+ self.__online_shared.value = 1
return
else:
logger.error("Invalid response from HID: request=%r; code=0x%x", request, code)
common_retries -= 1
error_occured = True
- self.__ok_shared.value = 0
+ self.__online_shared.value = 0
if common_retries and read_retries:
logger.error("Retries left: common_retries=%d; read_retries=%d", common_retries, read_retries)
diff --git a/kvmd/apps/kvmd/msd.py b/kvmd/apps/kvmd/msd.py
index 8ae9d9be..6b7d894e 100644
--- a/kvmd/apps/kvmd/msd.py
+++ b/kvmd/apps/kvmd/msd.py
@@ -253,18 +253,19 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
logger.info("Mass-storage device is disabled")
def get_state(self) -> Dict:
+ online = (self._enabled and bool(self._device_path))
info = (self.__saved_device_info._asdict() if self.__saved_device_info else None)
- if info:
- info["hw"] = (info["hw"]._asdict() if info["hw"] else None)
- info["image"] = (info["image"]._asdict() if info["image"] else None)
-
connected_to: Optional[str] = None
- if self._enabled and self._device_path:
+
+ if online:
+ if info:
+ info["hw"] = (info["hw"]._asdict() if info["hw"] else None)
+ info["image"] = (info["image"]._asdict() if info["image"] else None)
connected_to = ("kvm" if self.__device_info else "server")
return {
"enabled": self._enabled,
- "online": (self._enabled and bool(self._device_path)),
+ "online": online,
"connected_to": connected_to,
"busy": bool(self.__device_file),
"written": self.__written,
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 3c84dbe2..fc701c94 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -443,6 +443,10 @@ class Server: # pylint: disable=too-many-instance-attributes
# ===== HID
+ @_exposed("GET", "/hid")
+ async def __hid_state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ return _json(self.__hid.get_state())
+
@_exposed("POST", "/hid/reset")
async def __hid_reset_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
await self.__hid.reset()
diff --git a/web/share/js/kvm/keyboard.js b/web/share/js/kvm/keyboard.js
index f15c2b53..189abb2c 100644
--- a/web/share/js/kvm/keyboard.js
+++ b/web/share/js/kvm/keyboard.js
@@ -26,7 +26,7 @@ function Keyboard() {
/************************************************************************/
var __ws = null;
- var __ok = true;
+ var __online = true;
var __keys = [].slice.call($$$("div#keyboard-desktop div.keyboard-block div.keyboard-row div.key"));
var __modifiers = [].slice.call($$$("div#keyboard-desktop div.keyboard-block div.keyboard-row div.modifier"));
@@ -77,7 +77,7 @@ function Keyboard() {
};
self.setState = function(state) {
- __ok = state.ok;
+ __online = state.online;
__updateLeds();
};
@@ -102,7 +102,7 @@ function Keyboard() {
var title = "Keyboard free";
if (__ws) {
- if (__ok) {
+ if (__online) {
if (is_captured) {
led = "led-green";
title = "Keyboard captured";
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js
index 905c7a5d..1b93e6ab 100644
--- a/web/share/js/kvm/mouse.js
+++ b/web/share/js/kvm/mouse.js
@@ -26,7 +26,7 @@ function Mouse() {
/************************************************************************/
var __ws = null;
- var __ok = true;
+ var __online = true;
var __current_pos = {x: 0, y:0};
var __sent_pos = {x: 0, y:0};
@@ -68,7 +68,7 @@ function Mouse() {
};
self.setState = function(state) {
- __ok = state.ok;
+ __online = state.online;
__updateLeds();
};
@@ -88,7 +88,7 @@ function Mouse() {
var title = "Mouse free";
if (__ws) {
- if (__ok) {
+ if (__online) {
if (is_captured) {
led = "led-green";
title = "Mouse captured";