spm works maybe?

This commit is contained in:
2026-08-14 20:44:11 -04:00
parent 56646625c0
commit 10aa0c62ff
82 changed files with 1706 additions and 535 deletions
@@ -3,6 +3,7 @@
local kernel=...
kernel.cct={}
kernel.cct.peripheral={}
kernel.cct.callAsync=kernel.apis.callAsync
local peripheral=kernel.cct.peripheral
local apis = kernel.apis
local native = apis.peripheral
@@ -103,6 +104,40 @@ function peripheral.getName(peripheral)
end
function peripheral.call(name, method, ...)
if native.isPresent(name) then
local id = kernel.cct.callAsync(native.call, name, method, ...)
kernel.currentTask.io=function()
if kernel.apis.callAsyncReturn[id] then
local r=kernel.apis.callAsyncReturn[id]
if not r[1] then error(r[2]) end
kernel.apis.callAsyncReturn[id]=nil
return table.unpack(r,2)
end
end
kernel.currentTask.status="D"
return
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
local id = kernel.cct.callAsync(native.call, side, "callRemote", name, method, ...)
kernel.currentTask.io=function()
if kernel.apis.callAsyncReturn[id] then
local r=kernel.apis.callAsyncReturn[id]
if not r[1] then error(r[2]) end
kernel.apis.callAsyncReturn[id]=nil
return table.unpack(r,2)
end
end
kernel.currentTask.status="D"
return
end
end
return nil
end
function peripheral.callnative(name, method, ...)
if native.isPresent(name) then
return native.call(name, method, ...)
end
@@ -116,7 +151,7 @@ function peripheral.call(name, method, ...)
return nil
end
function peripheral.wrap(name)
function peripheral.wrap(name, wrap)
local methods = peripheral.getMethods(name)
if not methods then
return nil
@@ -130,9 +165,17 @@ function peripheral.wrap(name)
type = types[1],
types = types,
})
for _, method in ipairs(methods) do
result[method] = function(...)
return peripheral.call(name, method, ...)
if wrap then
for _, method in ipairs(methods) do
result[method] = function(...)
return peripheral.call(name, method, ...)
end
end
else
for _, method in ipairs(methods) do
result[method] = function(...)
return peripheral.callnative(name, method, ...)
end
end
end
return result
@@ -149,4 +192,4 @@ function peripheral.find(ty, filter)
end
end
return table.unpack(results)
end
end
@@ -0,0 +1,26 @@
--:Minify:--
local kernel=...
local peripheral=kernel.cct.peripheral
local function wrap(p)
return function(op, mode)
if op=="type" then
return "device"
elseif op=="open" then
if kernel.uid~=0 then error("EACCES") end
return peripheral.wrap(p, true)
end
end
end
local peripherals=peripheral.getNames()
for i=1, #peripherals do
local p=peripherals[i]
local typ=peripheral.getType(p)
local file=wrap(p)
kernel.devfs.data["raw"][p]=file
local typefolder=kernel.devfs.data["raw"]["by-type"][typ]
if not typefolder then typefolder={} end
typefolder[tostring(#table.keys(typefolder)+1)] = file
kernel.devfs.data["raw"]["by-type"][typ]=typefolder
end
@@ -120,6 +120,7 @@ function handler.connect(fd, address)
end
fdo.socket.active=true
fdo.socket.url=url
fdo.socket.loaded=false
return true
end
@@ -129,10 +130,11 @@ function handler.connect(fd, address)
return
end
if not kernel.cct.httpqueue[fdo.socket.url] then
if not kernel.cct.httpqueue[fdo.socket.url] and not fdo.socket.loaded then
fdo.socket.file=kernel.sfile(buildResponse(kernel.cct.httpresponse[fdo.socket.url]))
kernel.cct.httpqueue[fdo.socket.url]=nil
kernel.cct.httpresponse[fdo.socket.url]=nil
fdo.socket.loaded=true
end
if not fdo.socket.file then
@@ -141,6 +143,7 @@ function handler.connect(fd, address)
fdo.socket.file=kernel.sfile(buildResponse(kernel.cct.httpresponse[fdo.socket.url]))
kernel.cct.httpqueue[fdo.socket.url]=nil
kernel.cct.httpresponse[fdo.socket.url]=nil
fdo.socket.loaded=true
return fdo.socket.file.read(count)
end
end
@@ -156,10 +159,11 @@ function handler.connect(fd, address)
return
end
if not kernel.cct.httpqueue[fdo.socket.url] then
if not kernel.cct.httpqueue[fdo.socket.url] and not fdo.socket.loaded then
fdo.socket.file=kernel.sfile(buildResponse(kernel.cct.httpresponse[fdo.socket.url]))
kernel.cct.httpqueue[fdo.socket.url]=nil
kernel.cct.httpresponse[fdo.socket.url]=nil
fdo.socket.loaded=true
end
if not fdo.socket.file then
@@ -168,6 +172,7 @@ function handler.connect(fd, address)
fdo.socket.file=kernel.sfile(buildResponse(kernel.cct.httpresponse[fdo.socket.url]))
kernel.cct.httpqueue[fdo.socket.url]=nil
kernel.cct.httpresponse[fdo.socket.url]=nil
fdo.socket.loaded=true
return fdo.socket.file.seek(whence, offset)
end
end
@@ -144,7 +144,6 @@ local function write(text, term)
term.setCursorPos(x, y)
end
kernel.devfs.data.tty={}
kernel.cct.ctrl,kernel.cct.alt = false, false
local function serializeBool(bool)
@@ -1,10 +1,11 @@
--:Minify:--
local kernel=...
local keys=kernel.apis.keys
kernel.cct.eventhooks={}
kernel.processes.cctdeamon = function()
kernel.processes.cctdaemon = function()
local timeout = false
kernel.log("CCT deamon started")
kernel.log("CCT daemon started")
while true do
local event = {kernel.EFI:getMachineEvent()}
@@ -84,6 +85,13 @@ kernel.processes.cctdeamon = function()
kernel.cct.httperror[event[2]]=event[3]
kernel.cct.httpresponse[event[2]]=event[4]
end
else
if kernel.cct.eventhooks[eventType] then
local ok,err = xpcall(kernel.cct.eventhooks[eventType], debug.traceback, table.unpack(event))
if not ok then
kernel.log("Error on eventhook "..eventType.."\n"..err)
end
end
end
timeout = false
@@ -97,4 +105,4 @@ kernel.processes.cctdeamon = function()
end
end
kernel.log("CCT deamon queued for execution")
kernel.log("CCT daemon queued for execution")