AlkantarClanX12

Your IP : 52.14.178.241


Current Path : /proc/self/root/lib/python3.6/site-packages/tuned/daemon/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/tuned/daemon/__pycache__/controller.cpython-36.pyc

3

�<�eu2�@s�ddlmZddlZddlZddlmZddlZddljZddlm	Z	dgZ
ejj�Z
Gdd�de�ZGdd�dejjj�ZdS)	�)�exportsN)�TunedException)�commands�
Controllerc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TimerStorecCst�|_tj�|_dS)N)�dict�_timers�	threadingZLock�_timers_lock)�self�r� /usr/lib/python3.6/controller.py�__init__szTimerStore.__init__c
Cs |j�||j|<WdQRXdS)N)r
r)r�token�timerrrr
�store_timerszTimerStore.store_timercCsB|j�2y|j|}|j�|j|=WnYnXWdQRXdS)N)r
r�cancel)rrrrrr
�
drop_timers
zTimerStore.drop_timerc	Cs<|j�,x|jj�D]}|j�qW|jj�WdQRXdS)N)r
r�valuesr�clear)rrrrr
�
cancel_allszTimerStore.cancel_allN)�__name__�
__module__�__qualname__rrrrrrrr
r
s	rcs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zej	d
�dd��Z
d
d�Zejdd�dUdd��Z
ejdd�dVdd��Zejdd�dWdd��ZdXdd�Zejdd�dYdd��Zejdd�dZdd ��Zd!d"�Zejdd#�d[d$d%��Zejdd#�d\d&d'��Zejdd�d]d(d)��Zejdd*�d^d+d,��Zejdd�d_d-d.��Zejdd�d`d/d0��Zejdd�dad1d2��Zejdd3�dbd4d5��Zejdd6�dcd7d8��Zejdd9�ddd:d;��Zejdd�ded<d=��Zejdd�dfd>d?��Zejdd�dgd@dA��Z ejddB�dhdCdD��Z!ejdd�didEdF��Z"ejddG�djdHdI��Z#ejdd�dkdJdK��Z$ejdLd#�dldMdN��Z%ejddO�dmdPdQ��Z&ejddR�dndSdT��Z'�Z(S)orz�
	Controller's purpose is to keep the program running, start/stop the tuning,
	and export the controller interface (currently only over D-Bus).
	cs8tt|�j�||_||_tj�|_t�|_	t
