forked from AbleOS/ableos
60 lines
2 KiB
Plaintext
60 lines
2 KiB
Plaintext
.{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb");
|
|
.{Color, Surface, new_surface, put_surface, sync} := @use("../../render/src/lib.hb");
|
|
.{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("./lib.hb")
|
|
|
|
WindowServer := struct {
|
|
window_count: uint,
|
|
channel: Channel,
|
|
// ! replace this with an actual collection when we get an allocator
|
|
windows: [?WindowData; 10],
|
|
}
|
|
|
|
// ! in the future this should be safely handled
|
|
server := @as(WindowServer, idk)
|
|
|
|
start := fn(): void {
|
|
server = .(0, .{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)}, .(null, null, null, null, null, null, null, null, null, null))
|
|
log.info("server: started server\0")
|
|
}
|
|
|
|
incoming := fn(): bool {
|
|
msg := recv_header(server.channel.server)
|
|
if msg == null {
|
|
return true
|
|
}
|
|
if msg.kind == message.syn {
|
|
log.info("server: recv syn\0")
|
|
channel := Channel.(buffer.create_nameless(), buffer.create_nameless())
|
|
send_message(Channel, message.ack, channel, channel.client)
|
|
props := await_message(WindowProps, channel.server)
|
|
if props.header.kind != message.props {
|
|
return true
|
|
}
|
|
log.info("server: recv props\0")
|
|
// ! do inspection of requested props here
|
|
send_message(WindowData, message.ack, .(props.body, channel, permissions.default), channel.client)
|
|
}
|
|
return true
|
|
}
|
|
|
|
render_clients := fn(screen: Surface): void {
|
|
i := 0
|
|
loop if i == 10 break else {
|
|
window := server.windows[i]
|
|
if window == null {
|
|
continue
|
|
}
|
|
header := recv_header(window.channel.server)
|
|
if header == null | @unwrap(header).kind != message.frame_ready {
|
|
continue
|
|
}
|
|
send_header(message.ack, window.channel.client)
|
|
ptr := await_message(^Color, window.channel.server)
|
|
if ptr.header.kind != message.ack {
|
|
continue
|
|
}
|
|
put_surface(screen, .(ptr.body, window.props.dimensions.x, window.props.dimensions.y, window.props.dimensions.x * window.props.dimensions.y), window.props.position, false)
|
|
i += 1
|
|
}
|
|
sync(screen)
|
|
} |