1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-14 12:44:50 +00:00
opus/sys/apps/netdaemon.lua

46 lines
891 B
Lua
Raw Normal View History

2018-01-24 22:39:38 +00:00
_G.requireInjector(_ENV)
local Event = require('opus.event')
local Util = require('opus.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
2018-01-21 22:22:59 +00:00
print('Net daemon starting')
2019-06-29 20:35:33 +00:00
device.wireless_modem.closeAll()
2016-12-11 19:24:52 +00:00
for _,file in pairs(fs.list('sys/apps/network')) do
local fn, msg = Util.run(_ENV, 'sys/apps/network/' .. file)
2018-01-14 04:40:53 +00:00
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)
2018-01-21 22:22:59 +00:00
print('Net daemon started')
2018-01-21 11:09:25 +00:00
os.queueEvent('network_up')
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')