X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/8a9fdcac1ccddf56147f9cc34f42514b2384a5bd..094a4d970ccefa2e6409c8147c1edbdaaa74df0f:/tools/helpers/ipc.py diff --git a/tools/helpers/ipc.py b/tools/helpers/ipc.py index fbf522f..aa62061 100644 --- a/tools/helpers/ipc.py +++ b/tools/helpers/ipc.py @@ -3,24 +3,42 @@ # Currently implemented as FIFO import os +import dbus 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) + +def DBusContainerService(object_path="/ContainerManager", intf="id.waydro.ContainerManager"): + return dbus.Interface(dbus.SystemBus().get_object("id.waydro.Container", object_path), intf) + +def DBusSessionService(object_path="/SessionManager", intf="id.waydro.SessionManager"): + return dbus.Interface(dbus.SessionBus().get_object("id.waydro.Session", object_path), intf)