[cpu_freebsd] Deprecate synchronous sysctl

This commit is contained in:
mutlusun 2019-07-31 18:07:04 +02:00
parent 2b60a72d06
commit 04e8a49d2e
No known key found for this signature in database
GPG Key ID: C0AF8F434E1AB79B
4 changed files with 36 additions and 45 deletions

View File

@ -19,7 +19,8 @@ Fixed:
- Deprecate the use of `io.popen` in following widgets: - Deprecate the use of `io.popen` in following widgets:
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux * wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd * bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd,
cpu_freebsd
* volume, gmail, mdir, mpd, fs * volume, gmail, mdir, mpd, fs
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo - [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
- [pkg,weather,contrib/btc] Allow function call without Awesome - [pkg,weather,contrib/btc] Allow function call without Awesome

View File

@ -1,7 +1,5 @@
-- {{{ Grab environment -- {{{ Grab environment
local helpers = require("vicious.helpers") local helpers = require("vicious.helpers")
local tonumber = tonumber
local setmetatable = setmetatable
local math = { floor = math.floor } local math = { floor = math.floor }
local string = { gmatch = string.gmatch } local string = { gmatch = string.gmatch }
-- }}} -- }}}
@ -16,15 +14,15 @@ local cpu_total = {}
local cpu_idle = {} local cpu_idle = {}
-- {{{ CPU widget type -- {{{ CPU widget type
local function worker(format) function cpu_freebsd.async(format, warg, callback)
local cp_times = helpers.sysctl("kern.cp_times")
local matches = {} local matches = {}
local tmp_total = {} local tmp_total = {}
local tmp_idle = {} local tmp_idle = {}
local tmp_usage = {} local tmp_usage = {}
helpers.sysctl_async({ "kern.cp_times" }, function(ret)
-- Read input data -- Read input data
for v in string.gmatch(cp_times, "([%d]+)") do for v in string.gmatch(ret["kern.cp_times"], "([%d]+)") do
table.insert(matches, v) table.insert(matches, v)
end end
@ -62,8 +60,9 @@ local function worker(format)
cpu_total = tmp_total cpu_total = tmp_total
cpu_idle = tmp_idle cpu_idle = tmp_idle
return tmp_usage return callback(tmp_usage)
end)
end end
-- }}} -- }}}
return setmetatable(cpu_freebsd, { __call = function(_, ...) return worker(...) end }) return helpers.setasyncall(cpu_freebsd)

View File

@ -16,15 +16,7 @@ function thermal_freebsd.async(format, warg, callback)
helpers.sysctl_async(warg, function(ret) helpers.sysctl_async(warg, function(ret)
local thermals = {} local thermals = {}
for k, v in pairs(ret) do
print(k, v)
end
for i=1,#warg do for i=1,#warg do
print(warg[i])
print(ret[warg[i]])
print(ret["hw.acpi.thermal.tz0.temperature"])
print(ret['hw.acpi.thermal.tz0.temperature'])
if ret[warg[i]] ~= nil then if ret[warg[i]] ~= nil then
thermals[i] = string.match(ret[warg[i]], "[%d]+") thermals[i] = string.match(ret[warg[i]], "[%d]+")
else else

View File

@ -1,6 +1,5 @@
-- {{{ Grab environment -- {{{ Grab environment
local tonumber = tonumber local tonumber = tonumber
local setmetatable = setmetatable
local math = { floor = math.floor } local math = { floor = math.floor }
local string = { match = string.match } local string = { match = string.match }
local helpers = require("vicious.helpers") local helpers = require("vicious.helpers")