From 6390f8d7e7dfe8c0311cffc2e928e93abb92714b Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Wed, 1 Apr 2026 18:23:27 +0200 Subject: try to properly deal with constructors --- lib/CWayland/CWayland.cc | 74 +++++++++++++----------------------------------- lib/CWayland/CWayland.h | 23 +++++++-------- 2 files changed, 31 insertions(+), 66 deletions(-) (limited to 'lib/CWayland') diff --git a/lib/CWayland/CWayland.cc b/lib/CWayland/CWayland.cc index 7ff9332..abb9ee5 100644 --- a/lib/CWayland/CWayland.cc +++ b/lib/CWayland/CWayland.cc @@ -841,7 +841,7 @@ namespace { class argument_buffer { - enum class type { uninitialized, i32, u32, fixed, string, object, new_id, array, fd }; + enum class type { uninitialized, i32, u32, fixed, string, object, array, fd }; struct meta { type type{ type::uninitialized }; @@ -917,14 +917,6 @@ namespace meta[i].ref = std::move(value); } - void write_new_id(ref value) - { - auto i = next_write(); - args[i].o = static_cast(lean_get_external_data(value.get())); - meta[i].type = type::object; - meta[i].ref = std::move(value); - } - void write_array(ref value) { auto i = next_write(); @@ -974,7 +966,7 @@ namespace meta[i].ref = ref::steal(lean_box(0)); } } - else if (signature_type == "o" || signature_type == "?o") + else if (signature_type == "o" || signature_type == "?o" || signature_type == "n") { meta[i].type = type::object; if (arg.o) @@ -990,10 +982,6 @@ namespace meta[i].ref = ref::steal(lean_box(0)); } } - else if (signature_type == "n") - { - meta[i].type = type::new_id; - } else if (signature_type == "a") { meta[i].type = type::array; @@ -1041,12 +1029,6 @@ namespace return ref{ std::move(meta[i].ref) }; } - ref read_new_id() - { - auto i = next_read(type::new_id); - return ref::steal(lean_box_uint32(args[i].n)); - } - ref read_array() { auto i = next_read(type::array); @@ -1118,14 +1100,6 @@ lean_obj_res waylean_argument_buffer_write_object(b_lean_obj_arg buffer_obj, b_l return lean_io_result_mk_ok(lean_box(0)); } -// ArgumentBuffer.writeNewID : (buffer : @& ArgumentBuffer) → (value : @& Proxy) → IO Unit -lean_obj_res waylean_argument_buffer_write_new_id(b_lean_obj_arg buffer_obj, b_lean_obj_arg value) -{ - auto buffer = static_cast(lean_get_external_data(buffer_obj)); - buffer->write_new_id(ref{ value }); - return lean_io_result_mk_ok(lean_box(0)); -} - // ArgumentBuffer.writeArray : (buffer : @& ArgumentBuffer) → (value : @& ByteArray) → IO Unit lean_obj_res waylean_argument_buffer_write_array(b_lean_obj_arg buffer_obj, b_lean_obj_arg value) { @@ -1177,13 +1151,6 @@ lean_obj_res waylean_argument_buffer_read_object(b_lean_obj_arg buffer_obj) return lean_io_result_mk_ok(buffer->read_object().release()); } -// ArgumentBuffer.readNewID : (buffer : @& ArgumentBuffer) → IO UInt32 -lean_obj_res waylean_argument_buffer_read_new_id(b_lean_obj_arg buffer_obj) -{ - auto buffer = static_cast(lean_get_external_data(buffer_obj)); - return lean_io_result_mk_ok(buffer->read_new_id().release()); -} - // ArgumentBuffer.readArray : (buffer : @& ArgumentBuffer) → IO ByteArray lean_obj_res waylean_argument_buffer_read_array(b_lean_obj_arg buffer_obj) { @@ -1204,7 +1171,6 @@ namespace { int dispatcher_func(const void* user_data, void* target, uint32_t opcode, const wl_message* msg, wl_argument* args) { - fprintf(stderr, "Dispatcher func!\n"); if (!user_data) { return 0; } auto handler = ref{ (lean_object*)user_data }; @@ -1269,24 +1235,6 @@ lean_obj_res waylean_proxy_from_display(lean_obj_arg display) return lean_io_result_mk_ok(display); } -// Proxy.new : (factory : @& Proxy) → (typeMap : @& TypeMap) → (ifaceName : @& String) → IO Proxy -lean_obj_res waylean_proxy_new(b_lean_obj_arg factory_obj, b_lean_obj_arg map_obj, b_lean_obj_arg iface_name) -{ - auto factory = static_cast(lean_get_external_data(factory_obj)); - auto map = static_cast(lean_get_external_data(map_obj)); - auto iface = map->resolve_iface(lean_string_cstr(iface_name)); - - assert(iface->initialized && "expected interface to be initialized during construction"); - wl_proxy* res = wl_proxy_create(factory, &iface->desc); - lean_object* waylean_res = lean_alloc_external(waylean_proxy_class(), res); - if (!res) { return io_result_mk_from_errno(""); } - - int stat = wl_proxy_add_dispatcher(res, dispatcher_func, waylean_res, nullptr); - fprintf(stderr, "add_dispatcher: %d\n", stat); - - return lean_io_result_mk_ok(waylean_res); -} - // Proxy.send : (proxy : @& Proxy) → (opcode : UInt32) → (argumentBuffer : @& ArgumentBuffer) → IO Unit lean_obj_res waylean_proxy_send(b_lean_obj_arg proxy_obj, uint32_t opcode, b_lean_obj_arg buffer_obj) { @@ -1298,6 +1246,24 @@ lean_obj_res waylean_proxy_send(b_lean_obj_arg proxy_obj, uint32_t opcode, b_lea return lean_io_result_mk_ok(lean_box(0)); } +// Proxy.sendConstructor : (proxy : @& Proxy) → (opcode : UInt32) → (argumentBuffer : @& ArgumentBuffer) → (typeMap : @& TypeMap) → (ifaceName : @& String) → IO Proxy +lean_obj_res waylean_proxy_send_constructor(b_lean_obj_arg proxy_obj, uint32_t opcode, b_lean_obj_arg buffer_obj, b_lean_obj_arg map_obj, b_lean_obj_arg iface_name) +{ + auto proxy = static_cast(lean_get_external_data(proxy_obj)); + auto buffer = static_cast(lean_get_external_data(buffer_obj)); + auto map = static_cast(lean_get_external_data(map_obj)); + auto iface = map->resolve_iface(lean_string_cstr(iface_name)); + assert(iface->initialized && "expected interface to be initialized during construction"); + + wl_proxy* res = wl_proxy_marshal_array_constructor(proxy, opcode, buffer->get_args(), &iface->desc); + if (!res) { return io_result_mk_from_errno(""); } + + lean_object* waylean_res = lean_alloc_external(waylean_proxy_class(), res); + int stat = wl_proxy_add_dispatcher(res, dispatcher_func, waylean_res, nullptr); + + return lean_io_result_mk_ok(waylean_res); +} + // Proxy.listen : (proxy : @& Proxy) → (handler : UInt32 → ArgumentBuffer → EventLoop M × M) → IO Unit lean_obj_res waylean_proxy_listen(b_lean_obj_arg proxy_obj, lean_obj_arg handler) { diff --git a/lib/CWayland/CWayland.h b/lib/CWayland/CWayland.h index eecc1eb..2db206e 100644 --- a/lib/CWayland/CWayland.h +++ b/lib/CWayland/CWayland.h @@ -54,8 +54,6 @@ lean_obj_res waylean_argument_buffer_write_string(b_lean_obj_arg writer, b_lean_obj_arg value); lean_obj_res waylean_argument_buffer_write_object(b_lean_obj_arg writer, b_lean_obj_arg value); -lean_obj_res waylean_argument_buffer_write_new_id(b_lean_obj_arg writer, - b_lean_obj_arg value); lean_obj_res waylean_argument_buffer_write_array (b_lean_obj_arg writer, b_lean_obj_arg value); lean_obj_res waylean_argument_buffer_write_fd (b_lean_obj_arg writer, @@ -65,21 +63,22 @@ lean_obj_res waylean_argument_buffer_read_uint (b_lean_obj_arg reader); lean_obj_res waylean_argument_buffer_read_fixed (b_lean_obj_arg reader); lean_obj_res waylean_argument_buffer_read_string (b_lean_obj_arg reader); lean_obj_res waylean_argument_buffer_read_object (b_lean_obj_arg reader); -lean_obj_res waylean_argument_buffer_read_new_id (b_lean_obj_arg reader); lean_obj_res waylean_argument_buffer_read_array (b_lean_obj_arg reader); lean_obj_res waylean_argument_buffer_read_fd (b_lean_obj_arg reader); // -- Proxy -lean_obj_res waylean_proxy_from_display(lean_obj_arg display); -lean_obj_res waylean_proxy_new (b_lean_obj_arg factory, - b_lean_obj_arg type_map, - b_lean_obj_arg iface_name); -lean_obj_res waylean_proxy_send (b_lean_obj_arg proxy, - uint32_t opcode, - b_lean_obj_arg argument_buffer); -lean_obj_res waylean_proxy_listen (b_lean_obj_arg proxy, - lean_obj_arg handler); +lean_obj_res waylean_proxy_from_display (lean_obj_arg display); +lean_obj_res waylean_proxy_send (b_lean_obj_arg proxy, + uint32_t opcode, + b_lean_obj_arg argument_buffer); +lean_obj_res waylean_proxy_send_constructor(b_lean_obj_arg proxy, + uint32_t opcode, + b_lean_obj_arg argument_buffer, + b_lean_obj_arg type_map, + b_lean_obj_arg iface_name); +lean_obj_res waylean_proxy_listen (b_lean_obj_arg proxy, + lean_obj_arg handler); #ifdef __cplusplus } -- cgit v1.3.1