From 2b9417707a6cac377e2caca047fde8169236d93e Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Tue, 18 Oct 2005 04:38:05 +0000 Subject: * glib/dbus-gvalue-utils.c (hash_free_from_gtype): handle gdouble and G_TYPE_VALUE_ARRAY (DBUS_TYPE_STRUCT) (gvalue_from_hash_value, hash_value_from_gvalue): handle gdouble * glib/dbus-gvalue.c (dbus_gvalue_to_signature): add missing DBUS_STRUCT_BEGIN_CHAR and DBUS_STRUCT_END_CHAR charaters when constructing struct signatures * python/_dbus.py (Bus): handle private connections using the private keyword in the constructor. defaults to private=False (Bus::close): new method to close a connection to the bus * python/dbus_bindings.pyx (Connection::close): renamed method was previously called disconnect (bus_get): now supports getting a private connection * python/proxies.py (ProxyMethod::__call__): check if ignore_reply keyword is set to True. if it is, execute the method without waiting for a reply (ProxyObject::_introspect_execute_queue): new method for executing all the pending methods that were waiting for the introspect to finish. this is called when introspect either succeeds or fails (ProxyObject::_introspect_error_handler): call queued methods --- python/_dbus.py | 31 +++++++++++++++++-------------- python/dbus_bindings.pyx | 16 ++++++++++------ python/proxies.py | 44 +++++++++++++++++++++++++------------------- 3 files changed, 52 insertions(+), 39 deletions(-) (limited to 'python') diff --git a/python/_dbus.py b/python/_dbus.py index 890cdda8..2e7e671b 100644 --- a/python/_dbus.py +++ b/python/_dbus.py @@ -67,8 +67,8 @@ class Bus: START_REPLY_SUCCESS = dbus_bindings.DBUS_START_REPLY_SUCCESS START_REPLY_ALREADY_RUNNING = dbus_bindings.DBUS_START_REPLY_ALREADY_RUNNING - def __init__(self, bus_type=TYPE_SESSION, use_default_mainloop=True): - self._connection = dbus_bindings.bus_get(bus_type) + def __init__(self, bus_type=TYPE_SESSION, use_default_mainloop=True, private=False): + self._connection = dbus_bindings.bus_get(bus_type, private) self._connection.add_filter(self._signal_func) self._match_rule_tree = SignalMatchTree() @@ -78,25 +78,28 @@ class Bus: if func != None: func(self) + def close(self): + self._connection.close() + def get_connection(self): return self._connection - def get_session(): + def get_session(private=False): """Static method that returns the session bus""" - return SessionBus() + return SessionBus(private) get_session = staticmethod(get_session) - def get_system(): + def get_system(private=False): """Static method that returns the system bus""" - return SystemBus() + return SystemBus(private) get_system = staticmethod(get_system) - def get_starter(): + def get_starter(private=False): """Static method that returns the starter bus""" - return StarterBus() + return StarterBus(private) get_starter = staticmethod(get_starter) @@ -196,21 +199,21 @@ class Bus: class SystemBus(Bus): """The system-wide message bus """ - def __init__(self): - Bus.__init__(self, Bus.TYPE_SYSTEM) + def __init__(self, use_default_mainloop=True, private=False): + Bus.__init__(self, Bus.TYPE_SYSTEM, use_default_mainloop, private) class SessionBus(Bus): """The session (current login) message bus """ - def __init__(self): - Bus.__init__(self, Bus.TYPE_SESSION) + def __init__(self, use_default_mainloop=True, private=False): + Bus.__init__(self, Bus.TYPE_SESSION, use_default_mainloop, private) class StarterBus(Bus): """The bus that activated this process (if this process was launched by DBus activation) """ - def __init__(self): - Bus.__init__(self, Bus.TYPE_STARTER) + def __init__(self, use_default_mainloop=True, private=False): + Bus.__init__(self, Bus.TYPE_STARTER, use_default_mainloop, private) class Interface: """An inteface into a remote object diff --git a/python/dbus_bindings.pyx b/python/dbus_bindings.pyx index 35ad492b..f7c88006 100644 --- a/python/dbus_bindings.pyx +++ b/python/dbus_bindings.pyx @@ -278,8 +278,8 @@ cdef class Connection: def get_unique_name(self): return bus_get_unique_name(self) - def disconnect(self): - dbus_connection_disconnect(self.conn) + def close(self): + dbus_connection_close(self.conn) def get_is_connected(self): return dbus_connection_get_is_connected(self.conn) @@ -1638,14 +1638,18 @@ BUS_SESSION = DBUS_BUS_SESSION BUS_SYSTEM = DBUS_BUS_SYSTEM BUS_STARTER = DBUS_BUS_STARTER -def bus_get (bus_type): +def bus_get (bus_type, private=False): cdef DBusError error cdef Connection conn - dbus_error_init(&error) cdef DBusConnection *connection - connection = dbus_bus_get(bus_type, - &error) + dbus_error_init(&error) + if private: + connection = dbus_bus_get_private(bus_type, + &error) + else: + connection = dbus_bus_get(bus_type, + &error) if dbus_error_is_set(&error): errormsg = error.message diff --git a/python/proxies.py b/python/proxies.py index ee2a3f7e..efa2b501 100644 --- a/python/proxies.py +++ b/python/proxies.py @@ -46,6 +46,10 @@ class ProxyMethod: if keywords.has_key('error_handler'): error_handler = keywords['error_handler'] + ignore_reply = False + if keywords.has_key('ignore_reply'): + ignore_reply = keywords['ignore_reply'] + if not(reply_handler and error_handler): if reply_handler: raise MissingErrorHandlerException() @@ -65,8 +69,11 @@ class ProxyMethod: iter.append_strict(arg, sig) else: iter.append(arg) - - if reply_handler: + + if ignore_reply: + result = self._connection.send(message) + args_tuple = (result,) + elif reply_handler: result = self._connection.send_with_reply_handlers(message, timeout, reply_handler, error_handler) args_tuple = result else: @@ -94,8 +101,6 @@ class ProxyObject: INTROSPECT_STATE_INTROSPECT_IN_PROGRESS = 1 INTROSPECT_STATE_INTROSPECT_DONE = 2 - #TODO: default introspect to False right now because it is not done yet - # make sure to default to True later def __init__(self, bus, named_service, object_path, introspect=True): self._bus = bus self._named_service = named_service @@ -132,20 +137,8 @@ class ProxyObject: self._introspect_reply_handler, self._introspect_error_handler) return result - - - - def _introspect_reply_handler(self, data): - try: - self._introspect_method_map = introspect_parser.process_introspection_data(data) - except IntrospectionParserException, e: - self._introspect_error_handler(e) - return - - self._introspect_state = self.INTROSPECT_STATE_INTROSPECT_DONE - - #TODO: we should actually call these even if introspection fails + def _introspect_execute_queue(self): for call in self._pending_introspect_queue: (member, iface, args, keywords) = call @@ -162,14 +155,27 @@ class ProxyObject: call_object = self.ProxyMethodClass(self._bus.get_connection(), self._named_service, - self._object_path, iface, member, + self._object_path, + iface, + member, introspect_sig) call_object(args, keywords) + def _introspect_reply_handler(self, data): + try: + self._introspect_method_map = introspect_parser.process_introspection_data(data) + except IntrospectionParserException, e: + self._introspect_error_handler(e) + return + + self._introspect_state = self.INTROSPECT_STATE_INTROSPECT_DONE + #self._introspect_execute_queue() + def _introspect_error_handler(self, error): self._introspect_state = self.INTROSPECT_STATE_DONT_INTROSPECT - sys.stderr.write(str(error)) + self._introspect_execute_queue() + sys.stderr.write("Introspect error: " + str(error) + "\n") def __getattr__(self, member, **keywords): if member == '__call__': -- cgit