-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe_server_ravelled
executable file
·69 lines (60 loc) · 1.77 KB
/
pipe_server_ravelled
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python3
#+
# DBussy example -- demonstrate how to pass file descriptors
# over D-Bus. This is the server side, which receives requests
# to create either a transmit or receive pipe matching a
# given key value. Two clients specifying the same key can
# then exchange messages over the pipe. See the accompanying
# pipe_client script for an example of how to communicate with
# this server.
#
# Copyright 2018 by Lawrence D'Oliveiro <ldo@geek-central.gen.nz>. This
# script is licensed CC0
# <https://creativecommons.org/publicdomain/zero/1.0/>; do with it
# what you will.
#-
import sys
import os
import signal
import dbussy as dbus
from dbussy import \
DBUS
import ravel
my_bus_name = "com.example.pipes"
my_iface_name = "com.example.pipes"
#+
# Interface
#-
pipes = {}
# created pipes, indexed by object path
@ravel.interface(ravel.INTERFACE.SERVER, name = my_iface_name)
class PipeServer :
@ravel.method \
(
name = "get",
in_signature = "b",
out_signature = "h",
path_keyword = "path",
arg_keys = ("writing",),
result_keyword = "result",
)
def handle_get(self, path, writing, result) :
if path not in pipes :
sys.stderr.write("Create pipes for %s\n" % repr(path)) # debug
read_side, write_side = os.pipe()
pipes[path] = (read_side, write_side)
#end if
result[0] = pipes[path][writing]
#end handle_get
#end PipeServer
signal.signal(signal.SIGINT, signal.SIG_DFL) # abort without raising KeyboardInterrupt on CTRL/C
bus = ravel.session_bus()
bus.attach_asyncio()
bus.request_name(bus_name = my_bus_name, flags = DBUS.NAME_FLAG_DO_NOT_QUEUE)
bus.register \
(
path = "/",
fallback = True,
interface = PipeServer()
)
bus.loop.run_forever()