From 981ea559c62df3872ed395ccaf929361cc0deba8 Mon Sep 17 00:00:00 2001 From: 20kdc Date: Sun, 22 Apr 2018 19:40:08 +0100 Subject: [PATCH] automatic service startup (including test app 'ghostcall') and documentation updates --- .gitignore | 1 + code/README.asc => NOTE-TO-MS.asc | 0 code/apps/sys-icecap.lua | 82 ++++++++++++++++++++++-------- repository/apps/app-ghostcall.lua | 8 +++ repository/apps/svc-ghostie.lua | 36 +++++++++++++ repository/data/app-claw/local.lua | 14 +++++ repository/docs/kn-refer | 2 +- repository/docs/ul-neoux | 8 +++ repository/docs/us-evrst | 8 +++ 9 files changed, 136 insertions(+), 23 deletions(-) rename code/README.asc => NOTE-TO-MS.asc (100%) create mode 100644 repository/apps/app-ghostcall.lua create mode 100644 repository/apps/svc-ghostie.lua diff --git a/.gitignore b/.gitignore index 2dc72df..8eec4c7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ repobuild/*/*/* inst.lua com2/code.tar.bd upldr.sh +upldr-dev.sh repository/inst.lua diff --git a/code/README.asc b/NOTE-TO-MS.asc similarity index 100% rename from code/README.asc rename to NOTE-TO-MS.asc diff --git a/code/apps/sys-icecap.lua b/code/apps/sys-icecap.lua index bcb9edd..e0a14df 100644 --- a/code/apps/sys-icecap.lua +++ b/code/apps/sys-icecap.lua @@ -14,11 +14,19 @@ local targsDH = {} -- data disposal local todo = {} -local onEverest = {} +-- Specific registration callbacks +local onReg = {} local everestWindows = {} local nexus +local theEventHandler + +local function addOnReg(p, f) + onReg[p] = onReg[p] or {} + table.insert(onReg[p], f) +end + local function resumeWF(...) local ok, e = coroutine.resume(...) if not ok then @@ -26,22 +34,29 @@ local function resumeWF(...) neo.emergency(e) nexus.startDialog(e, "ice") end - return ok + return ok, e end nexus = { createNexusThread = function (f, ...) local t = coroutine.create(f) - if not resumeWF(t, ...) then return end - local early = neo.requestAccess("x.neo.pub.window") + local ok, cbi = resumeWF(t, ...) + if not ok then return end + local early = neo.requestAccess("x.neo.pub.window", theEventHandler) if early then - onEverest[#onEverest] = nil - resumeWF(t, early) + local r = onReg["x.neo.pub.window"] + -- r should not be nil here + onReg["x.neo.pub.window"] = nil + for k, v in ipairs(r) do + v() + end end return function () - for k, v in ipairs(onEverest) do - if v == t then - table.remove(onEverest, k) + local r = onReg["x.neo.pub.window"] + if not r then return end + for k, v in ipairs(r) do + if v == cbi then + table.remove(r, k) return end end @@ -49,8 +64,11 @@ nexus = { end, create = function (w, h, t) local thr = coroutine.running() - table.insert(onEverest, thr) - local everest = coroutine.yield() + local function cb() + coroutine.resume(thr, neo.requestAccess("x.neo.pub.window")) + end + addOnReg("x.neo.pub.window", cb) + local everest = coroutine.yield(cb) local dw = everest(w, h, title) everestWindows[dw.id] = thr return dw @@ -232,11 +250,27 @@ local function wrapWASS(perm, req) if paP then permAct = appAct:sub(1, #appAct - #paP) end - pcall(neo.executeAsync, appAct) - neo.scheduleTimer(0) - table.insert(todo, function () + -- Prepare for success + onReg[perm] = onReg[perm] or {} + table.insert(onReg[perm], function () req(res) + req = nil end) + pcall(neo.executeAsync, "svc-" .. appAct) + -- Fallback "quit now" + local time = os.uptime() + 30 + neo.scheduleTimer(time) + local f + function f() + if req then + if os.uptime() >= time then + req(res) + else + table.insert(todo, f) + end + end + end + table.insert(todo, f) return end end @@ -253,7 +287,7 @@ rootAccess.securityPolicy = function (pid, proc, perm, req) if neo.dead then return backup(pid, proc, perm, req) end - req = wrapWASS(req) + req = wrapWASS(perm, req) local def = proc.pkg:sub(1, 4) == "sys-" local secpol, err = require("sys-secpolicy") if not secpol then @@ -273,8 +307,8 @@ rootAccess.securityPolicy = function (pid, proc, perm, req) end) end -while true do - local ev = {coroutine.yield()} +function theEventHandler(...) + local ev = {...} if ev[1] == "k.procdie" then local _, pkg, pid, reason = table.unpack(ev) if targsDH[pid] then @@ -294,11 +328,11 @@ while true do end end elseif ev[1] == "k.registration" then - if ev[2] == "x.neo.pub.window" then - local nt = onEverest - onEverest = {} - for _, v in ipairs(nt) do - coroutine.resume(v, neo.requestAccess("x.neo.pub.window")) + if onReg[ev[2]] then + local tmp = onReg[ev[2]] + onReg[ev[2]] = nil + for _, v in ipairs(tmp) do + v() end end elseif ev[1] == "x.neo.pub.window" then @@ -311,3 +345,7 @@ while true do end end end + +while true do + theEventHandler(coroutine.yield()) +end diff --git a/repository/apps/app-ghostcall.lua b/repository/apps/app-ghostcall.lua new file mode 100644 index 0000000..8e00ca4 --- /dev/null +++ b/repository/apps/app-ghostcall.lua @@ -0,0 +1,8 @@ +-- This is released into the public domain. +-- No warranty is provided, implied or otherwise. + +-- app-ghostcall.lua : Who are you gonna call? +-- Authors: 20kdc + +local g = neo.requireAccess("x.svc.ghostie", "ghosts") +g() diff --git a/repository/apps/svc-ghostie.lua b/repository/apps/svc-ghostie.lua new file mode 100644 index 0000000..e86f8c7 --- /dev/null +++ b/repository/apps/svc-ghostie.lua @@ -0,0 +1,36 @@ +-- This is released into the public domain. +-- No warranty is provided, implied or otherwise. + +-- svc-ghostie.lua : Ghostie the test ghost! +-- Authors: 20kdc + +-- Since this should expect to be started on-demand, +-- take precautions here. +-- Specifically, register as soon as possible. +-- While not required, security dialogs can cause a timeout. + +local r = neo.requireAccess("r.svc.ghostie", "ghost registration") + +local waiting = 0 + +r(function (pkg, pid, sendSig) + -- just totally ignore the details + return function () + neo.scheduleTimer(os.uptime() + 5 + (math.random() * 10)) + waiting = waiting + 1 + end +end) + +local computer = neo.requireAccess("k.computer", "scare system") + +while true do + local ev = coroutine.yield() + if ev == "k.timer" then + -- boo! + computer.beep(440, 1) + waiting = waiting - 1 + if waiting == 0 then + return + end + end +end diff --git a/repository/data/app-claw/local.lua b/repository/data/app-claw/local.lua index 0d7d05d..212ab74 100644 --- a/repository/data/app-claw/local.lua +++ b/repository/data/app-claw/local.lua @@ -60,4 +60,18 @@ return { "apps/app-nprt2018.lua" }, }, + ["svc-ghostie"] = { + desc = "Application that schedules a scare after a random time to test svc autostart", + v = 0, + deps = { + "neo" + }, + dirs = { + "apps" + }, + files = { + "apps/svc-ghostie.lua", + "apps/app-ghostcall.lua" + }, + }, } diff --git a/repository/docs/kn-refer b/repository/docs/kn-refer index 0162a9f..d37dfae 100644 --- a/repository/docs/kn-refer +++ b/repository/docs/kn-refer @@ -305,7 +305,7 @@ The additional things available to is never touched by the kernel directly, called the "tag". The resulting event: - "k.timer", tag, time, ofs + "k.timer", tag, time These events are ONLY EVER sent as a consequence of this function, and this can be relied on safely. diff --git a/repository/docs/ul-neoux b/repository/docs/ul-neoux index 446c861..82cf015 100644 --- a/repository/docs/ul-neoux +++ b/repository/docs/ul-neoux @@ -47,6 +47,10 @@ Main functions: neoux.create(w, h, title, callback): Creates a window, including a NeoUX window wrapper. + NOTE: The width can never be smaller + than 8, under any circumstances. + Trying to will cause the width to be + forced to 8. The parameter list is compatible with the window "reset" function, and it is intended that you use @@ -156,6 +160,10 @@ UI framework window API (TODO): height. Like in the API this wraps, this is guaranteed to refresh all the lines of your window. + NOTE: The width can never be smaller + than 8, under any circumstances. + Trying to will cause the width to be + forced to 8. getDepth(...): Read the note in us-evrst for details. diff --git a/repository/docs/us-evrst b/repository/docs/us-evrst index e6ec8f6..b93723e 100644 --- a/repository/docs/us-evrst +++ b/repository/docs/us-evrst @@ -17,6 +17,10 @@ The API gives you a function: (w, h, title) -> window This function creates a window. +NOTE: The width can never be smaller + than 8, under any circumstances. +Trying to will cause the width to be + forced to 8. Window fields: @@ -25,6 +29,10 @@ Window fields: the window, and sends the line events (even if the size doesn't change) + NOTE: The width can never be smaller + than 8, under any circumstances. + Trying to will cause the width to be + forced to 8. getDepth(): Returns the depth of the screen the window is on. span(x, y, text, bg, fg): Draws a