a F `[@sddlZddlmZddlmZddlmZddlZeddddl m Z e e Z gdZGd d d eZGd d d eZGd ddeZdS)N)partial)DBUS_FLAG_NONE)SignalGioz2.0)r)DBusObserverError DBusObserverGLibMonitoringc@seZdZdZdS)rz'Exception class for the DBus observers.N)__name__ __module__ __qualname____doc__r r :/usr/lib/python3.9/site-packages/dasbus/client/observer.pyr(src@sHeZdZdZeeddfddZeddZeddZed d Z dS) rz4The low-level DBus monitoring library based on GLib.Nc CsTd}d}|rt|j|dfd}|r4t|j|dfd}t|||||}t|j||S)z,Watch a service name on the DBus connection.Nr ) user_data)r_name_appeared_callback_name_vanished_callbackrZbus_watch_name_on_connection _unwatch_name) cls connectionnameflagsZ name_appearedZ name_vanishedZname_appeared_closureZname_vanished_closureregistration_idr r r watch_name0s0zGLibMonitoring.watch_namecCs|\}}||g|RdS)zCallback for watch_name..Nr )rrrZ name_ownerrcallback callback_argsr r rrQsz&GLibMonitoring._name_appeared_callbackcCs|\}}||dS)zCallback for watch_name.Nr )rrrrrrr r rrZsz&GLibMonitoring._name_vanished_callbackcCst|dS)z5Stops watching a service name on the DBus connection.N)rZbus_unwatch_name)rrrr r rrcszGLibMonitoring._unwatch_name) r r r r classmethodrrrrrr r r rr-s   rc@seZdZdZefddZeddZeddZedd Z ed d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZd S)!ra4Base class for DBus observers. This class is recommended to use only to watch the availability of a service on DBus. It doesn't provide any support for accessing objects provided by the service. Usage: .. code-block:: python # Create the observer and connect to its signals. observer = DBusObserver(SystemBus, "org.freedesktop.NetworkManager") def callback1(observer): print("Service is available!") def callback2(observer): print("Service is unavailable!") observer.service_available.connect(callback1) observer.service_unavailable.connect(callback2) # Connect to the service once it is available. observer.connect_once_available() # Disconnect the observer. observer.disconnect() cCs2||_||_d|_t|_t|_||_g|_dS)zCreates a DBus service observer. :param message_bus: a message bus :param service_name: a DBus name of a service FN) _message_bus _service_name_is_service_availabler_service_available_service_unavailable _monitoring_subscriptions)selfZ message_bus service_nameZ monitoringr r r__init__szDBusObserver.__init__cCs|jS)zReturns a DBus name.rr#r r rr$szDBusObserver.service_namecCs|jS)zThe proxy can be accessed.)rr'r r ris_service_availablesz!DBusObserver.is_service_availablecCs|jS)zSignal that emits when the service is available. Signal emits this class as an argument. You have to call the watch method to activate the signals. )rr'r r rservice_availableszDBusObserver.service_availablecCs|jS)zSignal that emits when the service is unavailable. Signal emits this class as an argument. You have to call the watch method to activate the signals. )r r'r r rservice_unavailablesz DBusObserver.service_unavailablecCs |dS)zConnect to the service once it is available. The observer is not connected to the service until it emits the service_available signal. N)_watchr'r r rconnect_once_availablesz#DBusObserver.connect_once_availablecCs||jr|dS)zDisconnect from the service. Disconnect from the service if it is connected and stop watching its availability. N)_unwatchr(_disable_servicer'r r r disconnectszDBusObserver.disconnectcCs.|j|jj|jt|j|j}|j |dS)zWatch the service name on DBus.N) r!rrrr$r_service_name_appeared_callback_service_name_vanished_callbackr"append)r#Z subscriptionr r rr+szDBusObserver._watchcCs|jr|j}|qdS)z'Stop to watch the service name on DBus.N)r"pop)r#rr r rr-s zDBusObserver._unwatchcCsd|_|j|dS)zEnable the service.TN)rremitr'r r r_enable_serviceszDBusObserver._enable_servicecCsd|_|j|dS)zDisable the service.FN)rr r4r'r r rr.szDBusObserver._disable_servicecGs|js|dSzCallback for the watch method.N)r(r5r#argsr r rr0sz,DBusObserver._service_name_appeared_callbackcGs|jr|dSr6)r(r.r7r r rr1sz,DBusObserver._service_name_vanished_callbackcCs|jS)z(Returns a string version of this object.r&r'r r r__str__szDBusObserver.__str__cCsd|jj|jS)z Returns a string representation.z{}({}))format __class__r rr'r r r__repr__szDBusObserver.__repr__N)r r r r rr%propertyr$r(r)r*r,r/r+r-r5r.r0r1r9r<r r r rris(       r)Zlogging functoolsrZdasbus.constantsrZ dasbus.signalrZgiZrequire_versionZ gi.repositoryrZ getLoggerr log__all__ Exceptionrobjectrrr r r rs      <