55from .exitable import ExitableWithAliases
66from functools import partial
77from .method_call_context import MethodCallContext
8+ from . import unixfd
89import logging
910
1011try :
@@ -18,10 +19,12 @@ class ObjectWrapper(ExitableWithAliases("unwrap")):
1819 def __init__ (self , object , interfaces ):
1920 self .object = object
2021
22+ self .inargs = {}
2123 self .outargs = {}
2224 for iface in interfaces :
2325 for method in iface .methods :
2426 self .outargs [iface .name + "." + method .name ] = [arg .signature for arg in method .out_args ]
27+ self .inargs [iface .name + "." + method .name ] = [arg .signature for arg in method .in_args ]
2528
2629 self .readable_properties = {}
2730 self .writable_properties = {}
@@ -54,19 +57,23 @@ def onPropertiesChanged(iface, changed, invalidated):
5457 def call_method (self , connection , sender , object_path , interface_name , method_name , parameters , invocation ):
5558 try :
5659 try :
60+ inargs = self .inargs [interface_name + "." + method_name ]
5761 outargs = self .outargs [interface_name + "." + method_name ]
5862 method = getattr (self .object , method_name )
5963 except KeyError :
6064 if interface_name == "org.freedesktop.DBus.Properties" :
6165 if method_name == "Get" :
6266 method = self .Get
6367 outargs = ["v" ]
68+ inargs = ["ss" ]
6469 elif method_name == "GetAll" :
6570 method = self .GetAll
6671 outargs = ["a{sv}" ]
72+ inargs = ["s" ]
6773 elif method_name == "Set" :
6874 method = self .Set
6975 outargs = []
76+ inargs = ["ssv" ]
7077 else :
7178 raise
7279 else :
@@ -78,14 +85,23 @@ def call_method(self, connection, sender, object_path, interface_name, method_na
7885 if "dbus_context" in sig .parameters and sig .parameters ["dbus_context" ].kind in (Parameter .POSITIONAL_OR_KEYWORD , Parameter .KEYWORD_ONLY ):
7986 kwargs ["dbus_context" ] = MethodCallContext (invocation )
8087
88+ if unixfd .is_supported (connection ):
89+ parameters = unixfd .extract (
90+ parameters ,
91+ inargs ,
92+ invocation .get_message ().get_unix_fd_list ())
93+
8194 result = method (* parameters , ** kwargs )
8295
8396 if len (outargs ) == 0 :
8497 invocation .return_value (None )
85- elif len (outargs ) == 1 :
86- invocation .return_value (GLib .Variant ("(" + "" .join (outargs ) + ")" , (result ,)))
8798 else :
88- invocation .return_value (GLib .Variant ("(" + "" .join (outargs ) + ")" , result ))
99+ if len (outargs ) == 1 :
100+ result = (result , )
101+ if unixfd .is_supported (connection ):
102+ invocation .return_value_with_unix_fd_list (GLib .Variant ("(" + "" .join (outargs ) + ")" , result ), unixfd .make_fd_list (result , outargs , steal = True ))
103+ else :
104+ invocation .return_value (GLib .Variant ("(" + "" .join (outargs ) + ")" , result ))
89105
90106 except Exception as e :
91107 logger = logging .getLogger (__name__ )
@@ -151,6 +167,5 @@ def register_object(self, path, object, node_info):
151167
152168 node_info = [Gio .DBusNodeInfo .new_for_xml (ni ) for ni in node_info ]
153169 interfaces = sum ((ni .interfaces for ni in node_info ), [])
154-
155170 wrapper = ObjectWrapper (object , interfaces )
156171 return ObjectRegistration (self , path , interfaces , wrapper , own_wrapper = True )
0 commit comments