opus/sys/services/network.lua

48 lines
936 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
2018-01-13 20:17:26 +00:00
local multishell = _ENV.multishell
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
return
end
2016-12-11 19:24:52 +00:00
2018-01-13 20:17:26 +00:00
if multishell and multishell.setTitle then
multishell.setTitle(multishell.getCurrent(), 'Net Daemon')
end
2016-12-11 19:24:52 +00:00
print('Net daemon started')
for _,file in pairs(fs.list('sys/network')) do
local fn, msg = Util.run(_ENV, 'sys/network/' .. file)
if not fn then
2016-12-11 19:24:52 +00:00
printError(msg)
end
end
Event.on('device_detach', function()
if not device.wireless_modem then
Event.exitPullEvents()
2016-12-11 19:24:52 +00:00
end
end)
Event.pullEvents()
for _,c in pairs(network) do
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')
Util.clear(_G.network)
2016-12-11 19:24:52 +00:00
print('Net daemon stopped')