ó
æ\c           @   s   d  d l  m Z d  d l Td d l Z d d l m Z d d l Z d d l Z d d l	 Z	 e j
 j   Z e   Z d e j f d     YZ d S(   i   (   t   base(   t   *iĸĸĸĸN(   t   commandst   AudioPluginc           B   sđ   e  Z d  Z d   Z d   Z d   Z d   Z e d    Z d   Z	 d   Z
 e d d	 e d
    Z e d  e d   Z e d d	 e d    Z e d  e d   Z RS(   sŪ   
	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   sy   t  |  _ t   |  _ t   |  _ xQ |  j j d  j d  D]4 } |  j |  } | d k r= |  j j	 |  q= q= Wd  S(   Nt   sounds   card*t   snd_hda_intelt   snd_ac97_codec(   R   R   (
   t   Truet   _devices_supportedt   sett   _assigned_devicest   _free_devicest   _hardware_inventoryt   get_devicest   match_sys_namet   _device_module_namet   add(   t   selft   devicet   module_name(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _init_devices   s    	"c         C   s   t  | _ t | _ d  S(   N(   R   t   _has_static_tuningt   Falset   _has_dynamic_tuning(   R   t   instance(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _instance_init   s    	c         C   s   d  S(   N(    (   R   R   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _instance_cleanup#   s    c         C   s   y | j  j SWn d  SXd  S(   N(   t   parentt   drivert   None(   R   R   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyR   &   s    c         C   s   i d d 6t  d 6S(   Ni    t   timeoutt   reset_controller(   R   (   t   cls(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _get_config_options,   s    c         C   s   d | S(   Ns$   /sys/module/%s/parameters/power_save(    (   R   R   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _timeout_path3   s    c         C   s   d | S(   Ns/   /sys/module/%s/parameters/power_save_controller(    (   R   R   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _reset_controller_path6   s    R   t
   per_devicec         C   sz   y t  |  } Wn# t k
 r5 t j d |  d  SX| d k rr |  j |  } | sn t j | d |  n  | Sd  Sd  S(   Ns!   timeout value '%s' is not integeri    s   %d(   t   intt
   ValueErrort   logt   errorR   R"   t   cmdt   write_to_file(   R   t   valueR   t   simR   t   sys_file(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _set_timeout9   s    c         C   s>   |  j  |  } t j | d | } t |  d k r: | Sd  S(   Nt   no_errori    (   R"   R)   t	   read_filet   lenR   (   R   R   t   ignore_missingR-   R+   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _get_timeoutH   s
    R   c         C   sQ   t  j |  } |  j |  } t j j |  rM | sI t  j | |  n  | Sd  S(   N(   R)   t   get_boolR#   t   ost   patht   existsR*   R   (   R   R+   R   R,   t   vR-   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _set_reset_controllerP   s    c         C   sV   |  j  |  } t j j |  rR t j |  } t |  d k rR t j |  Sn  d  S(   Ni    (	   R#   R5   R6   R7   R)   R0   R1   R4   R   (   R   R   R2   R-   R+   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   _get_reset_controllerZ   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   t   classmethodR!   R"   R#   t   command_setR   R.   t   command_getR   R3   R9   R:   (    (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyR      s   	
						
	(   t    R    t
   decoratorst
   tuned.logst   tunedt   tuned.utils.commandsR   R5   t   structt   globt   logst   getR'   R)   t   PluginR   (    (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.pyt   <module>   s   
	