Static UUIDs.

This commit is contained in:
sam 2021-05-29 19:19:29 -04:00
parent f2436f8aa5
commit ecbee6c83a
16 changed files with 109 additions and 19 deletions

View File

@ -4,6 +4,7 @@ extern char lua_boot[];
extern char lua_component[];
extern char lua_computer[];
extern char lua_debug[];
extern char lua_drive[];
extern char lua_eeprom[];
extern char lua_fbgpu[];
extern char lua_filesystem[];
@ -12,9 +13,11 @@ extern char lua_gpudetect[];
extern char lua_init[];
extern char lua_internet[];
extern char lua_sandbox[];
extern char lua_serial[];
extern char lua_textgpu[];
extern char lua_util_buffer[];
extern char lua_util_color[];
extern char lua_util_random[];
extern char lua_uuidmgr[];
extern char lua_winapigpu[];
#endif

View File

@ -22,9 +22,13 @@ typedef unsigned short ushort;
lua_State* getL();
char * get_kbid(); // ugly hack
void run_init(int argc, char **argv);
void lupi_init();
void luanative_start(lua_State *L);
void serial_start(lua_State *L);
void blk_start(lua_State *L);
void fb_start(lua_State *L);
void setup_modules(lua_State *L);
void termutils_start(lua_State *L);

View File

