%PDF- %PDF-
Direktori : /lib/python3/dist-packages/pyudev/__pycache__/ |
Current File : //lib/python3/dist-packages/pyudev/__pycache__/monitor.cpython-312.pyc |
� 9*�b R � � � d Z ddlZddlZddlmZ ddlmZ ddlmZm Z ddl mZmZ ddl mZ G d� d e� Z G d � de� Zy)z� pyudev.monitor ============== Monitor implementation. .. moduleauthor:: Sebastian Wiesner <lunaryorn@gmail.com> � N)�partial)�Thread)�pipe�poll)�eintr_retry_call�ensure_byte_string)�Devicec � � e Zd ZdZd� Zd� Zedd�� Zed� � Z d� Z dd�Zd � Zd � Z d� Zd� Zd � Zd� Zdd�Zd� Zd� Zy)�Monitorat A synchronous device event monitor. A :class:`Monitor` objects connects to the udev daemon and listens for changes to the device list. A monitor is created by connecting to the kernel daemon through netlink (see :meth:`from_netlink`): >>> from pyudev import Context, Monitor >>> context = Context() >>> monitor = Monitor.from_netlink(context) Once the monitor is created, you can add a filter using :meth:`filter_by()` or :meth:`filter_by_tag()` to drop incoming events in subsystems, which are not of interest to the application: >>> monitor.filter_by('input') When the monitor is eventually set up, you can either poll for events synchronously: >>> device = monitor.poll(timeout=3) >>> if device: ... print('{0.action}: {0}'.format(device)) ... Or you can monitor events asynchronously with :class:`MonitorObserver`. To integrate into various event processing frameworks, the monitor provides a :func:`selectable <select.select>` file description by :meth:`fileno()`. However, do *not* read or write directly on this file descriptor. Instances of this class can directly be given as ``udev_monitor *`` to functions wrapped through :mod:`ctypes`. .. versionchanged:: 0.16 Remove :meth:`from_socket()` which is deprecated, and even removed in recent udev versions. c �P � || _ || _ |j | _ d| _ y )NF)�context�_as_parameter_�_libudev�_started)�selfr � monitor_ps �0/usr/lib/python3/dist-packages/pyudev/monitor.py�__init__zMonitor.__init__N s% � ����'����(�(�� ��� � c �: � | j j | � y �N)r �udev_monitor_unref�r s r �__del__zMonitor.__del__T s � �� � �(�(��.r c � � |dvrt dj |� � �|j j |t |� � }|st d� � | ||� S )a� Create a monitor by connecting to the kernel daemon through netlink. ``context`` is the :class:`Context` to use. ``source`` is a string, describing the event source. Two sources are available: ``'udev'`` (the default) Events emitted after udev as registered and configured the device. This is the absolutely recommended source for applications. ``'kernel'`` Events emitted directly after the kernel has seen the device. The device has not yet been configured by udev and might not be usable at all. **Never** use this, unless you know what you are doing. Return a new :class:`Monitor` object, which is connected to the given source. Raise :exc:`~exceptions.ValueError`, if an invalid source has been specified. Raise :exc:`~exceptions.EnvironmentError`, if the creation of the monitor failed. )�kernel�udevz8Invalid source: {0!r}. Must be one of "udev" or "kernel"zCould not create udev monitor)� ValueError�formatr �udev_monitor_new_from_netlinkr �EnvironmentError)�clsr �source�monitors r �from_netlinkzMonitor.from_netlinkW si � �. �+�+���$�f�V�n�� � �"�"�@�@��'��/� �� �"�#B�C�C��7�G�$�$r c � � | j S )z� ``True``, if this monitor was started, ``False`` otherwise. Readonly. .. seealso:: :meth:`start()` .. versionadded:: 0.16 )r r s r �startedzMonitor.startedz s � � �}�}�r c �8 � | j j | � S )z� Return the file description associated with this monitor as integer. This is really a real file descriptor ;), which can be watched and :func:`select.select`\ ed. )r �udev_monitor_get_fdr s r �filenozMonitor.fileno� s � � �}�}�0�0��6�6r Nc � � t |� }|�t |� }| j j | ||� | j j | � y)a Filter incoming events. ``subsystem`` is a byte or unicode string with the name of a subsystem (e.g. ``'input'``). Only events originating from the given subsystem pass the filter and are handed to the caller. If given, ``device_type`` is a byte or unicode string specifying the device type. Only devices with the given device type are propagated to the caller. If ``device_type`` is not given, no additional filter for a specific device type is installed. These filters are executed inside the kernel, and client processes will usually not be woken up for device, that do not match these filters. .. versionchanged:: 0.15 This method can also be after :meth:`start()` now. N)r r �/udev_monitor_filter_add_match_subsystem_devtype�udev_monitor_filter_update)r � subsystem�device_types r � filter_byzMonitor.filter_by� sK � �( '�y�1� ��"�,�[�9�K�� � �E�E��)�[� � � � �0�0��6r c � � | j j | t |� � | j j | � y)aR Filter incoming events by the given ``tag``. ``tag`` is a byte or unicode string with the name of a tag. Only events for devices which have this tag attached pass the filter and are handed to the caller. Like with :meth:`filter_by` this filter is also executed inside the kernel, so that client processes are usually not woken up for devices without the given ``tag``. .. udevversion:: 154 .. versionadded:: 0.9 .. versionchanged:: 0.15 This method can also be after :meth:`start()` now. N)r �!udev_monitor_filter_add_match_tagr r- )r �tags r � filter_by_tagzMonitor.filter_by_tag� s1 � �&