3 `éÏgÓ4ã@s€ddlmZddlZddlZddlmZddlZddljZddlm Z dgZ ej j ƒ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)r rrr r r Ú drop_timers  zTimerStore.drop_timerc Cs<|j�,x|jjƒD] }|jƒqW|jjƒWdQRXdS)N)r rÚvaluesrÚclear)r rr r r Ú cancel_alls zTimerStore.cancel_allN)Ú__name__Ú __module__Ú __qualname__rrrrr r r r r s rcsŠeZdZdZ‡fdd„Zdd„Zdd„Zdd „Zej d ƒd d „ƒZ d d„Z ej 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ƒdedd?„ƒ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|j j |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)r r r r Ú terminateFszController.terminatecCs0|jjjƒs,|jjjƒ|jƒs,|jjjƒdS)N)rZ_sighup_processingZis_setr.Úreloadr)r r r r ÚsighupIs  zController.sighupZsbscCsdS)Nr )r Ú profile_nameÚresultZerrstrr r r Úprofile_changedOszController.profile_changedcCstjj|ƒ|jj|ƒdS)N)ÚtunedÚlogsÚlog_capture_finishrr)r rr 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%)r Z log_levelZtimeoutÚcallerrrr r r r<\s zController.log_capture_startcCs4|dkr dStjj|ƒ}|jj|ƒ|dkr0dS|S)Nr:)r5r6r7rr)r rr=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%)r r=r r r r%rs  zController.startFcCs,|jjƒsd}n|jj|d�}|jjƒ|S)NT)Úprofile_switch)rr?r+rr)r rAr,r r r Ú_stop}s   zController._stopcCs|dkr dS|jdd�S)Nr:F)rA)rB)r r=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%)r r=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 j d|ƒd}nt j d|ƒ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+Z set_profiler5Ú exceptionsrÚstrÚprofileÚnamer#rCÚwarnr$r%)r r2ÚmanualZ was_runningÚmsgÚsuccessZreapplyrDr r r Ú_switch_profilešs, $  zController._switch_profilez(bs)cCs(|dkr dS|jj|ƒsdS|j|dƒS)Nr:FÚ UnauthorizedúInvalid profile_nameT)FrO)FrP)rÚ is_valid_namerN)r r2r=r r r Úswitch_profileµs  zController.switch_profilecCs |dkr dS|jƒ}|j|dƒS)Nr:FrO)FrO)Úrecommend_profilerN)r r=r2r r r Ú auto_profile½szController.auto_profilecCs*|dkr dS|jjdk r"|jjjSdSdS)Nr:)rrHrI)r r=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)rVrO) rrKrZget_active_profilerrGr'ZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)r r=rKrHrDÚmoderCr r r Ú profile_modeÍs zController.profile_modecCs|dkr dS|jjpdS)Nr:)rÚpost_loaded_profile)r r=r r r rYßszController.post_loaded_profilecCsB|dkr dS|jjƒr |jjƒ|jjƒr>|jjddddd�dS)Nr:FT)Zsave_instantly)rr?r+r@Zset_all_profiles)r r=r r r Údisableås    zController.disablecCs|dkr dS|jjƒS)Nr:F)rr?)r r=r r r r?ðszController.is_runningÚascCs|dkr gS|jjjjƒS)Nr:)rÚprofile_loaderÚprofile_locatorZget_known_names)r r=r r r ÚprofilesöszController.profilesza(ss)cCs|dkr gS|jjjjƒS)Nr:)rr\r]Zget_known_names_summary)r r=r r r Ú profiles2üszController.profiles2z(bsss)cCsT|dks|jj|ƒ rdS|dks*|dkr2|jƒ}t|jjjj|tj tj gdgƒƒS)Nr:F)Fr:r:r:) rrQrUÚtuplerr\r]Zget_profile_attrsr'ZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTION)r r2r=r r r Ú profile_infos zController.profile_infocCs|dkr dS|jjjƒS)Nr:)rZprofile_recommenderZ recommend)r r=r r r rS szController.recommend_profilecCs|dkr dS|jjdd�S)Nr:F)Úignore_missing)rÚverify_profile)r r=r r r rcszController.verify_profilecCs|dkr dS|jjdd�S)Nr:FT)rb)rrc)r r=r r r Úverify_profile_ignore_missingsz(Controller.verify_profile_ignore_missingz a{sa{ss}}cCsz|dkr iSi}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:Ú.r"Ú_éÿÿÿÿ)rÚget_all_pluginsrÚsplitZ_get_config_optionsÚitemsrG)r r=ZpluginsZ plugin_classÚ plugin_nameZ conf_optionsÚkeyÚvalr r r rhszController.get_all_pluginscCs*|dks|jj|ƒ rdS|jjt|ƒƒS)z"Return docstring of plugin's classr:)rrQrÚget_plugin_documentationrG)r rkr=r r r rn.sz#Controller.get_plugin_documentationza{ss}cCs*|dks|jj|ƒ riS|jjt|ƒƒS)zžReturn dictionary with plugin's parameters and their hints Parameters: plugin_name -- name of plugin Return: dictionary -- {parameter_name: hint} r:)rrQrÚget_plugin_hintsrG)r rkr=r r r ro5s zController.get_plugin_hintscCsD|dks|jj|ƒ rdS|jjr@|jjjr@|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)rrQrZ _applicationZ_unix_socket_exporterZregister_signal_path)r Úpathr=r r r Úregister_socket_signal_pathCs z&Controller.register_socket_signal_pathZssc Cs‚|dkr dS|jj|ƒsdS|jj|ƒs,dSd}x2|jjjD]$}|j|kr“sz*Controller.get_instances..cs |jjˆkS)N)ryrI)r})rkr r r•sTrEcSs|j|jjfS)N)rIry)r}r r r r–s) rrQrhÚkeysr#rCÚfilterrrtruÚlistÚmap)r rkr=r|rur )rkr Ú get_instancess      zController.get_instancesz(bsas)cCsv|dkrddgfS|jj|ƒs(ddgfSx0|jjjD]"}|j|kr4ddtt|jƒƒfSq4Wd|}t j |ƒ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:FrOzInvalid instance_nameTrEzInstance '%s' not found) rrQrrtrurIÚsortedr‚rwr#rC)r rzr=r}r|r 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+r0rNrRrTrUrXrYrZr?r^r_rarSrcrdrhrnrorqr~r„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 Ús