o
    _                     @   sZ   d dl Z d dlZ d dlZd dlmZ d dlmZmZ ddlm	Z	 dgZ
G dd deZdS )    N)DBusGMainLoop)GLibGObject   )TunedAdminDBusExceptionDBusControllerc                   @   s   e Zd Zd=ddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<S )>r   Fc                 C   sL   || _ || _|| _d | _d | _|| _d | _d | _d | _d| _	d| _
d | _d S )NTF)	_bus_name_interface_name_object_name_proxy
_interface_debug
_main_loop_action_on_exit_action_ret_exit
_exception)selfbus_nameinterface_nameobject_namedebug r   =/usr/lib/python3/dist-packages/tuned/admin/dbus_controller.py__init__   s   
zDBusController.__init__c                 C   st   z,| j d u r*tdd t | _t }|| j| j	| _ tj
| j | jd| _W d S W d S  tjjy9   tdw )NT)set_as_default)dbus_interfacez>Cannot talk to Tuned daemon via DBus. Is Tuned daemon running?)r   r   r   MainLoopr   dbus	SystemBus
get_objectr   r
   	Interfacer	   r   
exceptionsDBusExceptionr   )r   busr   r   r   _init_proxy   s   


zDBusController._init_proxyc              
   C   s   | j d ur+z| j | ji | j| _W n ty* } z|| _d| _W Y d }~nd }~ww | jrD| jd ur=| j| ji | j	 | j
  dS td dS )NTFr   )r   _action_args_action_kwargs_action_exit_coder   r   r   r   _on_exit_action_args_on_exit_action_kwargsr   quittimesleep)r   er   r   r   _idle$   s"   




zDBusController._idlec                 O      || _ || _|| _d S N)r   r*   r+   r   actionargskwargsr   r   r   set_on_exit_action7      
z!DBusController.set_on_exit_actionc                 O   r1   r2   )r   r'   r(   r3   r   r   r   
set_action<   r8   zDBusController.set_actionc                 C   s2   d | _ t| j | j  | j d ur| j | jS r2   )r   r   idle_addr0   r   runr   r   r   r   r   r;   A   s   

zDBusController.runc              
   O   sd   |    z| j|}||ddiW S  tjjy1 } zd}| jr)|dt| 7 }t|d }~ww )Ntimeout(   z DBus call to Tuned daemon failedz (%s))	r&   r   get_dbus_methodr   r#   r$   r   strr   )r   method_namer5   r6   methoddbus_exceptionerr_strr   r   r   _callJ   s   zDBusController._callc                 C   s   |    | j|| d S r2   )r&   r   connect_to_signal)r   signalcbr   r   r   set_signal_handlerV   s   z!DBusController.set_signal_handlerc                 C   
   |  dS )N
is_runningrE   r<   r   r   r   rK   Z      
zDBusController.is_runningc                 C   rJ   )NstartrL   r<   r   r   r   rN   ]   rM   zDBusController.startc                 C   rJ   )NstoprL   r<   r   r   r   rO   `   rM   zDBusController.stopc                 C   rJ   )NprofilesrL   r<   r   r   r   rP   c   rM   zDBusController.profilesc                 C   rJ   )N	profiles2rL   r<   r   r   r   rQ   f   rM   zDBusController.profiles2c                 C      |  d|S )Nprofile_inforL   )r   profile_namer   r   r   rS   i      zDBusController.profile_infoc                 C   s   |  d||S )Nlog_capture_startrL   )r   	log_levelr=   r   r   r   rV   l   s   z DBusController.log_capture_startc                 C   rR   )Nlog_capture_finishrL   )r   tokenr   r   r   rX   o   rU   z!DBusController.log_capture_finishc                 C   rJ   )Nactive_profilerL   r<   r   r   r   rZ   r   rM   zDBusController.active_profilec                 C   rJ   )Nprofile_moderL   r<   r   r   r   r[   u   rM   zDBusController.profile_modec                 C   rJ   )Npost_loaded_profilerL   r<   r   r   r   r\   x   rM   z"DBusController.post_loaded_profilec                 C   s   |dkrdS |  d|S )N )FzNo profile specifiedswitch_profilerL   )r   new_profiler   r   r   r^   {   s   zDBusController.switch_profilec                 C   rJ   )Nauto_profilerL   r<   r   r   r   r`      rM   zDBusController.auto_profilec                 C   rJ   )Nrecommend_profilerL   r<   r   r   r   ra      rM   z DBusController.recommend_profilec                 C   rJ   )Nverify_profilerL   r<   r   r   r   rb      rM   zDBusController.verify_profilec                 C   rJ   )Nverify_profile_ignore_missingrL   r<   r   r   r   rc      rM   z,DBusController.verify_profile_ignore_missingc                 C   rJ   )NdisablerL   r<   r   r   r   off   rM   zDBusController.offc                 C   rJ   )zzReturn dict with plugin names and their hints

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		get_all_pluginsrL   r<   r   r   r   get_plugins   s   
zDBusController.get_pluginsc                 C   rR   )z"Return docstring of plugin's classget_plugin_documentationrL   r   plugin_namer   r   r   rh      s   z'DBusController.get_plugin_documentationc                 C   rR   )zReturn dictionary with parameters of plugin and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		get_plugin_hintsrL   ri   r   r   r   rk      s   	zDBusController.get_plugin_hintsc                 C   s   |  d  || _d| _|S )NT)r9   r   r   )r   retr   r   r   exit   s   
zDBusController.exitN)F) __name__
__module____qualname__r   r&   r0   r7   r9   r;   rE   rI   rK   rN   rO   rP   rQ   rS   rV   rX   rZ   r[   r\   r^   r`   ra   rb   rc   re   rg   rh   rk   rm   r   r   r   r   r   
   s<    
	)r   dbus.exceptionsr-   dbus.mainloop.glibr   gi.repositoryr   r   r#   r   __all__objectr   r   r   r   r   <module>   s    