�|_dS)N)�superrr�_daemon�_global_configr	ZEvent�
_terminater�_cmdr�_timer_store)r�daemonZ
global_config)�	__class__rr
r+s
zController.__init__cCsxtjd�|j�}|jjtjtj�}|r6|r6tj�|rb|j	j
�x|jj|j	d�s`tj
�qFWtjd�|j�dS)z1
		Controller main loop. The call is blocking.
		zstarting controller�zterminating controllerN)�log�info�startr�get_bool�consts�
CFG_DAEMON�CFG_DEF_DAEMONrrrr�waitZperiod_check�stop)r�resr rrr
�run3s



zController.runcCs|jj�dS)N)r�set)rrrr
�	terminateFszController.terminatecCs0|jjj�s,|jjj�|j�s,|jjj�dS)N)rZ_sighup_processingZis_setr.�reloadr)rrrr
�sighupIszController.sighupZsbscCsdS)Nr)r�profile_name�resultZerrstrrrr
�profile_changedOszController.profile_changedcCstjj|�|jj|�dS)N)�tuned�logs�log_capture_finishrr)rrrrr
�_log_capture_abortXszController._log_capture_abortZii�sNcCsf|dkrdStjj|�}|dkr$dS|dkrVtj||j|gd�}|jj||�|j�|dkrbdS|S)N�r)�args)	r5r6�log_capture_startr	ZTimerr8rrr%)rZ	log_levelZtimeout�callerrrrrr
r<\szController.log_capture_startcCs4|dkrdStjj|�}|jj|�|dkr0dS|S)Nr:)r5r6r7rr)rrr=r,rrr
r7js
zController.log_capture_finishr:�bcCsD|dkrdS|jjtjtj�r:|jj�r,dS|jj�s:dS|jj�S)Nr:FT)	rr&r'r(r)r�
is_running�
is_enabledr%)rr=rrr
r%rs

zController.startFcCs,|jj�sd}n|jj|d�}|jj�|S)NT)�profile_switch)rr?r+rr)rrAr,rrr
�_stop}s


zController._stopcCs|dkrdS|jdd�S)Nr:F)rA)rB)rr=rrr
r+�szController.stopcCsp|dkrdS|jj�r*|jdd�}|s*dSy|jj�Wn.tk
rf}ztjd|�dSd}~XnX|j�S)Nr:FT)rAzFailed to reload TuneD: %s)rr?rBZreload_profile_configrr#�errorr%)rr=Zstop_ok�errr
r0�s
zController.reloadcCs�|jj�}d}d}d}z�y$|r,|jjdd�|jj||�Wnftjjk
r�}zFd}t|�}|r�|jjj	|kr�t
jd|�d}nt
jd|�WYdd}~XnXWd|r�|r�t
jd|�n|s�t
j
d�|jj�X||fS)	N�OKTF)rAz@Failed to reapply profile '%s'. Did it change on disk and break?zFailed to apply profile '%s'z>Applying previously applied (possibly out-dated) profile '%s'.z$Applying previously applied profile.)rr?r+Zset_profiler5�
exceptionsr�str�profile�namer#rC�warnr$r%)rr2�manualZwas_running�msg�successZreapplyrDrrr
�_switch_profile�s,
$
zController._switch_profilez(bs)cCs|dkrdS|j|d�S)Nr:F�UnauthorizedT)FrO)rN)rr2r=rrr
�switch_profile�szController.switch_profilecCs |dkrdS|j�}|j|d�S)Nr:FrO)FrO)�recommend_profilerN)rr=r2rrr
�auto_profile�szController.auto_profilecCs*|dkrdS|jjdk	r"|jjjSdSdS)Nr:)rrHrI)rr=rrr
�active_profile�s

zController.active_profilez(ss)cCs�|dkrdS|jj}|dkrpy"|jj�\}}|dkr<|dk	}Wn0tk
rn}zd}t|�}||fSd}~XnX|rztjntj}|dfS)Nr:�unknownrO)rTrO)	rrKrZget_active_profilerrGr'ZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)rr=rKrHrD�moderCrrr
�profile_mode�szController.profile_modecCs|dkrdS|jjpdS)Nr:)r�post_loaded_profile)rr=rrr
rW�szController.post_loaded_profilecCsB|dkrdS|jj�r |jj�|jj�r>|jjddddd�dS)Nr:FT)Zsave_instantly)rr?r+r@Zset_all_profiles)rr=rrr
�disable�s


zController.disablecCs|dkrdS|jj�S)Nr:F)rr?)rr=rrr
r?�szController.is_running�ascCs|dkrgS|jjjj�S)Nr:)r�profile_loader�profile_locatorZget_known_names)rr=rrr
�profiles�szController.profilesza(ss)cCs|dkrgS|jjjj�S)Nr:)rrZr[Zget_known_names_summary)rr=rrr
�	profiles2�szController.profiles2z(bsss)cCsP|dkrtdddd�S|dks&|dkr.|j�}t|jjjj|tjtjgdg��S)Nr:F)	�tuplerSrrZr[Zget_profile_attrsr'ZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTION)rr2r=rrr
�profile_infos
zController.profile_infocCs|dkrdS|jjj�S)Nr:)rZprofile_recommenderZ	recommend)rr=rrr
rQszController.recommend_profilecCs|dkrdS|jjdd�S)Nr:F)�ignore_missing)r�verify_profile)rr=rrr
raszController.verify_profilecCs|dkrdS|jjdd�S)Nr:FT)r`)rra)rr=rrr
�verify_profile_ignore_missingsz(Controller.verify_profile_ignore_missingz	a{sa{ss}}cCsz|dkrdSi}xd|jj�D]V}|jjd�djdd�d}|j�}i||<x$|j�D]\}}t|�|||<qVWqW|S)zuReturn dictionary with accesible plugins

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		r:F�.r"�_���)r�get_all_pluginsr�splitZ_get_config_options�itemsrG)rr=ZpluginsZplugin_class�plugin_nameZconf_options�key�valrrr
rfszController.get_all_pluginscCs|dkrdS|jjt|��S)z"Return docstring of plugin's classr:F)r�get_plugin_documentationrG)rrir=rrr
rl,sz#Controller.get_plugin_documentationza{ss}cCs|dkrdS|jjt|��S)z�Return dictionary with plugin's parameters and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		r:F)r�get_plugin_hintsrG)rrir=rrr
rm3s
zController.get_plugin_hintscCs6|dkrdS|jjr2|jjjr2|jjjj|�dSdS)z�Allows to dynamically add sockets to send signals to

		Parameters:
		path -- path to socket to register for sending signals

		Return:
		bool -- True on success
		r:FT)rZ_applicationZ_unix_socket_exporterZregister_signal_path)r�pathr=rrr
