X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/8a9fdcac1ccddf56147f9cc34f42514b2384a5bd..2fa63fdef4ed773f30b5166662fb5bc7ca87d8df:/tools/helpers/ipc.py diff --git a/tools/helpers/ipc.py b/tools/helpers/ipc.py index fbf522f..2ea28e1 100644 --- a/tools/helpers/ipc.py +++ b/tools/helpers/ipc.py @@ -6,21 +6,32 @@ import os BASE_DIR = "/var/run/" -def listen(channel): - pipe = BASE_DIR + "waydroid-" + channel - if not os.path.exists(pipe): - os.mkfifo(pipe) - with open(pipe) as fifo: +def pipe_for(channel): + return BASE_DIR + "waydroid-" + channel + +def read_one(channel): + with open_channel(channel, "r", 1) as fifo: while True: data = fifo.read() if len(data) != 0: return data +def create_channel(channel): + pipe = pipe_for(channel) + if not os.path.exists(pipe): + os.mkfifo(pipe) + +def open_channel(channel, mode, buffering=0): + return open(pipe_for(channel), mode, buffering) + def notify(channel, msg): - pipe = BASE_DIR + "waydroid-" + channel try: - fd = os.open(pipe, os.O_WRONLY | os.O_NONBLOCK) + fd = os.open(pipe_for(channel), os.O_WRONLY | os.O_NONBLOCK) with os.fdopen(fd, "w") as fifo: fifo.write(msg) except Exception: pass + +def notify_blocking(channel, msg): + with open_channel(channel, "w", 1) as channel: + channel.write(msg)