a Á]›iŸ ã@snddlmZddlTddlZddlmZddlZddlZddl Z ddl Z ej   ¡Z eƒZGdd„dejƒZdS)é)Úhotplug)Ú*éN)Úcommandsc@s˜eZdZdZdd„Zdd„Zdd„Zdd „Zed d „ƒZ d d „Z dd„Z e ddd�dd„ƒZ edƒddd„ƒZe ddd�dd„ƒZedƒddd„ƒZdS) Ú AudioPlugina¹ 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 ---- ==== cCsPd|_tƒ|_tƒ|_|j d¡ d¡D]"}| |¡}|dvr(|j |¡q(dS)NTZsoundzcard*)Z snd_hda_intelZsnd_ac97_codec) Z_devices_supportedÚsetZ_assigned_devicesZ _free_devicesZ_hardware_inventoryZ get_devicesZmatch_sys_nameÚ_device_module_nameÚadd)ÚselfÚdeviceZ module_name©r ú>/usr/lib/python3.9/site-packages/tuned/plugins/plugin_audio.pyÚ _init_devices&s zAudioPlugin._init_devicescCsd|_d|_dS)NTF)Z_has_static_tuningZ_has_dynamic_tuning©r Úinstancer r r Ú_instance_init0szAudioPlugin._instance_initcCsdS©Nr rr r r Ú_instance_cleanup4szAudioPlugin._instance_cleanupcCsz |jjWSYdS0dSr)ÚparentZdriver©r r r r r r7s zAudioPlugin._device_module_namecCs dddœS)NrT)ÚtimeoutÚreset_controllerr )Úclsr r r Ú_get_config_options=sþzAudioPlugin._get_config_optionscCsd|S)Nz$/sys/module/%s/parameters/power_saver rr r r Ú _timeout_pathDszAudioPlugin._timeout_pathcCsd|S)Nz//sys/module/%s/parameters/power_save_controllerr rr r r Ú_reset_controller_pathGsz"AudioPlugin._reset_controller_pathrT)Z per_devicecCsrz t|ƒ}Wn"ty.t d|¡YdS0|dkrj| |¡}|sftj|d||r^tjgndd�|SdSdS)Nz!timeout value '%s' is not integerrz%dF©Zno_error) ÚintÚ ValueErrorÚlogÚerrorrÚcmdÚ write_to_fileÚerrnoÚENOENT)r Úvaluer rÚsimÚremoverÚsys_filer r r Ú _set_timeoutJs    ÿzAudioPlugin._set_timeoutFcCs,| |¡}tj||d�}t|ƒdkr(|SdS)Nrr)rr!Ú read_fileÚlen©r r rZignore_missingr(r%r r r Ú _get_timeoutZs   zAudioPlugin._get_timeoutrcCsHt |¡}| |¡}tj |¡rD|s@tj|||r8tjgndd�|SdS)NFr) r!Úget_boolrÚosÚpathÚexistsr"r#r$)r r%r rr&r'Úvr(r r r Ú_set_reset_controllerbs   ÿz!AudioPlugin._set_reset_controllercCs:| |¡}tj |¡r6t |¡}t|ƒdkr6t |¡SdS)Nr)rr/r0r1r!r*r+r.r,r r r Ú_get_reset_controllerms      z!AudioPlugin._get_reset_controllerN)F)F)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrÚ classmethodrrrZ command_setr)Z command_getr-r3r4r r r r rs"       r)ÚrZ decoratorsZ tuned.logsZtunedZtuned.utils.commandsrr/r#ÚstructÚglobZlogsÚgetrr!ZPluginrr r r r Ús