]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/ipc.py
app_manager: Factor out common function to start session then launch
[waydroid.git] / tools / helpers / ipc.py
1 # Copyright 2022 Alessandro Astone
2 # SPDX-License-Identifier: GPL-3.0-or-later
3
4 # Currently implemented as FIFO
5 import os
6
7 BASE_DIR = "/var/run/"
8
9 def listen(channel):
10 pipe = BASE_DIR + "waydroid-" + channel
11 if not os.path.exists(pipe):
12 os.mkfifo(pipe)
13 with open(pipe) as fifo:
14 while True:
15 data = fifo.read()
16 if len(data) != 0:
17 return data
18
19 def notify(channel, msg):
20 pipe = BASE_DIR + "waydroid-" + channel
21 try:
22 fd = os.open(pipe, os.O_WRONLY | os.O_NONBLOCK)
23 with os.fdopen(fd, "w") as fifo:
24 fifo.write(msg)
25 except Exception:
26 pass