
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
À<×eW  ã               @   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dCd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<d=„ Z d>d?„ Z!d@dA„ Z"dBS )Dr   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)ÚselfZbus_nameZinterface_nameZobject_nameÚdebug© r   ú%/usr/lib/python3.6/dbus_controller.pyÚ__init__   s    zDBusController.__init__c             C   sv   yP| j d krNtdd� tjƒ | _tjƒ }|j| j| j	ƒ| _ tj
| j | jd�| _W n  tjjk
rp   tdƒ‚Y nX d S )NT)Zset_as_default)Zdbus_interfacez>Cannot talk to TuneD daemon via DBus. Is TuneD daemon running?)r   r   r   ZMainLoopr   ÚdbusZ	SystemBusZ
get_objectr   r
   Z	Interfacer	   r   Ú
exceptionsÚDBusExceptionr   )r   Zbusr   r   r   Ú_init_proxy   s    


zDBusController._init_proxyc             C   sŒ   | j d k	rPy| j | j| jŽ| _W n. tk
rN } z|| _d| _W Y d d }~X nX | jr~| jd k	rp| j| j| j	Ž | j
jƒ  dS tjdƒ dS )NTFr   )r   Ú_action_argsÚ_action_kwargsZ_action_exit_coder   r   r   r   Ú_on_exit_action_argsÚ_on_exit_action_kwargsr   ÚquitÚtimeZsleep)r   Úer   r   r   Ú_idle$   s    



zDBusController._idlec             O   s   || _ || _|| _d S )N)r   r   r    )r   ÚactionÚargsÚkwargsr   r   r   Úset_on_exit_action7   s    z!DBusController.set_on_exit_actionc             O   s   || _ || _|| _d S )N)r   r   r   )r   r%   r&   r'   r   r   r   Ú
set_action<   s    zDBusController.set_actionc             C   s2   d | _ tj| jƒ | jjƒ  | j d k	r,| j ‚| jS )N)r   r   Zidle_addr$   r   Úrunr   )r   r   r   r   r*   A   s    

zDBusController.runc             O   sp   | j ƒ  y| jj|ƒ}||ddiŽS  tjjk
rj } z(d}| jrR|dt|ƒ 7 }t|ƒ‚W Y d d }~X nX d S )NÚtimeouté(   z DBus call to TuneD daemon failedz (%s))	r   r   Zget_dbus_methodr   r   r   r   Ústrr   )r   Zmethod_namer&   r'   ÚmethodZdbus_exceptionZerr_strr   r   r   Ú_callJ   s    zDBusController._callc             C   s   | j ƒ  | jj||ƒ d S )N)r   r   Zconnect_to_signal)r   ÚsignalÚcbr   r   r   Úset_signal_handlerV   s    z!DBusController.set_signal_handlerc             C   s
   | j dƒS )NÚ
is_running)r/   )r   r   r   r   r3   Z   s    zDBusController.is_runningc             C   s
   | j dƒS )NÚstart)r/   )r   r   r   r   r4   ]   s    zDBusController.startc             C   s
   | j dƒS )NÚstop)r/   )r   r   r   r   r5   `   s    zDBusController.stopc             C   s
   | j dƒS )NÚprofiles)r/   )r   r   r   r   r6   c   s    zDBusController.profilesc             C   s
   | j dƒS )NÚ	profiles2)r/   )r   r   r   r   r7   f   s    zDBusController.profiles2c             C   s   | j d|ƒS )NÚprofile_info)r/   )r   Zprofile_namer   r   r   r8   i   s    zDBusController.profile_infoc             C   s   | j d||ƒS )NÚlog_capture_start)r/   )r   Z	log_levelr+   r   r   r   r9   l   s    z DBusController.log_capture_startc             C   s   | j d|ƒS )NÚlog_capture_finish)r/   )r   Útokenr   r   r   r:   o   s    z!DBusController.log_capture_finishc             C   s
   | j dƒS )NÚactive_profile)r/   )r   r   r   r   r<   r   s    zDBusController.active_profilec             C   s
   | j dƒS )NÚprofile_mode)r/   )r   r   r   r   r=   u   s    zDBusController.profile_modec             C   s
   | j dƒS )NÚpost_loaded_profile)r/   )r   r   r   r   r>   x   s    z"DBusController.post_loaded_profilec             C   s   |dkrdS | j d|ƒS )NÚ FúNo profile specifiedÚswitch_profile)Fr@   )r/   )r   Znew_profiler   r   r   rA   {   s    zDBusController.switch_profilec             C   s
   | j dƒS )NÚauto_profile)r/   )r   r   r   r   rB   €   s    zDBusController.auto_profilec             C   s
   | j dƒS )NÚrecommend_profile)r/   )r   r   r   r   rC   ƒ   s    z DBusController.recommend_profilec             C   s
   | j dƒS )NÚverify_profile)r/   )r   r   r   r   rD   †   s    zDBusController.verify_profilec             C   s
   | j dƒS )NÚverify_profile_ignore_missing)r/   )r   r   r   r   rE   ‰   s    z,DBusController.verify_profile_ignore_missingc             C   s
   | j dƒS )NÚdisable)r/   )r   r   r   r   ÚoffŒ   s    zDBusController.offc             C   s
   | j dƒS )zzReturn dict with plugin names and their hints

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		Zget_all_plugins)r/   )r   r   r   r   Úget_plugins�   s    zDBusController.get_pluginsc             C   s   | j d|ƒS )z"Return docstring of plugin's classÚget_plugin_documentation)r/   )r   Úplugin_namer   r   r   rI   —   s    z'DBusController.get_plugin_documentationc             C   s   | j d|ƒS )zŸReturn dictionary with parameters of plugin and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		Úget_plugin_hints)r/   )r   rJ   r   r   r   rK   ›   s    	zDBusController.get_plugin_hintsc             C   s   | j d||ƒS )NÚinstance_acquire_devices)r/   )r   ZdevicesÚinstancer   r   r   rL   ¦   s    z'DBusController.instance_acquire_devicesc             C   s   | j d|ƒS )NÚget_instances)r/   )r   rJ   r   r   r   rN   ©   s    zDBusController.get_instancesc             C   s   | j d|ƒS )NÚinstance_get_devices)r/   )r   rM   r   r   r   rO   ¬   s    z#DBusController.instance_get_devicesc             C   s   | j d ƒ || _d| _|S )NT)r)   r   r   )r   Úretr   r   r   Úexit¯   s    
zDBusController.exitN)F)#Ú__name__Ú
__module__Ú__qualname__r   r   r$   r(   r)   r*   r/   r2   r3   r4   r5   r6   r7   r8   r9   r:   r<   r=   r>   rA   rB   rC   rD   rE   rG   rH   rI   rK   rL   rN   rO   rQ   r   r   r   r   r   
   s@   
	)r   Zdbus.exceptionsr"   Zdbus.mainloop.glibr   Zgi.repositoryr   r   r   r   Ú__all__Úobjectr   r   r   r   r   Ú<module>   s   