Your IP : 3.145.170.164
3
�<�e� � @ sn d dl mZ d dlT ddlZddlmZ ddlZddlZddl Z ddl
Z
ejj� Z
e� ZG dd� dej�ZdS )� )�hotplug)�*� N)�commandsc @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zed
d� �Z dd
� Z
dd� Zeddd�dd� �Z
ed�ddd��Zeddd�dd� �Zed�ddd��ZdS ) �AudioPlugina�
`audio`::
Sets audio cards power saving options. The plug-in sets the auto suspend
timeout for audio codecs to the value specified by the [option]`timeout`
option.
+
Currently, the `snd_hda_intel` and `snd_ac97_codec` codecs are
supported and the [option]`timeout` value is in seconds. To disable
auto suspend for these codecs, set the [option]`timeout` value
to `0`. To enforce the controller reset, set the option
[option]`reset_controller` to `true`. Note that power management
is supported per module. Hence, the kernel module names are used as
device names.
+
.Set the timeout value to 10s and enforce the controller reset
====
----
[audio]
timeout=10
reset_controller=true
----
====
c C sT d| _ t� | _t� | _x8| jjd�jd�D ]"}| j|�}|dkr*| jj|� q*W d S )NTZsoundzcard*�
snd_hda_intel�snd_ac97_codec)r r ) Z_devices_supported�setZ_assigned_devicesZ
_free_devicesZ_hardware_inventoryZget_devicesZmatch_sys_name�_device_module_name�add)�self�deviceZmodule_name� r �"/usr/lib/python3.6/plugin_audio.py�
_init_devices( s
zAudioPlugin._init_devicesc C s d|_ d|_d S )NTF)Z_has_static_tuningZ_has_dynamic_tuning)r �instancer r r �_instance_init2 s zAudioPlugin._instance_initc C s d S )Nr )r r r r r �_instance_cleanup6 s zAudioPlugin._instance_cleanupc C s y|j jS d S d S )N)�parentZdriver)r r
r r r r
9 s zAudioPlugin._device_module_namec C s
ddd�S )Nr F)�timeout�reset_controllerr )�clsr r r �_get_config_options? s zAudioPlugin._get_config_optionsc C s d| S )Nz$/sys/module/%s/parameters/power_saver )r r
r r r �
_timeout_pathF s zAudioPlugin._timeout_pathc C s d| S )Nz//sys/module/%s/parameters/power_save_controllerr )r r
r r r �_reset_controller_pathI s z"AudioPlugin._reset_controller_pathr T)Z
per_devicec
C sr yt |�}W n" tk
r. tjd| � d S X |dkrj| j|�}|sftj|d| |r^tjgndd� |S d S d S )Nz!timeout value '%s' is not integerr z%dF)�no_error) �int�
ValueError�log�errorr �cmd�
write_to_file�errno�ENOENT)r �valuer
�sim�remover �sys_filer r r �_set_timeoutL s
zAudioPlugin._set_timeoutFc C s, | j |�}tj||d�}t|�dkr(|S d S )N)r r )r r � read_file�len)r r
�ignore_missingr'