1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-26 16:40:27 +00:00
opus/sys/apps/netdaemon.lua

43 lines
777 B
Lua
Raw Normal View History

2017-10-23 23:33:53 +00:00
_G.requireInjector()
local Event = require('event')
local Util = require('util')
2016-12-11 19:24:52 +00:00
2017-10-23 23:33:53 +00:00
local device = _G.device
local fs = _G.fs
local network = _G.network
2017-10-23 23:33:53 +00:00
local os = _G.os
local printError = _G.printError
if not device.wireless_modem then
2018-01-14 04:40:53 +00:00
return
2018-01-13 20:17:26 +00:00
end
2016-12-11 19:24:52 +00:00
print('Net daemon started')
for _,file in pairs(fs.list('sys/network')) do
2018-01-14 04:40:53 +00:00
local fn, msg = Util.run(_ENV, 'sys/network/' .. file)
if not fn then
printError(msg)
end
2016-12-11 19:24:52 +00:00
end
Event.on('device_detach', function()
2018-01-14 04:40:53 +00:00
if not device.wireless_modem then
Event.exitPullEvents()
end
end)
Event.pullEvents()
for _,c in pairs(network) do
2018-01-14 04:40:53 +00:00
c.active = false
os.queueEvent('network_detach', c)
2016-12-11 19:24:52 +00:00
end
os.queueEvent('network_down')
Event.pullEvent('network_down')
2018-01-14 04:40:53 +00:00
Util.clear(network)
2018-01-14 23:28:23 +00:00
print('Net daemon stopped')