1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/sysdata/libraries/sunset_proto/src/lib.hb

108 lines
2.3 KiB
Plaintext
Raw Normal View History

.{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb");
2024-11-10 12:57:48 -06:00
.{Surface} := @use("../../render/src/lib.hb")
2024-11-13 11:03:31 -06:00
$BUFFER_SERVER := "sunset_server\0"
$BUFFER_CLIENT := "sunset_client\0"
Channel := packed struct {
client: uint,
server: uint,
}
2024-11-10 12:57:48 -06:00
client := @use("./client.hb")
server := @use("./server.hb")
message := @use("./message.hb")
2024-11-13 11:03:31 -06:00
permissions := @use("./permissions.hb")
opaque := fn(i: uint): bool {
if i == 0 {
return true
}
return false
}
sleep := fn(): void {
i := 10000000
loop if opaque(i) break else i -= 1
}
$send_message := fn($Expr: type, kind: uint, msg: Expr, buffer_id: uint): void {
buffer.write(?Message(Expr), buffer_id, &@as(?Message(Expr), .(.(kind), msg)))
}
$send_header := fn(kind: uint, buffer_id: uint): void {
buffer.write(?MessageHeader, buffer_id, &@as(?MessageHeader, .(kind)))
}
2024-11-10 12:57:48 -06:00
2024-11-13 11:03:31 -06:00
$recv_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
response := @as(?Message(Expr), null)
buffer.recv(?Message(Expr), buffer_id, &response)
return response
}
2024-11-13 11:03:31 -06:00
$recv_header := fn(buffer_id: uint): ?MessageHeader {
response := @as(?MessageHeader, null)
buffer.recv(?MessageHeader, buffer_id, &response)
return response
}
2024-11-13 11:03:31 -06:00
await_channel := fn(): Channel {
server_id := 0
loop if server_id == 0 {
server_id = buffer.search(BUFFER_SERVER)
}
client_id := 0
loop if client_id == 0 {
client_id = buffer.search(BUFFER_CLIENT)
}
return .{client: client_id, server: server_id}
}
2024-11-13 11:03:31 -06:00
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
response := @as(?Message(Expr), null)
loop {
2024-11-13 11:03:31 -06:00
buffer.recv(?Message(Expr), buffer_id, &response)
if response != null {
2024-11-13 11:03:31 -06:00
return @as(Message(Expr), response)
}
}
}
await_header := fn(buffer_id: uint): MessageHeader {
response := @as(?MessageHeader, null)
loop {
buffer.recv(?MessageHeader, buffer_id, &response)
if response != null {
return @as(?MessageHeader, response)
}
}
}
2024-11-10 19:03:01 -06:00
MessageHeader := packed struct {
kind: uint,
2024-11-13 11:03:31 -06:00
}
Message := fn($Expr: type): type {
return packed struct {
header: MessageHeader,
body: Expr,
}
2024-11-10 12:57:48 -06:00
}
WindowProps := struct {
position: Vec2(uint),
dimensions: Vec2(uint),
// ! replace with owned string type later
2024-11-10 12:57:48 -06:00
title: ^u8,
}
2024-11-10 19:03:01 -06:00
WindowData := struct {
2024-11-10 12:57:48 -06:00
props: WindowProps,
2024-11-13 11:03:31 -06:00
channel: Channel,
permissions: uint,
2024-11-10 12:57:48 -06:00
}
Window := struct {
2024-11-10 19:03:01 -06:00
data: WindowData,
2024-11-10 12:57:48 -06:00
surface: Surface,
}