@ -35,7 +35,7 @@ static void handleStdin(evutil_socket_t fd, short what, void *eventc) {
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_down");
lua_pushstring(L, "TODO:SetThisUuid");/* Also in textgpu.lua */
lua_pushstring(L, get_kbid());/* Also in textgpu.lua */
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");
@ -43,7 +43,7 @@ static void handleStdin(evutil_socket_t fd, short what, void *eventc) {
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_up");
lua_pushstring(L, "TODO:SetThisUuid");
lua_pushstring(L, get_kbid());
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");

View File

@ -476,6 +476,20 @@ static int l_debug (lua_State *L) {
}
#endif
char * kbid = "TODO:SetThisUuid";
static int l_setkbid(lua_State *L) {
size_t len = 0;
char * id = luaL_checklstring(L, 1, &len);
kbid = malloc(len+1);
memcpy(kbid, id, len);
return 0;
}
char * get_kbid() {
return kbid;
}
void luanative_start(lua_State *L) {
struct timeval tp;
@ -511,6 +525,7 @@ void luanative_start(lua_State *L) {
{"pull", l_pull},
{"platform", l_platform},
{"isinit", l_isinit},
{"setkbid", l_setkbid},
#ifdef DEBUG
{"debug", l_debug},
#endif

View File

@ -27,6 +27,7 @@ void setup_modules(lua_State *L) {
pushstuple(L, "winapigpu", lua_winapigpu);
pushstuple(L, "color", lua_util_color);
pushstuple(L, "random", lua_util_random);
pushstuple(L, "uuidmgr", lua_uuidmgr);
pushstuple(L, "buffer", lua_util_buffer);
pushstuple(L, "eepromDefault", res_eepromDefault);

View File

@ -48,7 +48,7 @@ function drive.register()
return blk.size(disk)
end
modules.component.api.register("Block:"..ent, "drive", component)
modules.component.api.register(modules.uuidmgr.lookup("drive", ent), "drive", component)
else
lprint("Can't open blkdev: "..ent..": "..disk)
end

View File

@ -62,7 +62,7 @@ function eeprom.register()
function component.makeReadonly()
return false, "Method stub"
end
modules.component.api.register(nil, "eeprom", component)
modules.component.api.register(modules.uuidmgr.lookup("eeprom", "lmao"), "eeprom", component)
end
return eeprom

View File

@ -165,9 +165,9 @@ function fbgpu.start()
termutils.init()
write("\x1b[?25l") --Disable cursor
modules.component.api.register(nil, "gpu", gpu)
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
modules.component.api.register(modules.uuidmgr.lookup("gpu", "fbgpu"), "gpu", gpu)
screenAddr = modules.component.api.register(modules.uuidmgr.lookup("screen", "lmao"), "screen", {getKeyboards = function() return {modules.uuidmgr.lookup("keyboard", "lmao")} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register(modules.uuidmgr.lookup("keyboard", "lmao"), "keyboard", {})
deadhooks[#deadhooks + 1] = function()
write("\x1b[?25h") --Enable cursor on quit

View File

@ -156,7 +156,7 @@ function filesystem.register(basePath, uuid)
checkArg(1, value, "number")
return value --TODO: Implement, use real labels
end
return modules.component.api.register(uuid, "filesystem", fs)
return modules.component.api.register(modules.uuidmgr.lookup("filesystem", basePath), "filesystem", fs)
end
return filesystem

View File

@ -68,7 +68,7 @@ gpio.register = function ()
end
return _read("/sys/class/gpio/gpio" .. pin .. "/value")
end
return modules.component.api.register(uuid, "gpio", component)
return modules.component.api.register(modules.uuidmgr.lookup("gpio", "lmao"), "gpio", component)
end
return gpio

View File

@ -78,10 +78,14 @@ function main()
loadModule("debug")
end
loadModule("random")
loadModule("uuidmgr")
loadModule("color")
loadModule("buffer")
modules.address = modules.random.uuid() --TODO: PREALPHA: Make constant
--modules.address = modules.random.uuid() --TODO: PREALPHA: Make constant
modules.address = modules.uuidmgr.lookup("modules", "lmao") --Made constant
native.setkbid(modules.uuidmgr.lookup("keyboard", "lmao"))
--Core
loadModule("component")
@ -127,7 +131,7 @@ function main()
if native.debug then
modules.debug.hook()
end
modules.uuidmgr.store()
modules.boot.boot()
end

View File

@ -157,7 +157,7 @@ function internet.start()
}
end
modules.component.api.register(nil, "internet", component)
modules.component.api.register(modules.uuidmgr.lookup("internet", "lmao"), "internet", component)
end
return internet

View File

@ -24,7 +24,7 @@ function com.register()
return serial.read(dev, amt)
end
modules.component.api.register("Serial:"..ports[i], "serial", component)
modules.component.api.register(modules.uuidmgr.lookup("serial", ports[i]), "serial", component)
::continue::
end
end

View File

@ -255,9 +255,9 @@ function textgpu.start()
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0x000000)
local gpuaddr = modules.component.api.register(nil, "gpu", gpu)
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
local gpuaddr = modules.component.api.register(modules.uuidmgr.lookup("gpu", "text"), "gpu", gpu)
screenAddr = modules.component.api.register(modules.uuidmgr.lookup("screen", "lmao"), "screen", {getKeyboards = function() return {modules.uuidmgr.lookup("keyboard", "lmao")} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register(modules.uuidmgr.lookup("keyboard", "lmao"), "keyboard", {})
deadhooks[#deadhooks + 1] = function()
write("\x1b[?25h\x1b[" .. ((h-1)|0) .. ";1H") --Enable cursor on quit

63
src/lua/core/uuidmgr.lua Normal file
View File

@ -0,0 +1,63 @@
local uuidmgr = {}
local uuidstorage = {}
local storeheader = "c32BH"
do
local store = io.open("uuidstore.dat", "r")
if store then
pcall(function()
local count = string.unpack("H", store:read(2))
for i=1, count do
local uuid, clen, ilen = storeheader:unpack(store:read(storeheader:packsize()))
local cname, id = store:read(clen), store:read(ilen)
uuidstorage[cname] = uuidstorage[cname] or {}
uuidstorage[cname][id] = uuid
end
store:close()
end)
end
end
function uuidmgr.lookup(component, identifier)
uuidstorage[component] = uuidstorage[component] or {}
local uuid = uuidstorage[component][identifier]
if not uuid then
uuid = modules.random.uuid()
if native.debug then
lprint(string.format("DEBUG: Registed component of type %s with identifier %s as uuid %s", component, identifier, uuid))
end
uuidstorage[component][identifier] = uuid
uuidmgr.store()
else
if native.debug then
lprint(string.format("DEBUG: Looked up component of type %s with identifier %s as uuid %s", component, identifier, uuid))
end
end
return uuid
end
function uuidmgr.store()
local store = io.open("uuidstore.dat", "w")
local saved_ids = {}
for component, ids in pairs(uuidstorage) do
for id, uuid in pairs(ids) do
table.insert(saved_ids, {uuid=uuid, component=component, id=id})
end
end
if native.debug then
lprint(string.format("DEBUG: Saving %d static UUIDs", #saved_ids))
end
store:write(string.pack("H", #saved_ids))
for i=1, #saved_ids do
local uuid, component, id = saved_ids[i].uuid, saved_ids[i].component, saved_ids[i].id
store:write(storeheader:pack(uuid, #component, #id),component,id)
if native.debug then
lprint(string.format("DEBUG: Saving %s:%s as %s", component, id, uuid))
end
end
store:close()
end
return uuidmgr

View File

@ -158,9 +158,9 @@ function wingpu.start()
lprint("Couldn't open window: " .. tostring(reason))
end
modules.component.api.register(nil, "gpu", gpu)
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
modules.component.api.register(modules.uuidmgr.lookup("gpu", "wingpu"), "gpu", gpu)
screenAddr = modules.component.api.register(modules.uuidmgr.lookup("screen", "lmao"), "screen", {getKeyboards = function() return {modules.uuidmgr.lookup("keyboard", "lmao")} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register(modules.uuidmgr.lookup("keyboard", "lmao"), "keyboard", {})
return s
end