mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-01-09 06:37:55 -05:00
panctl: Remove unneeded DbusT class.
This commit is contained in:
parent
6dd47e7a53
commit
46ff19ea3c
@ -14,8 +14,6 @@ from prompt_toolkit.completion import Completer, Completion
|
|||||||
import dbus
|
import dbus
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
from janus import Queue
|
|
||||||
from queue import Empty
|
|
||||||
|
|
||||||
DBusGMainLoop(set_as_default=True)
|
DBusGMainLoop(set_as_default=True)
|
||||||
|
|
||||||
@ -52,35 +50,8 @@ class PanCompleter(Completer):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
|
||||||
class DbusT:
|
|
||||||
loop = attr.ib()
|
|
||||||
receive_queue = attr.ib()
|
|
||||||
send_queue = attr.ib()
|
|
||||||
|
|
||||||
async def send(self, message):
|
|
||||||
self.receive_queue.async_q.put(message)
|
|
||||||
GLib.idle_add(self._message_callback)
|
|
||||||
|
|
||||||
def quit(self):
|
|
||||||
self.loop.quit()
|
|
||||||
|
|
||||||
def _message_callback(self):
|
|
||||||
print("Message")
|
|
||||||
try:
|
|
||||||
message = self.receive_queue.get_nowait()
|
|
||||||
except Empty:
|
|
||||||
return True
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def dbus_loop(self):
|
|
||||||
self.loop.run()
|
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class PanCtl:
|
class PanCtl:
|
||||||
bus_thread = attr.ib()
|
|
||||||
bus = attr.ib(init=False)
|
bus = attr.ib(init=False)
|
||||||
ctl = attr.ib(init=False)
|
ctl = attr.ib(init=False)
|
||||||
devices = attr.ib(init=False)
|
devices = attr.ib(init=False)
|
||||||
@ -257,21 +228,17 @@ class PanCtl:
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
main_queue = Queue()
|
|
||||||
glib_queue = Queue()
|
|
||||||
glib_loop = GLib.MainLoop()
|
glib_loop = GLib.MainLoop()
|
||||||
|
|
||||||
bus_thread = DbusT(glib_loop, main_queue.sync_q, glib_queue.sync_q)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
panctl = PanCtl(bus_thread)
|
panctl = PanCtl()
|
||||||
except dbus.exceptions.DBusException:
|
except dbus.exceptions.DBusException:
|
||||||
print("Error, no pantalaimon bus found")
|
print("Error, no pantalaimon bus found")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
fut = loop.run_in_executor(
|
fut = loop.run_in_executor(
|
||||||
None,
|
None,
|
||||||
bus_thread.dbus_loop
|
glib_loop.run
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -279,7 +246,7 @@ def main():
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
GLib.idle_add(bus_thread.quit)
|
GLib.idle_add(glib_loop.quit)
|
||||||
loop.run_until_complete(fut)
|
loop.run_until_complete(fut)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user