]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/helpers/ipc.py
Disable overlays if mounting fails once
[waydroid.git] / tools / helpers / ipc.py
index fbf522f180a707422f4d52f634c23eb6ff13add4..aa620615bfcae0a2e1e4e01fd110adc2fb0d7541 100644 (file)
@@ -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)