]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/interfaces/IClipboard.py
drivers: Allocate binder nodes dynamically
[waydroid.git] / tools / interfaces / IClipboard.py
1 import gbinder
2 import logging
3 from tools import helpers
4 from gi.repository import GLib
5
6
7 INTERFACE = "lineageos.waydroid.IClipboard"
8 SERVICE_NAME = "waydroidclipboard"
9
10 TRANSACTION_sendClipboardData = 1
11 TRANSACTION_getClipboardData = 2
12
13 def add_service(args, sendClipboardData, getClipboardData):
14 helpers.drivers.loadBinderNodes(args)
15 serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER)
16
17 def response_handler(req, code, flags):
18 logging.debug(
19 "{}: Received transaction: {}".format(SERVICE_NAME, code))
20 reader = req.init_reader()
21 local_response = response.new_reply()
22 if code == TRANSACTION_sendClipboardData:
23 arg1 = reader.read_string16()
24 sendClipboardData(arg1)
25 local_response.append_int32(0)
26 if code == TRANSACTION_getClipboardData:
27 ret = getClipboardData()
28 local_response.append_int32(0)
29 local_response.append_string16(ret)
30
31 return local_response, 0
32
33 def binder_presence():
34 if serviceManager.is_present():
35 status = serviceManager.add_service_sync(SERVICE_NAME, response)
36
37 if status:
38 logging.error("Failed to add service {}: {}".format(
39 SERVICE_NAME, status))
40 args.clipboardLoop.quit()
41
42 response = serviceManager.new_local_object(INTERFACE, response_handler)
43 args.clipboardLoop = GLib.MainLoop()
44 binder_presence()
45 status = serviceManager.add_presence_handler(binder_presence)
46 if status:
47 args.clipboardLoop.run()
48 serviceManager.remove_handler(status)
49 del serviceManager
50 else:
51 logging.error("Failed to add presence handler: {}".format(status))