o
    _	                     @   sf   d dl mZ d dlT ddlZddlmZ ddlZddlZddl	Z	ej
 Ze ZG dd dejZdS )   )base)*    N)commandsc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	dd Z
dd Zeddddd ZeddddZeddddd ZeddddZdS )AudioPluginz
	Plugin for tuning audio cards powersaving options.

	Power management is supported per module, not device. From this reason,
	we take kernel module names as device names.
	c                 C   sP   d| _ t | _t | _| jddD ]}| |}|dv r%| j| qd S )NTsoundzcard*)snd_hda_intelsnd_ac97_codec)	_devices_supportedset_assigned_devices_free_devices_hardware_inventoryget_devicesmatch_sys_name_device_module_nameadd)selfdevicemodule_name r   </usr/lib/python3/dist-packages/tuned/plugins/plugin_audio.py_init_devices   s   
zAudioPlugin._init_devicesc                 C   s   d|_ d|_d S )NTF)_has_static_tuning_has_dynamic_tuningr   instancer   r   r   _instance_init   s   
zAudioPlugin._instance_initc                 C   s   d S Nr   r   r   r   r   _instance_cleanup#   s   zAudioPlugin._instance_cleanupc                 C   s   z|j jW S    Y d S r   )parentdriverr   r   r   r   r   r   &   s   
zAudioPlugin._device_module_namec                 C   s
   dddS )Nr   F)timeoutreset_controllerr   )clsr   r   r   _get_config_options,   s   zAudioPlugin._get_config_optionsc                 C      d| S )Nz$/sys/module/%s/parameters/power_saver   r"   r   r   r   _timeout_path3      zAudioPlugin._timeout_pathc                 C   r'   )Nz//sys/module/%s/parameters/power_save_controllerr   r"   r   r   r   _reset_controller_path6   r)   z"AudioPlugin._reset_controller_pathr#   T)
per_devicec                 C   s^   zt |}W n ty   td|  Y d S w |dkr-| |}|s+t|d|  |S d S )Nz!timeout value '%s' is not integerr   z%d)int
ValueErrorlogerrorr(   cmdwrite_to_file)r   valuer   simr#   sys_filer   r   r   _set_timeout9   s   
zAudioPlugin._set_timeoutFc                 C   s,   |  |}tj||d}t|dkr|S d S )N)no_errorr   )r(   r0   	read_filelenr   r   ignore_missingr4   r2   r   r   r   _get_timeoutH   s
   
zAudioPlugin._get_timeoutr$   c                 C   s8   t |}| |}tj|r|st || |S d S r   )r0   get_boolr*   ospathexistsr1   )r   r2   r   r3   vr4   r   r   r   _set_reset_controllerP   s   

z!AudioPlugin._set_reset_controllerc                 C   s:   |  |}tj|rt|}t|dkrt|S d S )Nr   )r*   r=   r>   r?   r0   r7   r8   r<   r9   r   r   r   _get_reset_controllerZ   s   


z!AudioPlugin._get_reset_controllerN)F)__name__
__module____qualname____doc__r   r   r   r   classmethodr&   r(   r*   command_setr5   command_getr;   rA   rB   r   r   r   r   r      s$    





	r   ) r   
decorators
tuned.logstunedtuned.utils.commandsr   r=   structgloblogsgetr.   r0   Pluginr   r   r   r   r   <module>   s    