�register_socket_signal_pathAs
z&Controller.register_socket_signal_pathZssc
Csb|dkrdSd}x2|jjjD]$}|j|krtjd|j�d}PqW|sbd|}tj|�d|fSt|jj	|��}tjd|jt
|�f�x�|jjjD]�}|j|@}	t|	�r�||	8}tj
dt
|	�|j|jf�|jj|jjk�rd	|j|jjt
|	�|j|jjf}tj|�d|fS|jj||	�|jj||	�q�Wt|��r^d
t
|�}tj
|�d|fSd
S)Nr:FrOzFound instance '%s'.TzInstance '%s' not foundz-Instance '%s' trying to acquire devices '%s'.z8Moving devices '%s' from instance '%s' to instance '%s'.ztTarget instance '%s' is of type '%s', but devices '%s' are currently handled by instance '%s' which is of type '%s'.z2Ignoring devices not handled by any instance '%s'.rE)FrO)TrE)r�
_unit_manager�	instancesrIr#�debugrCr.rZdevstr2devsrG�processed_devices�lenr$�pluginZ_remove_devices_nocheckZ_add_devices_nocheck)
rZdevices�
instance_namer=�foundZinstance_target�retsZdevs�instanceZdevs_movingrrr
�instance_acquire_devicesUsB





z#Controller.instance_acquire_devicesz	(bsa(ss))cs�|dkrddgfS�dkrF�|j�j�krFd�}tj|�d|gfStdd�|jjj�}�dkrtt�fdd�|�}dd	tt	d
d�|��fS)aReturn a list of active instances of a plugin or all active instances

		Parameters:
		plugin_name -- name of the plugin or an empty string

		Return:
		bool -- True on success
		string -- error message or "OK"
		list of string pairs -- [(instance_name, plugin_name)]
		r:FrOzPlugin '%s' does not existcSs|jS)N)Zactive)ryrrr
�<lambda>�sz*Controller.get_instances.<locals>.<lambda>cs|jj�kS)N)rurI)ry)rirr
r{�sTrEcSs|j|jjfS)N)rIru)ryrrr
r{�s)
rf�keysr#rC�filterrrprq�list�map)rrir=rxrqr)rir
�
get_instancesys


zController.get_instancesz(bsas)cCs`|dkrddgfSx0|jjjD]"}|j|krddtt|j��fSqWd|}tj|�d|gfS)z�Return a list of devices assigned to an instance

		Parameters:
		instance_name -- name of the instance

		Return:
		bool -- True on success
		string -- error message or "OK"
		list of strings -- device names
		r:FrOTrEzInstance '%s' not found)	rrprqrI�sortedr~rsr#rC)rrvr=ryrxrrr
�instance_get_devices�s


zController.instance_get_devices)N)N)N)F)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N))rrr�__doc__rr-r/r1r�signalr4r8Zexportr<r7r%rBr+r0rNrPrRrSrVrWrXr?r\r]r_rQrarbrfrlrmrorzr�r��
__classcell__rr)r!r
r%sv	

























#

)r5rZ
tuned.logsZtuned.exceptionsrr	Ztuned.constsr'Ztuned.utils.commandsr�__all__r6�getr#�objectrZ
interfacesZExportableInterfacerrrrr
�<module>s